Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b6f18561 authored by Laurent Montel's avatar Laurent Montel 😁

Port to qcommandlineparser. Kdelibs4support--

parent 13c86a26
......@@ -24,25 +24,25 @@
#include <QtCore/QFutureWatcher>
#include <QtCore/QTimer>
#include <QApplication>
#include <KCmdLineArgs>
#include <QDebug>
#include <KLocalizedString>
#include <KNotification>
Palapeli::ImportHelper::ImportHelper(KCmdLineArgs* args)
: m_args(args)
Palapeli::ImportHelper::ImportHelper(const QString &path)
: m_path(path)
{
QTimer::singleShot(0, this, SLOT(doWork()));
}
void Palapeli::ImportHelper::doWork()
{
if (m_args->count() == 0)
if (m_path.isEmpty())
{
qCritical() << i18nc("command line message", "Error: No puzzle file given.");
qApp->quit();
}
//import puzzle
Palapeli::Puzzle* puzzle = Palapeli::Collection::instance()->importPuzzle(m_args->arg(0));
Palapeli::Puzzle* puzzle = Palapeli::Collection::instance()->importPuzzle(m_path);
//show notification
puzzle->get(Palapeli::PuzzleComponent::Metadata).waitForFinished();
const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>();
......
......@@ -20,7 +20,6 @@
#define PALAPELI_IMPORTHELPER_H
#include <QObject>
class KCmdLineArgs;
namespace Palapeli
{
......@@ -28,11 +27,11 @@ namespace Palapeli
{
Q_OBJECT
public:
ImportHelper(KCmdLineArgs* args);
ImportHelper(const QString &path);
public Q_SLOTS:
void doWork();
private:
KCmdLineArgs* m_args;
QString m_path;
};
}
......
......@@ -21,35 +21,48 @@
#include <ctime>
#include <QTimer>
#include <K4AboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <KAboutData>
#include <QApplication>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QCommandLineOption>
int main(int argc, char** argv)
{
qsrand(time(0));
K4AboutData about("palapeli", 0, ki18nc("The application's name", "Palapeli"), "2.0", ki18n("KDE Jigsaw Puzzle Game"), K4AboutData::License_GPL, ki18n("Copyright 2009, 2010, Stefan Majewsky"));
about.addAuthor(ki18n("Stefan Majewsky"), KLocalizedString(), "majewsky@gmx.net", "http://majewsky.wordpress.com");
about.addCredit (ki18n ("Johannes Loehnert"),
ki18n ("The option to preview the completed puzzle"),
KAboutData about("palapeli", i18nc("The application's name", "Palapeli"), "2.0", i18n("KDE Jigsaw Puzzle Game"), KAboutLicense::GPL, i18n("Copyright 2009, 2010, Stefan Majewsky"));
about.addAuthor(i18n("Stefan Majewsky"), QString(), "majewsky@gmx.net", "http://majewsky.wordpress.com");
about.addCredit (i18n ("Johannes Loehnert"),
i18n ("The option to preview the completed puzzle"),
"loehnert.kde@gmx.de");
KCmdLineArgs::init(argc, argv, &about);
QApplication app(argc, argv);
QCommandLineParser parser;
KAboutData::setApplicationData(about);
parser.addVersionOption();
parser.addHelpOption();
parser.addPositionalArgument(QLatin1String("puzzlefile"), i18n("Path to puzzle file (will be opened if -i is not given)"));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("i") << QLatin1String("import"), i18n("Import the given puzzle file into the local collection (does nothing if no puzzle file is given)")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String(""), i18n("If the -i/--import option is specified, the main window will not be shown after importing the given puzzle.")));
KCmdLineOptions options;
options.add("+puzzlefile", ki18n("Path to puzzle file (will be opened if -i is not given)"));
options.add("i").add("import", ki18n("Import the given puzzle file into the local collection (does nothing if no puzzle file is given)"));
options.add("", ki18n("If the -i/--import option is specified, the main window will not be shown after importing the given puzzle."));
KCmdLineArgs::addCmdLineOptions(options);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
KApplication app;
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
//NOTE: Syntax errors are reported on stderr, while file errors are presented to the user.
if (args->isSet("import"))
if (parser.isSet("import"))
//perform import request
new Palapeli::ImportHelper(args);
else
new Palapeli::ImportHelper(parser.value("import"));
else {
const QStringList args = parser.positionalArguments();
QString path;
if (args.count()>1) {
path = args.at(1);
}
//no import request, show main window
(new Palapeli::MainWindow(args))->show();
(new Palapeli::MainWindow(path))->show();
}
return app.exec();
}
......@@ -26,13 +26,12 @@
#include <KGlobal>
#include <QAction>
#include <KActionCollection>
#include <KCmdLineArgs>
#include <KLocalizedString>
#include <KStandardAction>
#include <KToggleAction>
#include <KMessageBox>
Palapeli::MainWindow::MainWindow(KCmdLineArgs* args)
Palapeli::MainWindow::MainWindow(const QString &path)
: m_game(new Palapeli::GamePlay(this))
{
setupActions();
......@@ -42,11 +41,7 @@ Palapeli::MainWindow::MainWindow(KCmdLineArgs* args)
setupGUI(QSize(500, 500), guiOptions);
m_game->init();
//start a puzzle if a puzzle URL has been given
if (args->count() != 0)
{
m_game->playPuzzleFile(args->arg(0));
}
args->clear();
m_game->playPuzzleFile(path);
}
bool Palapeli::MainWindow::queryClose()
......
......@@ -20,7 +20,6 @@
#define PALAPELI_MAINWINDOW_H
class QStackedWidget;
class KCmdLineArgs;
#include <KXmlGuiWindow>
namespace Palapeli
......@@ -35,7 +34,7 @@ namespace Palapeli
{
Q_OBJECT
public:
MainWindow(KCmdLineArgs* args);
MainWindow(const QString &path);
protected:
virtual bool queryClose();
private Q_SLOTS:
......
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