Akonadi

collectioncombobox.h
1 /*
2  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "akonadiwidgets_export.h"
10 // AkonadiCore
11 #include <akonadi/collection.h>
12 
13 #include <QComboBox>
14 
15 #include <memory>
16 
17 class QAbstractItemModel;
18 
19 namespace Akonadi
20 {
21 class CollectionComboBoxPrivate;
22 
23 /**
24  * @short A combobox for selecting an Akonadi collection.
25  *
26  * This widget provides a combobox to select a collection
27  * from the Akonadi storage.
28  * The available collections can be filtered by mime type and
29  * access rights.
30  *
31  * Example:
32  *
33  * @code
34  *
35  * using namespace Akonadi;
36  *
37  * QStringList contentMimeTypes;
38  * contentMimeTypes << KContacts::Addressee::mimeType();
39  * contentMimeTypes << KContacts::ContactGroup::mimeType();
40  *
41  * CollectionComboBox *box = new CollectionComboBox( this );
42  * box->setMimeTypeFilter( contentMimeTypes );
43  * box->setAccessRightsFilter( Collection::CanCreateItem );
44  * ...
45  *
46  * const Collection collection = box->currentCollection();
47  *
48  * @endcode
49  *
50  * @author Tobias Koenig <[email protected]>
51  * @since 4.4
52  */
53 class AKONADIWIDGETS_EXPORT CollectionComboBox : public QComboBox
54 {
55  Q_OBJECT
56 
57 public:
58  /**
59  * Creates a new collection combobox.
60  *
61  * @param parent The parent widget.
62  */
63  explicit CollectionComboBox(QWidget *parent = nullptr);
64 
65  /**
66  * Creates a new collection combobox with a custom @p model.
67  *
68  * The filtering by content mime type and access rights is done
69  * on top of the custom model.
70  *
71  * @param model The custom model to use.
72  * @param parent The parent widget.
73  */
74  explicit CollectionComboBox(QAbstractItemModel *model, QWidget *parent = nullptr);
75 
76  /**
77  * Destroys the collection combobox.
78  */
79  ~CollectionComboBox() override;
80 
81  /**
82  * Sets the content @p mimetypes the collections shall be filtered by.
83  */
84  void setMimeTypeFilter(const QStringList &mimetypes);
85 
86  /**
87  * Returns the content mimetype the collections are filtered by.
88  * Don't assume this list has the original order.
89  */
90  Q_REQUIRED_RESULT QStringList mimeTypeFilter() const;
91 
92  /**
93  * Sets the access @p rights the collections shall be filtered by.
94  */
95  void setAccessRightsFilter(Collection::Rights rights);
96 
97  /**
98  * Returns the access rights the collections are filtered by.
99  */
100  Q_REQUIRED_RESULT Collection::Rights accessRightsFilter() const;
101 
102  /**
103  * Sets the @p collection that shall be selected by default.
104  */
105  void setDefaultCollection(const Collection &collection);
106 
107  /**
108  * Returns the current selection.
109  */
110  Q_REQUIRED_RESULT Akonadi::Collection currentCollection() const;
111 
112  /**
113  * @since 4.12
114  */
115  void setExcludeVirtualCollections(bool b);
116  /**
117  * @since 4.12
118  */
119  Q_REQUIRED_RESULT bool excludeVirtualCollections() const;
120 
121 Q_SIGNALS:
122  /**
123  * This signal is emitted whenever the current selection
124  * has been changed.
125  *
126  * @param collection The current selection.
127  */
128  void currentChanged(const Akonadi::Collection &collection);
129 
130 private:
131  /// @cond PRIVATE
132  std::unique_ptr<CollectionComboBoxPrivate> const d;
133 
134  Q_PRIVATE_SLOT(d, void activated(int))
135  Q_PRIVATE_SLOT(d, void activated(const QModelIndex &))
136  /// @endcond
137 };
138 
139 }
140 
A combobox for selecting an Akonadi collection.
Represents a collection of PIM items.
Definition: collection.h:61
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.