1 | /* |
2 | Copyright 2008 Ingo Klöcker <kloecker@kde.org> |
3 | Copyright 2010 Laurent Montel <montel@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or modify it |
6 | under the terms of the GNU Library General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or (at your |
8 | option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
13 | License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to the |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef AKONADI_COLLECTIONDIALOG_H |
22 | #define AKONADI_COLLECTIONDIALOG_H |
23 | |
24 | #include "akonadi_export.h" |
25 | |
26 | #include <kdialog.h> |
27 | |
28 | #include <akonadi/collection.h> |
29 | |
30 | #include <QAbstractItemView> |
31 | |
32 | namespace Akonadi { |
33 | |
34 | /** |
35 | * @short A collection selection dialog. |
36 | * |
37 | * Provides a dialog that lists collections that are available |
38 | * on the Akonadi storage and allows the selection of one or multiple |
39 | * collections. |
40 | * |
41 | * The list of shown collections can be filtered by mime type and access |
42 | * rights. Note that mime types are not enabled by default, so |
43 | * setMimeTypeFilter() must be called to enable the desired mime types. |
44 | * |
45 | * Example: |
46 | * |
47 | * @code |
48 | * |
49 | * using namespace Akonadi; |
50 | * |
51 | * // Show the user a dialog to select a writable collection of contacts |
52 | * CollectionDialog dlg( this ); |
53 | * dlg.setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() ); |
54 | * dlg.setAccessRightsFilter( Collection::CanCreateItem ); |
55 | * dlg.setDescription( i18n( "Select an address book for saving:" ) ); |
56 | * |
57 | * if ( dlg.exec() ) { |
58 | * const Collection collection = dlg.selectedCollection(); |
59 | * ... |
60 | * } |
61 | * |
62 | * @endcode |
63 | * |
64 | * @author Ingo Klöcker <kloecker@kde.org> |
65 | * @since 4.3 |
66 | */ |
67 | class AKONADI_EXPORT CollectionDialog : public KDialog |
68 | { |
69 | Q_OBJECT |
70 | Q_DISABLE_COPY(CollectionDialog) |
71 | |
72 | public: |
73 | /* @since 4.6 |
74 | */ |
75 | enum CollectionDialogOption { |
76 | None = 0, |
77 | AllowToCreateNewChildCollection = 1, |
78 | KeepTreeExpanded = 2 |
79 | }; |
80 | |
81 | Q_DECLARE_FLAGS(CollectionDialogOptions, CollectionDialogOption) |
82 | |
83 | /** |
84 | * Creates a new collection dialog. |
85 | * |
86 | * @param parent The parent widget. |
87 | */ |
88 | explicit CollectionDialog(QWidget *parent = 0); |
89 | |
90 | /** |
91 | * Creates a new collection dialog with a custom @p model. |
92 | * |
93 | * The filtering by content mime type and access rights is done |
94 | * on top of the custom model. |
95 | * |
96 | * @param model The custom model to use. |
97 | * @param parent The parent widget. |
98 | * |
99 | * @since 4.4 |
100 | */ |
101 | explicit CollectionDialog(QAbstractItemModel *model, QWidget *parent = 0); |
102 | |
103 | /** |
104 | * Creates a new collection dialog with a custom @p model. |
105 | * |
106 | * The filtering by content mime type and access rights is done |
107 | * on top of the custom model. |
108 | * |
109 | * @param options The collection dialog options. |
110 | * @param model The custom model to use. |
111 | * @param parent The parent widget. |
112 | * |
113 | * @since 4.6 |
114 | */ |
115 | |
116 | explicit CollectionDialog(CollectionDialogOptions options, QAbstractItemModel *model = 0, QWidget *parent = 0); |
117 | |
118 | /** |
119 | * Destroys the collection dialog. |
120 | */ |
121 | ~CollectionDialog(); |
122 | |
123 | /** |
124 | * Sets the mime types any of which the selected collection(s) shall support. |
125 | * Note that mime types are not enabled by default. |
126 | * @param mimeTypes MIME type filter values |
127 | */ |
128 | void setMimeTypeFilter(const QStringList &mimeTypes); |
129 | |
130 | /** |
131 | * Returns the mime types any of which the selected collection(s) shall support. |
132 | */ |
133 | QStringList mimeTypeFilter() const; |
134 | |
135 | /** |
136 | * Sets the access @p rights that the listed collections shall match with. |
137 | * @param rights access rights filter values |
138 | * @since 4.4 |
139 | */ |
140 | void setAccessRightsFilter(Collection::Rights rights); |
141 | |
142 | /** |
143 | * Sets the access @p rights that the listed collections shall match with. |
144 | * |
145 | * @since 4.4 |
146 | */ |
147 | Collection::Rights accessRightsFilter() const; |
148 | |
149 | /** |
150 | * Sets the @p text that will be shown in the dialog. |
151 | * @param text the dialog's description text |
152 | * @since 4.4 |
153 | */ |
154 | void setDescription(const QString &text); |
155 | |
156 | /** |
157 | * Sets the @p collection that shall be selected by default. |
158 | * @param collection the dialog's pre-selected collection |
159 | * @since 4.4 |
160 | */ |
161 | void setDefaultCollection(const Collection &collection); |
162 | |
163 | /** |
164 | * Sets the selection mode. The initial default mode is |
165 | * QAbstractItemView::SingleSelection. |
166 | * @param mode the selection mode to use |
167 | * @see QAbstractItemView::setSelectionMode() |
168 | */ |
169 | void setSelectionMode(QAbstractItemView::SelectionMode mode); |
170 | |
171 | /** |
172 | * Returns the selection mode. |
173 | * @see QAbstractItemView::selectionMode() |
174 | */ |
175 | QAbstractItemView::SelectionMode selectionMode() const; |
176 | |
177 | /** |
178 | * Returns the selected collection if the selection mode is |
179 | * QAbstractItemView::SingleSelection. If another selection mode was set, |
180 | * or nothing is selected, an invalid collection is returned. |
181 | */ |
182 | Akonadi::Collection selectedCollection() const; |
183 | |
184 | /** |
185 | * Returns the list of selected collections. |
186 | */ |
187 | Akonadi::Collection::List selectedCollections() const; |
188 | |
189 | /** |
190 | * Change collection dialog options. |
191 | * @param options the collection dialog options to change |
192 | * @since 4.6 |
193 | */ |
194 | void changeCollectionDialogOptions(CollectionDialogOptions options); |
195 | |
196 | /** |
197 | * @since 4.13 |
198 | */ |
199 | void setUseFolderByDefault(bool b); |
200 | /** |
201 | * @since 4.13 |
202 | */ |
203 | bool useFolderByDefault() const; |
204 | |
205 | private: |
206 | //@cond PRIVATE |
207 | class Private; |
208 | Private *const d; |
209 | |
210 | Q_PRIVATE_SLOT(d, void slotCollectionAvailable(const QModelIndex &)) |
211 | Q_PRIVATE_SLOT(d, void slotSelectionChanged()) |
212 | Q_PRIVATE_SLOT(d, void slotAddChildCollection()) |
213 | Q_PRIVATE_SLOT(d, void slotCollectionCreationResult(KJob *job)) |
214 | Q_PRIVATE_SLOT(d, void slotFilterFixedString(const QString &)) |
215 | //@endcond |
216 | }; |
217 | |
218 | } // namespace Akonadi |
219 | |
220 | #endif // AKONADI_COLLECTIONDIALOG_H |
221 | |