From 966d85717c115cc03f2d1b0f41a24fd363726027 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 23 May 2017 12:00:31 +0200 Subject: All of the MailViewer in one place --- framework/qml/ConversationView.qml | 342 ++--------------------------- framework/qml/MailViewer.qml | 386 +++++++++++++++++++++++++++++---- framework/src/domain/messageparser.cpp | 6 + 3 files changed, 368 insertions(+), 366 deletions(-) (limited to 'framework') diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 5850d2c7..f59704d0 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -207,339 +207,23 @@ Rectangle { } } - Rectangle { + MailViewer { id: sheet anchors.centerIn: parent - implicitHeight: header.height + attachments.height + body.height + incompleteBody.height + footer.height + Kube.Units.largeSpacing width: parent.width - Kube.Units.gridUnit * 2 - //Overlay for non-active mails - Rectangle { - anchors.fill: parent - visible: !wrapper.isCurrent - color: "lightGrey" - z: 1 - opacity: 0.2 - } - - color: Kube.Colors.viewBackgroundColor - - //BEGIN header - Item { - id: header - - anchors { - top: parent.top - left: parent.left - right: parent.right - margins: Kube.Units.largeSpacing - } - - height: headerContent.height + Kube.Units.smallSpacing - - states: [ - State { - name: "small" - PropertyChanges { target: subject; wrapMode: Text.NoWrap} - PropertyChanges { target: recipients; visible: true} - PropertyChanges { target: to; visible: false} - PropertyChanges { target: cc; visible: false} - PropertyChanges { target: bcc; visible: false} - }, - State { - name: "details" - PropertyChanges { target: subject; wrapMode: Text.WrapAnywhere} - PropertyChanges { target: recipients; visible: false} - PropertyChanges { target: to; visible: true} - PropertyChanges { target: cc; visible: true} - PropertyChanges { target: bcc; visible: true} - } - ] - - state: "small" - - Kube.Label { - id: date_label - - anchors { - right: seperator.right - top: parent.top - } - - text: Qt.formatDateTime(model.date, "dd MMM yyyy hh:mm") - - font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.7 - opacity: 0.75 - } - - Column { - id: headerContent - - anchors { - //left: to_l.right - horizontalCenter: parent.horizontalCenter - } - - //spacing: Kube.Units.smallSpacing - - width: parent.width - - Row{ - id: from - - width: parent.width - - spacing: Kube.Units.smallSpacing - clip: true - - Kube.Label { - id: senderName - - text: model.senderName - font.weight: Font.DemiBold - opacity: 0.75 - } - - Kube.Label { - width: parent.width - senderName.width - date_label.width - Kube.Units.largeSpacing - - - text: model.sender - elide: Text.ElideRight - opacity: 0.75 - clip: true - } - } - - Kube.Label { - id: subject - - width: to.width - - text: model.subject - elide: Text.ElideRight - opacity: 0.75 - font.italic: true - states: [ - State { - name: "trash"; when: model.trash - PropertyChanges { target: subject; text: "Trash: " + model.subject } - }, - State { - name: "draft"; when: model.draft - PropertyChanges { target: subject; text: "Draft: " + model.subject } - }, - State { - name: "sent"; when: model.sent - PropertyChanges { target: subject; text: "Sent: " + model.subject } - } - ] - } - - Kube.Label { - id: recipients - - width: parent.width - goDown.width - Kube.Units.smallSpacing - - text:"to: "+ model.to + " " + model.cc + " " + model.bcc - elide: Text.ElideRight - opacity: 0.75 - } - - Kube.Label { - id: to - - width: parent.width - goDown.width - Kube.Units.smallSpacing - - text:"to: " + model.to - wrapMode: Text.WordWrap - opacity: 0.75 - } - - Kube.Label { - id: cc - - width: parent.width - goDown.width - Kube.Units.smallSpacing - - text:"cc: " + model.cc - wrapMode: Text.WordWrap - opacity: 0.75 - } - - Kube.Label { - id: bcc - - width: parent.width - goDown.width - Kube.Units.smallSpacing - - text:"bcc: " + model.bcc - wrapMode: Text.WordWrap - opacity: 0.75 - } - - } - - Rectangle { - id: goDown - - anchors { - bottom: seperator.top - right: seperator.right - } - - height: Kube.Units.gridUnit - width: height - - color: Kube.Colors.backgroundColor - - Controls1.ToolButton { - anchors.fill: parent - - iconName: header.state === "details" ? Kube.Icons.goUp : Kube.Icons.goDown - - onClicked: { - header.state === "details" ? header.state = "small" : header.state = "details" - } - } - } - - Rectangle { - id: seperator - - anchors { - left: parent.left - right: parent.right - bottom: parent.bottom - } - - height: 1 - - color: Kube.Colors.textColor - opacity: 0.5 - } - } - //END header - - Flow { - id: attachments - - anchors { - top: header.bottom - topMargin: Kube.Units.smallSpacing - right: header.right - } - - width: header.width - Kube.Units.largeSpacing - - layoutDirection: Qt.RightToLeft - spacing: Kube.Units.smallSpacing - clip: true - - Repeater { - model: body.attachments - - delegate: AttachmentDelegate { - name: model.name - icon: "mail-attachment" - - clip: true - - //TODO size encrypted signed type - } - } - } - - MailViewer { - id: body - - anchors { - top: header.bottom - left: header.left - right: header.right - leftMargin: Kube.Units.largeSpacing - rightMargin: Kube.Units.largeSpacing - topMargin: Math.max(attachments.height, Kube.Units.largeSpacing) - } - - width: header.width - Kube.Units.largeSpacing * 2 - height: desiredHeight - - message: model.mimeMessage - visible: !model.incomplete - } - - Kube.Label { - id: incompleteBody - anchors { - top: header.bottom - left: header.left - right: header.right - leftMargin: Kube.Units.largeSpacing - rightMargin: Kube.Units.largeSpacing - topMargin: Math.max(attachments.height, Kube.Units.largeSpacing) - } - visible: model.incomplete - text: "Incomplete body..." - color: Kube.Colors.textColor - enabled: false - states: [ - State { - name: "inprogress"; when: model.status == Kube.MailListModel.InProgressStatus - PropertyChanges { target: incompleteBody; text: "Downloading message..." } - }, - State { - name: "error"; when: model.status == Kube.MailListModel.ErrorStatus - PropertyChanges { target: incompleteBody; text: "Failed to download message..." } - } - ] - } - Item { - id: footer - - anchors.bottom: parent.bottom - - height: Kube.Units.gridUnit * 2 - width: parent.width - - Kube.Label { - anchors{ - verticalCenter: parent.verticalCenter - left: parent.left - leftMargin: Kube.Units.largeSpacing - } - - text: model.trash ? qsTr("Delete Mail") : qsTr("Move to trash") - opacity: 0.5 - MouseArea { - anchors.fill: parent - enabled: parent.enabled - onClicked: { - if (model.trash) { - Kube.Fabric.postMessage(Kube.Messages.remove, {"mail": model.mail}) - } else { - Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": model.mail}) - } - } - } - } - - Controls1.ToolButton { - visible: !model.trash - anchors{ - verticalCenter: parent.verticalCenter - right: parent.right - rightMargin: Kube.Units.largeSpacing - } - - iconName: model.draft ? Kube.Icons.edit : Kube.Icons.replyToSender - onClicked: { - if (model.draft) { - Kube.Fabric.postMessage(Kube.Messages.edit, {"mail": model.mail, "isDraft": model.draft}) - } else { - Kube.Fabric.postMessage(Kube.Messages.reply, {"mail": model.mail, "isDraft": model.draft}) - } - } - } - } + message: model.mimeMessage + subject: model.subject + sender: model.sender + senderName: model.senderName + to: model.to + cc: model.cc + bcc: model.bcc + date: model.date + trash: model.trash + draft: model.draft + sent: model.sent + incomplete: model.incomplete } } } diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml index 3e118a8d..b6ea4502 100644 --- a/framework/qml/MailViewer.qml +++ b/framework/qml/MailViewer.qml @@ -18,59 +18,371 @@ import QtQuick 2.7 import QtQuick.Controls 1.4 as Controls1 +import QtQuick.Controls 2 import QtQuick.Layouts 1.1 import org.kube.components.mailviewer 1.0 as MV import org.kube.framework 1.0 as Kube -Item { +import QtQuick.Layouts 1.1 +import org.kde.kirigami 1.0 as Kirigami + +Rectangle { id: root + property variant message; - property int desiredHeight: mailViewer.height + 20 - property variant attachments: messageParser.attachments + property variant subject; + property variant sender; + property variant senderName; + property variant to; + property variant cc; + property variant bcc; + property variant date; + property variant trash; + property variant draft; + property variant sent; + property bool incomplete: false; - clip: true + implicitHeight: header.height + attachments.height + body.height + incompleteBody.height + footer.height + Kube.Units.largeSpacing - MV.MailViewer { - anchors.top: root.top - id: mailViewer - model: messageParser.newTree - debug: false - width: parent.width + //Overlay for non-active mails + Rectangle { + anchors.fill: parent + visible: !wrapper.isCurrent + color: "lightGrey" + z: 1 + opacity: 0.2 } - Controls1.TreeView { - id: mailStructure - // anchors.fill: parent - // anchors.top: root.attachments.rowCount() > 0 ? attachments.bottom : mailViewer.bottom - visible: mailViewer.debug - width: parent.width - height: 400 - Controls1.TableViewColumn { - role: "type" - title: "Type" - width: 300 + color: Kube.Colors.viewBackgroundColor + + Kube.MessageParser { + id: messageParser + message: root.message + } + + //BEGIN header + Item { + id: header + + anchors { + top: parent.top + left: parent.left + right: parent.right + margins: Kube.Units.largeSpacing + } + + height: headerContent.height + Kube.Units.smallSpacing + + states: [ + State { + name: "small" + PropertyChanges { target: subject; wrapMode: Text.NoWrap} + PropertyChanges { target: recipients; visible: true} + PropertyChanges { target: to; visible: false} + PropertyChanges { target: cc; visible: false} + PropertyChanges { target: bcc; visible: false} + }, + State { + name: "details" + PropertyChanges { target: subject; wrapMode: Text.WrapAnywhere} + PropertyChanges { target: recipients; visible: false} + PropertyChanges { target: to; visible: true} + PropertyChanges { target: cc; visible: true} + PropertyChanges { target: bcc; visible: true} + } + ] + + state: "small" + + Kube.Label { + id: date_label + + anchors { + right: seperator.right + top: parent.top + } + + text: Qt.formatDateTime(root.date, "dd MMM yyyy hh:mm") + + font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.7 + opacity: 0.75 + } + + Column { + id: headerContent + + anchors { + //left: to_l.right + horizontalCenter: parent.horizontalCenter + } + + //spacing: Kube.Units.smallSpacing + + width: parent.width + + Row{ + id: from + + width: parent.width + + spacing: Kube.Units.smallSpacing + clip: true + + Kube.Label { + id: senderName + + text: root.senderName + font.weight: Font.DemiBold + opacity: 0.75 + } + + Kube.Label { + width: parent.width - senderName.width - date_label.width - Kube.Units.largeSpacing + + + text: root.sender + elide: Text.ElideRight + opacity: 0.75 + clip: true + } + } + + Kube.Label { + id: subject + + width: to.width + + text: root.subject + elide: Text.ElideRight + opacity: 0.75 + font.italic: true + states: [ + State { + name: "trash"; when: root.trash + PropertyChanges { target: subject; text: "Trash: " + root.subject } + }, + State { + name: "draft"; when: root.draft + PropertyChanges { target: subject; text: "Draft: " + root.subject } + }, + State { + name: "sent"; when: root.sent + PropertyChanges { target: subject; text: "Sent: " + root.subject } + } + ] + } + + Kube.Label { + id: recipients + + width: parent.width - goDown.width - Kube.Units.smallSpacing + + text:"to: "+ root.to + " " + root.cc + " " + root.bcc + elide: Text.ElideRight + opacity: 0.75 + } + + Kube.Label { + id: to + + width: parent.width - goDown.width - Kube.Units.smallSpacing + + text:"to: " + root.to + wrapMode: Text.WordWrap + opacity: 0.75 + } + + Kube.Label { + id: cc + + width: parent.width - goDown.width - Kube.Units.smallSpacing + + text:"cc: " + root.cc + wrapMode: Text.WordWrap + opacity: 0.75 + } + + Kube.Label { + id: bcc + + width: parent.width - goDown.width - Kube.Units.smallSpacing + + text:"bcc: " + root.bcc + wrapMode: Text.WordWrap + opacity: 0.75 + } + + } + + Rectangle { + id: goDown + + anchors { + bottom: seperator.top + right: seperator.right + } + + height: Kube.Units.gridUnit + width: height + + color: Kube.Colors.backgroundColor + + Controls1.ToolButton { + anchors.fill: parent + + iconName: header.state === "details" ? Kube.Icons.goUp : Kube.Icons.goDown + + onClicked: { + header.state === "details" ? header.state = "small" : header.state = "details" + } + } + } + + Rectangle { + id: seperator + + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + } + + height: 1 + + color: Kube.Colors.textColor + opacity: 0.5 + } + } + //END header + + Flow { + id: attachments + + anchors { + top: header.bottom + topMargin: Kube.Units.smallSpacing + right: header.right + } + + width: header.width - Kube.Units.largeSpacing + + layoutDirection: Qt.RightToLeft + spacing: Kube.Units.smallSpacing + clip: true + + Repeater { + model: messageParser.attachments + + delegate: AttachmentDelegate { + name: model.name + icon: "mail-attachment" + + clip: true + + //TODO size encrypted signed type + } } - Controls1.TableViewColumn { - role: "embeded" - title: "Embeded" - width: 60 + } + + Item { + id: body + + visible: !root.incomplete + anchors { + top: header.bottom + left: header.left + right: header.right + leftMargin: Kube.Units.largeSpacing + rightMargin: Kube.Units.largeSpacing + topMargin: Math.max(attachments.height, Kube.Units.largeSpacing) } - Controls1.TableViewColumn { - role: "securityLevel" - title: "SecurityLevel" - width: 60 + height: mailViewer.height + 20 + + clip: true + + MV.MailViewer { + id: mailViewer + anchors.top: body.top + anchors.left: body.left + anchors.right: body.right + model: messageParser.newTree + debug: false } - Controls1.TableViewColumn { - role: "content" - title: "Content" - width: 200 + + } + + Kube.Label { + id: incompleteBody + anchors { + top: header.bottom + left: header.left + right: header.right + leftMargin: Kube.Units.largeSpacing + rightMargin: Kube.Units.largeSpacing + topMargin: Math.max(attachments.height, Kube.Units.largeSpacing) } - model: messageParser.newTree + visible: root.incomplete + text: "Incomplete body..." + color: Kube.Colors.textColor + enabled: false + states: [ + State { + name: "inprogress"; when: model.status == Kube.MailListModel.InProgressStatus + PropertyChanges { target: incompleteBody; text: "Downloading message..." } + }, + State { + name: "error"; when: model.status == Kube.MailListModel.ErrorStatus + PropertyChanges { target: incompleteBody; text: "Failed to download message..." } + } + ] } + Item { + id: footer - Kube.MessageParser { - id: messageParser - message: root.message + anchors.bottom: parent.bottom + + height: Kube.Units.gridUnit * 2 + width: parent.width + + Kube.Label { + anchors{ + verticalCenter: parent.verticalCenter + left: parent.left + leftMargin: Kube.Units.largeSpacing + } + + text: model.trash ? qsTr("Delete Mail") : qsTr("Move to trash") + opacity: 0.5 + MouseArea { + anchors.fill: parent + enabled: parent.enabled + onClicked: { + if (model.trash) { + Kube.Fabric.postMessage(Kube.Messages.remove, {"mail": model.mail}) + } else { + Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": model.mail}) + } + } + } + } + + Controls1.ToolButton { + visible: !model.trash + anchors{ + verticalCenter: parent.verticalCenter + right: parent.right + rightMargin: Kube.Units.largeSpacing + } + + iconName: model.draft ? Kube.Icons.edit : Kube.Icons.replyToSender + onClicked: { + if (model.draft) { + Kube.Fabric.postMessage(Kube.Messages.edit, {"mail": model.mail, "isDraft": model.draft}) + } else { + Kube.Fabric.postMessage(Kube.Messages.reply, {"mail": model.mail, "isDraft": model.draft}) + } + } + } } } diff --git a/framework/src/domain/messageparser.cpp b/framework/src/domain/messageparser.cpp index 6df50ebd..76c060f0 100644 --- a/framework/src/domain/messageparser.cpp +++ b/framework/src/domain/messageparser.cpp @@ -54,6 +54,9 @@ void MessageParser::setMessage(const QVariant &message) QAbstractItemModel *MessageParser::newTree() const { + if (!d->mParser) { + return nullptr; + } const auto model = new NewModel(d->mParser); // new ModelTest(model, model); return model; @@ -61,6 +64,9 @@ QAbstractItemModel *MessageParser::newTree() const QAbstractItemModel *MessageParser::attachments() const { + if (!d->mParser) { + return nullptr; + } const auto model = new AttachmentModel(d->mParser); // new ModelTest(model, model); return model; -- cgit v1.2.3