diff options
Diffstat (limited to 'framework/domain/accountsmodel.cpp')
-rw-r--r-- | framework/domain/accountsmodel.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/framework/domain/accountsmodel.cpp b/framework/domain/accountsmodel.cpp new file mode 100644 index 00000000..96306464 --- /dev/null +++ b/framework/domain/accountsmodel.cpp | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "accountsmodel.h" | ||
20 | |||
21 | #include <settings/settings.h> | ||
22 | |||
23 | #include <QVariant> | ||
24 | |||
25 | AccountsModel::AccountsModel(QObject *parent) : QAbstractListModel() | ||
26 | { | ||
27 | Kube::Settings settings("accounts"); | ||
28 | mAccounts = settings.property("accounts").toStringList(); | ||
29 | } | ||
30 | |||
31 | AccountsModel::~AccountsModel() | ||
32 | { | ||
33 | |||
34 | } | ||
35 | |||
36 | QHash< int, QByteArray > AccountsModel::roleNames() const | ||
37 | { | ||
38 | QHash<int, QByteArray> roles; | ||
39 | |||
40 | roles[Name] = "name"; | ||
41 | roles[Icon] = "icon"; | ||
42 | roles[AccountId] = "accountId"; | ||
43 | |||
44 | return roles; | ||
45 | } | ||
46 | |||
47 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const | ||
48 | { | ||
49 | const auto identifier = mAccounts.at(idx.row()); | ||
50 | Kube::Account accountSettings(identifier.toLatin1()); | ||
51 | switch (role) { | ||
52 | case Name: | ||
53 | return accountSettings.property("name").toString(); | ||
54 | case Icon: | ||
55 | return accountSettings.property("icon").toString(); | ||
56 | case AccountId: | ||
57 | return identifier; | ||
58 | } | ||
59 | return QVariant(); | ||
60 | } | ||
61 | |||
62 | int AccountsModel::rowCount(const QModelIndex &idx) const | ||
63 | { | ||
64 | return mAccounts.size(); | ||
65 | } | ||