File indexing completed on 2024-04-28 07:54:27

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