diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,18 +7,20 @@ find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) -find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Qml Quick QuickWidgets Svg Test OpenGL) +find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Qml Quick QuickWidgets PrintSupport Svg Test OpenGL) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS + Archive Config ConfigWidgets CoreAddons Crash DBusAddons + DocTools GuiAddons I18n ItemModels - KDELibs4Support KIO + JobWidgets NewStuff NotifyConfig TextWidgets diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -36,11 +36,14 @@ target_link_libraries(ksudoku_gui ksudoku_logic KF5KDEGames - KF5::Archive - KF5::KDELibs4Support + KF5::Archive + KF5::GuiAddons KF5::KIOCore + KF5::KIOWidgets + KF5::XmlGui Qt5::Core Qt5::Gui + Qt5::PrintSupport Qt5::Svg ) diff --git a/src/gui/ksudoku.cpp b/src/gui/ksudoku.cpp --- a/src/gui/ksudoku.cpp +++ b/src/gui/ksudoku.cpp @@ -2,8 +2,7 @@ * Copyright 2005-2007 Francesco Rossi * * Copyright 2006-2007 Mick Kappenburg * * Copyright 2006-2008 Johannes Bergmeier * - * Copyright 2012 Ian Wadham * - * Copyright 2015 Ian Wadham * + * Copyright 2012-2015 Ian Wadham * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -25,35 +24,39 @@ #include "globals.h" #include "ksudoku.h" +#include +#include +#include #include #include #include - -#include -#include -#include - +#include +#include #include - +#include +#include +#include #include #include #include +#include +#include +#include -#include #include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API #include -#include -#include -#include -#include -#include -#include -#include #include "ksview.h" #include "gameactions.h" @@ -65,14 +68,6 @@ #include "puzzleprinter.h" -#include -#include -#include -#include -#include -#include -#include - #include "gamevariants.h" #include "welcomescreen.h" #include "valuelistwidget.h" @@ -871,17 +866,26 @@ return; // user cancelled } - QString tmpFile; - if(!KIO::NetAccess::download( Url, tmpFile, this )) + QTemporaryFile tmpFile; + if ( !tmpFile.open() ) + { + return; + } + KIO::FileCopyJob *downloadJob = KIO::file_copy(Url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite); + KJobWidgets::setWindow(downloadJob , this); + downloadJob->exec(); + + if( downloadJob->error() ) { - //TODO ERROR + KMessageBox::error(this, i18n("Unable to download file."), i18n("Error Reading File")); return; } const QString destDir = QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) + QStringLiteral("/ksudoku/"); - QDir().mkpath( destDir ); + QDir dest(destDir); + dest.mkpath( destDir ); - KTar archive( tmpFile ); + KTar archive( tmpFile.fileName() ); if ( archive.open( QIODevice::ReadOnly ) ) { @@ -892,10 +896,9 @@ else { //just copy - KIO::file_copy (Url, QUrl::fromLocalFile(destDir + '/' + Url.fileName())); + KIO::file_copy( Url, QUrl::fromLocalFile(dest.filePath(Url.fileName()))); } - KIO::NetAccess::removeTempFile(tmpFile); updateShapesList(); } diff --git a/src/gui/serializer.cpp b/src/gui/serializer.cpp --- a/src/gui/serializer.cpp +++ b/src/gui/serializer.cpp @@ -24,16 +24,17 @@ #include "ksudokugame.h" #include "puzzle.h" -#include -//Added by qt3to4: +#include +#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include #include "ksudoku.h" #include "symbols.h" @@ -399,28 +400,36 @@ } SKGraph *Serializer::loadCustomShape(const QUrl &url, QWidget* window, QString *errorMsg) { - if ( url.isEmpty() ) return 0; - QString tmpFile; + if ( url.isEmpty() ) return nullptr; bool success = false; QDomDocument doc; - if(KIO::NetAccess::download(url, tmpFile, window) ) { - QFile file(tmpFile); - if(file.open(QIODevice::ReadOnly)) { - int errorLine; - if(!doc.setContent(&file, 0, &errorLine)) { - if(errorMsg) - *errorMsg = i18n("Cannot read XML file on line %1", errorLine); - - return 0; - } - success = true; - } - KIO::NetAccess::removeTempFile(tmpFile); + + QTemporaryFile tmpFile; + if ( !tmpFile.open() ) { + return nullptr; + } + KIO::FileCopyJob *downloadJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite); + KJobWidgets::setWindow(downloadJob, window); + downloadJob->exec(); + + if( downloadJob->error() ) { + KMessageBox::error(window, i18n("Unable to download file."), i18n("Error Reading File")); + return nullptr; } + + int errorLine; + if(!doc.setContent(&tmpFile, 0, &errorLine)) { + if(errorMsg) + *errorMsg = i18n("Cannot read XML file on line %1", errorLine); + + return nullptr; + } + success = true; + if ( !success ) { if(errorMsg) *errorMsg = i18n("Cannot load file."); - return 0; + return nullptr; } QDomNode child = doc.documentElement().firstChild(); @@ -433,27 +442,35 @@ child = child.nextSibling(); } - return 0; + return nullptr; } Game Serializer::load(const QUrl& url, QWidget* window, QString *errorMsg) { if ( url.isEmpty() ) return Game(); - QString tmpFile; bool success = false; QDomDocument doc; - if(KIO::NetAccess::download(url, tmpFile, window) ) { - QFile file(tmpFile); - if(file.open(QIODevice::ReadOnly)) { - int errorLine; - if(!doc.setContent(&file, 0, &errorLine)) { - if(errorMsg) - *errorMsg = i18n("Cannot read XML file on line %1", errorLine); - return Game(); - } - success = true; - } - KIO::NetAccess::removeTempFile(tmpFile); + + QTemporaryFile tmpFile; + if ( !tmpFile.open() ) { + return Game(); + } + KIO::FileCopyJob *downloadJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite); + KJobWidgets::setWindow(downloadJob, window); + downloadJob->exec(); + + if( downloadJob->error() ) { + KMessageBox::error(window, i18n("Unable to download file."), i18n("Error Reading File")); + return Game(); } + + int errorLine; + if(!doc.setContent(&tmpFile, 0, &errorLine)) { + if(errorMsg) + *errorMsg = i18n("Cannot read XML file on line %1", errorLine); + return Game(); + } + success = true; + if ( !success ) { if(errorMsg) *errorMsg = i18n("Cannot load file."); @@ -696,7 +713,14 @@ stream << doc.toString(); stream.flush(); - KIO::NetAccess::upload(file.fileName(), url, window); + KIO::FileCopyJob *copyJob = KIO::file_copy(QUrl::fromLocalFile(file.fileName()), url); + KJobWidgets::setWindow(copyJob , window); + copyJob->exec(); + if(copyJob->error()) + { + KMessageBox::error(window, i18n("Unable to upload file."), i18n("Error Writing File")); + return false; + } return true; } diff --git a/src/gui/symbols.cpp b/src/gui/symbols.cpp --- a/src/gui/symbols.cpp +++ b/src/gui/symbols.cpp @@ -26,7 +26,7 @@ namespace ksudoku { -/// returns the symbol vor a value used for loading and saving +/// returns the symbol for a value used for loading and saving QChar Symbols::ioValue2Symbol(int value) { if (value == VACANT) return '_'; if (value == UNUSABLE) return '.'; @@ -35,7 +35,7 @@ /// returns the number of the index int Symbols::ioSymbol2Value(const QChar& symbol) { - char c = symbol.toAscii(); + char c = symbol.toLatin1(); if(symbol == '_') return VACANT; if(symbol == '.') return UNUSABLE; return c - 'a'; diff --git a/src/gui/views/view2d.cpp b/src/gui/views/view2d.cpp --- a/src/gui/views/view2d.cpp +++ b/src/gui/views/view2d.cpp @@ -71,7 +71,7 @@ }; CellGraphicsItem::CellGraphicsItem(QPoint pos, int id, View2DScene* scene) { - setAcceptsHoverEvents(true); + setAcceptHoverEvents(true); setShapeMode(QGraphicsPixmapItem::BoundingRectShape); m_pos = pos; m_size = 0;