all repos — mgba @ 6f7573dda4eea59cd2ea8291890476861281ddaa

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