diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-05 15:04:00 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-05 15:04:00 +0200 |
commit | 4b1798f0cdf87361869e7cf2b341acacd056c410 (patch) | |
tree | 3ff780641acdcb20b81f9b41533afd50a2525d38 /framework/src/accounts/accountsmodel.cpp | |
parent | 71721aa4f3e85bea1a2fe504e86d99f80a3106a9 (diff) | |
download | kube-4b1798f0cdf87361869e7cf2b341acacd056c410.tar.gz kube-4b1798f0cdf87361869e7cf2b341acacd056c410.zip |
Moved cpp code into src directory
Diffstat (limited to 'framework/src/accounts/accountsmodel.cpp')
-rw-r--r-- | framework/src/accounts/accountsmodel.cpp | 101 |
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 | |||
22 | using namespace Sink; | ||
23 | using namespace Sink::ApplicationDomain; | ||
24 | |||
25 | AccountsModel::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 | |||
35 | AccountsModel::~AccountsModel() | ||
36 | { | ||
37 | |||
38 | } | ||
39 | |||
40 | QHash< 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 | |||
52 | QVariant 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 | |||
79 | void AccountsModel::runQuery(const Sink::Query &query) | ||
80 | { | ||
81 | mModel = Sink::Store::loadModel<SinkAccount>(query); | ||
82 | setSourceModel(mModel.data()); | ||
83 | } | ||
84 | |||
85 | void 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 | |||
98 | QByteArray AccountsModel::accountId() const | ||
99 | { | ||
100 | return {}; | ||
101 | } | ||