File indexing completed on 2024-04-28 16:09:54

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003  *  SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef SERVICES_MODEL_H
0009 #define SERVICES_MODEL_H
0010 
0011 #include "kaccounts_export.h"
0012 
0013 #include <QAbstractListModel>
0014 
0015 namespace KAccounts
0016 {
0017 
0018 /**
0019  * @brief A model which represents the services in a single account
0020  *
0021  * You can create this manually, but usually you would get an instance of it from the
0022  * AccountsModel::Roles::ServicesRole data role (model.services) of an AccountsModel
0023  * instance.
0024  *
0025  * # Roles
0026  *
0027  * The following role names are available in this model:
0028  *
0029  * * name: The internal name for the service, as understood by the backend
0030  * * description: A (usually single line) description of the service
0031  * * displayName: A human-readable name for the service (use this in the UI instead of name)
0032  * * serviceType: A machine-readable category for the service (e.g. microblogging, e-mail, IM...)
0033  * * providerName: The machine-readable name of the provider which this service is related to
0034  * * iconName: An XDG Icon specification icon name representing this service
0035  * * tags: A list of strings representing tags set on this service
0036  * * enabled: Whether or not the service is enabled for the given account
0037  */
0038 class KACCOUNTS_EXPORT ServicesModel : public QAbstractListModel
0039 {
0040     Q_OBJECT
0041     /**
0042      * The Accounts::Account instance which this model should use for fetching the list of services
0043      */
0044     Q_PROPERTY(QObject *account READ account WRITE setAccount NOTIFY accountChanged)
0045     /**
0046      * The internal ID for the account this model represents
0047      */
0048     Q_PROPERTY(quint32 accountId READ accountId NOTIFY accountChanged)
0049     /**
0050      * The human-readable name of the account this model represents
0051      */
0052     Q_PROPERTY(QString accountDisplayName READ accountDisplayName NOTIFY accountChanged)
0053     /**
0054      * The name of the provider this model's account is signed in through
0055      */
0056     Q_PROPERTY(QString accountProviderName READ accountProviderName NOTIFY accountChanged)
0057     /**
0058      * The XDG Icon specification icon name for this model's account
0059      */
0060     Q_PROPERTY(QString accountIconName READ accountIconName NOTIFY accountChanged)
0061 public:
0062     enum Roles {
0063         NameRole = Qt::UserRole + 1,
0064         DescriptionRole,
0065         DisplayNameRole,
0066         ServiceTypeRole,
0067         ProviderNameRole,
0068         IconNameRole,
0069         TagsRole,
0070         EnabledRole,
0071     };
0072     explicit ServicesModel(QObject *parent = nullptr);
0073     ~ServicesModel() override;
0074 
0075     QHash<int, QByteArray> roleNames() const override;
0076     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0077     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0078 
0079     void setAccount(QObject *account);
0080     QObject *account() const;
0081     quint32 accountId() const;
0082     QString accountDisplayName() const;
0083     QString accountProviderName() const;
0084     QString accountIconName() const;
0085 Q_SIGNALS:
0086     void accountChanged();
0087 
0088 private:
0089     class Private;
0090     Private *d;
0091 };
0092 
0093 };
0094 
0095 #endif // SERVICES_MODEL_H