all repos — mgba @ 253719d7a14e0002c8e987beff4c6a6a3604704f

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