1/*
2 Copyright (c) 2006 - 2008 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_COLLECTIONMODEL_H
21#define AKONADI_COLLECTIONMODEL_H
22
23#include "akonadi_export.h"
24
25#include <akonadi/collection.h>
26
27#include <QtCore/QAbstractItemModel>
28
29namespace Akonadi {
30
31class CollectionModelPrivate;
32
33/**
34 * @short A model for collections.
35 *
36 * This class provides the interface of QAbstractItemModel for the
37 * collection tree of the Akonadi storage.
38 *
39 * @code
40 *
41 * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this );
42 *
43 * QTreeView *view = new QTreeView( this );
44 * view->setModel( model );
45 *
46 * @endcode
47 *
48 * If you want to list only collections of a special mime type, use
49 * CollectionFilterProxyModel on top of this model.
50 *
51 * @author Volker Krause <vkrause@kde.org>
52 * @deprecated Use Akonadi::EntityTreeModel instead
53 */
54class AKONADI_DEPRECATED_EXPORT CollectionModel : public QAbstractItemModel
55{
56 Q_OBJECT
57
58public:
59 /**
60 * Describes the roles for collections.
61 */
62 enum Roles {
63 OldCollectionIdRole = Qt::UserRole + 1, ///< The collection identifier. For binary compatibility to <4.3
64 OldCollectionRole = Qt::UserRole + 2, ///< The actual collection object. For binary compatibility to <4.3
65 CollectionIdRole = Qt::UserRole + 10, ///< The collection identifier.
66 CollectionRole = Qt::UserRole + 11, ///< The actual collection object.
67 UserRole = Qt::UserRole + 42 ///< Role for user extensions.
68 };
69
70 /**
71 * Creates a new collection model.
72 *
73 * @param parent The parent object.
74 */
75 explicit CollectionModel(QObject *parent = 0);
76
77 /**
78 * Destroys the collection model.
79 */
80 virtual ~CollectionModel();
81
82 /**
83 * Sets whether collection statistics information shall be provided
84 * by the model.
85 *
86 * @see CollectionStatistics.
87 * @param enable whether to fetch collecton statistics
88 */
89 void fetchCollectionStatistics(bool enable);
90
91 /**
92 * Sets whether unsubscribed collections shall be listed in the model.
93 */
94 void includeUnsubscribed(bool include = true);
95
96 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
97 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
98 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
99 virtual QModelIndex parent(const QModelIndex &index) const;
100 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
101 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
102 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
103 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
104 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
105 virtual Qt::DropActions supportedDropActions() const;
106 virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
107 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
108 virtual QStringList mimeTypes() const;
109
110protected:
111 /**
112 * Returns the collection for a given collection @p id.
113 */
114 Collection collectionForId(Collection::Id id) const;
115
116 //@cond PRIVATE
117 Akonadi::CollectionModelPrivate *d_ptr;
118 explicit CollectionModel(CollectionModelPrivate *d, QObject *parent = 0);
119 //@endcond
120
121private:
122 Q_DECLARE_PRIVATE(CollectionModel)
123
124 //@cond PRIVATE
125 Q_PRIVATE_SLOT(d_func(), void startFirstListJob())
126 Q_PRIVATE_SLOT(d_func(), void collectionRemoved(const Akonadi::Collection &))
127 Q_PRIVATE_SLOT(d_func(), void collectionChanged(const Akonadi::Collection &))
128 Q_PRIVATE_SLOT(d_func(), void updateDone(KJob *))
129 Q_PRIVATE_SLOT(d_func(), void collectionStatisticsChanged(
130 Akonadi::Collection::Id,
131 const Akonadi::CollectionStatistics &))
132 Q_PRIVATE_SLOT(d_func(), void listDone(KJob *))
133 Q_PRIVATE_SLOT(d_func(), void editDone(KJob *))
134 Q_PRIVATE_SLOT(d_func(), void dropResult(KJob *))
135 Q_PRIVATE_SLOT(d_func(), void collectionsChanged(const Akonadi::Collection::List &))
136 //@endcond
137};
138
139}
140
141#endif
142