File indexing completed on 2022-09-20 12:22:40

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Sebastian Gottfried <sebastiangottfried@web.de>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include <QCommandLineParser>
0008 
0009 #include <KAboutData>
0010 #include <KLocalizedString>
0011 
0012 #include "application.h"
0013 #include "mainwindow.h"
0014 #include "version.h"
0015 
0016 int main(int argc, char **argv)
0017 {
0018     Application::setAttribute(Qt::AA_EnableHighDpiScaling);
0019     Application::setAttribute(Qt::AA_UseHighDpiPixmaps);
0020 
0021     Application app(argc, argv);
0022 
0023     KLocalizedString::setApplicationDomain("ktouch");
0024 
0025     KAboutData about(QStringLiteral("ktouch"),
0026                 i18n("Typewriting Trainer"),
0027                 QStringLiteral(KTOUCH_VERSION_STRING),
0028                 i18n("Learn and practice typewriting"),
0029                 KAboutLicense::GPL,
0030                 i18n(
0031                     "Copyright (C) 2011-2015 by Sebastian Gottfried\n"
0032                     "Copyright (C) 2000-2007 by Håvard Frøiland and Andreas Nicolai"
0033                 ),
0034                 QString(),
0035                 QStringLiteral("https://edu.kde.org/ktouch"),
0036                 QStringLiteral("submit@bugs.kde.org"));
0037 
0038     about.addAuthor(i18n("Sebastian Gottfried"), i18n("Current maintainer"), QStringLiteral("sebastiangottfried@web.de"));
0039     about.addAuthor(i18n("Andreas Nicolai"), i18n("Former maintainer and programmer"), QStringLiteral("Andreas.Nicolai@gmx.net"));
0040     about.addAuthor(i18n("Håvard Frøiland"), i18n("Original author"), QStringLiteral("haavard@users.sourceforge.net"));
0041 
0042     about.addCredit(i18n("David Vignoni"), i18n("Creator of the SVG icon"), QStringLiteral("david80v@tin.it"));
0043     about.addCredit(i18n("Anne-Marie Mahfouf"), i18n("Lots of patches, fixes and updates"), QStringLiteral("annma@kde.org"));
0044     about.addCredit(i18n("All the creators of training and keyboard files"));
0045 
0046     about.setOrganizationDomain(QByteArray("kde.org"));
0047 
0048     KAboutData::setApplicationData(about);
0049 
0050     app.setApplicationName(about.componentName());
0051     app.setApplicationDisplayName(about.displayName());
0052     app.setOrganizationDomain(about.organizationDomain());
0053     app.setApplicationVersion(about.version());
0054 
0055     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("ktouch")));
0056 
0057 
0058     QCommandLineParser parser;
0059     about.setupCommandLine(&parser);
0060 
0061     parser.addOption(QCommandLineOption(QStringLiteral("resource-editor"), i18n("Launch the course and keyboard layout editor")));
0062 
0063     parser.addOption({{"I", "import-path"}, i18n("Prepend the path to the list of QML import paths"), QStringLiteral("path")});
0064 
0065     parser.process(app);
0066 
0067     about.processCommandLine(&parser);
0068 
0069     if (parser.isSet(QStringLiteral("import-path")))
0070     {
0071         foreach (const QString& path, parser.values("import-path"))
0072         {
0073             app.qmlImportPaths().append(path);
0074         }
0075     }
0076 
0077 
0078     if (app.isSessionRestored())
0079     {
0080         for (int i = 1; KMainWindow::canBeRestored(i); i++)
0081         {
0082             const QString name = KMainWindow::classNameOfToplevel(i);
0083 
0084             if (name == QLatin1String("MainWindow"))
0085             {
0086                 (new MainWindow)->restore(i);
0087             }
0088             else if (name == QLatin1String("ResourceEditor"))
0089             {
0090                 QPointer<ResourceEditor>& resourceEditorRef = Application::resourceEditorRef();
0091 
0092                 if (resourceEditorRef.isNull())
0093                 {
0094                     resourceEditorRef = QPointer<ResourceEditor>(new ResourceEditor());
0095                     resourceEditorRef.data()->restore(i);
0096                 }
0097             }
0098         }
0099     }
0100     else
0101     {
0102         if (parser.isSet(QStringLiteral("resource-editor")))
0103         {
0104             QPointer<ResourceEditor>& resourceEditorRef = Application::resourceEditorRef();
0105             if (resourceEditorRef.isNull())
0106             {
0107                 resourceEditorRef = QPointer<ResourceEditor>(new ResourceEditor());
0108             }
0109 
0110             ResourceEditor* resourceEditor = resourceEditorRef.data();
0111 
0112             resourceEditor->show();
0113         }
0114         else
0115         {
0116             MainWindow *mainWin = 0;
0117             mainWin = new MainWindow();
0118             mainWin->show();
0119         }
0120     }
0121 
0122     return app.exec();
0123 }