src/platform/qt/main.cpp (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7// This must be defined before anything else is included.
8#define SDL_MAIN_HANDLED
9
10#include "ConfigController.h"
11#include "GBAApp.h"
12#include "Window.h"
13
14#include <mgba/core/version.h>
15#include <mgba/internal/gba/video.h>
16
17#include <QLibraryInfo>
18#include <QTranslator>
19
20#ifdef QT_STATIC
21#include <QtPlugin>
22#ifdef Q_OS_WIN
23Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
24#ifdef BUILD_QT_MULTIMEDIA
25Q_IMPORT_PLUGIN(QWindowsAudioPlugin);
26Q_IMPORT_PLUGIN(DSServicePlugin);
27#endif
28#elif defined(Q_OS_MAC)
29Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
30#ifdef BUILD_QT_MULTIMEDIA
31Q_IMPORT_PLUGIN(CoreAudioPlugin);
32Q_IMPORT_PLUGIN(AVFServicePlugin);
33#endif
34#endif
35#endif
36
37using namespace QGBA;
38
39int main(int argc, char* argv[]) {
40#ifdef BUILD_SDL
41#if SDL_VERSION_ATLEAST(2, 0, 0) // CPP does not shortcut function lookup
42 SDL_SetMainReady();
43#endif
44#endif
45
46 ConfigController configController;
47
48 QLocale locale;
49 if (!configController.getQtOption("language").isNull()) {
50 locale = QLocale(configController.getQtOption("language").toString());
51 QLocale::setDefault(locale);
52 }
53
54 mArguments args;
55 mGraphicsOpts graphicsOpts;
56 mSubParser subparser;
57 initParserForGraphics(&subparser, &graphicsOpts);
58 bool loaded = configController.parseArguments(&args, argc, argv, &subparser);
59 if (loaded && args.showHelp) {
60 usage(argv[0], subparser.usage);
61 return 0;
62 }
63
64 QApplication::setApplicationName(projectName);
65 QApplication::setApplicationVersion(projectVersion);
66
67 GBAApp application(argc, argv, &configController);
68
69#ifndef Q_OS_MAC
70 QApplication::setWindowIcon(QIcon(":/res/mgba-1024.png"));
71#endif
72
73 QTranslator qtTranslator;
74 qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
75 application.installTranslator(&qtTranslator);
76
77#ifdef QT_STATIC
78 QTranslator qtStaticTranslator;
79 qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
80 application.installTranslator(&qtStaticTranslator);
81#endif
82
83 QTranslator langTranslator;
84 langTranslator.load(locale, binaryName, "-", ":/translations/");
85 application.installTranslator(&langTranslator);
86
87 Window* w = application.newWindow();
88 if (loaded) {
89 w->argumentsPassed(&args);
90 } else {
91 w->loadConfig();
92 }
93 freeArguments(&args);
94
95 if (graphicsOpts.multiplier) {
96 w->resizeFrame(QSize(VIDEO_HORIZONTAL_PIXELS * graphicsOpts.multiplier, VIDEO_VERTICAL_PIXELS * graphicsOpts.multiplier));
97 }
98 if (graphicsOpts.fullscreen) {
99 w->enterFullScreen();
100 }
101
102 w->show();
103
104 return application.exec();
105}