From be511a719851c14c5ea5c1479ed2d814fbd3a8e6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 20 May 2017 12:03:33 +0200 Subject: Get the folder name in the status bar --- framework/qml/Messages.qml | 1 + framework/qml/StatusBar.qml | 28 +++++++++++++++++++++++++--- framework/src/domain/folderlistmodel.cpp | 24 +++++++++++++++++++++--- framework/src/domain/folderlistmodel.h | 4 ++++ framework/src/sinkfabric.cpp | 5 +++++ 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/framework/qml/Messages.qml b/framework/qml/Messages.qml index aa43de76..485f7816 100644 --- a/framework/qml/Messages.qml +++ b/framework/qml/Messages.qml @@ -36,6 +36,7 @@ Item { property string notification: "notification" property string progressNotification: "progressNotification" + property string errorNotification: "errorNotification" property string search: "search" property string synchronize: "synchronize" property string reply: "reply" diff --git a/framework/qml/StatusBar.qml b/framework/qml/StatusBar.qml index fa85f872..ea2b4db5 100644 --- a/framework/qml/StatusBar.qml +++ b/framework/qml/StatusBar.qml @@ -22,6 +22,18 @@ import org.kube.framework 1.0 as Kube Item { id: root property string accountId: "" + property string currentFolderName: "" + property string currentFolderId: "" + property string errorText: "Error" + + onCurrentFolderIdChanged: root.currentFolderName = "" + Kube.FolderListModel { + id: folderModel + folderId: root.currentFolderId + onRowsInserted: root.currentFolderName = folderModel.data(folderModel.index(0, 0), Kube.FolderListModel.Name) + onRowsRemoved: root.currentFolderName = "" + } + Repeater { model: Kube.AccountsModel { accountId: root.accountId @@ -44,14 +56,13 @@ Item { State { name: "busy"; when: model.status == Kube.AccountsModel.BusyStatus PropertyChanges { target: statusBar; visible: true } - PropertyChanges { target: statusText; text: "Synchronizing..."; visible: true } + PropertyChanges { target: statusText; text: root.currentFolderName.length > 0 ? "Synchronizing " + root.currentFolderName: "Synchronizing..."; visible: true } PropertyChanges { target: progressBar; visible: true } }, State { name: "error"; when: model.status == Kube.AccountsModel.ErrorStatus PropertyChanges { target: statusBar; visible: true } - //TODO get to an error description - PropertyChanges { target: statusText; text: "Error"; visible: true } + PropertyChanges { target: statusText; text: root.errorText; visible: true } } ] } @@ -71,6 +82,17 @@ Item { progressBar.from = 0 progressBar.to = message.total progressBar.value = message.progress + if (message.folderId) { + root.currentFolderId = message.folderId + } else { + root.currentFolderId = "" + } + } + } + Kube.Listener { + filter: Kube.Messages.errorNotification + onMessageReceived: { + root.errorText = message.message } } } diff --git a/framework/src/domain/folderlistmodel.cpp b/framework/src/domain/folderlistmodel.cpp index 4437e75b..1ef6f761 100644 --- a/framework/src/domain/folderlistmodel.cpp +++ b/framework/src/domain/folderlistmodel.cpp @@ -105,7 +105,6 @@ void FolderListModel::setAccountId(const QVariant &accountId) auto query = Query(); query.resourceFilter(account); query.setFlags(Sink::Query::LiveQuery | Sink::Query::UpdateStatus); - query.requestTree(); query.request() .request() .request() @@ -115,6 +114,11 @@ void FolderListModel::setAccountId(const QVariant &accountId) runQuery(query); } +QVariant FolderListModel::accountId() const +{ + return {}; +} + static int getPriority(const Sink::ApplicationDomain::Folder &folder) { auto specialPurpose = folder.getSpecialPurpose(); @@ -144,8 +148,22 @@ bool FolderListModel::lessThan(const QModelIndex &left, const QModelIndex &right return leftPriority < rightPriority; } -QVariant FolderListModel::accountId() const +void FolderListModel::setFolderId(const QVariant &folderId) { - return QVariant(); + const auto folder = folderId.toString().toUtf8(); + + //Get all folders of an account + auto query = Query(); + query.filter(folder); + query.request() + .request() + .request() + .request(); + query.setId("folder" + folder); + runQuery(query); } +QVariant FolderListModel::folderId() const +{ + return {}; +} diff --git a/framework/src/domain/folderlistmodel.h b/framework/src/domain/folderlistmodel.h index 8f157ca2..0e412202 100644 --- a/framework/src/domain/folderlistmodel.h +++ b/framework/src/domain/folderlistmodel.h @@ -34,6 +34,7 @@ class FolderListModel : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY (QVariant accountId READ accountId WRITE setAccountId) + Q_PROPERTY (QVariant folderId READ folderId WRITE setFolderId) public: enum Status { @@ -63,6 +64,9 @@ public: void setAccountId(const QVariant &accountId); QVariant accountId() const; + + void setFolderId(const QVariant &folderId); + QVariant folderId() const; protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp index 8231b7df..82351ebb 100644 --- a/framework/src/sinkfabric.cpp +++ b/framework/src/sinkfabric.cpp @@ -160,6 +160,7 @@ public: default: message["message"] = "An unknown error occurred: " + notification.message; } + Fabric::Fabric{}.postMessage("errorNotification", message); } else if (notification.type == Sink::Notification::Info) { if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { message["type"] = Notification::Info; @@ -170,6 +171,10 @@ public: } else if (notification.type == Sink::Notification::Progress) { message["progress"] = notification.progress; message["total"] = notification.total; + if (!notification.entities.isEmpty()) { + message["folderId"] = notification.entities.first(); + } + message["resourceId"] = notification.resource; Fabric::Fabric{}.postMessage("progressNotification", message); return; } else { -- cgit v1.2.3