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 QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString());
63 QString getOpenDirectoryName(QWidget* owner, const QString& title);
64
65 const NoIntroDB* gameDB() const { return m_db; }
66 bool reloadGameDB();
67
68 qint64 submitWorkerJob(std::function<void ()> job, std::function<void ()> callback = {});
69 qint64 submitWorkerJob(std::function<void ()> job, QObject* context, std::function<void ()> callback);
70 bool removeWorkerJob(qint64 jobId);
71 bool waitOnJob(qint64 jobId, QObject* context, std::function<void ()> callback);
72
73signals:
74 void jobFinished(qint64 jobId);
75
76protected:
77 bool event(QEvent*);
78
79private slots:
80 void finishJob(qint64 jobId);
81 void cleanup();
82
83private:
84 class WorkerJob : public QRunnable {
85 public:
86 WorkerJob(qint64 id, std::function<void ()> job, GBAApp* owner);
87
88 public:
89 void run() override;
90
91 private:
92 qint64 m_id;
93 std::function<void ()> m_job;
94 GBAApp* m_owner;
95 };
96
97 Window* newWindowInternal();
98
99 void pauseAll(QList<Window*>* paused);
100 void continueAll(const QList<Window*>& paused);
101
102 ConfigController* m_configController;
103 QList<Window*> m_windows;
104 MultiplayerController m_multiplayer;
105 CoreManager m_manager;
106
107 QMap<qint64, WorkerJob*> m_workerJobs;
108 QMultiMap<qint64, QMetaObject::Connection> m_workerJobCallbacks;
109 QThreadPool m_workerThreads;
110 qint64 m_nextJob = 1;
111
112 NoIntroDB* m_db = nullptr;
113};
114
115}