File indexing completed on 2024-05-19 07:55:15
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 0015 #include <QApplication> 0016 #include <KLocalizedString> 0017 #include <QCommandLineParser> 0018 #include <QCommandLineOption> 0019 0020 #include <iostream> 0021 0022 int main(int argc, char** argv) 0023 { 0024 QApplication app(argc, argv); 0025 0026 KLocalizedString::setApplicationDomain("palapeli"); 0027 0028 KAboutData about(QStringLiteral("palapeli"), 0029 i18nc("The application's name", "Palapeli"), 0030 QStringLiteral(PALAPELI_VERSION_STRING), 0031 i18n("Jigsaw Puzzle Game"), 0032 KAboutLicense::GPL, 0033 i18n("Copyright 2009, 2010, Stefan Majewsky"), 0034 QString(), 0035 QStringLiteral("https://apps.kde.org/palapeli")); 0036 about.addAuthor(i18n("Stefan Majewsky"), QString(), QStringLiteral("majewsky@gmx.net"), QStringLiteral("https://majewsky.wordpress.com/")); 0037 about.addCredit (i18n ("Johannes Loehnert"), 0038 i18n ("The option to preview the completed puzzle"), 0039 QStringLiteral("loehnert.kde@gmx.de")); 0040 0041 KAboutData::setApplicationData(about); 0042 QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("palapeli"))); 0043 0044 KCrash::initialize(); 0045 0046 QCommandLineParser parser; 0047 parser.addPositionalArgument(QStringLiteral("puzzlefile"), i18n("Path to puzzle file (will be opened if -i is not given)")); 0048 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.")); 0049 parser.addOption(importOption); 0050 about.setupCommandLine(&parser); 0051 0052 parser.process(app); 0053 about.processCommandLine(&parser); 0054 0055 //NOTE: Syntax errors are reported on stderr, while file errors are presented to the user. 0056 if (parser.isSet(importOption)) { 0057 //perform import request 0058 0059 if (parser.positionalArguments().isEmpty()) { 0060 std::cout << i18n("No file to import given").toStdString() << std::endl; 0061 return 1; 0062 } 0063 0064 new Palapeli::ImportHelper(parser.positionalArguments().first()); 0065 } else { 0066 const QStringList args = parser.positionalArguments(); 0067 QString path; 0068 if (!args.isEmpty()) { 0069 path = args.first(); 0070 } 0071 //no import request, show main window 0072 (new Palapeli::MainWindow(path))->show(); 0073 } 0074 0075 return app.exec(); 0076 }