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