Changeset View
Changeset View
Standalone View
Standalone View
src/contentlist/ContentList.h
Show All 17 Lines | |||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef CONTENTLISTBASE_H | 22 | #ifndef CONTENTLISTBASE_H | ||
23 | #define CONTENTLISTBASE_H | 23 | #define CONTENTLISTBASE_H | ||
24 | 24 | | |||
25 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> | ||
26 | #include <QQmlListProperty> | ||||
27 | #include <QQmlParserStatus> | ||||
26 | 28 | | |||
27 | class ContentList : public QAbstractListModel | 29 | #include "ContentQuery.h" | ||
30 | | ||||
31 | class ContentList : public QAbstractListModel, public QQmlParserStatus | ||||
28 | { | 32 | { | ||
29 | Q_OBJECT | 33 | Q_OBJECT | ||
34 | Q_CLASSINFO("DefaultProperty", "queries") | ||||
35 | Q_PROPERTY(QQmlListProperty<ContentQuery> queries READ queries) | ||||
36 | Q_PROPERTY(bool autoSearch READ autoSearch WRITE setAutoSearch NOTIFY autoSearchChanged) | ||||
37 | Q_PROPERTY(bool cacheResults READ cacheResults WRITE setCacheResults NOTIFY cacheResultsChanged) | ||||
30 | public: | 38 | public: | ||
31 | explicit ContentList(QObject* parent = nullptr); | 39 | explicit ContentList(QObject* parent = nullptr); | ||
32 | ~ContentList() override; | 40 | ~ContentList() override; | ||
33 | 41 | | |||
34 | Q_INVOKABLE static QString getMimetype(QString filePath); | | |||
35 | | ||||
36 | Q_SLOT void addLocation(QString path); | | |||
37 | Q_SLOT void addMimetype(QString mimetype); | | |||
38 | Q_SLOT void setSearchString(const QString& searchString); | | |||
39 | Q_SLOT void setKnownFiles(QStringList knownFiles); | | |||
40 | Q_SLOT void startSearch(); | | |||
41 | | ||||
42 | enum Roles { | 42 | enum Roles { | ||
43 | FilenameRole = Qt::UserRole + 1, | 43 | FilenameRole = Qt::UserRole + 1, | ||
44 | FilePathRole, | ||||
44 | MetadataRole | 45 | MetadataRole | ||
45 | }; | 46 | }; | ||
46 | 47 | | |||
48 | QQmlListProperty<ContentQuery> queries(); | ||||
49 | | ||||
50 | bool autoSearch() const; | ||||
51 | bool cacheResults() const; | ||||
52 | | ||||
47 | QHash<int, QByteArray> roleNames() const override; | 53 | QHash<int, QByteArray> roleNames() const override; | ||
48 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 54 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
49 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 55 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
50 | 56 | | |||
51 | Q_SLOT void fileFound(const QString& filePath, const QVariantHash& metaData); | 57 | void classBegin() override; | ||
58 | void componentComplete() override; | ||||
59 | | ||||
60 | Q_SLOT void setAutoSearch(bool autoSearch); | ||||
61 | Q_SLOT void setCacheResults(bool cacheResults); | ||||
62 | | ||||
63 | Q_SLOT void setKnownFiles(const QStringList& results); | ||||
64 | Q_SLOT void startSearch(); | ||||
65 | | ||||
66 | Q_SIGNAL void autoSearchChanged(); | ||||
67 | Q_SIGNAL void cacheResultsChanged(); | ||||
52 | Q_SIGNAL void searchCompleted(); | 68 | Q_SIGNAL void searchCompleted(); | ||
69 | | ||||
70 | Q_INVOKABLE static QString getMimetype(QString filePath); | ||||
71 | | ||||
53 | private: | 72 | private: | ||
73 | bool isComplete() const; | ||||
74 | Q_SLOT void fileFound(const QString& filePath, const QVariantMap& metaData); | ||||
75 | | ||||
54 | class Private; | 76 | class Private; | ||
55 | Private* d; | 77 | Private* d; | ||
56 | }; | 78 | }; | ||
57 | 79 | | |||
58 | #endif//CONTENTLISTBASE_H | 80 | #endif//CONTENTLISTBASE_H |