all repos — mgba @ d8687d32c49e75c5f665df10a92d1b0a9e10687f

mGBA Game Boy Advance Emulator

src/platform/qt/LibraryModel.h (view raw)

 1/* Copyright (c) 2013-2016 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#ifndef QGBA_LIBRARY_MODEL
 7#define QGBA_LIBRARY_MODEL
 8
 9#include <QAbstractItemModel>
10#include <QStringList>
11#include <QThread>
12
13#include <mgba/core/library.h>
14
15struct VDir;
16struct VFile;
17
18namespace QGBA {
19
20class LibraryLoader;
21class LibraryModel : public QAbstractItemModel {
22Q_OBJECT
23
24public:
25	LibraryModel(const QString& path, QObject* parent = nullptr);
26	virtual ~LibraryModel();
27
28	bool entryAt(int row, mLibraryEntry* out) const;
29	VFile* openVFile(const QModelIndex& index) const;
30
31	virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
32	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
33
34	virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
35	virtual QModelIndex parent(const QModelIndex& index) const override;
36
37	virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
38	virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
39
40signals:
41	void doneLoading();
42
43public slots:
44	void loadDirectory(const QString& path);
45
46	void constrainBase(const QString& path);
47	void clearConstraints();
48
49private slots:
50	void directoryLoaded(const QString& path);
51
52private:
53	mLibrary* m_library;
54	mLibraryEntry m_constraints;
55	LibraryLoader* m_loader;
56	QThread m_loaderThread;
57	QStringList m_queue;
58};
59
60class LibraryLoader : public QObject {
61Q_OBJECT
62
63public:
64	LibraryLoader(mLibrary* library, QObject* parent = nullptr);
65
66public slots:
67	void loadDirectory(const QString& path);
68
69signals:
70	void directoryLoaded(const QString& path);
71
72private:
73	mLibrary* m_library;
74};
75
76}
77
78#endif