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 --- framework/domain/outboxmodel.cpp | 34 +++++++++++++++++++++++++++++++--- framework/domain/outboxmodel.h | 11 ++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'framework/domain') 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