File indexing completed on 2024-05-26 04:49:09
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 #include <QQmlEngine> 0011 0012 namespace Akonadi 0013 { 0014 namespace Quick 0015 { 0016 class CollectionComboBoxModelPrivate; 0017 0018 /** 0019 * @short The model for a combobox for selecting an Akonadi collection. 0020 * 0021 * This model provides a way easily select a collection 0022 * from the Akonadi storage. 0023 * The available collections can be filtered by mime type and 0024 * access rights. 0025 * 0026 * Example: 0027 * 0028 * @code{.qml} 0029 * 0030 * import QtQuick.Controls 2.15 as QQC2 0031 * import org.kde.akonadi 1.0 as Akonadi 0032 * 0033 * QQC2.ComboBox { 0034 * model: AkonadiQuick.ComboBoxModel { 0035 * mimeTypeFilter: [Akonadi.MimeTypes.address, Akonadi.MimeTypes.contactGroup] 0036 * accessRightsFilter: Akonadi.Collection.CanCreateItem 0037 * } 0038 * } 0039 * @endcode 0040 * 0041 * @author Carl Schwan <carl@carlschwan.eu> 0042 */ 0043 class CollectionComboBoxModel : public QSortFilterProxyModel 0044 { 0045 Q_OBJECT 0046 QML_ELEMENT 0047 Q_PROPERTY(QStringList mimeTypeFilter READ mimeTypeFilter WRITE setMimeTypeFilter NOTIFY mimeTypeFilterChanged) 0048 Q_PROPERTY(int accessRightsFilter READ accessRightsFilter WRITE setAccessRightsFilter NOTIFY accessRightsFilterChanged) 0049 0050 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 0051 Q_PROPERTY(qint64 defaultCollectionId READ defaultCollectionId WRITE setDefaultCollectionId NOTIFY defaultCollectionIdChanged) 0052 0053 public: 0054 explicit CollectionComboBoxModel(QObject *parent = nullptr); 0055 ~CollectionComboBoxModel() override; 0056 0057 /** 0058 * Sets the content @p mimetypes the collections shall be filtered by. 0059 */ 0060 void setMimeTypeFilter(const QStringList &mimetypes); 0061 0062 /** 0063 * Returns the content mimetype the collections are filtered by. 0064 * Don't assume this list has the original order. 0065 */ 0066 Q_REQUIRED_RESULT QStringList mimeTypeFilter() const; 0067 0068 /** 0069 * Sets the access @p rights the collections shall be filtered by. 0070 */ 0071 void setAccessRightsFilter(int rights); 0072 0073 /** 0074 * Returns the access rights the collections are filtered by. 0075 */ 0076 Q_REQUIRED_RESULT int accessRightsFilter() const; 0077 0078 /** 0079 * Return the default collection id. 0080 */ 0081 qint64 defaultCollectionId() const; 0082 0083 /** 0084 * Sets the @p collection that shall be selected by default. 0085 */ 0086 void setDefaultCollectionId(qint64 collectionId); 0087 0088 /** 0089 * Sets if the virtual collections are excluded. 0090 */ 0091 void setExcludeVirtualCollections(bool b); 0092 0093 /** 0094 * Returns if the virual exollections are excluded 0095 */ 0096 Q_REQUIRED_RESULT bool excludeVirtualCollections() const; 0097 0098 int currentIndex() const; 0099 void setCurrentIndex(int currendIndex); 0100 0101 Q_SIGNALS: 0102 void mimeTypeFilterChanged(); 0103 void accessRightsFilterChanged(); 0104 void defaultCollectionIdChanged(); 0105 void currentIndexChanged(); 0106 0107 private: 0108 std::unique_ptr<CollectionComboBoxModelPrivate> const d; 0109 }; 0110 0111 } 0112 }