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