File indexing completed on 2024-06-23 05:06:41

0001 /*
0002     SPDX-FileCopyrightText: 2006-2008 Tobias Koenig <tokoe@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 <QAbstractItemModel>
0012 
0013 #include <memory>
0014 
0015 namespace Akonadi
0016 {
0017 class AgentInstanceModelPrivate;
0018 
0019 /**
0020  * @short Provides a data model for agent instances.
0021  *
0022  * This class provides the interface of a QAbstractItemModel to
0023  * access all available agent instances: their name, identifier,
0024  * supported mimetypes and capabilities.
0025  *
0026  * @code
0027  *
0028  * Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this );
0029  *
0030  * QListView *view = new QListView( this );
0031  * view->setModel( model );
0032  *
0033  * @endcode
0034  *
0035  * To show only agent instances that match a given mime type or special
0036  * capabilities, use the AgentFilterProxyModel on top of this model.
0037  *
0038  * @author Tobias Koenig <tokoe@kde.org>
0039  */
0040 class AKONADICORE_EXPORT AgentInstanceModel : public QAbstractItemModel
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     /**
0046      * Describes the roles of this model.
0047      */
0048     enum Roles {
0049         TypeRole = Qt::UserRole + 1, ///< The agent type itself
0050         NameRole, /// The display name of the agent type
0051         IconNameRole, /// The icon name of the agent
0052         TypeIdentifierRole, ///< The identifier of the agent type
0053         DescriptionRole, ///< A description of the agent type
0054         MimeTypesRole, ///< A list of supported mimetypes
0055         CapabilitiesRole, ///< A list of supported capabilities
0056         InstanceRole, ///< The agent instance itself
0057         InstanceIdentifierRole, ///< The identifier of the agent instance
0058         StatusRole, ///< The current status (numerical) of the instance
0059         StatusMessageRole, ///< A textual presentation of the current status
0060         ProgressRole, ///< The current progress (numerical in percent) of an operation
0061         OnlineRole, ///< The current online/offline status
0062         UserRole = Qt::UserRole + 42 ///< Role for user extensions
0063     };
0064 
0065     /**
0066      * Creates a new agent instance model.
0067      *
0068      * @param parent The parent object.
0069      */
0070     explicit AgentInstanceModel(QObject *parent = nullptr);
0071 
0072     /**
0073      * Destroys the agent instance model.
0074      */
0075     ~AgentInstanceModel() override;
0076 
0077     [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
0078     [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0079     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0080     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0081     [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0082     [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0083     [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
0084     [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
0085     [[nodiscard]] bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0086 
0087 private:
0088     /// @cond PRIVATE
0089     friend class AgentInstanceModelPrivate;
0090     std::unique_ptr<AgentInstanceModelPrivate> const d;
0091     /// @endcond
0092 };
0093 
0094 }