File indexing completed on 2024-09-22 04:41:03

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QIdentityProxyModel>
0012 
0013 #include "entitytreemodel.h"
0014 
0015 #include <memory>
0016 
0017 namespace Akonadi
0018 {
0019 class Monitor;
0020 class SubscriptionModelPrivate;
0021 
0022 /**
0023  * @internal
0024  *
0025  * A proxy model to be used on top of ETM to display a checkable tree of collections
0026  * for user to select which collections should be locally subscribed.
0027  *
0028  * Used in SubscriptionDialog
0029  */
0030 class AKONADICORE_EXPORT SubscriptionModel : public QIdentityProxyModel
0031 {
0032     Q_OBJECT
0033 public:
0034     /** Additional roles. */
0035     enum Roles {
0036         SubscriptionChangedRole = EntityTreeModel::UserRole + 1 ///< Indicate the subscription status has been changed.
0037     };
0038 
0039     /**
0040       Create a new subscription model.
0041       @param parent The parent object.
0042     */
0043     explicit SubscriptionModel(Monitor *monitor, QObject *parent = nullptr);
0044 
0045     /**
0046       Destructor.
0047     */
0048     ~SubscriptionModel() override;
0049 
0050     /**
0051      * Sets a source model for the SubscriptionModel.
0052      *
0053      * Should be based on an ETM with only collections.
0054      */
0055     void setSourceModel(QAbstractItemModel *model) override;
0056 
0057     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0058     [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
0059     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0060 
0061     [[nodiscard]] Collection::List subscribed() const;
0062     [[nodiscard]] Collection::List unsubscribed() const;
0063 
0064     /**
0065      * @param showHidden shows hidden collections if set as @c true
0066      * @since: 4.9
0067      */
0068     void setShowHiddenCollections(bool showHidden);
0069     [[nodiscard]] bool showHiddenCollections() const;
0070 
0071 Q_SIGNALS:
0072     void modelLoaded();
0073 
0074 private:
0075     std::unique_ptr<SubscriptionModelPrivate> const d;
0076 };
0077 
0078 }