diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-30 15:18:02 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-30 15:18:02 +0200 |
commit | 211fdde3ab546142e8aaf9d2b6508c949474b634 (patch) | |
tree | 1ddd10924f91f33b1a405f4f8f6593d3d72c32b3 /framework/domain | |
parent | 7339cc0c0a0c63576f38f0bc96c15f28967b92d1 (diff) | |
download | kube-211fdde3ab546142e8aaf9d2b6508c949474b634.tar.gz kube-211fdde3ab546142e8aaf9d2b6508c949474b634.zip |
Outbox: added resource state
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/outboxmodel.cpp | 34 | ||||
-rw-r--r-- | framework/domain/outboxmodel.h | 11 |
2 files changed, 41 insertions, 4 deletions
diff --git a/framework/domain/outboxmodel.cpp b/framework/domain/outboxmodel.cpp index 68a0e8be..7cfdc71a 100644 --- a/framework/domain/outboxmodel.cpp +++ b/framework/domain/outboxmodel.cpp | |||
@@ -25,10 +25,14 @@ | |||
25 | #include <QString> | 25 | #include <QString> |
26 | 26 | ||
27 | #include <sink/standardqueries.h> | 27 | #include <sink/standardqueries.h> |
28 | #include <sink/notifier.h> | ||
29 | #include <sink/notification.h> | ||
28 | 30 | ||
29 | 31 | ||
30 | OutboxModel::OutboxModel(QObject *parent) | 32 | OutboxModel::OutboxModel(QObject *parent) |
31 | : QSortFilterProxyModel() | 33 | : QSortFilterProxyModel(), |
34 | mNotifier(new Sink::Notifier{Sink::Query{}.containsFilter<Sink::ApplicationDomain::SinkResource::Capabilities>(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)}), | ||
35 | mStatus(NoStatus) | ||
32 | { | 36 | { |
33 | setDynamicSortFilter(true); | 37 | setDynamicSortFilter(true); |
34 | sort(0, Qt::DescendingOrder); | 38 | sort(0, Qt::DescendingOrder); |
@@ -42,6 +46,25 @@ OutboxModel::OutboxModel(QObject *parent) | |||
42 | runQuery(query); | 46 | runQuery(query); |
43 | connect(this, &QAbstractItemModel::rowsInserted, this, &OutboxModel::countChanged); | 47 | connect(this, &QAbstractItemModel::rowsInserted, this, &OutboxModel::countChanged); |
44 | connect(this, &QAbstractItemModel::rowsRemoved, this, &OutboxModel::countChanged); | 48 | connect(this, &QAbstractItemModel::rowsRemoved, this, &OutboxModel::countChanged); |
49 | |||
50 | mNotifier->registerHandler([this] (const Sink::Notification &n) { | ||
51 | if (n.type == Sink::Notification::Status) { | ||
52 | switch (n.code) { | ||
53 | case Sink::ApplicationDomain::Status::ErrorStatus: | ||
54 | mStatus = ErrorStatus; | ||
55 | break; | ||
56 | case Sink::ApplicationDomain::Status::BusyStatus: | ||
57 | mStatus = InProgressStatus; | ||
58 | break; | ||
59 | default: | ||
60 | mStatus = NoStatus; | ||
61 | break; | ||
62 | } | ||
63 | emit statusChanged(); | ||
64 | } | ||
65 | |||
66 | }); | ||
67 | |||
45 | } | 68 | } |
46 | 69 | ||
47 | OutboxModel::~OutboxModel() | 70 | OutboxModel::~OutboxModel() |
@@ -94,11 +117,16 @@ bool OutboxModel::lessThan(const QModelIndex &left, const QModelIndex &right) co | |||
94 | 117 | ||
95 | void OutboxModel::runQuery(const Sink::Query &query) | 118 | void OutboxModel::runQuery(const Sink::Query &query) |
96 | { | 119 | { |
97 | m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | 120 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); |
98 | setSourceModel(m_model.data()); | 121 | setSourceModel(mModel.data()); |
99 | } | 122 | } |
100 | 123 | ||
101 | int OutboxModel::count() const | 124 | int OutboxModel::count() const |
102 | { | 125 | { |
103 | return rowCount(); | 126 | return rowCount(); |
104 | } | 127 | } |
128 | |||
129 | int OutboxModel::status() const | ||
130 | { | ||
131 | return mStatus; | ||
132 | } | ||
diff --git a/framework/domain/outboxmodel.h b/framework/domain/outboxmodel.h index 4e226223..4be9c7f8 100644 --- a/framework/domain/outboxmodel.h +++ b/framework/domain/outboxmodel.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #pragma once | 21 | #pragma once |
22 | 22 | ||
23 | #include <sink/store.h> | 23 | #include <sink/store.h> |
24 | #include <sink/notifier.h> | ||
24 | 25 | ||
25 | #include <QSortFilterProxyModel> | 26 | #include <QSortFilterProxyModel> |
26 | #include <QSharedPointer> | 27 | #include <QSharedPointer> |
@@ -31,8 +32,11 @@ class OutboxModel : public QSortFilterProxyModel | |||
31 | Q_OBJECT | 32 | Q_OBJECT |
32 | 33 | ||
33 | Q_PROPERTY (int count READ count NOTIFY countChanged) | 34 | Q_PROPERTY (int count READ count NOTIFY countChanged) |
35 | Q_PROPERTY (int status READ status NOTIFY statusChanged) | ||
36 | |||
34 | public: | 37 | public: |
35 | enum Status { | 38 | enum Status { |
39 | NoStatus, | ||
36 | PendingStatus, | 40 | PendingStatus, |
37 | InProgressStatus, | 41 | InProgressStatus, |
38 | ErrorStatus | 42 | ErrorStatus |
@@ -60,9 +64,14 @@ public: | |||
60 | void runQuery(const Sink::Query &query); | 64 | void runQuery(const Sink::Query &query); |
61 | 65 | ||
62 | int count() const; | 66 | int count() const; |
67 | int status() const; | ||
68 | |||
63 | signals: | 69 | signals: |
70 | void statusChanged(); | ||
64 | void countChanged(); | 71 | void countChanged(); |
65 | 72 | ||
66 | private: | 73 | private: |
67 | QSharedPointer<QAbstractItemModel> m_model; | 74 | QSharedPointer<QAbstractItemModel> mModel; |
75 | QSharedPointer<Sink::Notifier> mNotifier; | ||
76 | int mStatus; | ||
68 | }; | 77 | }; |