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/gba/interface.h>
16
17#include <QLibraryInfo>
18#include <QTranslator>
19
20#ifdef BUILD_GLES2
21#include <QSurfaceFormat>
22#endif
23
24#ifdef QT_STATIC
25#include <QtPlugin>
26#ifdef Q_OS_WIN
27Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
28Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
29#ifdef BUILD_QT_MULTIMEDIA
30Q_IMPORT_PLUGIN(QWindowsAudioPlugin);
31Q_IMPORT_PLUGIN(DSServicePlugin);
32#endif
33#elif defined(Q_OS_MAC)
34Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
35#ifdef BUILD_QT_MULTIMEDIA
36Q_IMPORT_PLUGIN(CoreAudioPlugin);
37Q_IMPORT_PLUGIN(AVFServicePlugin);
38#endif
39#endif
40#endif
41
42using namespace QGBA;
43
44int main(int argc, char* argv[]) {
45#ifdef BUILD_SDL
46#if SDL_VERSION_ATLEAST(2, 0, 0) // CPP does not shortcut function lookup
47 SDL_SetMainReady();
48#endif
49#endif
50
51 ConfigController configController;
52
53 QLocale locale;
54 if (!configController.getQtOption("language").isNull()) {
55 locale = QLocale(configController.getQtOption("language").toString());
56 QLocale::setDefault(locale);
57 }
58
59 mArguments args;
60 mGraphicsOpts graphicsOpts;
61 mSubParser subparser;
62 initParserForGraphics(&subparser, &graphicsOpts);
63 bool loaded = configController.parseArguments(&args, argc, argv, &subparser);
64 if (loaded && args.showHelp) {
65 usage(argv[0], subparser.usage);
66 return 0;
67 }
68
69 QApplication::setApplicationName(projectName);
70 QApplication::setApplicationVersion(projectVersion);
71
72#ifdef BUILD_GLES2
73 QSurfaceFormat format;
74 format.setVersion(3, 0);
75 QSurfaceFormat::setDefaultFormat(format);
76#endif
77
78 GBAApp application(argc, argv, &configController);
79
80#ifndef Q_OS_MAC
81 QApplication::setWindowIcon(QIcon(":/res/mgba-1024.png"));
82#endif
83
84 QTranslator qtTranslator;
85 qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
86 application.installTranslator(&qtTranslator);
87
88#ifdef QT_STATIC
89 QTranslator qtStaticTranslator;
90 qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
91 application.installTranslator(&qtStaticTranslator);
92#endif
93
94 QTranslator langTranslator;
95 langTranslator.load(locale, binaryName, "-", ":/translations/");
96 application.installTranslator(&langTranslator);
97
98 Window* w = application.newWindow();
99 if (loaded) {
100 w->argumentsPassed(&args);
101 } else {
102 w->loadConfig();
103 }
104 freeArguments(&args);
105
106 if (graphicsOpts.multiplier) {
107 w->resizeFrame(QSize(GBA_VIDEO_HORIZONTAL_PIXELS * graphicsOpts.multiplier, GBA_VIDEO_VERTICAL_PIXELS * graphicsOpts.multiplier));
108 }
109 if (graphicsOpts.fullscreen) {
110 w->enterFullScreen();
111 }
112
113 w->show();
114
115 return application.exec();
116}
117
118#ifdef _WIN32
119#include <mgba-util/string.h>
120#include <vector>
121
122extern "C"
123int wmain(int argc, wchar_t* argv[]) {
124 std::vector<char*> argv8;
125 for (int i = 0; i < argc; ++i) {
126 argv8.push_back(utf16to8(reinterpret_cast<uint16_t*>(argv[i]), wcslen(argv[i]) * 2));
127 }
128 int ret = main(argc, argv8.data());
129 for (char* ptr : argv8) {
130 free(ptr);
131 }
132 return ret;
133}
134#endif