all repos — mgba @ a0f70c361fa28d73704bce2c0147e6715a0edf9a

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