all repos — mgba @ 71379aac66f002e8bc87bc3bc936fbfc4b688b27

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