all repos — mgba @ 42db8282350df4b2679c7bc4c7d631df0472af5b

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	struct LibraryColumn {
 54		QString name;
 55		std::function<QString(const mLibraryEntry&)> value;
 56	};
 57
 58	class LibraryHandle {
 59	public:
 60		LibraryHandle(mLibrary*, const QString& path = QString());
 61		~LibraryHandle();
 62
 63		mLibrary* const library;
 64		LibraryLoader* const loader;
 65		const QString path;
 66
 67		void ref();
 68		bool deref();
 69
 70	private:
 71		QThread m_loaderThread;
 72		size_t m_ref;
 73	};
 74
 75	LibraryHandle* m_library;
 76	static QMap<QString, LibraryHandle*> s_handles;
 77
 78	mLibraryEntry m_constraints;
 79	QStringList m_queue;
 80
 81	QList<LibraryColumn> m_columns;
 82	static QMap<QString, LibraryColumn> s_columns;
 83};
 84
 85class LibraryLoader : public QObject {
 86Q_OBJECT
 87
 88public:
 89	LibraryLoader(mLibrary* library, QObject* parent = nullptr);
 90
 91public slots:
 92	void loadDirectory(const QString& path);
 93
 94signals:
 95	void directoryLoaded(const QString& path);
 96
 97private:
 98	mLibrary* m_library;
 99};
100
101}
102
103#endif