GameTracker: use WorkQueueThread

This commit is contained in:
Michael M 2017-08-20 14:06:33 -07:00
parent de9378bf63
commit 8c13e0230c
3 changed files with 9 additions and 40 deletions

View File

@ -35,7 +35,7 @@ public:
{
{
std::unique_lock<std::mutex> lg(m_lock);
m_items.emplace(std::move(args)...);
m_items.emplace(std::forward<Args>(args)...);
}
m_wakeup.Set();
}

View File

@ -17,23 +17,11 @@ static const QStringList game_filters{
GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
{
m_loader = new GameLoader;
m_loader->moveToThread(&m_loader_thread);
qRegisterMetaType<QSharedPointer<GameFile>>();
connect(&m_loader_thread, &QThread::finished, m_loader, &QObject::deleteLater);
connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory);
connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile);
connect(this, &GameTracker::PathChanged, m_loader, &GameLoader::LoadGame);
connect(m_loader, &GameLoader::GameLoaded, this, &GameTracker::GameLoaded);
m_loader_thread.start();
}
GameTracker::~GameTracker()
{
m_loader_thread.quit();
m_loader_thread.wait();
m_load_thread.Reset([this](const QString& path) { LoadGame(path); });
}
void GameTracker::AddDirectory(const QString& dir)
@ -81,7 +69,7 @@ void GameTracker::UpdateDirectory(const QString& dir)
{
addPath(path);
m_tracked_files[path] = QSet<QString>{dir};
emit PathChanged(path);
m_load_thread.EmplaceItem(path);
}
}
@ -127,7 +115,7 @@ void GameTracker::UpdateFile(const QString& file)
GameRemoved(file);
addPath(file);
emit PathChanged(file);
m_load_thread.EmplaceItem(file);
}
else if (removePath(file))
{
@ -136,7 +124,7 @@ void GameTracker::UpdateFile(const QString& file)
}
}
void GameLoader::LoadGame(const QString& path)
void GameTracker::LoadGame(const QString& path)
{
if (!DiscIO::ShouldHideFromGameList(path.toStdString()))
{

View File

@ -9,25 +9,19 @@
#include <QSet>
#include <QSharedPointer>
#include <QString>
#include <QStringList>
#include <QThread>
#include "Common/WorkQueueThread.h"
#include "DolphinQt2/GameList/GameFile.h"
class GameLoader;
// Watches directories and loads GameFiles in a separate thread.
// To use this, just add directories using AddDirectory, and listen for the
// GameLoaded and GameRemoved signals. Ignore the PathChanged signal, it's
// only there because the Qt people made fileChanged and directoryChanged
// private.
// GameLoaded and GameRemoved signals.
class GameTracker final : public QFileSystemWatcher
{
Q_OBJECT
public:
explicit GameTracker(QObject* parent = nullptr);
~GameTracker();
void AddDirectory(const QString& dir);
void RemoveDirectory(const QString& dir);
@ -36,28 +30,15 @@ signals:
void GameLoaded(QSharedPointer<GameFile> game);
void GameRemoved(const QString& path);
void PathChanged(const QString& path);
private:
void LoadGame(const QString& path);
void UpdateDirectory(const QString& dir);
void UpdateFile(const QString& path);
QSet<QString> FindMissingFiles(const QString& dir);
// game path -> directories that track it
QMap<QString, QSet<QString>> m_tracked_files;
QThread m_loader_thread;
GameLoader* m_loader;
};
class GameLoader final : public QObject
{
Q_OBJECT
public:
void LoadGame(const QString& path);
signals:
void GameLoaded(QSharedPointer<GameFile> game);
Common::WorkQueueThread<QString> m_load_thread;
};
Q_DECLARE_METATYPE(QSharedPointer<GameFile>)