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

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include <Akonadi/CollectionFilterProxyModel>
0007 #include <Akonadi/Item>
0008 #include <QObject>
0009 #include <QSortFilterProxyModel>
0010 #include <qobjectdefs.h>
0011 
0012 namespace Akonadi
0013 {
0014 class ETMViewStateSaver;
0015 class EntityMimeTypeFilterModel;
0016 }
0017 class KCheckableProxyModel;
0018 class QAbstractItemModel;
0019 class QItemSelectionModel;
0020 class ColorProxyModel;
0021 
0022 class ContactManager : public QObject
0023 {
0024     Q_OBJECT
0025 
0026     /// Model for getting the contact collections available for the mainDrawer
0027     Q_PROPERTY(QAbstractItemModel *contactCollections READ contactCollections CONSTANT)
0028 
0029     /// Model containing the contacts from the selected collection
0030     Q_PROPERTY(QAbstractItemModel *filteredContacts READ filteredContacts CONSTANT)
0031 public:
0032     explicit ContactManager(QObject *parent = nullptr);
0033     ~ContactManager() override;
0034     QAbstractItemModel *contactCollections() const;
0035     QAbstractItemModel *filteredContacts() const;
0036 
0037     Q_INVOKABLE QUrl decorationToUrl(QVariant decoration);
0038     Q_INVOKABLE Akonadi::Item getItem(qint64 itemId);
0039 
0040     Q_INVOKABLE void setCollectionColor(Akonadi::Collection collection, const QColor &color);
0041     Q_INVOKABLE void deleteItem(const Akonadi::Item &item);
0042     Q_INVOKABLE void updateAllCollections();
0043     Q_INVOKABLE void updateCollection(const Akonadi::Collection &collection);
0044     Q_INVOKABLE void deleteCollection(const Akonadi::Collection &collection);
0045     Q_INVOKABLE void editCollection(const Akonadi::Collection &collection);
0046     Q_INVOKABLE QVariantMap getCollectionDetails(const Akonadi::Collection &collection);
0047 
0048 private:
0049     void saveState() const;
0050 
0051     Akonadi::EntityMimeTypeFilterModel *m_collectionTree;
0052     QItemSelectionModel *m_collectionSelectionModel;
0053     Akonadi::ETMViewStateSaver *m_collectionSelectionModelStateSaver;
0054     QSortFilterProxyModel *m_filteredContacts;
0055     KCheckableProxyModel *m_checkableProxyModel;
0056     ColorProxyModel *m_colorProxy;
0057 };