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 CollectionComboBoxModelPrivate; 0016 0017 /** 0018 * @short The model for a combobox 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.ComboBox { 0033 * model: AkonadiQuick.ComboBoxModel { 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 CollectionComboBoxModel : public QSortFilterProxyModel 0043 { 0044 Q_OBJECT 0045 Q_PROPERTY(QStringList mimeTypeFilter READ mimeTypeFilter WRITE setMimeTypeFilter NOTIFY mimeTypeFilterChanged) 0046 Q_PROPERTY(int accessRightsFilter READ accessRightsFilter WRITE setAccessRightsFilter NOTIFY accessRightsFilterChanged) 0047 0048 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 0049 Q_PROPERTY(qint64 defaultCollectionId READ defaultCollectionId WRITE setDefaultCollectionId NOTIFY defaultCollectionIdChanged) 0050 0051 public: 0052 explicit CollectionComboBoxModel(QObject *parent = nullptr); 0053 ~CollectionComboBoxModel() override; 0054 0055 /** 0056 * Sets the content @p mimetypes the collections shall be filtered by. 0057 */ 0058 void setMimeTypeFilter(const QStringList &mimetypes); 0059 0060 /** 0061 * Returns the content mimetype the collections are filtered by. 0062 * Don't assume this list has the original order. 0063 */ 0064 [[nodiscard]] QStringList mimeTypeFilter() const; 0065 0066 /** 0067 * Sets the access @p rights the collections shall be filtered by. 0068 */ 0069 void setAccessRightsFilter(int rights); 0070 0071 /** 0072 * Returns the access rights the collections are filtered by. 0073 */ 0074 [[nodiscard]] int accessRightsFilter() const; 0075 0076 /** 0077 * Return the default collection id. 0078 */ 0079 qint64 defaultCollectionId() const; 0080 0081 /** 0082 * Sets the @p collection that shall be selected by default. 0083 */ 0084 void setDefaultCollectionId(qint64 collectionId); 0085 0086 /** 0087 * Sets if the virtual collections are excluded. 0088 */ 0089 void setExcludeVirtualCollections(bool b); 0090 0091 /** 0092 * Returns if the virual exollections are excluded 0093 */ 0094 [[nodiscard]] bool excludeVirtualCollections() const; 0095 0096 int currentIndex() const; 0097 void setCurrentIndex(int currendIndex); 0098 0099 Q_SIGNALS: 0100 void mimeTypeFilterChanged(); 0101 void accessRightsFilterChanged(); 0102 void defaultCollectionIdChanged(); 0103 void currentIndexChanged(); 0104 0105 private: 0106 std::unique_ptr<CollectionComboBoxModelPrivate> const d; 0107 }; 0108 0109 } 0110 }