Changeset View
Changeset View
Standalone View
Standalone View
src/lib/servicesmodel.h
- This file was added.
1 | /************************************************************************************* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> * | ||||
3 | * Copyright (C) 2020 by Dan Leinir Turthra Jensen <admin@leinir.dk> * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or * | ||||
6 | * modify it under the terms of the GNU General Public License * | ||||
7 | * as published by the Free Software Foundation; either version 2 * | ||||
8 | * of the License, or (at your option) any later version. * | ||||
9 | * * | ||||
10 | * This program is distributed in the hope that it will be useful, * | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
13 | * GNU General Public License for more details. * | ||||
14 | * * | ||||
15 | * You should have received a copy of the GNU General Public License * | ||||
16 | * along with this program; if not, write to the Free Software * | ||||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||||
18 | *************************************************************************************/ | ||||
19 | | ||||
20 | #ifndef SERVICES_MODEL_H | ||||
21 | #define SERVICES_MODEL_H | ||||
22 | | ||||
23 | #include "kaccounts_export.h" | ||||
24 | | ||||
25 | #include <QAbstractListModel> | ||||
26 | | ||||
27 | /** | ||||
28 | * @brief A model which represents the services in a single account | ||||
29 | * | ||||
30 | * You can create this manually, but usually you would get an instance of it from the | ||||
31 | * AccountsModel::Roles::ServicesRole data role (model.services) of an AccountsModel | ||||
32 | * instance. | ||||
33 | * | ||||
34 | * # Roles | ||||
35 | * | ||||
36 | * The following role names are available in this model: | ||||
37 | * | ||||
38 | * * name: The internal name for the service, as understood by the backend | ||||
39 | * * description: A (usually single line) description of the service | ||||
40 | * * displayName: A human-readable name for the service (use this in the UI instead of name) | ||||
41 | * * serviceType: A machine-readable category for the service (e.g. microblogging, e-mail, IM...) | ||||
42 | * * providerName: The machine-readable name of the provider which this service is related to | ||||
43 | * * iconName: An XDG Icon specification icon name representing this service | ||||
44 | * * tags: A list of strings representing tags set on this service | ||||
45 | * * enabled: Whether or not the service is enabled for the given account | ||||
46 | */ | ||||
47 | class KACCOUNTS_EXPORT ServicesModel : public QAbstractListModel | ||||
48 | { | ||||
49 | Q_OBJECT | ||||
50 | /** | ||||
51 | * The Accounts::Account instance which this model should use for fetching the list of services | ||||
52 | */ | ||||
53 | Q_PROPERTY(QObject* account READ account WRITE setAccount NOTIFY accountChanged) | ||||
54 | /** | ||||
55 | * The internal ID for the account this model represents | ||||
56 | */ | ||||
57 | Q_PROPERTY(quint32 accountId READ accountId NOTIFY accountChanged) | ||||
58 | /** | ||||
59 | * The human-readable name of the account this model represents | ||||
60 | */ | ||||
61 | Q_PROPERTY(QString accountDisplayName READ accountDisplayName NOTIFY accountChanged) | ||||
62 | /** | ||||
63 | * The name of the provider this model's account is signed in through | ||||
64 | */ | ||||
65 | Q_PROPERTY(QString accountProviderName READ accountProviderName NOTIFY accountChanged) | ||||
66 | /** | ||||
67 | * The XDG Icon specification icon name for this model's account | ||||
68 | */ | ||||
69 | Q_PROPERTY(QString accountIconName READ accountIconName NOTIFY accountChanged) | ||||
70 | public: | ||||
71 | enum Roles { | ||||
72 | NameRole = Qt::UserRole + 1, | ||||
73 | DescriptionRole, | ||||
74 | DisplayNameRole, | ||||
75 | ServiceTypeRole, | ||||
76 | ProviderNameRole, | ||||
77 | IconNameRole, | ||||
78 | TagsRole, | ||||
79 | EnabledRole | ||||
80 | }; | ||||
81 | explicit ServicesModel(QObject* parent = nullptr); | ||||
82 | virtual ~ServicesModel(); | ||||
83 | | ||||
84 | QHash< int, QByteArray > roleNames() const override; | ||||
85 | virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
86 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||||
87 | | ||||
88 | void setAccount(QObject* account); | ||||
89 | QObject* account() const; | ||||
90 | quint32 accountId() const; | ||||
91 | QString accountDisplayName() const; | ||||
92 | QString accountProviderName() const; | ||||
93 | QString accountIconName() const; | ||||
94 | Q_SIGNAL void accountChanged(); | ||||
95 | | ||||
96 | private: | ||||
97 | class Private; | ||||
98 | Private *d; | ||||
99 | }; | ||||
100 | | ||||
101 | #endif//SERVICES_MODEL_H |