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 struct LibraryColumn {
54 QString name;
55 std::function<QString(const mLibraryEntry&)> value;
56 };
57
58 mLibrary* m_library;
59 mLibraryEntry m_constraints;
60 LibraryLoader* m_loader;
61 QThread m_loaderThread;
62 QStringList m_queue;
63
64 QList<LibraryColumn> m_columns;
65 static QMap<QString, LibraryColumn> s_columns;
66};
67
68class LibraryLoader : public QObject {
69Q_OBJECT
70
71public:
72 LibraryLoader(mLibrary* library, QObject* parent = nullptr);
73
74public slots:
75 void loadDirectory(const QString& path);
76
77signals:
78 void directoryLoaded(const QString& path);
79
80private:
81 mLibrary* m_library;
82};
83
84}
85
86#endif