Commit 45e1f086 authored by Johan Ouwerkerk's avatar Johan Ouwerkerk

Port usage of KUrl and friends to equivalent constructs with QUrl.

Summary:
KUrl is part of the deprecated kdelibs4support API.
Porting away from it removes one obstacle towards legacy free sudoku for KDE.

Test Plan:
Using XDG_DATA_DIRS to point to locally built copy of ksudoku game assets, I tested the following:

  # Generate a Killer type (i.e. a custom Sudoku variant) puzzle using defaults for difficulty/symmetry
  # Reconfigured toolbars to add the Home Page action & invoke the Home Page action
  # Save the puzzle/game file & Quit the application
  # Reload the application and load the previously saved puzzle.

Reviewers: #kde_games, ltoscano, stikonas

Reviewed By: ltoscano, stikonas

Subscribers: stikonas, ltoscano, #kde_games

Differential Revision: https://phabricator.kde.org/D5544
parent 5bdb63cd
......@@ -2,7 +2,7 @@ project(ksudoku)
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
set (QT_MIN_VERSION "5.3.0")
set (KF5_MIN_VERSION "5.15.0")
set (KF5_MIN_VERSION "5.31.0")
find_package(ECM 1.7.0 REQUIRED CONFIG)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
......
......@@ -363,7 +363,7 @@ KsView* RoxdokuGame::createView(const Game& /*game*/) const {
// class CustomGame
///////////////////////////////////////////////////////////////////////////////
CustomGame::CustomGame(const QString& name, const KUrl& url,
CustomGame::CustomGame(const QString& name, const QUrl& url,
GameVariantCollection* collection)
: GameVariant(name, collection), m_url(url), m_graph(0)
{
......
......@@ -23,7 +23,7 @@
#include <QObject>
#include <QList>
#include <KUrl>
#include <QUrl>
#include <QItemDelegate>
#include <QAbstractListModel>
......@@ -167,7 +167,7 @@ private:
class CustomGame : public GameVariant {
public:
CustomGame(const QString& name, const KUrl& url, GameVariantCollection* collection=0);
CustomGame(const QString& name, const QUrl& url, GameVariantCollection* collection=0);
public:
bool canConfigure() const;
......@@ -181,7 +181,7 @@ private:
uint m_order;
uint m_symmetry;
KUrl m_url;
QUrl m_url;
SKGraph* m_graph;
bool createSKGraphObject();
};
......
......@@ -31,6 +31,8 @@
#include <QLabel>
#include <QComboBox>
#include <QMimeData>
#include <QPrinter>
#include <QPrintDialog>
#include <QStandardPaths>
......@@ -44,7 +46,7 @@
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgamethemeselector.h>
#include <QKeySequence>
#include <KUrl>
#include <QUrl>
#include <kmessagebox.h>
#include <KLocalizedString>
#include <qstatusbar.h>
......@@ -67,6 +69,7 @@
#include <QDir>
#include <KSharedConfig>
#include <QFileDialog>
#include <QFileInfo>
#include "gamevariants.h"
#include "welcomescreen.h"
......@@ -204,18 +207,20 @@ void KSudoku::updateShapesList()
QString variantIcon;
foreach(const QString &filepath, filepaths) {
const QFileInfo configFileInfo(filepath);
const QDir variantDir = configFileInfo.dir();
KConfig variantConfig(filepath, KConfig::SimpleConfig);
KConfigGroup group = variantConfig.group ("KSudokuVariant");
variantName = group.readEntry("Name", i18n("Missing Variant Name")); // Translated.
variantDescr = group.readEntry("Description", ""); // Translated.
variantIcon = group.readEntry("Icon", "ksudoku-ksudoku_9x9");
variantDataPath = group.readEntry("FileName", "");
if(variantDataPath == "") continue;
const QString variantDataFile = group.readEntry("FileName", "");
if(variantDataFile == "") continue;
variantDataPath = filepath.left(filepath.lastIndexOf("/")+1) + variantDataPath;
variantDataPath = variantDir.filePath(variantDataFile);
variant = new CustomGame(variantName, variantDataPath, m_gameVariants);
variant = new CustomGame(variantName, QUrl::fromLocalFile(variantDataPath), m_gameVariants);
variant->setDescription(variantDescr);
variant->setIcon(variantIcon);
}
......@@ -364,7 +369,7 @@ void KSudoku::endCurrentGame() {
}
void KSudoku::loadGame(const KUrl& Url) {
void KSudoku::loadGame(const QUrl& Url) {
QString errorMsg;
Game game = ksudoku::Serializer::load(Url, this, &errorMsg);
if(!game.isValid()) {
......@@ -383,7 +388,7 @@ void KSudoku::showWelcomeScreen() {
void KSudoku::homepage()
{
KRun::runUrl (KUrl("http://ksudoku.sourceforge.net/"), "text/html", this);
KRun::runUrl (QUrl("http://ksudoku.sourceforge.net/"), "text/html", this, KRun::RunFlags());
}
void KSudoku::giveHint()
......@@ -622,35 +627,30 @@ void KSudoku::pop()
// if(glwin) glwin->pop();
}
void KSudoku::dragEnterEvent(QDragEnterEvent */*event*/)
void KSudoku::dragEnterEvent(QDragEnterEvent * event)
{
// accept uri drops only
//TODO PORT
//KUrl::List::fromMimeData( e->mimeData() )
//event->accept(KUrlDrag::canDecode(event));
if(event->mimeData()->hasUrls())
event->accept();
}
void KSudoku::dropEvent(QDropEvent *event)
{
//TODO PORT
KUrl::List Urls = KUrl::List::fromMimeData( event->mimeData() );
if ( !Urls.isEmpty() )
const QMimeData * data = event->mimeData();
if(data->hasUrls())
{
// okay, we have a URI.. process it
const KUrl &Url = Urls.first();
QList<QUrl> Urls = data->urls();
Game game = ksudoku::Serializer::load(Url, this);
// if(game)
// (new KSudoku(game))->show();
if(game.isValid())
startGame(game);
// delete game;
}
if ( !Urls.isEmpty() )
{
// okay, we have a URI.. process it
const QUrl &Url = Urls.first();
Game game = ksudoku::Serializer::load(Url, this);
if(game.isValid())
startGame(game);
}
}
}
void KSudoku::gameNew()
......@@ -680,7 +680,7 @@ void KSudoku::gameOpen()
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
// standard filedialog
KUrl Url = QFileDialog::getOpenFileUrl(this, i18n("Open Location"), QUrl::fromLocalFile(QDir::homePath()), QString());
const QUrl Url = QFileDialog::getOpenFileUrl(this, i18n("Open Location"), QUrl::fromLocalFile(QDir::homePath()), QString());
if (!Url.isEmpty() && Url.isValid())
{
......
......@@ -24,6 +24,8 @@
#ifndef _KSUDOKU_H_
#define _KSUDOKU_H_
#include <QUrl>
#include <kxmlguiwindow.h>
#if 0
#include <knewstuff/knewstuff.h>
......@@ -31,8 +33,8 @@
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgamedifficulty.h>
class QPrinter;
class KUrl;
namespace ksudoku {
class KsView;
......@@ -85,7 +87,7 @@ public:
*/
virtual ~KSudoku();
void loadGame(const KUrl& url);
void loadGame(const QUrl& url);
public:
void updateShapesList();
......
......@@ -35,7 +35,7 @@
#include <QDebug> // IDW
#include <kurl.h>
#include <QUrl>
class QWidget;
......@@ -81,7 +81,7 @@ public:
Puzzle* puzzle;
QTime time;
int accumTime;
KUrl url;
QUrl url;
QList<HistoryEvent> history;
int historyPos;
......@@ -218,14 +218,14 @@ Puzzle* Game::puzzle() const {
return m_private->puzzle;
}
void Game::setUrl(const KUrl& url) {
void Game::setUrl(const QUrl& url) {
if(!m_private) return;
m_private->url = url;
}
KUrl Game::getUrl() const {
if(!m_private) return KUrl();
QUrl Game::getUrl() const {
if(!m_private) return QUrl();
return m_private->url;
}
......
......@@ -24,11 +24,9 @@
#define _KSUDOKUGAME_H_
#include <qobject.h>
#include <QUrl>
#include "history.h"
class KUrl;
class SKGraph;
class QWidget;
......@@ -201,12 +199,12 @@ public:
/**
* Sets the URL. Game itself doesn't use the URL, but remembers it for other users.
*/
void setUrl(const KUrl& url);
void setUrl(const QUrl& url);
/**
* Gets the URL. Game itself doesn't use the URL, but remembers it for other users.
*/
KUrl getUrl() const;
QUrl getUrl() const;
/**
* Returns whether the user requested some hint.
......
......@@ -28,7 +28,7 @@
//Added by qt3to4:
#include <QList>
#include <QTextStream>
#include <kurl.h>
#include <QUrl>
#include <QTemporaryFile>
#include <kio/netaccess.h>
#include <qfile.h>
......@@ -398,7 +398,7 @@ HistoryEvent Serializer::deserializeComplexHistoryEvent(QDomElement /*element*/)
return HistoryEvent();
}
SKGraph *Serializer::loadCustomShape(const KUrl &url, QWidget* window, QString *errorMsg) {
SKGraph *Serializer::loadCustomShape(const QUrl &url, QWidget* window, QString *errorMsg) {
if ( url.isEmpty() ) return 0;
QString tmpFile;
bool success = false;
......@@ -436,7 +436,7 @@ SKGraph *Serializer::loadCustomShape(const KUrl &url, QWidget* window, QString *
return 0;
}
Game Serializer::load(const KUrl& 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;
......@@ -682,7 +682,7 @@ bool Serializer::serializeHistoryEvent(QDomElement& parent, const HistoryEvent&
return true;
}
bool Serializer::store(const Game& game, const KUrl& url, QWidget* window) {
bool Serializer::store(const Game& game, const QUrl& url, QWidget* window) {
QDomDocument doc( "ksudoku" );
QDomElement root = doc.createElement( "ksudoku" );
doc.appendChild( root );
......
......@@ -24,12 +24,12 @@
#define _KSUDOKUSERIALIZER_H_
#include <QList>
#include <QString>
#include <QUrl>
class SKGraph;
class QDomElement;
class KUrl;
class QWidget;
class QString;
namespace ksudoku {
......@@ -39,11 +39,11 @@ class HistoryEvent;
class Serializer {
public:
static SKGraph* loadCustomShape
(const KUrl& url, QWidget* window, QString* errorMsg = 0);
(const QUrl& url, QWidget* window, QString* errorMsg = 0);
static bool store
(const Game& game, const KUrl& url, QWidget* window);
(const Game& game, const QUrl& url, QWidget* window);
static Game load
(const KUrl& url, QWidget* window, QString* errorMsg = 0);
(const QUrl& url, QWidget* window, QString* errorMsg = 0);
private:
// TODO - IDW. Maybe there should be shared methods for file handling.
......
......@@ -28,7 +28,7 @@
#include <KLocalizedString>
#include <kconfigdialogmanager.h>
#include <KUrl>
#include <QUrl>
#include <QApplication>
#include <QCommandLineParser>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment