src/platform/qt/GBAApp.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#include "GBAApp.h"
7
8#include "AudioProcessor.h"
9#include "GameController.h"
10
11#include <QFileOpenEvent>
12
13extern "C" {
14#include "platform/commandline.h"
15}
16
17using namespace QGBA;
18
19GBAApp::GBAApp(int& argc, char* argv[])
20 : QApplication(argc, argv)
21 , m_window(&m_configController)
22{
23#ifdef BUILD_SDL
24 SDL_Init(SDL_INIT_NOPARACHUTE);
25#endif
26
27 QApplication::setApplicationName(PROJECT_NAME);
28 QApplication::setApplicationVersion(PROJECT_VERSION);
29
30#ifndef Q_OS_MAC
31 m_window.show();
32#endif
33
34 GBAArguments args = {};
35 if (m_configController.parseArguments(&args, argc, argv)) {
36 m_window.argumentsPassed(&args);
37 } else {
38 m_window.loadConfig();
39 }
40 freeArguments(&args);
41
42 AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController.getQtOption("audioDriver").toInt()));
43 m_window.controller()->reloadAudioDriver();
44
45#ifdef Q_OS_MAC
46 m_window.show();
47#endif
48}
49
50bool GBAApp::event(QEvent* event) {
51 if (event->type() == QEvent::FileOpen) {
52 m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());
53 return true;
54 }
55 return QApplication::event(event);
56}