all repos — mgba @ 38f938f64867a07e1f925a11ac80b388d42d463d

mGBA Game Boy Advance Emulator

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#if defined(BUILD_SDL)
21#include <SDL.h>
22#endif
23
24#ifdef QT_STATIC
25#include <QtPlugin>
26#ifdef Q_OS_WIN
27Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
28#ifdef BUILD_QT_MULTIMEDIA
29Q_IMPORT_PLUGIN(QWindowsAudioPlugin);
30#endif
31#elif defined(Q_OS_MAC)
32Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
33#ifdef BUILD_QT_MULTIMEDIA
34Q_IMPORT_PLUGIN(CoreAudioPlugin);
35Q_IMPORT_PLUGIN(AVFServicePlugin);
36#endif
37#endif
38#endif
39
40using namespace QGBA;
41
42int main(int argc, char* argv[]) {
43#if defined(BUILD_SDL) && SDL_VERSION_ATLEAST(2, 0, 0)
44	SDL_SetMainReady();
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	GBAApp application(argc, argv, &configController);
66
67	QTranslator qtTranslator;
68	qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
69	application.installTranslator(&qtTranslator);
70
71#ifdef QT_STATIC
72	QTranslator qtStaticTranslator;
73	qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
74	application.installTranslator(&qtStaticTranslator);
75#endif
76
77	QTranslator langTranslator;
78	langTranslator.load(locale, binaryName, "-", ":/translations/");
79	application.installTranslator(&langTranslator);
80
81	Window* w = application.newWindow();
82	if (loaded) {
83		w->argumentsPassed(&args);
84	} else {
85		w->loadConfig();
86	}
87	freeArguments(&args);
88
89	if (graphicsOpts.multiplier) {
90		w->resizeFrame(QSize(VIDEO_HORIZONTAL_PIXELS * graphicsOpts.multiplier, VIDEO_VERTICAL_PIXELS * graphicsOpts.multiplier));
91	}
92	if (graphicsOpts.fullscreen) {
93		w->enterFullScreen();
94	}
95
96	w->show();
97
98	return application.exec();
99}