1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <tackat@kde.org>
4 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
5 // SPDX-FileCopyrightText: 2014 Dennis Nienhüser <nienhueser@kde.org>
6 //
7 
8 #include "GameMainWindow.h"
9 
10 #include <marble/MarbleDirs.h>
11 #include <marble/MarbleDebug.h>
12 #include <marble/MarbleLocale.h>
13 #include <marble/MarbleGlobal.h>
14 
15 #include <QApplication>
16 #include <QDir>
17 #include <QLocale>
18 #include <QTranslator>
19 #include <QDebug>
20 
21 using namespace Marble;
22 
main(int argc,char * argv[])23 int main(int argc, char *argv[])
24 {
25     QApplication app(argc, argv);
26     app.setApplicationName(QStringLiteral("Marble Game"));
27     app.setOrganizationName(QStringLiteral("KDE"));
28     app.setOrganizationDomain(QStringLiteral("kde.org"));
29     // Widget translation
30 
31     QString      lang = QLocale::system().name().section(QLatin1Char('_'), 0, 0);
32     QTranslator  translator;
33     translator.load(QLatin1String("marble-") + lang, MarbleDirs::path(QStringLiteral("lang")));
34     app.installTranslator(&translator);
35 
36     // For non static builds on mac and win
37     // we need to be sure we can find the qt image
38     // plugins. In mac be sure to look in the
39     // application bundle...
40 
41 #ifdef Q_WS_WIN
42     QApplication::addLibraryPath( QApplication::applicationDirPath()
43                                   + QDir::separator() + QLatin1String("plugins"));
44 #endif
45 
46     QString marbleDataPath;
47     int dataPathIndex=0;
48 
49     QStringList args = QApplication::arguments();
50 
51     if (args.contains(QStringLiteral("-h")) || args.contains(QStringLiteral("--help"))) {
52         qWarning() << "Usage: marble [options]";
53         qWarning();
54         qWarning() << "general options:";
55         qWarning() << "  --marbledatapath=<path> .... Overwrite the compile-time path to map themes and other data";
56         qWarning();
57         qWarning() << "debug options:";
58         qWarning() << "  --debug-info ............... write (more) debugging information to the console";
59 
60         return 0;
61     }
62 
63     for ( int i = 1; i < args.count(); ++i ) {
64         const QString arg = args.at(i);
65 
66         if ( arg == QLatin1String( "--debug-info" ) )
67         {
68             MarbleDebug::setEnabled( true );
69         }
70         else if ( arg.startsWith( QLatin1String( "--marbledatapath=" ), Qt::CaseInsensitive ) )
71         {
72             marbleDataPath = args.at(i).mid(17);
73         }
74         else if ( arg.compare( QLatin1String( "--marbledatapath" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) {
75             dataPathIndex = i + 1;
76             marbleDataPath = args.value( dataPathIndex );
77             ++i;
78         }
79     }
80 
81     MarbleLocale::MeasurementSystem const measurement =
82             (MarbleLocale::MeasurementSystem)QLocale::system().measurementSystem();
83     MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement );
84 
85     MainWindow *window = new MainWindow( marbleDataPath );
86     window->show();
87     return app.exec();
88 }
89