File indexing completed on 2024-04-21 04:04:58

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 #include <KDBusService>
0015 
0016 #include "ksquareswindow.h"
0017 #include "ksquaresdemowindow.h"
0018 #include "settings.h"
0019 #include "ksquares_version.h"
0020 
0021 
0022 int main(int argc, char **argv)
0023 {
0024     QApplication app(argc, argv);
0025 
0026     KLocalizedString::setApplicationDomain(QByteArrayLiteral("ksquares"));
0027 
0028     KAboutData about(QStringLiteral("ksquares"), i18n("KSquares"),
0029                      QStringLiteral(KSQUARES_VERSION_STRING),
0030                      i18n("Take it in turns to draw lines.\nIf you complete a squares, you get another go."),
0031                      KAboutLicense::GPL,
0032                      i18n("(C) 2006-2007 Matt Williams"),
0033                      QString(),
0034                      QStringLiteral("https://apps.kde.org/ksquares"));
0035     about.addAuthor(i18n("Matt Williams"), i18n("Original creator and maintainer"), QStringLiteral("matt@milliams.com"), QStringLiteral("https://milliams.com"));
0036     about.addCredit(i18n("Fela Winkelmolen"), i18n("Many patches and bugfixes"));
0037     about.addCredit(i18n("Tom Vincent Peters"), i18n("Hard AI"));
0038 
0039     KAboutData::setApplicationData(about);
0040 
0041     KCrash::initialize();
0042 
0043     QCommandLineParser parser;
0044     parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("demo"), i18n("Run game in demo (autoplay) mode")));
0045     about.setupCommandLine(&parser);
0046     parser.process(app);
0047     about.processCommandLine(&parser);
0048 
0049     KDBusService service;
0050 
0051     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("ksquares")));
0052 
0053     // default names for players
0054     KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("General"));
0055     if (cg.readEntry<bool>("initializeNames", true)) {
0056         QStringList playerNames;
0057         playerNames << KUser().property(KUser::FullName).toString();
0058         playerNames << i18nc("default name of player", "Player %1", 2);
0059         playerNames << i18nc("default name of player", "Player %1", 3);
0060         playerNames << i18nc("default name of player", "Player %1", 4);
0061         Settings::setPlayerNames(playerNames);
0062         cg.writeEntry("initializeNames", false);
0063     }
0064 
0065     if (parser.isSet(QStringLiteral("demo"))) {
0066       auto demoWindow = new KSquaresDemoWindow;
0067       demoWindow->show();
0068       demoWindow->gameNew();
0069     } else {
0070       auto mainWindow = new KSquaresWindow;
0071       mainWindow->show();
0072     }
0073 
0074     return app.exec();
0075 }