Changeset View
Changeset View
Standalone View
Standalone View
src/lib/accountsmodel.h
- This file was copied from src/declarative/kaccountsdeclarativeplugin.cpp.
1 | /************************************************************************************* | 1 | /************************************************************************************* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2015 by Aleix Pol <aleixpol@kde.org> * | 2 | * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> * | ||
3 | * Copyright (C) 2020 by Dan Leinir Turthra Jensen <admin@leinir.dk> * | ||||
3 | * * | 4 | * * | ||
4 | * This program is free software; you can redistribute it and/or * | 5 | * This program is free software; you can redistribute it and/or * | ||
5 | * modify it under the terms of the GNU General Public License * | 6 | * modify it under the terms of the GNU General Public License * | ||
6 | * as published by the Free Software Foundation; either version 2 * | 7 | * as published by the Free Software Foundation; either version 2 * | ||
7 | * of the License, or (at your option) any later version. * | 8 | * of the License, or (at your option) any later version. * | ||
8 | * * | 9 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 10 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
12 | * GNU General Public License for more details. * | 13 | * GNU General Public License for more details. * | ||
13 | * * | 14 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 15 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the Free Software * | 16 | * along with this program; if not, write to the Free Software * | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||
17 | *************************************************************************************/ | 18 | *************************************************************************************/ | ||
18 | 19 | | |||
19 | #include "kaccountsdeclarativeplugin.h" | 20 | #ifndef ACCOUNTS_MODEL_H | ||
20 | #include "createaccountjob.h" | 21 | #define ACCOUNTS_MODEL_H | ||
21 | #include "accountservicetogglejob.h" | | |||
22 | #include <qqml.h> | | |||
23 | 22 | | |||
24 | void KAccountsDeclarativePlugin::registerTypes(const char* uri) | 23 | #include "kaccounts_export.h" | ||
24 | | ||||
25 | #include <QAbstractListModel> | ||||
26 | | ||||
27 | #include <Accounts/Account> | ||||
28 | | ||||
29 | /** | ||||
30 | * @brief A model representing all the accounts registered on a system | ||||
31 | */ | ||||
32 | class KACCOUNTS_EXPORT AccountsModel : public QAbstractListModel | ||||
25 | { | 33 | { | ||
26 | qmlRegisterType<CreateAccountJob>(uri, 1, 0, "CreateAccountJob"); | 34 | Q_OBJECT | ||
27 | qmlRegisterType<AccountServiceToggleJob>(uri, 1, 1, "AccountServiceToggleJob"); | 35 | | ||
28 | } | 36 | public: | ||
37 | enum Roles { | ||||
38 | IdRole = Qt::UserRole + 1, | ||||
39 | ServicesRole, | ||||
40 | EnabledRole, | ||||
41 | CredentialsIdRole, | ||||
42 | DisplayNameRole, | ||||
43 | ProviderNameRole, | ||||
44 | IconNameRole, | ||||
45 | DataObjectRole | ||||
46 | }; | ||||
47 | explicit AccountsModel(QObject* parent = nullptr); | ||||
48 | virtual ~AccountsModel(); | ||||
49 | | ||||
50 | QHash< int, QByteArray > roleNames() const override; | ||||
51 | virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
52 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||||
53 | | ||||
54 | private: | ||||
55 | class Private; | ||||
56 | Private *d; | ||||
57 | }; | ||||
58 | | ||||
59 | #endif //ACCOUNTS_MODEL_H |