all repos — mgba @ 8aa5880afd76a2fa25ab6c702fab886d17494057

mGBA Game Boy Advance Emulator

Support FileOpen events on OS X
Jeffrey Pfau jeffrey@endrift.com
Sat, 18 Oct 2014 23:18:08 -0700
commit

8aa5880afd76a2fa25ab6c702fab886d17494057

parent

8fc3ef27ad646863b156cb68e122eeadc0301f67

M res/info.plist.inres/info.plist.in

@@ -28,5 +28,18 @@ <key>NSHighResolutionCapable</key>

<true/> <key>NSHumanReadableCopyright</key> <string>${MACOSX_BUNDLE_COPYRIGHT}</string> + <key>CFBundleDocumentTypes</key> + <array> + <dict> + <key>CFBundleTypeExtensions</key> + <array> + <string>gba</string> + </array> + <key>CFBundleTypeName</key> + <string>Game Boy Advance ROM Image</string> + <key>CFBundleTypeRole</key> + <string>Viewer</string> + </dict> + </array> </dict> </plist>
M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -28,6 +28,7 @@ set(SOURCE_FILES

AudioDevice.cpp AudioProcessor.cpp Display.cpp + GBAApp.cpp GameController.cpp LoadSaveState.cpp LogView.cpp
A src/platform/qt/GBAApp.cpp

@@ -0,0 +1,32 @@

+#include "GBAApp.h" + +#include "GameController.h" + +#include <QFileOpenEvent> + +using namespace QGBA; + +GBAApp::GBAApp(int& argc, char* argv[]) + : QApplication(argc, argv) +{ + QApplication::setApplicationName(PROJECT_NAME); + QApplication::setApplicationVersion(PROJECT_VERSION); + + if (parseCommandArgs(&m_opts, argc, argv, 0)) { + m_window.optionsPassed(&m_opts); + } + + m_window.show(); +} + +GBAApp::~GBAApp() { + freeOptions(&m_opts); +} + +bool GBAApp::event(QEvent* event) { + if (event->type() == QEvent::FileOpen) { + m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file()); + return true; + } + return QApplication::event(event); +}
A src/platform/qt/GBAApp.h

@@ -0,0 +1,34 @@

+#ifndef QGBA_APP_H +#define QGBA_APP_H + +#include <QApplication> + +#include "Window.h" + +extern "C" { +#include "platform/commandline.h" +} + +namespace QGBA { + +class GameController; + +class GBAApp : public QApplication { +Q_OBJECT + +public: + GBAApp(int& argc, char* argv[]); + virtual ~GBAApp(); + +protected: + bool event(QEvent*); + +private: + Window m_window; + + StartupOptions m_opts; +}; + +} + +#endif
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -26,6 +26,8 @@ public:

Window(QWidget* parent = nullptr); virtual ~Window(); + GameController* controller() { return m_controller; } + static GBAKey mapKey(int qtKey); void optionsPassed(StartupOptions*);
M src/platform/qt/main.cppsrc/platform/qt/main.cpp

@@ -1,24 +1,7 @@

-#include <QApplication> +#include "GBAApp.h" #include "Window.h" - -extern "C" { -#include "platform/commandline.h" -} int main(int argc, char* argv[]) { - QApplication application(argc, argv); - QApplication::setApplicationName(PROJECT_NAME); - QApplication::setApplicationVersion(PROJECT_VERSION); - - QGBA::Window window; - - struct StartupOptions opts; - if (parseCommandArgs(&opts, argc, argv, 0)) { - window.optionsPassed(&opts); - } - window.show(); - - int rcode = application.exec(); - freeOptions(&opts); - return rcode; + QGBA::GBAApp application(argc, argv); + return application.exec(); }