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/gamevariants.cpp b/src/gui/gamevariants.cpp --- a/src/gui/gamevariants.cpp +++ b/src/gui/gamevariants.cpp @@ -416,7 +416,8 @@ m_graph = 0; // Killer Sudoku game (re-inits cages and size). } if (m_graph == 0) { - m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, 0); + QString errorMsg; + m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, errorMsg); } return (m_graph != 0); // True if the shapes/*.xml file loaded OK. } diff --git a/src/gui/ksudoku.h b/src/gui/ksudoku.h --- a/src/gui/ksudoku.h +++ b/src/gui/ksudoku.h @@ -91,7 +91,6 @@ public: void updateShapesList(); - void loadCustomShapeFromPath(); void createCustomShape(); ksudoku::Game currentGame() const; 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" @@ -373,7 +368,7 @@ void KSudoku::loadGame(const QUrl& Url) { QString errorMsg; - Game game = ksudoku::Serializer::load(Url, this, &errorMsg); + const Game game = ksudoku::Serializer::load(Url, this, errorMsg); if(!game.isValid()) { KMessageBox::information(this, errorMsg); return; @@ -648,9 +643,12 @@ // okay, we have a URI.. process it const QUrl &Url = Urls.first(); - Game game = ksudoku::Serializer::load(Url, this); + QString errorMsg; + const Game game = ksudoku::Serializer::load(Url, this, errorMsg); if(game.isValid()) startGame(game); + else + KMessageBox::error(this, i18n("Could not load game: %1.", errorMsg)); } } } @@ -686,9 +684,10 @@ if (!Url.isEmpty() && Url.isValid()) { - Game game = ksudoku::Serializer::load(Url, this); + QString errorMsg; + Game game = ksudoku::Serializer::load(Url, this, errorMsg); if(!game.isValid()) { - KMessageBox::error(this, i18n("Could not load game.")); + KMessageBox::error(this, i18n("Could not load game: %1.", errorMsg)); return; } @@ -862,43 +861,6 @@ return m_gameUI; } -void KSudoku::loadCustomShapeFromPath() -{ - QUrl Url = QFileDialog::getOpenFileUrl(this, i18n("Open Location"), QUrl(), QString()); - - if ( Url.isEmpty() || !Url.isValid() ) - { - return; // user cancelled - } - - QString tmpFile; - if(!KIO::NetAccess::download( Url, tmpFile, this )) - { - //TODO ERROR - return; - } - - const QString destDir = QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) + QStringLiteral("/ksudoku/"); - QDir().mkpath( destDir ); - - KTar archive( tmpFile ); - - if ( archive.open( QIODevice::ReadOnly ) ) - { - const KArchiveDirectory *archiveDir = archive.directory(); - archiveDir->copyTo( destDir ); - archive.close(); - } - else - { - //just copy - KIO::file_copy (Url, QUrl::fromLocalFile(destDir + '/' + Url.fileName())); - } - - KIO::NetAccess::removeTempFile(tmpFile); - updateShapesList(); -} - void KSudoku::enableMessages() { // Enable all messages that the user has marked "Do not show again". diff --git a/src/gui/serializer.h b/src/gui/serializer.h --- a/src/gui/serializer.h +++ b/src/gui/serializer.h @@ -39,11 +39,11 @@ class Serializer { public: static SKGraph* loadCustomShape - (const QUrl& url, QWidget* window, QString* errorMsg = 0); + (const QUrl& url, QWidget* window, QString& errorMsg); static bool store (const Game& game, const QUrl& url, QWidget* window); static Game load - (const QUrl& url, QWidget* window, QString* errorMsg = 0); + (const QUrl& url, QWidget* window, QString& errorMsg); private: // TODO - IDW. Maybe there should be shared methods for file handling. 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" @@ -398,29 +399,32 @@ return HistoryEvent(); } -SKGraph *Serializer::loadCustomShape(const QUrl &url, QWidget* window, QString *errorMsg) { - if ( url.isEmpty() ) return 0; - QString tmpFile; - bool success = false; +SKGraph *Serializer::loadCustomShape(const QUrl& url, QWidget* window, QString& errorMsg) { + if ( url.isEmpty() ) { + errorMsg = i18n("Unable to download file: URL is empty."); + return nullptr; + } 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() ) { + errorMsg = i18n("Unable to create temporary file."); + return nullptr; } - if ( !success ) { - if(errorMsg) - *errorMsg = i18n("Cannot load file."); - return 0; + KIO::FileCopyJob *downloadJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite); + KJobWidgets::setWindow(downloadJob, window); + downloadJob->exec(); + + if( downloadJob->error() ) { + errorMsg = i18n("Unable to download file."); + return nullptr; + } + + int errorLine; + if(!doc.setContent(&tmpFile, 0, &errorLine)) { + errorMsg = i18n("Cannot read XML file on line %1", errorLine); + + return nullptr; } QDomNode child = doc.documentElement().firstChild(); @@ -433,30 +437,30 @@ child = child.nextSibling(); } - return 0; + return nullptr; } -Game Serializer::load(const QUrl& url, QWidget* window, QString *errorMsg) { +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() ) { + errorMsg = i18n("Unable to create temporary file."); + return Game(); } - if ( !success ) { - if(errorMsg) - *errorMsg = i18n("Cannot load file."); + KIO::FileCopyJob *downloadJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite); + KJobWidgets::setWindow(downloadJob, window); + downloadJob->exec(); + + if( downloadJob->error() ) { + errorMsg = i18n("Unable to download file."); + return Game(); + } + + int errorLine; + if(!doc.setContent(&tmpFile, 0, &errorLine)) { + errorMsg = i18n("Cannot read XML file on line %1", errorLine); return Game(); } @@ -690,13 +694,23 @@ serializeGame(root, game); QTemporaryFile file; - file.open(); + if ( !file.open() ) { + KMessageBox::error(window, i18n("Unable to create temporary file."), i18n("Error Opening File")); + return false; + } QTextStream stream(&file); 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;