diff options
Diffstat (limited to 'framework/accounts')
-rw-r--r-- | framework/accounts/accountsmodel.cpp | 33 | ||||
-rw-r--r-- | framework/accounts/accountsmodel.h | 4 |
2 files changed, 31 insertions, 6 deletions
diff --git a/framework/accounts/accountsmodel.cpp b/framework/accounts/accountsmodel.cpp index ea37784b..f0487f4f 100644 --- a/framework/accounts/accountsmodel.cpp +++ b/framework/accounts/accountsmodel.cpp | |||
@@ -19,13 +19,16 @@ | |||
19 | #include "accountsmodel.h" | 19 | #include "accountsmodel.h" |
20 | #include <sink/store.h> | 20 | #include <sink/store.h> |
21 | 21 | ||
22 | using namespace Sink; | ||
23 | using namespace Sink::ApplicationDomain; | ||
24 | |||
22 | AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel() | 25 | AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel() |
23 | { | 26 | { |
24 | Sink::Query query; | 27 | Sink::Query query; |
25 | query.setFlags(Sink::Query::LiveQuery); | 28 | query.setFlags(Query::LiveQuery); |
26 | query.request<Sink::ApplicationDomain::SinkAccount::Name>(); | 29 | query.request<SinkAccount::Name>(); |
27 | query.request<Sink::ApplicationDomain::SinkAccount::Icon>(); | 30 | query.request<SinkAccount::Icon>(); |
28 | query.request<Sink::ApplicationDomain::SinkAccount::Status>(); | 31 | query.request<SinkAccount::Status>(); |
29 | runQuery(query); | 32 | runQuery(query); |
30 | } | 33 | } |
31 | 34 | ||
@@ -51,7 +54,7 @@ QHash< int, QByteArray > AccountsModel::roleNames() const | |||
51 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const | 54 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const |
52 | { | 55 | { |
53 | auto srcIdx = mapToSource(idx); | 56 | auto srcIdx = mapToSource(idx); |
54 | auto account = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>(); | 57 | auto account = srcIdx.data(Sink::Store::DomainObjectRole).value<SinkAccount::Ptr>(); |
55 | switch (role) { | 58 | switch (role) { |
56 | case Name: | 59 | case Name: |
57 | return account->getName(); | 60 | return account->getName(); |
@@ -77,6 +80,24 @@ QVariant AccountsModel::data(const QModelIndex &idx, int role) const | |||
77 | 80 | ||
78 | void AccountsModel::runQuery(const Sink::Query &query) | 81 | void AccountsModel::runQuery(const Sink::Query &query) |
79 | { | 82 | { |
80 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::SinkAccount>(query); | 83 | mModel = Sink::Store::loadModel<SinkAccount>(query); |
81 | setSourceModel(mModel.data()); | 84 | setSourceModel(mModel.data()); |
82 | } | 85 | } |
86 | |||
87 | void AccountsModel::setAccountId(const QByteArray &accountId) | ||
88 | { | ||
89 | qWarning() << "Setting account id" << accountId; | ||
90 | //Get all folders of an account | ||
91 | Sink::Query query; | ||
92 | query.filter(accountId); | ||
93 | query.setFlags(Query::LiveQuery); | ||
94 | query.request<SinkAccount::Name>(); | ||
95 | query.request<SinkAccount::Icon>(); | ||
96 | query.request<SinkAccount::Status>(); | ||
97 | runQuery(query); | ||
98 | } | ||
99 | |||
100 | QByteArray AccountsModel::accountId() const | ||
101 | { | ||
102 | return {}; | ||
103 | } | ||
diff --git a/framework/accounts/accountsmodel.h b/framework/accounts/accountsmodel.h index e3c08cd4..3a2dd712 100644 --- a/framework/accounts/accountsmodel.h +++ b/framework/accounts/accountsmodel.h | |||
@@ -32,6 +32,7 @@ class AccountsModel : public QIdentityProxyModel | |||
32 | { | 32 | { |
33 | Q_OBJECT | 33 | Q_OBJECT |
34 | 34 | ||
35 | Q_PROPERTY (QByteArray accountId READ accountId WRITE setAccountId) | ||
35 | public: | 36 | public: |
36 | AccountsModel(QObject *parent = Q_NULLPTR); | 37 | AccountsModel(QObject *parent = Q_NULLPTR); |
37 | ~AccountsModel(); | 38 | ~AccountsModel(); |
@@ -50,6 +51,9 @@ public: | |||
50 | 51 | ||
51 | QHash<int, QByteArray> roleNames() const; | 52 | QHash<int, QByteArray> roleNames() const; |
52 | 53 | ||
54 | void setAccountId(const QByteArray &id); | ||
55 | QByteArray accountId() const; | ||
56 | |||
53 | private: | 57 | private: |
54 | void runQuery(const Sink::Query &query); | 58 | void runQuery(const Sink::Query &query); |
55 | QSharedPointer<QAbstractItemModel> mModel; | 59 | QSharedPointer<QAbstractItemModel> mModel; |