9#include "collectioncomboboxmodel.h"
11#include <Akonadi/CollectionFetchScope>
12#include <Akonadi/CollectionFilterProxyModel>
13#include <Akonadi/CollectionUtils>
14#include <Akonadi/EntityRightsFilterModel>
15#include <Akonadi/EntityTreeModel>
16#include <Akonadi/Monitor>
17#include <Akonadi/Session>
19#include <KDescendantsProxyModel>
21#include <QAbstractItemModel>
22#include "colorproxymodel.h"
24using namespace Akonadi::Quick;
26class Akonadi::Quick::CollectionComboBoxModelPrivate
29 CollectionComboBoxModelPrivate(CollectionComboBoxModel *parent)
32 mMonitor =
new Akonadi::Monitor(mParent);
33 mMonitor->setObjectName(QStringLiteral(
"CollectionComboBoxMonitor"));
34 mMonitor->fetchCollection(
true);
38 auto entityModel =
new Akonadi::EntityTreeModel(mMonitor, mParent);
43 auto colorProxy =
new ColorProxyModel(mParent);
44 colorProxy->setObjectName(QStringLiteral(
"Show collection colors"));
45 colorProxy->setDynamicSortFilter(
true);
46 colorProxy->setSourceModel(entityModel);
52 auto proxyModel =
new KDescendantsProxyModel(parent);
53 proxyModel->setDisplayAncestorData(
true);
54 proxyModel->setSourceModel(colorProxy);
58 mMimeTypeFilterModel =
new Akonadi::CollectionFilterProxyModel(parent);
59 mMimeTypeFilterModel->setSourceModel(proxyModel);
62 mRightsFilterModel =
new Akonadi::EntityRightsFilterModel(parent);
63 mRightsFilterModel->setSourceModel(mMimeTypeFilterModel);
65 mParent->setSourceModel(mRightsFilterModel);
76 ~CollectionComboBoxModelPrivate() =
default;
80 CollectionComboBoxModel *
const mParent;
82 Akonadi::Monitor *mMonitor =
nullptr;
83 Akonadi::CollectionFilterProxyModel *mMimeTypeFilterModel =
nullptr;
84 Akonadi::EntityRightsFilterModel *mRightsFilterModel =
nullptr;
85 qint64 mDefaultCollectionId = -1;
86 int mCurrentIndex = -1;
89bool CollectionComboBoxModelPrivate::scanSubTree()
91 for (
int row = 0; row < mRightsFilterModel->rowCount(); ++row) {
94 if (mDefaultCollectionId ==
id &&
id > 0) {
95 mParent->setCurrentIndex(row);
103CollectionComboBoxModel::CollectionComboBoxModel(QObject *parent)
104 : QSortFilterProxyModel(parent)
105 , d(new CollectionComboBoxModelPrivate(this))
109CollectionComboBoxModel::~CollectionComboBoxModel() =
default;
113 d->mMimeTypeFilterModel->clearFilters();
114 d->mMimeTypeFilterModel->addMimeTypeFilters(contentMimeTypes);
117 for (
const QString &mimeType : contentMimeTypes) {
118 d->mMonitor->setMimeTypeMonitored(mimeType,
true);
125 return d->mMimeTypeFilterModel->mimeTypeFilters();
130 d->mRightsFilterModel->setAccessRights((Collection::Right)rights);
131 Q_EMIT accessRightsFilterChanged();
134int CollectionComboBoxModel::accessRightsFilter()
const
136 return (
int)d->mRightsFilterModel->accessRights();
139qint64 CollectionComboBoxModel::defaultCollectionId()
const
141 return d->mDefaultCollectionId;
146 if (d->mDefaultCollectionId == collectionId) {
149 d->mDefaultCollectionId = collectionId;
151 Q_EMIT defaultCollectionIdChanged();
156 d->mMimeTypeFilterModel->setExcludeVirtualCollections(b);
161 return d->mMimeTypeFilterModel->excludeVirtualCollections();
164int CollectionComboBoxModel::currentIndex()
const
166 return d->mCurrentIndex;
169void CollectionComboBoxModel::setCurrentIndex(
int currentIndex)
171 if (d->mCurrentIndex == currentIndex) {
174 d->mCurrentIndex = currentIndex;
175 Q_EMIT currentIndexChanged();
178#include "moc_collectioncomboboxmodel.cpp"
void setDefaultCollectionId(qint64 collectionId)
Sets the collection that shall be selected by default.
void setMimeTypeFilter(const QStringList &mimetypes)
Sets the content mimetypes the collections shall be filtered by.
bool excludeVirtualCollections() const
Returns if the virual exollections are excluded.
void setExcludeVirtualCollections(bool b)
Sets if the virtual collections are excluded.
void setAccessRightsFilter(int rights)
Sets the access rights the collections shall be filtered by.
Q_SCRIPTABLE Q_NOREPLY void start()
void rowsInserted(const QModelIndex &parent, int first, int last)