File indexing completed on 2025-01-05 04:47:07

0001 /*
0002     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadiwidgets_export.h"
0010 // AkonadiCore
0011 #include "akonadi/collection.h"
0012 
0013 #include <QComboBox>
0014 
0015 #include <memory>
0016 
0017 class QAbstractItemModel;
0018 
0019 namespace Akonadi
0020 {
0021 class CollectionComboBoxPrivate;
0022 
0023 /**
0024  * @short A combobox for selecting an Akonadi collection.
0025  *
0026  * This widget provides a combobox to select a collection
0027  * from the Akonadi storage.
0028  * The available collections can be filtered by mime type and
0029  * access rights.
0030  *
0031  * Example:
0032  *
0033  * @code
0034  *
0035  * using namespace Akonadi;
0036  *
0037  * QStringList contentMimeTypes;
0038  * contentMimeTypes << KContacts::Addressee::mimeType();
0039  * contentMimeTypes << KContacts::ContactGroup::mimeType();
0040  *
0041  * CollectionComboBox *box = new CollectionComboBox( this );
0042  * box->setMimeTypeFilter( contentMimeTypes );
0043  * box->setAccessRightsFilter( Collection::CanCreateItem );
0044  * ...
0045  *
0046  * const Collection collection = box->currentCollection();
0047  *
0048  * @endcode
0049  *
0050  * @author Tobias Koenig <tokoe@kde.org>
0051  * @since 4.4
0052  */
0053 class AKONADIWIDGETS_EXPORT CollectionComboBox : public QComboBox
0054 {
0055     Q_OBJECT
0056 
0057 public:
0058     /**
0059      * Creates a new collection combobox.
0060      *
0061      * @param parent The parent widget.
0062      */
0063     explicit CollectionComboBox(QWidget *parent = nullptr);
0064 
0065     /**
0066      * Creates a new collection combobox with a custom @p model.
0067      *
0068      * The filtering by content mime type and access rights is done
0069      * on top of the custom model.
0070      *
0071      * @param model The custom model to use.
0072      * @param parent The parent widget.
0073      */
0074     explicit CollectionComboBox(QAbstractItemModel *model, QWidget *parent = nullptr);
0075 
0076     /**
0077      * Destroys the collection combobox.
0078      */
0079     ~CollectionComboBox() override;
0080 
0081     /**
0082      * Sets the content @p mimetypes the collections shall be filtered by.
0083      */
0084     void setMimeTypeFilter(const QStringList &mimetypes);
0085 
0086     /**
0087      * Returns the content mimetype the collections are filtered by.
0088      * Don't assume this list has the original order.
0089      */
0090     [[nodiscard]] QStringList mimeTypeFilter() const;
0091 
0092     /**
0093      * Sets the access @p rights the collections shall be filtered by.
0094      */
0095     void setAccessRightsFilter(Collection::Rights rights);
0096 
0097     /**
0098      * Returns the access rights the collections are filtered by.
0099      */
0100     [[nodiscard]] Collection::Rights accessRightsFilter() const;
0101 
0102     /**
0103      * Sets the @p collection that shall be selected by default.
0104      */
0105     void setDefaultCollection(const Collection &collection);
0106 
0107     /**
0108      * Returns the current selection.
0109      */
0110     [[nodiscard]] Akonadi::Collection currentCollection() const;
0111 
0112     /**
0113      * @since 4.12
0114      */
0115     void setExcludeVirtualCollections(bool b);
0116     /**
0117      * @since 4.12
0118      */
0119     [[nodiscard]] bool excludeVirtualCollections() const;
0120 
0121 Q_SIGNALS:
0122     /**
0123      * This signal is emitted whenever the current selection
0124      * has been changed.
0125      *
0126      * @param collection The current selection.
0127      */
0128     void currentChanged(const Akonadi::Collection &collection);
0129 
0130 private:
0131     /// @cond PRIVATE
0132     std::unique_ptr<CollectionComboBoxPrivate> const d;
0133 
0134     Q_PRIVATE_SLOT(d, void activated(int))
0135     Q_PRIVATE_SLOT(d, void activated(const QModelIndex &))
0136     /// @endcond
0137 };
0138 
0139 }