From d7b40aeb125ece23bf2f039f4bb938f5cd010896 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 14 Jun 2017 17:24:07 +0200 Subject: Attachment removal We'd rather do something via the model index instead of requering an additional role, but this works for the time being. --- components/kube/contents/ui/ComposerView.qml | 1 + framework/src/domain/composercontroller.cpp | 15 ++++++++++++++- framework/src/domain/composercontroller.h | 5 +++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/components/kube/contents/ui/ComposerView.qml b/components/kube/contents/ui/ComposerView.qml index b92b0f2a..b8da8a83 100644 --- a/components/kube/contents/ui/ComposerView.qml +++ b/components/kube/contents/ui/ComposerView.qml @@ -271,6 +271,7 @@ Kube.View { icon: model.iconName clip: true actionIcon: Kube.Icons.remove + onExecute: composerController.removeAttachment(model.url) } } } diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp index 31cb896d..9e006af4 100644 --- a/framework/src/domain/composercontroller.cpp +++ b/framework/src/domain/composercontroller.cpp @@ -97,6 +97,7 @@ ComposerController::ComposerController() {MimeTypeRole, "mimetype"}, {DescriptionRole, "description"}, {IconNameRole, "iconName"}, + {UrlRole, "url"}, {InlineRole, "inline"}}); updateSaveAsDraftAction(); // mSendAction->monitorProperty(); @@ -218,13 +219,25 @@ void ComposerController::addAttachment(const QUrl &url) item->setData(fileInfo.fileName(), FilenameRole); item->setData(false, InlineRole); item->setData(mimeType.iconName(), IconNameRole); + item->setData(url, UrlRole); item->setData(data, ContentRole); mAttachmentModel->appendRow(item); } } -void ComposerController::removeAttachment(const QString &s) +void ComposerController::removeAttachment(const QUrl &url) { + auto root = mAttachmentModel->invisibleRootItem(); + if (root->hasChildren()) { + for (int row = 0; row < root->rowCount(); row++) { + auto item = root->child(row, 0); + const auto url = item->data(UrlRole).toUrl(); + if (url == item->data(UrlRole).toUrl()) { + root->removeRow(row); + return; + } + } + } } Completer *ComposerController::recipientCompleter() const diff --git a/framework/src/domain/composercontroller.h b/framework/src/domain/composercontroller.h index de154b66..b2486cee 100644 --- a/framework/src/domain/composercontroller.h +++ b/framework/src/domain/composercontroller.h @@ -92,7 +92,7 @@ public: Q_INVOKABLE void addBcc(const QString &); Q_INVOKABLE void removeBcc(const QString &); Q_INVOKABLE void addAttachment(const QUrl &); - Q_INVOKABLE void removeAttachment(const QString &); + Q_INVOKABLE void removeAttachment(const QUrl &); public slots: virtual void clear() Q_DECL_OVERRIDE; @@ -109,7 +109,8 @@ private: MimeTypeRole, DescriptionRole, InlineRole, - IconNameRole + IconNameRole, + UrlRole }; void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); -- cgit v1.2.3