SVN_SILENT shhh.
[kdelibs.git] / kfile / kfileplacesmodel.h
blob6637267e61a2affbd7dde029ec7128346d9159f7
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>
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.
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.
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.
20 #ifndef KFILEPLACESMODEL_H
21 #define KFILEPLACESMODEL_H
23 #include <kfile_export.h>
25 #include <QtCore/QAbstractItemModel>
26 #include <kurl.h>
27 #include <kbookmark.h>
28 #include <kicon.h>
30 #include <solid/device.h>
32 class QMimeData;
33 class QAction;
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.
40 class KFILE_EXPORT KFilePlacesModel : public QAbstractItemModel
42 Q_OBJECT
43 public:
44 enum AdditionalRoles {
45 UrlRole = 0x069CD12B,
46 HiddenRole = 0x0741CAAC,
47 SetupNeededRole = 0x059A935D
50 KFilePlacesModel(QObject *parent=0);
51 ~KFilePlacesModel();
53 KUrl url(const QModelIndex &index) const;
54 bool setupNeeded(const QModelIndex &index) const;
55 KIcon icon(const QModelIndex &index) const;
56 QString text(const QModelIndex &index) const;
57 bool isHidden(const QModelIndex &index) const;
58 bool isDevice(const QModelIndex &index) const;
59 Solid::Device deviceForIndex(const QModelIndex &index) const;
60 KBookmark bookmarkForIndex(const QModelIndex &index) const;
62 QAction *teardownActionForIndex(const QModelIndex &index) const;
63 QAction *ejectActionForIndex(const QModelIndex &index) const;
64 void requestTeardown(const QModelIndex &index);
65 void requestEject(const QModelIndex &index);
66 void requestSetup(const QModelIndex &index);
68 void addPlace(const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString());
69 void editPlace(const QModelIndex &index, const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString());
70 void removePlace(const QModelIndex &index) const;
71 void setPlaceHidden(const QModelIndex &index, bool hidden);
73 int hiddenCount() const;
75 /**
76 * @brief Get a visible data based on Qt role for the given index.
77 * Return the device information for the give index.
79 * @param index The QModelIndex which contains the row, column to fetch the data.
80 * @param role The Interview data role(ex: Qt::DisplayRole).
82 * @return the data for the given index and role.
84 QVariant data(const QModelIndex &index, int role) const;
86 /**
87 * @brief Get the children model index for the given row and column.
89 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
91 /**
92 * @brief Get the parent QModelIndex for the given model child.
94 QModelIndex parent(const QModelIndex &child) const;
96 /**
97 * @brief Get the number of rows for a model index.
99 int rowCount(const QModelIndex &parent = QModelIndex()) const;
102 * @brief Get the number of columns for a model index.
104 int columnCount(const QModelIndex &parent = QModelIndex()) const;
107 * Returns the closest item for the URL \a url.
108 * The closest item is defined as item which is equal to
109 * the URL or at least is a parent URL. If there are more than
110 * one possible parent URL candidates, the item which covers
111 * the bigger range of the URL is returned.
113 * Example: the url is '/home/peter/Documents/Music'.
114 * Available items are:
115 * - /home/peter
116 * - /home/peter/Documents
118 * The returned item will the one for '/home/peter/Documents'.
120 QModelIndex closestItem(const KUrl &url) const;
123 Qt::DropActions supportedDropActions() const;
124 Qt::ItemFlags flags(const QModelIndex &index) const;
125 QStringList mimeTypes() const;
126 QMimeData *mimeData(const QModelIndexList &indexes) const;
127 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
128 int row, int column, const QModelIndex &parent);
130 Q_SIGNALS:
131 void errorMessage(const QString &message);
132 void setupDone(const QModelIndex &index, bool success);
134 private:
135 Q_PRIVATE_SLOT(d, void _k_initDeviceList())
136 Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString&))
137 Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString&))
138 Q_PRIVATE_SLOT(d, void _k_itemChanged(const QString&))
139 Q_PRIVATE_SLOT(d, void _k_reloadBookmarks())
140 Q_PRIVATE_SLOT(d, void _k_storageSetupDone(Solid::ErrorType, QVariant))
141 Q_PRIVATE_SLOT(d, void _k_storageTeardownDone(Solid::ErrorType, QVariant))
143 class Private;
144 Private * const d;
145 friend class Private;
148 #endif