Warning, /pim/kube/views/composer/qml/View.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
0003  *  Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
0004  *
0005  *  This program is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU General Public License as published by
0007  *  the Free Software Foundation; either version 2 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License along
0016  *  with this program; if not, write to the Free Software Foundation, Inc.,
0017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 
0020 
0021 import QtQuick 2.7
0022 import QtQuick.Layouts 1.1
0023 import QtQuick.Dialogs 1.0 as Dialogs
0024 
0025 import org.kube.framework 1.0 as Kube
0026 
0027 Kube.View {
0028     id: root
0029 
0030     visibleViews: 2
0031     property bool newMessage: false
0032     property int loadType: Kube.ComposerController.Draft
0033     property variant message: {}
0034     property variant recipients: []
0035     property variant accountId: {}
0036 
0037     resources: [
0038         Kube.ComposerController {
0039             id: composerController
0040             objectName: "composerController"
0041             sign: signCheckbox.enabled && signCheckbox.checked
0042             encrypt: encryptCheckbox.enabled && encryptCheckbox.checked
0043             onDone: root.done()
0044 
0045             property bool foundAllKeys: composerController.to.foundAllKeys && composerController.cc.foundAllKeys && composerController.bcc.foundAllKeys
0046 
0047             sendAction.enabled: composerController.accountId &&
0048                                 composerController.subject &&
0049                                 (!composerController.encrypt || composerController.foundAllKeys) &&
0050                                 (!composerController.sign && !composerController.encrypt || composerController.foundPersonalKeys) &&
0051                                 !composerController.to.empty
0052             saveAsDraftAction.enabled: composerController.accountId
0053             onMessageLoaded: { editorPage.initialText = body }
0054             onCleared: { editorPage.initialText = "" }
0055         }
0056     ]
0057 
0058     onSetup: {
0059         loadMessage(root.message, root.loadType)
0060         if (root.accountId) {
0061             composerController.identitySelector.currentAccountId = root.accountId
0062         }
0063     }
0064 
0065     onRefresh: {
0066         Kube.Fabric.postMessage(Kube.Messages.synchronize, {"type": "mail", "specialPurpose": "drafts"})
0067         //For autocompletion
0068         Kube.Fabric.postMessage(Kube.Messages.synchronize, {"type": "contacts"})
0069     }
0070 
0071     onAborted: {
0072         //Avoid loosing the message
0073         if (composerController.saveAsDraftAction.enabled) {
0074             composerController.saveAsDraftAction.execute()
0075         }
0076     }
0077 
0078     function loadMessage(message, loadType) {
0079         if (message) {
0080             switch(loadType) {
0081                 case Kube.ComposerController.Draft:
0082                     composerController.loadDraft(message)
0083                     break;
0084                 case Kube.ComposerController.Reply:
0085                     composerController.loadReply(message)
0086                     editorPage.focusBody()
0087                     break;
0088                 case Kube.ComposerController.Forward:
0089                     composerController.loadForward(message)
0090                     editorPage.forceActiveFocus()
0091                     break;
0092             }
0093 
0094         } else if (newMessage) {
0095             composerController.clear()
0096             if (root.recipients) {
0097                 for (var i = 0; i < root.recipients.length; ++i) {
0098                     composerController.to.add({name: root.recipients[i]})
0099                 }
0100             }
0101             editorPage.forceActiveFocus()
0102         }
0103     }
0104 
0105     function closeFirstSplitIfNecessary() {
0106         //Move the view forward
0107         if (root.currentIndex == 0) {
0108             root.incrementCurrentIndex()
0109         }
0110     }
0111 
0112     //Drafts
0113     Rectangle {
0114         width: Kube.Units.gridUnit * 15
0115         Layout.minimumWidth: Kube.Units.gridUnit * 5
0116         Layout.fillHeight: true
0117 
0118         color: Kube.Colors.darkBackgroundColor
0119 
0120         ColumnLayout {
0121 
0122             anchors {
0123                 fill: parent
0124                 topMargin: Kube.Units.largeSpacing
0125                 leftMargin: Kube.Units.largeSpacing
0126             }
0127 
0128             spacing: Kube.Units.largeSpacing
0129 
0130             Kube.PositiveButton {
0131                 objectName: "newMailButton"
0132 
0133                 width: parent.width - Kube.Units.largeSpacing
0134                 focus: true
0135                 text: qsTr("New Email")
0136                 onClicked: {
0137                     listView.currentIndex = -1
0138                     composerController.clear()
0139                     editorPage.forceActiveFocus()
0140                 }
0141             }
0142 
0143             Kube.Label{
0144                 text: qsTr("Drafts")
0145                 color: Kube.Colors.highlightedTextColor
0146                 font.weight: Font.Bold
0147             }
0148 
0149             Kube.ListView {
0150                 id: listView
0151                 activeFocusOnTab: true
0152 
0153                 Layout.fillWidth: true
0154                 Layout.fillHeight: true
0155                 clip: true
0156                 currentIndex: -1
0157                 highlightFollowsCurrentItem: false
0158 
0159                 //BEGIN keyboard nav
0160                 onActiveFocusChanged: {
0161                     if (activeFocus && currentIndex < 0) {
0162                         currentIndex = 0
0163                     }
0164                 }
0165                 //END keyboard nav
0166 
0167                 onCurrentItemChanged: {
0168                     if (currentItem) {
0169                         root.loadMessage(currentItem.currentData.domainObject, Kube.ComposerController.Draft)
0170                     }
0171                 }
0172 
0173                 model: Kube.MailListModel {
0174                     id: mailListModel
0175                     filter: {
0176                         "drafts": true,
0177                         "headersOnly": false,
0178                         "fetchMails": true
0179                     }
0180                 }
0181 
0182                 delegate: Kube.ListDelegate {
0183                     id: delegateRoot
0184 
0185                     color: Kube.Colors.darkBackgroundColor
0186                     border.width: 0
0187 
0188                     Item {
0189                         id: content
0190 
0191                         anchors {
0192                             fill: parent
0193                             margins: Kube.Units.smallSpacing
0194                         }
0195 
0196                         Kube.Label {
0197                             width: content.width - Kube.Units.largeSpacing
0198                             text: model.subject == "" ? "no subject" : model.subject
0199                             color: Kube.Colors.highlightedTextColor
0200                             maximumLineCount: 2
0201                             wrapMode: Text.WrapAnywhere
0202                             elide: Text.ElideRight
0203                         }
0204 
0205                         Kube.Label {
0206                             anchors {
0207                                 right: parent.right
0208                                 rightMargin: Kube.Units.largeSpacing
0209                                 bottom: parent.bottom
0210                             }
0211                             text: Qt.formatDateTime(model.date, "dd MMM yyyy")
0212                             font.italic: true
0213                             color: Kube.Colors.disabledTextColor
0214                             font.pointSize: Kube.Units.smallFontSize
0215                             visible: !delegateRoot.hovered
0216                         }
0217                     }
0218                     Row {
0219                         id: buttons
0220 
0221                         anchors {
0222                             right: parent.right
0223                             bottom: parent.bottom
0224                             bottomMargin: Kube.Units.smallSpacing
0225                             rightMargin: Kube.Units.largeSpacing
0226                         }
0227 
0228                         visible: delegateRoot.hovered
0229                         spacing: Kube.Units.smallSpacing
0230                         opacity: 0.7
0231 
0232                         Kube.IconButton {
0233                             id: deleteButton
0234                             activeFocusOnTab: true
0235                             iconName: Kube.Icons.moveToTrash
0236                             visible: enabled
0237                             enabled: !!model.mail
0238                             onClicked: Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": model.mail})
0239                         }
0240                     }
0241                 }
0242             }
0243         }
0244     }
0245 
0246     //Content
0247     EditorPage {
0248         id: editorPage
0249         Layout.fillWidth: true
0250         Layout.minimumWidth: Kube.Units.gridUnit * 5
0251         Layout.fillHeight: true
0252 
0253         controller: composerController
0254         onDone: recipients.forceActiveFocus(Qt.TabFocusReason)
0255         onFocusChange: closeFirstSplitIfNecessary()
0256     }
0257 
0258     //Recipients
0259     FocusScope {
0260         id: recipients
0261         Layout.fillHeight: true
0262         width: Kube.Units.gridUnit * 15
0263         activeFocusOnTab: true
0264 
0265         //background
0266         Rectangle {
0267             anchors.fill: parent
0268             color: Kube.Colors.backgroundColor
0269 
0270             Rectangle {
0271                 height: parent.height
0272                 width: 1
0273                 color: Kube.Colors.buttonColor
0274             }
0275         }
0276 
0277         //Content
0278         ColumnLayout {
0279             anchors {
0280                 fill: parent
0281                 margins: Kube.Units.largeSpacing
0282             }
0283 
0284             spacing: Kube.Units.largeSpacing
0285             ColumnLayout {
0286                 Layout.maximumWidth: parent.width
0287                 Layout.fillWidth: true
0288                 Layout.fillHeight: true
0289                 Layout.minimumHeight: Kube.Units.gridUnit
0290 
0291                 AddresseeListEditor {
0292                     id: addressListEditorTo
0293                     label: qsTr("Sending email to:")
0294                     Layout.minimumHeight: Kube.Units.gridUnit
0295                     //FIXME workaround for height of all entries in this ColumnLayout to grow over the size of the layout
0296                     Layout.maximumHeight: parent.height - addressListEditorCc.height - addressListEditorBcc.height
0297                     Layout.preferredHeight: implicitHeight
0298                     Layout.fillWidth: true
0299                     focus: true
0300                     activeFocusOnTab: true
0301                     encrypt: composerController.encrypt
0302                     controller: composerController.to
0303                     completer: composerController.recipientCompleter
0304                 }
0305 
0306                 AddresseeListEditor {
0307                     id: addressListEditorCc
0308                     label: qsTr("Sending copy to (Cc):")
0309                     Layout.minimumHeight: Kube.Units.gridUnit
0310                     //FIXME workaround for height of all entries in this ColumnLayout to grow over the size of the layout
0311                     Layout.maximumHeight: parent.height - addressListEditorTo.height - addressListEditorBcc.height
0312                     Layout.preferredHeight: implicitHeight
0313                     Layout.fillWidth: true
0314                     activeFocusOnTab: true
0315                     encrypt: composerController.encrypt
0316                     controller: composerController.cc
0317                     completer: composerController.recipientCompleter
0318                 }
0319 
0320                 AddresseeListEditor {
0321                     id: addressListEditorBcc
0322                     label: qsTr("Sending secret copy to (Bcc):")
0323                     Layout.minimumHeight: Kube.Units.gridUnit
0324                     //FIXME workaround for height of all entries in this ColumnLayout to grow over the size of the layout
0325                     Layout.maximumHeight: parent.height - addressListEditorCc.height - addressListEditorBcc.height
0326                     Layout.preferredHeight: implicitHeight
0327                     Layout.fillWidth: true
0328                     activeFocusOnTab: true
0329                     encrypt: composerController.encrypt
0330                     controller: composerController.bcc
0331                     completer: composerController.recipientCompleter
0332                 }
0333                 Item {
0334                     Layout.preferredHeight: 0
0335                     width: parent.width
0336                     Layout.fillHeight: true
0337                 }
0338             }
0339 
0340             RowLayout {
0341                 enabled: composerController.foundPersonalKeys
0342                 Kube.CheckBox {
0343                     id: encryptCheckbox
0344                     checked: composerController.encrypt
0345                 }
0346                 Kube.Label {
0347                     text: qsTr("encrypt")
0348                 }
0349             }
0350 
0351             RowLayout {
0352                 enabled: composerController.foundPersonalKeys
0353                 Kube.CheckBox {
0354                     id: signCheckbox
0355                     checked: composerController.sign
0356                 }
0357                 Kube.Label {
0358                     text: qsTr("sign")
0359                 }
0360             }
0361             Kube.Label {
0362                 visible: !composerController.foundPersonalKeys
0363                 Layout.maximumWidth: parent.width
0364                 text: qsTr("Encryption is not available because your personal key has not been found.")
0365                 wrapMode: Text.Wrap
0366             }
0367 
0368             RowLayout {
0369                 Layout.maximumWidth: parent.width
0370                 width: parent.width
0371                 height: Kube.Units.gridUnit
0372 
0373                 Kube.Button {
0374                     width: saveDraftButton.width
0375                     text: qsTr("Discard")
0376                     onClicked: root.done()
0377                 }
0378 
0379                 Kube.Button {
0380                     id: saveDraftButton
0381 
0382                     text: qsTr("Save as Draft")
0383                     enabled: composerController.saveAsDraftAction.enabled
0384                     onClicked: {
0385                         composerController.saveAsDraftAction.execute()
0386                     }
0387                 }
0388             }
0389 
0390             ColumnLayout {
0391                 Layout.maximumWidth: parent.width
0392                 Layout.fillWidth: true
0393                 Kube.Label {
0394                     id: fromLabel
0395                     text: qsTr("You are sending this from:")
0396                 }
0397 
0398                 Kube.ComboBox {
0399                     id: identityCombo
0400                     objectName: "identityCombo"
0401 
0402                     width: parent.width - Kube.Units.largeSpacing * 2
0403 
0404                     model: composerController.identitySelector.model
0405                     textRole: "address"
0406                     Layout.fillWidth: true
0407                     //A regular binding is not enough in this case, we have to use the Binding element
0408                     Binding { target: identityCombo; property: "currentIndex"; value: composerController.identitySelector.currentIndex }
0409                     onCurrentIndexChanged: {
0410                         composerController.identitySelector.currentIndex = currentIndex
0411                     }
0412                 }
0413             }
0414 
0415             Kube.PositiveButton {
0416                 objectName: "sendButton"
0417                 id: sendButton
0418 
0419                 width: parent.width
0420 
0421                 text: qsTr("Send")
0422                 enabled: composerController.sendAction.enabled
0423                 onClicked: {
0424                     composerController.sendAction.execute()
0425                 }
0426             }
0427         }
0428     }//FocusScope
0429 }