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#if defined(BUILD_SDL) && SDL_VERSION_ATLEAST(2, 0, 0)
41 SDL_SetMainReady();
42#endif
43
44 ConfigController configController;
45
46 QLocale locale;
47 if (!configController.getQtOption("language").isNull()) {
48 locale = QLocale(configController.getQtOption("language").toString());
49 QLocale::setDefault(locale);
50 }
51
52 mArguments args;
53 mGraphicsOpts graphicsOpts;
54 mSubParser subparser;
55 initParserForGraphics(&subparser, &graphicsOpts);
56 bool loaded = configController.parseArguments(&args, argc, argv, &subparser);
57 if (loaded && args.showHelp) {
58 usage(argv[0], subparser.usage);
59 return 0;
60 }
61
62 GBAApp application(argc, argv, &configController);
63
64 QTranslator qtTranslator;
65 qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
66 application.installTranslator(&qtTranslator);
67
68#ifdef QT_STATIC
69 QTranslator qtStaticTranslator;
70 qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
71 application.installTranslator(&qtStaticTranslator);
72#endif
73
74 QTranslator langTranslator;
75 langTranslator.load(locale, binaryName, "-", ":/translations/");
76 application.installTranslator(&langTranslator);
77
78 Window* w = application.newWindow();
79 if (loaded) {
80 w->argumentsPassed(&args);
81 } else {
82 w->loadConfig();
83 }
84 freeArguments(&args);
85
86 if (graphicsOpts.multiplier) {
87 w->resizeFrame(QSize(VIDEO_HORIZONTAL_PIXELS * graphicsOpts.multiplier, VIDEO_VERTICAL_PIXELS * graphicsOpts.multiplier));
88 }
89 if (graphicsOpts.fullscreen) {
90 w->enterFullScreen();
91 }
92
93 w->show();
94
95 return application.exec();
96}