1/*
2 Copyright (c) 2009 Tobias Koenig <tokoe@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_COLLECTIONCOMBOBOX_H
21#define AKONADI_COLLECTIONCOMBOBOX_H
22
23#include "akonadi_export.h"
24
25#include <akonadi/collection.h>
26#include <kcombobox.h>
27
28class QAbstractItemModel;
29
30namespace Akonadi {
31
32/**
33 * @short A combobox for selecting an Akonadi collection.
34 *
35 * This widget provides a combobox to select a collection
36 * from the Akonadi storage.
37 * The available collections can be filtered by mime type and
38 * access rights.
39 *
40 * Example:
41 *
42 * @code
43 *
44 * using namespace Akonadi;
45 *
46 * QStringList contentMimeTypes;
47 * contentMimeTypes << KABC::Addressee::mimeType();
48 * contentMimeTypes << KABC::ContactGroup::mimeType();
49 *
50 * CollectionComboBox *box = new CollectionComboBox( this );
51 * box->setMimeTypeFilter( contentMimeTypes );
52 * box->setAccessRightsFilter( Collection::CanCreateItem );
53 * ...
54 *
55 * const Collection collection = box->currentCollection();
56 *
57 * @endcode
58 *
59 * @author Tobias Koenig <tokoe@kde.org>
60 * @since 4.4
61 */
62class AKONADI_EXPORT CollectionComboBox : public KComboBox
63{
64 Q_OBJECT
65
66public:
67 /**
68 * Creates a new collection combobox.
69 *
70 * @param parent The parent widget.
71 */
72 explicit CollectionComboBox(QWidget *parent = 0);
73
74 /**
75 * Creates a new collection combobox with a custom @p model.
76 *
77 * The filtering by content mime type and access rights is done
78 * on top of the custom model.
79 *
80 * @param model The custom model to use.
81 * @param parent The parent widget.
82 */
83 explicit CollectionComboBox(QAbstractItemModel *model, QWidget *parent = 0);
84
85 /**
86 * Destroys the collection combobox.
87 */
88 ~CollectionComboBox();
89
90 /**
91 * Sets the content @p mimetypes the collections shall be filtered by.
92 */
93 void setMimeTypeFilter(const QStringList &mimetypes);
94
95 /**
96 * Returns the content mimetype the collections are filtered by.
97 * Don't assume this list has the original order.
98 */
99 QStringList mimeTypeFilter() const;
100
101 /**
102 * Sets the access @p rights the collections shall be filtered by.
103 */
104 void setAccessRightsFilter(Collection::Rights rights);
105
106 /**
107 * Returns the access rights the collections are filtered by.
108 */
109 Collection::Rights accessRightsFilter() const;
110
111 /**
112 * Sets the @p collection that shall be selected by default.
113 */
114 void setDefaultCollection(const Collection &collection);
115
116 /**
117 * Returns the current selection.
118 */
119 Akonadi::Collection currentCollection() const;
120
121 /**
122 * @since 4.12
123 */
124 void setExcludeVirtualCollections(bool b);
125 /**
126 * @since 4.12
127 */
128 bool excludeVirtualCollections() const;
129
130Q_SIGNALS:
131 /**
132 * This signal is emitted whenever the current selection
133 * has been changed.
134 *
135 * @param collection The current selection.
136 */
137 void currentChanged(const Akonadi::Collection &collection);
138
139private:
140 //@cond PRIVATE
141 class Private;
142 Private *const d;
143
144 Q_PRIVATE_SLOT(d, void activated(int))
145 Q_PRIVATE_SLOT(d, void activated(const QModelIndex &))
146 //@endcond
147};
148
149}
150
151#endif
152