Qt: Load No-Intro DB on a thread
Jeffrey Pfau jeffrey@endrift.com
Tue, 10 Jan 2017 20:13:34 -0800
3 files changed,
59 insertions(+),
7 deletions(-)
M
src/feature/sqlite3/no-intro.c
→
src/feature/sqlite3/no-intro.c
@@ -19,7 +19,7 @@
struct NoIntroDB* NoIntroDBLoad(const char* path) { struct NoIntroDB* db = malloc(sizeof(*db)); - if (sqlite3_open(path, &db->db)) { + if (sqlite3_open_v2(path, &db->db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL)) { goto error; }
M
src/platform/qt/GBAApp.cpp
→
src/platform/qt/GBAApp.cpp
@@ -105,6 +105,11 @@ w->controller()->setMultiplayerController(&m_multiplayer);
w->multiplayerChanged(); } +GBAApp::~GBAApp() { + m_parseThread.quit(); + m_parseThread.wait(); +} + bool GBAApp::event(QEvent* event) { if (event->type() == QEvent::FileOpen) { m_windows[0]->controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());@@ -208,25 +213,32 @@ #endif
return path; } -bool GBAApp::reloadGameDB() { #ifdef USE_SQLITE3 +bool GBAApp::reloadGameDB() { NoIntroDB* db = nullptr; db = NoIntroDBLoad((m_configController.configDir() + "/nointro.sqlite3").toLocal8Bit().constData()); if (db && m_db) { NoIntroDBDestroy(m_db); } if (db) { - VFile* vf = VFileDevice::open(dataDir() + "/nointro.dat", O_RDONLY); - if (vf) { - NoIntroDBLoadClrMamePro(db, vf); - vf->close(vf); + if (m_parseThread.isRunning()) { + m_parseThread.quit(); + m_parseThread.wait(); } + GameDBParser* parser = new GameDBParser(db); + m_parseThread.start(); + parser->moveToThread(&m_parseThread); + QMetaObject::invokeMethod(parser, "parseNoIntroDB"); m_db = db; return true; } -#endif + return false; +} +#else +bool GBAApp::loadGameDB() { return false; } +#endif GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& caption, const QString& filter) : QFileDialog(parent, caption, app->m_configController.getOption("lastDirectory"), filter)@@ -245,3 +257,21 @@ }
m_app->continueAll(&paused); return didAccept; } + +#ifdef USE_SQLITE3 +GameDBParser::GameDBParser(NoIntroDB* db, QObject* parent) + : QObject(parent) + , m_db(db) +{ + // Nothing to do +} + +void GameDBParser::parseNoIntroDB() { + VFile* vf = VFileDevice::open(GBAApp::dataDir() + "/nointro.dat", O_RDONLY); + if (vf) { + NoIntroDBLoadClrMamePro(m_db, vf); + vf->close(vf); + } +} + +#endif
M
src/platform/qt/GBAApp.h
→
src/platform/qt/GBAApp.h
@@ -8,6 +8,7 @@ #define QGBA_APP_H
#include <QApplication> #include <QFileDialog> +#include <QThread> #include "ConfigController.h" #include "MultiplayerController.h"@@ -23,11 +24,28 @@
class GameController; class Window; +#ifdef USE_SQLITE3 +class GameDBParser : public QObject { +Q_OBJECT + +public: + GameDBParser(NoIntroDB* db, QObject* parent = nullptr); + +public slots: + void parseNoIntroDB(); + +private: + NoIntroDB* m_db; +}; +#endif + + class GBAApp : public QApplication { Q_OBJECT public: GBAApp(int& argc, char* argv[]); + ~GBAApp(); static GBAApp* app(); static QString dataDir();@@ -66,7 +84,11 @@
ConfigController m_configController; Window* m_windows[MAX_GBAS]; MultiplayerController m_multiplayer; + +#ifdef USE_SQLITE3 NoIntroDB* m_db; + QThread m_parseThread; +#endif }; }