Commit 753365bb authored by Luigi Toscano's avatar Luigi Toscano

Port away from KStandardDirs, KCmdLine*, K4AboutData

... and from KApplication and KGlobal as a side effect.
parent bc6e9fed
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <QPrinter> #include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
#include <QStandardPaths>
#include <KLocalizedString> #include <KLocalizedString>
#include <KActionCollection> #include <KActionCollection>
...@@ -44,9 +45,6 @@ ...@@ -44,9 +45,6 @@
#include <libkdegamesprivate/kgamethemeselector.h> #include <libkdegamesprivate/kgamethemeselector.h>
#include <KShortcut> #include <KShortcut>
#include <KUrl> #include <KUrl>
#include <KCmdLineArgs>
#include <K4AboutData>
#include <KGlobal>
#include <kmessagebox.h> #include <kmessagebox.h>
#include <KLocalizedString> #include <KLocalizedString>
#include <qstatusbar.h> #include <qstatusbar.h>
...@@ -65,10 +63,10 @@ ...@@ -65,10 +63,10 @@
#include "puzzleprinter.h" #include "puzzleprinter.h"
#include <ktar.h> #include <ktar.h>
#include <kstandarddirs.h>
#include <kio/job.h> #include <kio/job.h>
#include <kstandardgameaction.h> #include <kstandardgameaction.h>
#include <QDir> #include <QDir>
#include <KSharedConfig>
#include "gamevariants.h" #include "gamevariants.h"
#include "welcomescreen.h" #include "welcomescreen.h"
...@@ -160,9 +158,6 @@ KSudoku::KSudoku() ...@@ -160,9 +158,6 @@ KSudoku::KSudoku()
showWelcomeScreen(); showWelcomeScreen();
// Register the gamevariants resource
KGlobal::dirs()->addResourceType ("gamevariant", "data", KCmdLineArgs::aboutData()->appName());
updateShapesList(); updateShapesList();
// QTimer *timer = new QTimer( this ); // QTimer *timer = new QTimer( this );
...@@ -191,7 +186,17 @@ void KSudoku::updateShapesList() ...@@ -191,7 +186,17 @@ void KSudoku::updateShapesList()
variant->setIcon("ksudoku-roxdoku_3x3x3"); variant->setIcon("ksudoku-roxdoku_3x3x3");
#endif #endif
QStringList filepaths = KGlobal::dirs()->findAllResources("gamevariant", "*.desktop", KStandardDirs::NoDuplicates); // Find files. QStringList gamevariantdirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "ksudoku", QStandardPaths::LocateDirectory);
QStringList filepaths;
Q_FOREACH (const QString& gamevariantdir, gamevariantdirs) {
const QStringList fileNames = QDir(gamevariantdir).entryList(QStringList() << QStringLiteral("*.desktop"));
Q_FOREACH (const QString &file, fileNames) {
if (!filepaths.contains(gamevariantdir + '/' + file)) {
filepaths.append(gamevariantdir + '/' + file);
}
}
}
QString variantName; QString variantName;
QString variantDescr; QString variantDescr;
...@@ -867,8 +872,7 @@ void KSudoku::loadCustomShapeFromPath() ...@@ -867,8 +872,7 @@ void KSudoku::loadCustomShapeFromPath()
return; return;
} }
KStandardDirs myStdDir; const QString destDir = QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) + QStringLiteral("/ksudoku/");
const QString destDir = myStdDir.saveLocation( "data", /*kapp->instanceName() + TODO PORT */"ksudoku/", true );
QDir().mkpath( destDir ); QDir().mkpath( destDir );
KTar archive( tmpFile ); KTar archive( tmpFile );
...@@ -896,7 +900,7 @@ void KSudoku::enableMessages() ...@@ -896,7 +900,7 @@ void KSudoku::enableMessages()
i18n("Enable all messages")); i18n("Enable all messages"));
if (result == KMessageBox::Yes) { if (result == KMessageBox::Yes) {
KMessageBox::enableAllMessages(); KMessageBox::enableAllMessages();
KGlobal::config()->sync(); // Save the changes to disk. KSharedConfig::openConfig()->sync(); // Save the changes to disk.
} }
} }
...@@ -914,8 +918,7 @@ bool KSudokuNewStuff::install( const QString &fileName ) ...@@ -914,8 +918,7 @@ bool KSudokuNewStuff::install( const QString &fileName )
return false; return false;
const KArchiveDirectory *archiveDir = archive.directory(); const KArchiveDirectory *archiveDir = archive.directory();
KStandardDirs myStdDir; const QString destDir = QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) + QStringLiteral("/ksudoku/");
const QString destDir = myStdDir.saveLocation("data", /*kapp->instanceName() + TODO PORT*/"ksudoku/", true);
QDir().mkpath(destDir); QDir().mkpath(destDir);
archiveDir->copyTo(destDir); archiveDir->copyTo(destDir);
......
...@@ -18,14 +18,17 @@ ...@@ -18,14 +18,17 @@
***************************************************************************/ ***************************************************************************/
#include <kapplication.h>
#include <dcopclient.h> #include <dcopclient.h>
#include <qdatastream.h> #include <qdatastream.h>
#include <qstring.h> #include <qstring.h>
#include <QApplication>
#include <KAboutData>
#include <KLocalizedString>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
KApplication app(argc, argv, "ksudoku_client", false); QApplication app(argc, argv);
// get our DCOP client and attach so that we may use it // get our DCOP client and attach so that we may use it
DCOPClient *client = app.dcopClient(); DCOPClient *client = app.dcopClient();
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <kio/netaccess.h> #include <kio/netaccess.h>
#include <qfile.h> #include <qfile.h>
#include <KLocalizedString> #include <KLocalizedString>
#include <kstandarddirs.h>
#include "ksudoku.h" #include "ksudoku.h"
#include "symbols.h" #include "symbols.h"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "renderer.h" #include "renderer.h"
#include <QSvgRenderer> #include <QSvgRenderer>
#include <KStandardDirs>
#include <kpixmapcache.h> #include <kpixmapcache.h>
#include <KDebug> #include <KDebug>
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
......
...@@ -21,15 +21,20 @@ ...@@ -21,15 +21,20 @@
***************************************************************************/ ***************************************************************************/
#include "ksudoku.h" #include "ksudoku.h"
#include <kapplication.h>
//#include <dcopclient.h> //#include <dcopclient.h>
#include <K4AboutData> #include <KAboutData>
#include <KCrash> #include <KCrash>
#include <kcmdlineargs.h>
#include <KLocalizedString> #include <KLocalizedString>
#include <kconfigdialogmanager.h> #include <kconfigdialogmanager.h>
#include <KUrl> #include <KUrl>
#include <QApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDir>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
...@@ -43,35 +48,42 @@ static const char version[] = "1.3"; ...@@ -43,35 +48,42 @@ static const char version[] = "1.3";
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
qsrand(std::time(nullptr)); qsrand(std::time(nullptr));
QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("ksudoku");
K4AboutData about("ksudoku", 0, KAboutData about("ksudoku",
ki18n("KSudoku"), i18n("KSudoku"),
version, version,
ki18n("KSudoku - Sudoku games and more"), i18n(description),
K4AboutData::License_GPL_V2, KAboutLicense::GPL_V2,
ki18n("(c) 2005-2007 The KSudoku Authors"), i18n("(c) 2005-2007 The KSudoku Authors"),
KLocalizedString(), "http://ksudoku.sourceforge.net/"); QString(), "https://games.kde.org/game.php?game=ksudoku");
about.addAuthor( ki18n("Francesco Rossi"), ki18n("KSudoku Author"), "redsh@email.it" ); about.addAuthor( i18n("Francesco Rossi"), i18n("KSudoku Author"), "redsh@email.it" );
about.addAuthor( ki18n("Johannes Bergmeier"), ki18n("Maintainer"), "Johannes.Bergmeier@gmx.net" ); about.addAuthor( i18n("Johannes Bergmeier"), i18n("Maintainer"), "Johannes.Bergmeier@gmx.net" );
about.addAuthor( ki18n("Ian Wadham"), ki18n("New puzzle generator and solver"), "iandw.au@gmail.com" ); about.addAuthor( i18n("Ian Wadham"), i18n("New puzzle generator and solver"), "iandw.au@gmail.com" );
about.addAuthor( ki18n("Mick Kappenburg"), ki18n("Printing and export of 0.4"), "ksudoku@kappendburg.net"); about.addAuthor( i18n("Mick Kappenburg"), i18n("Printing and export of 0.4"), "ksudoku@kappendburg.net");
about.addAuthor( ki18n("Thanks to NeHe for OpenGL tutorials"), KLocalizedString(), "nehe.gamedev.net"); about.addAuthor( i18n("Thanks to NeHe for OpenGL tutorials"), QString(), "nehe.gamedev.net");
about.addCredit( ki18n("David Bau"), ki18n("Algorithms for new puzzle generator and solver at davidbau.com/archives/2006/09/04/sudoku_generator.html"), ""); about.addCredit( i18n("David Bau"), i18n("Algorithms for new puzzle generator and solver at davidbau.com/archives/2006/09/04/sudoku_generator.html"), "");
KCmdLineArgs::init(argc, argv, &about);
KAboutData::setApplicationData(about);
KCmdLineOptions options; app.setOrganizationDomain(QStringLiteral("kde.org"));
options.add("+[URL]", ki18n( "Document to open" )); app.setWindowIcon(QIcon::fromTheme(QStringLiteral("ksudoku")));
KCmdLineArgs::addCmdLineOptions(options);
KApplication app; QCommandLineParser parser;
about.setupCommandLine(&parser);
KLocalizedString::setApplicationDomain("ksudoku"); parser.addVersionOption();
parser.addHelpOption();
KCrash::initialize(); parser.addPositionalArgument(QLatin1String("[URL]"), i18n( "Document to open" ));
parser.process(app);
about.processCommandLine(&parser);
KCrash::initialize();
// register ourselves as a dcop client // register ourselves as a dcop client
// app.dcopClient()->registerAs(app.name(), false); //TODO PORT // app.dcopClient()->registerAs(app.name(), false); //TODO PORT
KConfigDialogManager::changedMap()->insert("ksudoku::SymbolConfigListWidget", SIGNAL(itemChanged(QListWidgetItem*))); KConfigDialogManager::changedMap()->insert("ksudoku::SymbolConfigListWidget", SIGNAL(itemChanged(QListWidgetItem*)));
// see if we are starting with session management // see if we are starting with session management
/*if (app.isRestored()) /*if (app.isRestored())
...@@ -84,18 +96,15 @@ int main(int argc, char **argv) ...@@ -84,18 +96,15 @@ int main(int argc, char **argv)
widget->show(); widget->show();
// no session.. just start up normally // no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (parser.positionalArguments().count() != 0)
if (args->count() != 0)
{ {
for (int i = 0; i < args->count(); ++i) for (int i = 0; i < parser.positionalArguments().count(); ++i)
{ {
widget->loadGame(args->url(i)); widget->loadGame(QUrl::fromUserInput(parser.positionalArguments().at(i), QDir::currentPath()));
} }
} }
args->clear();
//} //TODO PORT
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("ksudoku"))); //} //TODO PORT
return app.exec(); return app.exec();
} }
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