summaryrefslogtreecommitdiffstats
path: root/framework/domain/accountsmodel.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-14 20:41:35 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-14 20:41:35 +0100
commitbf039428e22a10887e8d85a95ff5f38dc17e7ec2 (patch)
tree981390fff4d561760edaf1b7c8e3bbcb750ade09 /framework/domain/accountsmodel.cpp
parent68f95cf68c3a8d29c2cc81929287eabb3a6d7682 (diff)
downloadkube-bf039428e22a10887e8d85a95ff5f38dc17e7ec2.tar.gz
kube-bf039428e22a10887e8d85a95ff5f38dc17e7ec2.zip
Multi-Account support in the folderview
Diffstat (limited to 'framework/domain/accountsmodel.cpp')
-rw-r--r--framework/domain/accountsmodel.cpp65
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
25AccountsModel::AccountsModel(QObject *parent) : QAbstractListModel()
26{
27 Kube::Settings settings("accounts");
28 mAccounts = settings.property("accounts").toStringList();
29}
30
31AccountsModel::~AccountsModel()
32{
33
34}
35
36QHash< 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
47QVariant 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
62int AccountsModel::rowCount(const QModelIndex &idx) const
63{
64 return mAccounts.size();
65}