summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-30 15:18:02 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-30 15:18:02 +0200
commit211fdde3ab546142e8aaf9d2b6508c949474b634 (patch)
tree1ddd10924f91f33b1a405f4f8f6593d3d72c32b3
parent7339cc0c0a0c63576f38f0bc96c15f28967b92d1 (diff)
downloadkube-211fdde3ab546142e8aaf9d2b6508c949474b634.tar.gz
kube-211fdde3ab546142e8aaf9d2b6508c949474b634.zip
Outbox: added resource state
-rw-r--r--components/package/contents/ui/Outbox.qml36
-rw-r--r--framework/domain/outboxmodel.cpp34
-rw-r--r--framework/domain/outboxmodel.h11
3 files changed, 69 insertions, 12 deletions
diff --git a/components/package/contents/ui/Outbox.qml b/components/package/contents/ui/Outbox.qml
index 1f0400d3..f293cfb3 100644
--- a/components/package/contents/ui/Outbox.qml
+++ b/components/package/contents/ui/Outbox.qml
@@ -19,6 +19,7 @@
19import QtQuick 2.4 19import QtQuick 2.4
20import QtQuick.Layouts 1.1 20import QtQuick.Layouts 1.1
21import QtQuick.Controls 2.0 21import QtQuick.Controls 2.0
22import QtQuick.Controls 1.3 as Controls
22 23
23import org.kde.kirigami 1.0 as Kirigami 24import org.kde.kirigami 1.0 as Kirigami
24 25
@@ -30,7 +31,33 @@ import org.kube.components.theme 1.0 as KubeTheme
30Button { 31Button {
31 id: root 32 id: root
32 33
33 text: "outbox" 34 text: outboxModel.count > 0 ? "outbox (" + outboxModel.count + ")" : "outbox"
35 contentItem: Item {
36 Text {
37 text: parent.text
38 font: parent.font
39 horizontalAlignment: Text.AlignHCenter
40 verticalAlignment: Text.AlignVCenter
41 elide: Text.ElideRight
42 }
43 Controls.ToolButton {
44 id: statusIcon
45 anchors {
46 right: parent.right
47 }
48 visible: false
49 states: [
50 State {
51 name: "busy"; when: outboxModel.status == KubeFramework.OutboxModel.InProgressStatus
52 PropertyChanges { target: statusIcon; iconName: KubeTheme.Icons.busy; visible: true }
53 },
54 State {
55 name: "error"; when: outboxModel.status == KubeFramework.OutboxModel.ErrorStatus
56 PropertyChanges { target: statusIcon; iconName: KubeTheme.Icons.error; visible: true }
57 }
58 ]
59 }
60 }
34 61
35 onClicked: { 62 onClicked: {
36 dialog.visible = dialog.visible ? false : true 63 dialog.visible = dialog.visible ? false : true
@@ -44,13 +71,6 @@ Button {
44 id: outboxModel 71 id: outboxModel
45 } 72 }
46 73
47 states: [
48 State {
49 name: "noempty"; when: outboxModel.count > 0
50 PropertyChanges { target: root; text: "outbox (" + outboxModel.count + ")" }
51 }
52 ]
53
54 Popup { 74 Popup {
55 id: dialog 75 id: dialog
56 76
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
30OutboxModel::OutboxModel(QObject *parent) 32OutboxModel::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
47OutboxModel::~OutboxModel() 70OutboxModel::~OutboxModel()
@@ -94,11 +117,16 @@ bool OutboxModel::lessThan(const QModelIndex &left, const QModelIndex &right) co
94 117
95void OutboxModel::runQuery(const Sink::Query &query) 118void 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
101int OutboxModel::count() const 124int OutboxModel::count() const
102{ 125{
103 return rowCount(); 126 return rowCount();
104} 127}
128
129int 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
34public: 37public:
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
63signals: 69signals:
70 void statusChanged();
64 void countChanged(); 71 void countChanged();
65 72
66private: 73private:
67 QSharedPointer<QAbstractItemModel> m_model; 74 QSharedPointer<QAbstractItemModel> mModel;
75 QSharedPointer<Sink::Notifier> mNotifier;
76 int mStatus;
68}; 77};