1 | /* This file is part of the KDE project |
2 | Copyright (C) 2007 Kevin Ottens <ervin@kde.org> |
3 | Copyright (C) 2007 David Faure <faure@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | |
19 | */ |
20 | #ifndef KFILEPLACESMODEL_H |
21 | #define KFILEPLACESMODEL_H |
22 | |
23 | #include <kfile_export.h> |
24 | |
25 | #include <QtCore/QAbstractItemModel> |
26 | #include <kurl.h> |
27 | #include <kbookmark.h> |
28 | #include <kicon.h> |
29 | |
30 | #include <solid/device.h> |
31 | |
32 | class QMimeData; |
33 | class QAction; |
34 | |
35 | /** |
36 | * This class is a list view model. Each entry represents a "place" |
37 | * where user can access files. Only revelant when |
38 | * used with QListView or QTableView. |
39 | */ |
40 | class KFILE_EXPORT KFilePlacesModel : public QAbstractItemModel |
41 | { |
42 | Q_OBJECT |
43 | public: |
44 | enum AdditionalRoles { |
45 | UrlRole = 0x069CD12B, |
46 | HiddenRole = 0x0741CAAC, |
47 | SetupNeededRole = 0x059A935D, |
48 | FixedDeviceRole = 0x332896C1, |
49 | CapacityBarRecommendedRole = 0x1548C5C4 |
50 | }; |
51 | |
52 | KFilePlacesModel(QObject *parent=0); |
53 | ~KFilePlacesModel(); |
54 | |
55 | KUrl url(const QModelIndex &index) const; |
56 | bool setupNeeded(const QModelIndex &index) const; |
57 | KIcon icon(const QModelIndex &index) const; |
58 | QString text(const QModelIndex &index) const; |
59 | bool isHidden(const QModelIndex &index) const; |
60 | bool isDevice(const QModelIndex &index) const; |
61 | Solid::Device deviceForIndex(const QModelIndex &index) const; |
62 | KBookmark bookmarkForIndex(const QModelIndex &index) const; |
63 | |
64 | QAction *teardownActionForIndex(const QModelIndex &index) const; |
65 | QAction *ejectActionForIndex(const QModelIndex &index) const; |
66 | void requestTeardown(const QModelIndex &index); |
67 | void requestEject(const QModelIndex &index); |
68 | void requestSetup(const QModelIndex &index); |
69 | |
70 | void addPlace(const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString()); |
71 | void addPlace(const QString &text, const KUrl &url, const QString &iconName, const QString &appName, const QModelIndex &after); |
72 | void editPlace(const QModelIndex &index, const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString()); |
73 | void removePlace(const QModelIndex &index) const; |
74 | void setPlaceHidden(const QModelIndex &index, bool hidden); |
75 | |
76 | int hiddenCount() const; |
77 | |
78 | /** |
79 | * @brief Get a visible data based on Qt role for the given index. |
80 | * Return the device information for the give index. |
81 | * |
82 | * @param index The QModelIndex which contains the row, column to fetch the data. |
83 | * @param role The Interview data role(ex: Qt::DisplayRole). |
84 | * |
85 | * @return the data for the given index and role. |
86 | */ |
87 | QVariant data(const QModelIndex &index, int role) const; |
88 | |
89 | /** |
90 | * @brief Get the children model index for the given row and column. |
91 | */ |
92 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
93 | |
94 | /** |
95 | * @brief Get the parent QModelIndex for the given model child. |
96 | */ |
97 | QModelIndex parent(const QModelIndex &child) const; |
98 | |
99 | /** |
100 | * @brief Get the number of rows for a model index. |
101 | */ |
102 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
103 | |
104 | /** |
105 | * @brief Get the number of columns for a model index. |
106 | */ |
107 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
108 | |
109 | /** |
110 | * Returns the closest item for the URL \a url. |
111 | * The closest item is defined as item which is equal to |
112 | * the URL or at least is a parent URL. If there are more than |
113 | * one possible parent URL candidates, the item which covers |
114 | * the bigger range of the URL is returned. |
115 | * |
116 | * Example: the url is '/home/peter/Documents/Music'. |
117 | * Available items are: |
118 | * - /home/peter |
119 | * - /home/peter/Documents |
120 | * |
121 | * The returned item will the one for '/home/peter/Documents'. |
122 | */ |
123 | QModelIndex closestItem(const KUrl &url) const; |
124 | |
125 | |
126 | Qt::DropActions supportedDropActions() const; |
127 | Qt::ItemFlags flags(const QModelIndex &index) const; |
128 | QStringList mimeTypes() const; |
129 | QMimeData *mimeData(const QModelIndexList &indexes) const; |
130 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, |
131 | int row, int column, const QModelIndex &parent); |
132 | |
133 | Q_SIGNALS: |
134 | void errorMessage(const QString &message); |
135 | void setupDone(const QModelIndex &index, bool success); |
136 | |
137 | private: |
138 | Q_PRIVATE_SLOT(d, void _k_initDeviceList()) |
139 | Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString&)) |
140 | Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString&)) |
141 | Q_PRIVATE_SLOT(d, void _k_itemChanged(const QString&)) |
142 | Q_PRIVATE_SLOT(d, void _k_reloadBookmarks()) |
143 | Q_PRIVATE_SLOT(d, void _k_storageSetupDone(Solid::ErrorType, QVariant)) |
144 | Q_PRIVATE_SLOT(d, void _k_storageTeardownDone(Solid::ErrorType, QVariant)) |
145 | |
146 | class Private; |
147 | Private * const d; |
148 | friend class Private; |
149 | }; |
150 | |
151 | #endif |
152 | |