File indexing completed on 2024-04-28 04:05:19

0001 /*
0002     SPDX-FileCopyrightText: 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "importhelper.h"
0008 #include "window/mainwindow.h"
0009 #include "palapeli_version.h"
0010 
0011 #include <ctime>
0012 #include <KAboutData>
0013 #include <KCrash>
0014 #include <KDBusService>
0015 
0016 #include <QApplication>
0017 #include <KLocalizedString>
0018 #include <QCommandLineParser>
0019 #include <QCommandLineOption>
0020 
0021 #include <iostream>
0022 
0023 int main(int argc, char** argv)
0024 {
0025     QApplication app(argc, argv);
0026 
0027     KLocalizedString::setApplicationDomain(QByteArrayLiteral("palapeli"));
0028 
0029     KAboutData about(QStringLiteral("palapeli"),
0030                      i18nc("The application's name", "Palapeli"),
0031                      QStringLiteral(PALAPELI_VERSION_STRING),
0032                      i18n("Jigsaw Puzzle Game"),
0033                      KAboutLicense::GPL,
0034                      i18n("Copyright 2009, 2010, Stefan Majewsky"),
0035                      QString(),
0036                      QStringLiteral("https://apps.kde.org/palapeli"));
0037     about.addAuthor(i18n("Stefan Majewsky"), QString(), QStringLiteral("majewsky@gmx.net"), QStringLiteral("https://majewsky.wordpress.com/"));
0038     about.addCredit (i18n ("Johannes Loehnert"),
0039             i18n ("The option to preview the completed puzzle"),
0040             QStringLiteral("loehnert.kde@gmx.de"));
0041 
0042     KAboutData::setApplicationData(about);
0043     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("palapeli")));
0044 
0045     KCrash::initialize();
0046 
0047     QCommandLineParser parser;
0048     parser.addPositionalArgument(QStringLiteral("puzzlefile"), i18n("Path to puzzle file (will be opened if -i is not given)"));
0049     const QCommandLineOption importOption(QStringList() << QStringLiteral("i") << QStringLiteral("import"), i18n("Import the given puzzle file into the local collection (does nothing if no puzzle file is given). The main window will not be shown after importing the given puzzle."));
0050     parser.addOption(importOption);
0051     about.setupCommandLine(&parser);
0052 
0053     parser.process(app);
0054     about.processCommandLine(&parser);
0055 
0056     KDBusService service;
0057 
0058     //NOTE: Syntax errors are reported on stderr, while file errors are presented to the user.
0059     if (parser.isSet(importOption)) {
0060         //perform import request
0061 
0062         if (parser.positionalArguments().isEmpty()) {
0063             std::cout << i18n("No file to import given").toStdString() << std::endl;
0064             return 1;
0065         }
0066 
0067         new Palapeli::ImportHelper(parser.positionalArguments().first());
0068     } else {
0069         const QStringList args = parser.positionalArguments();
0070         QString path;
0071         if (!args.isEmpty()) {
0072             path = args.first();
0073         }
0074         //no import request, show main window
0075         (new Palapeli::MainWindow(path))->show();
0076     }
0077 
0078     return app.exec();
0079 }