From 211fdde3ab546142e8aaf9d2b6508c949474b634 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 30 Mar 2017 15:18:02 +0200 Subject: Outbox: added resource state --- components/package/contents/ui/Outbox.qml | 36 ++++++++++++++++++++++++------- framework/domain/outboxmodel.cpp | 34 ++++++++++++++++++++++++++--- framework/domain/outboxmodel.h | 11 +++++++++- 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 @@ import QtQuick 2.4 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.0 +import QtQuick.Controls 1.3 as Controls import org.kde.kirigami 1.0 as Kirigami @@ -30,7 +31,33 @@ import org.kube.components.theme 1.0 as KubeTheme Button { id: root - text: "outbox" + text: outboxModel.count > 0 ? "outbox (" + outboxModel.count + ")" : "outbox" + contentItem: Item { + Text { + text: parent.text + font: parent.font + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + Controls.ToolButton { + id: statusIcon + anchors { + right: parent.right + } + visible: false + states: [ + State { + name: "busy"; when: outboxModel.status == KubeFramework.OutboxModel.InProgressStatus + PropertyChanges { target: statusIcon; iconName: KubeTheme.Icons.busy; visible: true } + }, + State { + name: "error"; when: outboxModel.status == KubeFramework.OutboxModel.ErrorStatus + PropertyChanges { target: statusIcon; iconName: KubeTheme.Icons.error; visible: true } + } + ] + } + } onClicked: { dialog.visible = dialog.visible ? false : true @@ -44,13 +71,6 @@ Button { id: outboxModel } - states: [ - State { - name: "noempty"; when: outboxModel.count > 0 - PropertyChanges { target: root; text: "outbox (" + outboxModel.count + ")" } - } - ] - Popup { id: dialog 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 @@ #include #include +#include +#include OutboxModel::OutboxModel(QObject *parent) - : QSortFilterProxyModel() + : QSortFilterProxyModel(), + mNotifier(new Sink::Notifier{Sink::Query{}.containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)}), + mStatus(NoStatus) { setDynamicSortFilter(true); sort(0, Qt::DescendingOrder); @@ -42,6 +46,25 @@ OutboxModel::OutboxModel(QObject *parent) runQuery(query); connect(this, &QAbstractItemModel::rowsInserted, this, &OutboxModel::countChanged); connect(this, &QAbstractItemModel::rowsRemoved, this, &OutboxModel::countChanged); + + mNotifier->registerHandler([this] (const Sink::Notification &n) { + if (n.type == Sink::Notification::Status) { + switch (n.code) { + case Sink::ApplicationDomain::Status::ErrorStatus: + mStatus = ErrorStatus; + break; + case Sink::ApplicationDomain::Status::BusyStatus: + mStatus = InProgressStatus; + break; + default: + mStatus = NoStatus; + break; + } + emit statusChanged(); + } + + }); + } OutboxModel::~OutboxModel() @@ -94,11 +117,16 @@ bool OutboxModel::lessThan(const QModelIndex &left, const QModelIndex &right) co void OutboxModel::runQuery(const Sink::Query &query) { - m_model = Sink::Store::loadModel(query); - setSourceModel(m_model.data()); + mModel = Sink::Store::loadModel(query); + setSourceModel(mModel.data()); } int OutboxModel::count() const { return rowCount(); } + +int OutboxModel::status() const +{ + return mStatus; +} 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 @@ #pragma once #include +#include #include #include @@ -31,8 +32,11 @@ class OutboxModel : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY (int count READ count NOTIFY countChanged) + Q_PROPERTY (int status READ status NOTIFY statusChanged) + public: enum Status { + NoStatus, PendingStatus, InProgressStatus, ErrorStatus @@ -60,9 +64,14 @@ public: void runQuery(const Sink::Query &query); int count() const; + int status() const; + signals: + void statusChanged(); void countChanged(); private: - QSharedPointer m_model; + QSharedPointer mModel; + QSharedPointer mNotifier; + int mStatus; }; -- cgit v1.2.3