File indexing completed on 2022-09-27 13:19:29

0001 /*
0002     SPDX-FileCopyrightText: 2006 Matthew Williams <matt@milliams.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <KAboutData>
0008 #include <KCrash>
0009 #include <KUser>
0010 #include <QApplication>
0011 #include <KLocalizedString>
0012 #include <QCommandLineParser>
0013 #include <QCommandLineOption>
0014 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0015 #include <Kdelibs4ConfigMigrator>
0016 #endif
0017 #include <KDBusService>
0018 
0019 #include "ksquareswindow.h"
0020 #include "ksquaresdemowindow.h"
0021 #include "settings.h"
0022 #include "ksquares_version.h"
0023 
0024 
0025 int main(int argc, char **argv)
0026 {
0027     // Fixes blurry icons with fractional scaling
0028 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0029     QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0030 #endif
0031     QApplication app(argc, argv);
0032 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0033     Kdelibs4ConfigMigrator migrate(QStringLiteral("ksquares"));
0034     migrate.setConfigFiles(QStringList() << QStringLiteral("ksquaresrc"));
0035     migrate.setUiFiles(QStringList() << QStringLiteral("ksquaresui.rc"));
0036     migrate.migrate();
0037 #endif
0038     KLocalizedString::setApplicationDomain("ksquares");
0039     KAboutData about(QStringLiteral("ksquares"), i18n("KSquares"),
0040                      QStringLiteral(KSQUARES_VERSION_STRING),
0041                      i18n("Take it in turns to draw lines.\nIf you complete a squares, you get another go."),
0042                      KAboutLicense::GPL,
0043                      i18n("(C) 2006-2007 Matt Williams"),
0044                      QString(),
0045                      QStringLiteral("https://apps.kde.org/ksquares"));
0046     about.addAuthor(i18n("Matt Williams"), i18n("Original creator and maintainer"), QStringLiteral("matt@milliams.com"), QStringLiteral("https://milliams.com"));
0047     about.addCredit(i18n("Fela Winkelmolen"), i18n("Many patches and bugfixes"));
0048     about.addCredit(i18n("Tom Vincent Peters"), i18n("Hard AI"));
0049 
0050     QCommandLineParser parser;
0051     KAboutData::setApplicationData(about);
0052     KCrash::initialize();
0053     parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("demo"), i18n("Run game in demo (autoplay) mode")));
0054 
0055     about.setupCommandLine(&parser);
0056     parser.process(app);
0057     about.processCommandLine(&parser);
0058     KDBusService service;
0059 
0060     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("ksquares")));
0061 
0062     // default names for players
0063     KConfigGroup cg(KSharedConfig::openConfig(), "General");
0064     if (cg.readEntry<bool>("initializeNames", true)) {
0065         QStringList playerNames;
0066         playerNames << KUser().property(KUser::FullName).toString();
0067         playerNames << i18nc("default name of player", "Player %1", 2);
0068         playerNames << i18nc("default name of player", "Player %1", 3);
0069         playerNames << i18nc("default name of player", "Player %1", 4);
0070         Settings::setPlayerNames(playerNames);
0071         cg.writeEntry("initializeNames", false);
0072     }
0073 
0074     if (parser.isSet(QStringLiteral("demo"))) {
0075       auto demoWindow = new KSquaresDemoWindow;
0076       demoWindow->show();
0077       demoWindow->gameNew();
0078     } else {
0079       auto mainWindow = new KSquaresWindow;
0080       mainWindow->show();
0081     }
0082 
0083     return app.exec();
0084 }