1 | /* |
2 | Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | 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 the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef AKONADI_ITEMMODEL_H |
21 | #define AKONADI_ITEMMODEL_H |
22 | |
23 | #include "akonadi_export.h" |
24 | #include <akonadi/item.h> |
25 | #include <akonadi/job.h> |
26 | |
27 | #include <QtCore/QAbstractTableModel> |
28 | |
29 | namespace Akonadi { |
30 | |
31 | class Collection; |
32 | class ItemFetchScope; |
33 | class Job; |
34 | class Session; |
35 | |
36 | /** |
37 | * @short A table model for items. |
38 | * |
39 | * A self-updating table model that shows all items of |
40 | * a collection. |
41 | * |
42 | * @code |
43 | * |
44 | * QTableView *view = new QTableView( this ); |
45 | * |
46 | * Akonadi::ItemModel *model = new Akonadi::ItemModel(); |
47 | * view->setModel( model ); |
48 | * |
49 | * model->setCollection( Akonadi::Collection::root() ); |
50 | * |
51 | * @endcode |
52 | * |
53 | * @author Volker Krause <vkrause@kde.org> |
54 | * @deprecated Use Akonadi::EntityTreeModel instead |
55 | */ |
56 | class AKONADI_DEPRECATED_EXPORT ItemModel : public QAbstractTableModel |
57 | { |
58 | Q_OBJECT |
59 | |
60 | public: |
61 | /** |
62 | * Describes the types of the columns in the model. |
63 | */ |
64 | enum Column { |
65 | Id = 0, ///< The unique id. |
66 | RemoteId, ///< The remote identifier. |
67 | MimeType ///< The item's mime type. |
68 | }; |
69 | |
70 | /** |
71 | * Describes the roles of the model. |
72 | */ |
73 | enum Roles { |
74 | IdRole = Qt::UserRole + 1, ///< The id of the item. |
75 | ItemRole, ///< The item object. |
76 | MimeTypeRole, ///< The mime type of the item. |
77 | UserRole = Qt::UserRole + 42 ///< Role for user extensions. |
78 | }; |
79 | |
80 | /** |
81 | * Creates a new item model. |
82 | * |
83 | * @param parent The parent object. |
84 | */ |
85 | explicit ItemModel(QObject *parent = 0); |
86 | |
87 | /** |
88 | * Destroys the item model. |
89 | */ |
90 | virtual ~ItemModel(); |
91 | |
92 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; |
93 | |
94 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
95 | |
96 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |
97 | |
98 | virtual QVariant (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
99 | |
100 | virtual Qt::ItemFlags flags(const QModelIndex &index) const; |
101 | |
102 | virtual QMimeData *mimeData(const QModelIndexList &indexes) const; |
103 | |
104 | virtual QStringList mimeTypes() const; |
105 | |
106 | virtual Qt::DropActions supportedDropActions() const; |
107 | |
108 | /** |
109 | * Sets the item fetch scope. |
110 | * |
111 | * The ItemFetchScope controls how much of an item's data is fetched from the |
112 | * server, e.g. whether to fetch the full item payload or only meta data. |
113 | * |
114 | * @param fetchScope The new scope for item fetch operations. |
115 | * |
116 | * @see fetchScope() |
117 | */ |
118 | void setFetchScope(const ItemFetchScope &fetchScope); |
119 | |
120 | /** |
121 | * Returns the item fetch scope. |
122 | * |
123 | * Since this returns a reference it can be used to conveniently modify the |
124 | * current scope in-place, i.e. by calling a method on the returned reference |
125 | * without storing it in a local variable. See the ItemFetchScope documentation |
126 | * for an example. |
127 | * |
128 | * @return a reference to the current item fetch scope. |
129 | * |
130 | * @see setFetchScope() for replacing the current item fetch scope. |
131 | */ |
132 | ItemFetchScope &fetchScope(); |
133 | |
134 | /** |
135 | * Returns the item at the given @p index. |
136 | */ |
137 | Item itemForIndex(const QModelIndex &index) const; |
138 | |
139 | /** |
140 | * Returns the model index for the given item, with the given column. |
141 | * |
142 | * @param item The item to find. |
143 | * @param column The column for the returned index. |
144 | */ |
145 | QModelIndex indexForItem(const Akonadi::Item &item, const int column) const; |
146 | |
147 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); |
148 | |
149 | /** |
150 | * Returns the collection being displayed in the model. |
151 | */ |
152 | Collection collection() const; |
153 | |
154 | public Q_SLOTS: |
155 | /** |
156 | * Sets the collection the model should display. If the collection has |
157 | * changed, the model is reset and a new message listing is requested |
158 | * from the Akonadi storage. |
159 | * |
160 | * @param collection The collection. |
161 | */ |
162 | void setCollection(const Akonadi::Collection &collection); |
163 | |
164 | Q_SIGNALS: |
165 | /** |
166 | * This signal is emitted whenever setCollection is called. |
167 | * |
168 | * @param collection The new collection. |
169 | */ |
170 | void collectionChanged(const Akonadi::Collection &collection); |
171 | |
172 | protected: |
173 | /** |
174 | * Returns the Session object used for all operations by this model. |
175 | */ |
176 | Session *session() const; |
177 | |
178 | private: |
179 | //@cond PRIVATE |
180 | class Private; |
181 | Private *const d; |
182 | |
183 | Q_PRIVATE_SLOT(d, void listingDone(KJob *)) |
184 | Q_PRIVATE_SLOT(d, void collectionFetchResult(KJob *)) |
185 | Q_PRIVATE_SLOT(d, void itemChanged(const Akonadi::Item &, const QSet<QByteArray> &)) |
186 | Q_PRIVATE_SLOT(d, void itemMoved(const Akonadi::Item &, const Akonadi::Collection &, const Akonadi::Collection &)) |
187 | Q_PRIVATE_SLOT(d, void itemAdded(const Akonadi::Item &)) |
188 | Q_PRIVATE_SLOT(d, void itemsAdded(const Akonadi::Item::List &)) |
189 | Q_PRIVATE_SLOT(d, void itemRemoved(const Akonadi::Item &)) |
190 | //@endcond |
191 | }; |
192 | |
193 | } |
194 | |
195 | #endif |
196 | |