all repos — mgba @ 2e2c2e8386344915dde93396b35eed7af401c9fc

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