File indexing completed on 2024-11-24 04:50:45

0001 // SPDX-FileCopyrightText: 2007-2009 Tobias Koenig <tokoe@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <Akonadi/Collection>
0007 #include <QSortFilterProxyModel>
0008 #include <memory>
0009 #include <qobjectdefs.h>
0010 
0011 namespace Akonadi
0012 {
0013 namespace Quick
0014 {
0015 class CollectionPickerModelPrivate;
0016 
0017 /**
0018  * @short The model for a Picker for selecting an Akonadi collection.
0019  *
0020  * This model provides a way easily select a collection
0021  * from the Akonadi storage.
0022  * The available collections can be filtered by mime type and
0023  * access rights.
0024  *
0025  * Example:
0026  *
0027  * @code{.qml}
0028  *
0029  * import QtQuick.Controls 2.15 as QQC2
0030  * import org.kde.akonadi 1.0 as Akonadi
0031  *
0032  * QQC2.Picker {
0033  *     model: AkonadiQuick.PickerModel {
0034  *         mimeTypeFilter: [Akonadi.MimeTypes.address, Akonadi.MimeTypes.contactGroup]
0035  *         accessRightsFilter: Akonadi.Collection.CanCreateItem
0036  *     }
0037  * }
0038  * @endcode
0039  *
0040  * @author Carl Schwan <carl@carlschwan.eu>
0041  */
0042 class CollectionPickerModel : public QSortFilterProxyModel
0043 {
0044     Q_OBJECT
0045     Q_PROPERTY(QStringList mimeTypeFilter READ mimeTypeFilter WRITE setMimeTypeFilter NOTIFY mimeTypeFilterChanged)
0046     Q_PROPERTY(Akonadi::Collection::Right accessRightsFilter READ accessRightsFilter WRITE setAccessRightsFilter NOTIFY accessRightsFilterChanged)
0047     Q_PROPERTY(bool excludeVirtualCollections READ excludeVirtualCollections WRITE setExcludeVirtualCollections NOTIFY excludeVirtualCollectionsChanged)
0048 
0049 public:
0050     explicit CollectionPickerModel(QObject *parent = nullptr);
0051     ~CollectionPickerModel() override;
0052 
0053     /**
0054      * Sets the content @p mimetypes the collections shall be filtered by.
0055      */
0056     void setMimeTypeFilter(const QStringList &mimetypes);
0057 
0058     /**
0059      * Returns the content mimetype the collections are filtered by.
0060      * Don't assume this list has the original order.
0061      */
0062     [[nodiscard]] QStringList mimeTypeFilter() const;
0063 
0064     /**
0065      * Sets the access @p rights the collections shall be filtered by.
0066      */
0067     void setAccessRightsFilter(Akonadi::Collection::Right rights);
0068 
0069     /**
0070      * Returns the access rights the collections are filtered by.
0071      */
0072     [[nodiscard]] Akonadi::Collection::Right accessRightsFilter() const;
0073 
0074     /**
0075      * Sets if the virtual collections are excluded.
0076      */
0077     void setExcludeVirtualCollections(bool b);
0078 
0079     /**
0080      * Returns if the virual exollections are excluded
0081      */
0082     [[nodiscard]] bool excludeVirtualCollections() const;
0083 
0084 Q_SIGNALS:
0085     void mimeTypeFilterChanged();
0086     void accessRightsFilterChanged();
0087     void excludeVirtualCollectionsChanged();
0088 
0089 private:
0090     std::unique_ptr<CollectionPickerModelPrivate> const d;
0091 };
0092 
0093 }
0094 }