Changeset View
Changeset View
Standalone View
Standalone View
kcms/baloo/filteredfoldermodel.h
- This file was moved from kcms/baloo/folderselectionwidget.h.
Show All 15 Lines | |||||
16 | * License along with this library; if not, write to the Free Software | 16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | * | 18 | * | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef FOLDERSELECTIONWIDGET_H | 21 | #ifndef FOLDERSELECTIONWIDGET_H | ||
22 | #define FOLDERSELECTIONWIDGET_H | 22 | #define FOLDERSELECTIONWIDGET_H | ||
23 | 23 | | |||
24 | #include <QWidget> | 24 | #include <QAbstractListModel> | ||
25 | #include <QListWidget> | | |||
26 | #include <QPushButton> | | |||
27 | #include <KMessageWidget> | | |||
28 | 25 | | |||
29 | class FolderSelectionWidget : public QWidget | 26 | class FilteredFolderModel : public QAbstractListModel | ||
30 | { | 27 | { | ||
31 | Q_OBJECT | 28 | Q_OBJECT | ||
32 | public: | 29 | public: | ||
33 | explicit FolderSelectionWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); | 30 | explicit FilteredFolderModel(QObject* parent); | ||
34 | 31 | | |||
35 | void setDirectoryList(QStringList includeDirs, QStringList exclude); | 32 | void setDirectoryList(const QStringList& includeDirs, const QStringList& exclude); | ||
36 | QStringList includeFolders() const; | 33 | QStringList includeFolders() const; | ||
37 | QStringList excludeFolders() const; | 34 | QStringList excludeFolders() const; | ||
38 | 35 | | |||
39 | enum Roles { | 36 | enum Roles { | ||
40 | UrlRole = Qt::UserRole + 1 | 37 | Folder = Qt::UserRole + 1, | ||
38 | Url | ||||
41 | }; | 39 | }; | ||
42 | 40 | | |||
43 | Q_SIGNALS: | 41 | QVariant data(const QModelIndex& idx, int role) const override; | ||
44 | void changed(); | 42 | int rowCount(const QModelIndex& parent) const override; | ||
45 | | ||||
46 | private Q_SLOTS: | | |||
47 | void slotAddButtonClicked(); | | |||
48 | void slotRemoveButtonClicked(); | | |||
49 | void slotCurrentItemChanged(QListWidgetItem* current, QListWidgetItem*); | | |||
50 | 43 | | |||
44 | Q_INVOKABLE void addFolder(const QString& folder); | ||||
45 | Q_INVOKABLE void removeFolder(int row); | ||||
46 | QHash<int, QByteArray> roleNames() const override; | ||||
51 | private: | 47 | private: | ||
52 | QString folderDisplayName(const QString& url) const; | 48 | QString folderDisplayName(const QString& url) const; | ||
53 | bool shouldShowMountPoint(const QString& mountPoint); | 49 | bool shouldShowMountPoint(const QString& mountPoint); | ||
54 | QString fetchMountPoint(const QString& url) const; | 50 | QString fetchMountPoint(const QString& url) const; | ||
55 | void showMessage(const QString& message); | 51 | void showMessage(const QString& message); | ||
56 | 52 | | |||
57 | /** | 53 | /** | ||
58 | * @brief Get the theme valid icon name for \p path. | 54 | * @brief Get the theme valid icon name for \p path. | ||
59 | * | 55 | * | ||
60 | * @param path Path to be analysed. | 56 | * @param path Path to be analysed. | ||
61 | * @return One of: "user-home", "drive-harddisk" or "folder" | 57 | * @return One of: "user-home", "drive-harddisk" or "folder" | ||
62 | */ | 58 | */ | ||
63 | QString iconName(QString path) const; | 59 | QString iconName(QString path) const; | ||
64 | 60 | | |||
65 | /** | 61 | /** | ||
66 | * @brief Widget with the list of directories. | 62 | * @brief Widget with the list of directories. | ||
67 | * | 63 | * | ||
68 | */ | 64 | */ | ||
69 | QListWidget* m_listWidget; | | |||
70 | QStringList m_mountPoints; | 65 | QStringList m_mountPoints; | ||
71 | 66 | QStringList m_excludeList; | |||
72 | /** | | |||
73 | * @brief Button to add a directory to the list. | | |||
74 | * | | |||
75 | */ | | |||
76 | QPushButton* m_addButton; | | |||
77 | /** | | |||
78 | * @brief Button to remove the selected directory from the list. | | |||
79 | * | | |||
80 | */ | | |||
81 | QPushButton* m_removeButton; | | |||
82 | | ||||
83 | /** | | |||
84 | * @brief Information, warning or error message widget. | | |||
85 | * | | |||
86 | */ | | |||
87 | KMessageWidget* m_messageWidget; | | |||
88 | }; | 67 | }; | ||
89 | 68 | | |||
90 | #endif // FOLDERSELECTIONWIDGET_H | 69 | #endif // FOLDERSELECTIONWIDGET_H |