summaryrefslogtreecommitdiffstats
path: root/framework/src/accounts/accountsmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/accounts/accountsmodel.cpp')
-rw-r--r--framework/src/accounts/accountsmodel.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/framework/src/accounts/accountsmodel.cpp b/framework/src/accounts/accountsmodel.cpp
new file mode 100644
index 00000000..f98e8ca3
--- /dev/null
+++ b/framework/src/accounts/accountsmodel.cpp
@@ -0,0 +1,101 @@
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#include <sink/store.h>
21
22using namespace Sink;
23using namespace Sink::ApplicationDomain;
24
25AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel()
26{
27 Sink::Query query;
28 query.setFlags(Query::LiveQuery);
29 query.request<SinkAccount::Name>();
30 query.request<SinkAccount::Icon>();
31 query.request<SinkAccount::Status>();
32 runQuery(query);
33}
34
35AccountsModel::~AccountsModel()
36{
37
38}
39
40QHash< int, QByteArray > AccountsModel::roleNames() const
41{
42 QHash<int, QByteArray> roles;
43
44 roles[Name] = "name";
45 roles[Icon] = "icon";
46 roles[AccountId] = "accountId";
47 roles[Status] = "status";
48
49 return roles;
50}
51
52QVariant AccountsModel::data(const QModelIndex &idx, int role) const
53{
54 auto srcIdx = mapToSource(idx);
55 auto account = srcIdx.data(Sink::Store::DomainObjectRole).value<SinkAccount::Ptr>();
56 switch (role) {
57 case Name:
58 return account->getName();
59 case Icon:
60 return account->getIcon();
61 case AccountId:
62 return account->identifier();
63 case Status:
64 switch (account->getStatus()) {
65 case Sink::ApplicationDomain::ErrorStatus:
66 return ErrorStatus;
67 case Sink::ApplicationDomain::BusyStatus:
68 return BusyStatus;
69 case Sink::ApplicationDomain::ConnectedStatus:
70 return ConnectedStatus;
71 case Sink::ApplicationDomain::OfflineStatus:
72 return OfflineStatus;
73 }
74 return NoStatus;
75 }
76 return QIdentityProxyModel::data(idx, role);
77}
78
79void AccountsModel::runQuery(const Sink::Query &query)
80{
81 mModel = Sink::Store::loadModel<SinkAccount>(query);
82 setSourceModel(mModel.data());
83}
84
85void AccountsModel::setAccountId(const QByteArray &accountId)
86{
87 qWarning() << "Setting account id" << accountId;
88 //Get all folders of an account
89 Sink::Query query;
90 query.filter(accountId);
91 query.setFlags(Query::LiveQuery);
92 query.request<SinkAccount::Name>();
93 query.request<SinkAccount::Icon>();
94 query.request<SinkAccount::Status>();
95 runQuery(query);
96}
97
98QByteArray AccountsModel::accountId() const
99{
100 return {};
101}