all repos — mgba @ 709149458319ec6bdf1a95c615a3ce5a6bbe1cb0

mGBA Game Boy Advance Emulator

src/platform/qt/GBAApp.h (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#pragma once
  7
  8#include <QApplication>
  9#include <QFileDialog>
 10#include <QList>
 11#include <QMap>
 12#include <QMultiMap>
 13#include <QObject>
 14#include <QRunnable>
 15#include <QString>
 16#include <QThreadPool>
 17
 18#include <functional>
 19
 20#include "CoreManager.h"
 21#include "MultiplayerController.h"
 22
 23struct NoIntroDB;
 24
 25#include <mgba/core/log.h>
 26
 27mLOG_DECLARE_CATEGORY(QT);
 28
 29namespace QGBA {
 30
 31class ConfigController;
 32class CoreController;
 33class Window;
 34
 35#ifdef USE_SQLITE3
 36class GameDBParser : public QObject {
 37Q_OBJECT
 38
 39public:
 40	GameDBParser(NoIntroDB* db, QObject* parent = nullptr);
 41
 42public slots:
 43	void parseNoIntroDB();
 44
 45private:
 46	NoIntroDB* m_db;
 47};
 48#endif
 49
 50class GBAApp : public QApplication {
 51Q_OBJECT
 52
 53public:
 54	GBAApp(int& argc, char* argv[], ConfigController*);
 55	static GBAApp* app();
 56
 57	static QString dataDir();
 58
 59	Window* newWindow();
 60
 61	QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString());
 62	QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = QString());
 63	QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString());
 64	QString getOpenDirectoryName(QWidget* owner, const QString& title);
 65
 66	const NoIntroDB* gameDB() const { return m_db; }
 67	bool reloadGameDB();
 68
 69	qint64 submitWorkerJob(std::function<void ()> job, std::function<void ()> callback = {});
 70	qint64 submitWorkerJob(std::function<void ()> job, QObject* context, std::function<void ()> callback);
 71	bool removeWorkerJob(qint64 jobId);
 72	bool waitOnJob(qint64 jobId, QObject* context, std::function<void ()> callback);
 73
 74signals:
 75	void jobFinished(qint64 jobId);
 76
 77protected:
 78	bool event(QEvent*);
 79
 80private slots:
 81	void finishJob(qint64 jobId);
 82	void cleanup();
 83
 84private:
 85	class WorkerJob : public QRunnable {
 86	public:
 87		WorkerJob(qint64 id, std::function<void ()> job, GBAApp* owner);
 88
 89	public:
 90		void run() override;
 91
 92	private:
 93		qint64 m_id;
 94		std::function<void ()> m_job;
 95		GBAApp* m_owner;
 96	};
 97
 98	Window* newWindowInternal();
 99
100	void pauseAll(QList<Window*>* paused);
101	void continueAll(const QList<Window*>& paused);
102
103	ConfigController* m_configController;
104	QList<Window*> m_windows;
105	MultiplayerController m_multiplayer;
106	CoreManager m_manager;
107
108	QMap<qint64, WorkerJob*> m_workerJobs;
109	QMultiMap<qint64, QMetaObject::Connection> m_workerJobCallbacks;
110	QThreadPool m_workerThreads;
111	qint64 m_nextJob = 1;
112
113	NoIntroDB* m_db = nullptr;
114};
115
116}