Changeset View
Changeset View
Standalone View
Standalone View
src/filepicker/lib/dirmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Linus Jahn <lnj@kaidan.im> | ||||
3 | * Copyright 2019 Jonah Brüchert <jbb@kaidan.im> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License or (at your option) version 3 or any later version | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | * defined in Section 14 of version 3 of the license. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | */ | ||||
21 | | ||||
22 | #ifndef DIRMODEL_H | ||||
23 | #define DIRMODEL_H | ||||
24 | | ||||
25 | #include <QAbstractListModel> | ||||
26 | #include <QVariant> | ||||
27 | #include <KIOCore/KFileItem> | ||||
28 | class KCoreDirLister; | ||||
29 | class KFileItemList; | ||||
30 | | ||||
31 | class DirModel : public QAbstractListModel | ||||
32 | { | ||||
33 | Q_OBJECT | ||||
34 | Q_PROPERTY(const QUrl& folder READ folder WRITE setFolder NOTIFY folderChanged) | ||||
35 | Q_PROPERTY(bool showDotFiles READ showDotFiles WRITE setShowDotFiles NOTIFY showDotFilesChanged) | ||||
36 | Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged) | ||||
37 | Q_PROPERTY(QString nameFilter READ nameFilter NOTIFY nameFilterChanged) | ||||
38 | Q_PROPERTY(QStringList mimeFilters READ mimeFilters NOTIFY mimeFiltersChanged) | ||||
39 | | ||||
40 | public: | ||||
41 | enum Roles { | ||||
42 | Name = Qt::UserRole + 1, | ||||
43 | Url, | ||||
44 | IconName, | ||||
45 | IsDir, | ||||
46 | IsLink, | ||||
47 | FileSize, | ||||
48 | MimeType, | ||||
49 | IsHidden, | ||||
50 | IsReadable, | ||||
51 | IsWritable, | ||||
52 | ModificationTime | ||||
53 | }; | ||||
54 | | ||||
55 | Q_ENUM(Roles) | ||||
56 | | ||||
57 | explicit DirModel(QObject *parent = nullptr); | ||||
58 | | ||||
59 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
60 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
61 | | ||||
62 | QHash<int, QByteArray> roleNames() const override; | ||||
63 | | ||||
64 | QUrl folder() const; | ||||
65 | void setFolder(const QUrl &folder); | ||||
66 | | ||||
67 | bool showDotFiles() const; | ||||
68 | void setShowDotFiles(bool showDotFiles); | ||||
69 | | ||||
70 | bool isLoading() const; | ||||
71 | void setIsLoading(bool isLoading); | ||||
72 | | ||||
73 | QString nameFilter() const; | ||||
74 | void setNameFilter(const QString &nameFilter); | ||||
75 | | ||||
76 | QStringList mimeFilters() const; | ||||
77 | void setMimeFilters(const QStringList &mimeFilters); | ||||
78 | | ||||
79 | Q_SIGNALS: | ||||
80 | void folderChanged(); | ||||
81 | void showDotFilesChanged(); | ||||
82 | void isLoadingChanged(); | ||||
83 | void nameFilterChanged(); | ||||
84 | void mimeFiltersChanged(); | ||||
85 | | ||||
86 | private Q_SLOTS: | ||||
87 | void handleCompleted(); | ||||
88 | void handleNewItems(const KFileItemList &items); | ||||
89 | void handleItemsDeleted(const KFileItemList &items); | ||||
90 | void handleRedirection(const QUrl &oldUrl, const QUrl &newUrl); | ||||
91 | | ||||
92 | private: | ||||
93 | KCoreDirLister *m_lister; | ||||
94 | QVector<KFileItem> m_items; | ||||
95 | | ||||
96 | QUrl m_folder; | ||||
97 | bool m_showDotFiles; | ||||
98 | bool m_isLoading; | ||||
99 | QString m_nameFilter; | ||||
100 | QStringList m_mimeFilters; | ||||
101 | }; | ||||
102 | | ||||
103 | #endif // DIRMODEL_H |