From 7037e7270a2a06e726871d953061213b26d66ea7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 2 Jan 2017 10:27:44 +0100 Subject: Move to trash from mailview --- components/package/contents/ui/SingleMailView.qml | 15 +++++++++++++++ framework/domain/mailcontroller.cpp | 10 ++++++++++ framework/domain/mailcontroller.h | 2 ++ framework/domain/maillistmodel.cpp | 7 +++++++ framework/domain/maillistmodel.h | 4 +++- 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/components/package/contents/ui/SingleMailView.qml b/components/package/contents/ui/SingleMailView.qml index 9b38b5be..5576391d 100644 --- a/components/package/contents/ui/SingleMailView.qml +++ b/components/package/contents/ui/SingleMailView.qml @@ -353,9 +353,24 @@ Item { leftMargin: Kirigami.Units.gridUnit } + KubeFramework.MailController { + id: mailController + mail: model.mail + } + text: "Delete Mail" color: Kirigami.Theme.textColor opacity: 0.5 + enabled: mailController.moveToTrashAction.enabled + MouseArea { + anchors.fill: parent + enabled: mailController.moveToTrashAction.enabled + onClicked: { + if (mailController.moveToTrashAction.enabled) { + mailController.moveToTrashAction.execute(); + } + } + } } Controls1.ToolButton { diff --git a/framework/domain/mailcontroller.cpp b/framework/domain/mailcontroller.cpp index 4c5ae5c6..3d29ba22 100644 --- a/framework/domain/mailcontroller.cpp +++ b/framework/domain/mailcontroller.cpp @@ -32,6 +32,16 @@ MailController::MailController() QObject::connect(markAsReadAction(), &Kube::ControllerAction::triggered, this, &MailController::markAsRead); QObject::connect(moveToTrashAction(), &Kube::ControllerAction::triggered, this, &MailController::moveToTrash); QObject::connect(removeAction(), &Kube::ControllerAction::triggered, this, &MailController::remove); + + QObject::connect(this, &MailController::mailChanged, &MailController::updateActions); + updateActions(); +} + +void MailController::updateActions() +{ + if (auto mail = getMail()) { + action_moveToTrash->setEnabled(!mail->getTrash()); + } } void MailController::markAsRead() diff --git a/framework/domain/mailcontroller.h b/framework/domain/mailcontroller.h index 6c41f433..c20cf595 100644 --- a/framework/domain/mailcontroller.h +++ b/framework/domain/mailcontroller.h @@ -32,4 +32,6 @@ class MailController : public Kube::Controller public: explicit MailController(); +private slots: + void updateActions(); }; diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index 17b98c2b..950a2b8d 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp @@ -55,6 +55,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const roles[MimeMessage] = "mimeMessage"; roles[DomainObject] = "domainObject"; roles[ThreadSize] = "threadSize"; + roles[Mail] = "mail"; return roles; } @@ -97,6 +98,8 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const return mail->getProperty("importantCollected").toList().contains(true); case Draft: return mail->getDraft(); + case Trash: + return mail->getTrash(); case Id: return mail->identifier(); case DomainObject: @@ -105,6 +108,8 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const return mail->getMimeMessage(); case ThreadSize: return mail->getProperty("count").toInt(); + case Mail: + return QVariant::fromValue(mail); } return QSortFilterProxyModel::data(idx, role); } @@ -142,6 +147,7 @@ void MailListModel::setParentFolder(const QVariant &parentFolder) query.request(); query.request(); query.request(); + query.request(); query.request(); qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); runQuery(query); @@ -170,6 +176,7 @@ void MailListModel::setMail(const QVariant &variant) query.request(); query.request(); query.request(); + query.request(); query.request(); qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); runQuery(query); diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index 22b97e11..71a0a6df 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h @@ -51,10 +51,12 @@ public: Unread, Important, Draft, + Trash, Id, MimeMessage, DomainObject, - ThreadSize + ThreadSize, + Mail }; QHash roleNames() const Q_DECL_OVERRIDE; -- cgit v1.2.3