Warning, /pim/kube/views/conversation/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.9
0022 import QtQuick.Controls 1.3 as Controls1
0023 import QtQuick.Controls 2
0024 import QtQuick.Layouts 1.1
0025 
0026 import org.kube.framework 1.0 as Kube
0027 
0028 Kube.View {
0029     id: root
0030     property var currentFolder: null
0031     property bool important: false
0032     property bool hideTrash: false
0033     property bool hideNonTrash: false
0034 
0035     //We have to hardcode because all the mapToItem/mapFromItem functions are garbage
0036     searchArea: Qt.rect(ApplicationWindow.window.sidebarWidth + mailListView.parent.x, 0, (mailView.x + mailView.width) - mailListView.parent.x, (mailView.y + mailView.height) - mailListView.y)
0037 
0038     onFilterChanged: {
0039         Kube.Fabric.postMessage(Kube.Messages.searchString, {"searchString": filter})
0040     }
0041 
0042     Kube.Listener {
0043         filter: Kube.Messages.folderSelection
0044         onMessageReceived: {
0045             //TODO we don't currently expect this to be changed outside of this view.
0046             //Otherwise we'd have to select the correct entry in the listview
0047             root.currentFolder = message.folder
0048         }
0049     }
0050 
0051     onRefresh: {
0052         if (!!root.currentFolder) {
0053             Kube.Fabric.postMessage(Kube.Messages.synchronize, {"folder": root.currentFolder});
0054             Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": Kube.Context.currentAccountId, "type": "folder"})
0055         } else {
0056             Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": Kube.Context.currentAccountId})
0057         }
0058     }
0059 
0060     onCurrentFolderChanged: {
0061         if (!!root.currentFolder) {
0062             root.important = false
0063         }
0064     }
0065 
0066     Kube.Listener {
0067         filter: Kube.Messages.search
0068         onMessageReceived: root.triggerSearch()
0069     }
0070 
0071     helpViewComponent: Kube.HelpPopup {
0072         ListModel {
0073             ListElement { description: qsTr("Jump to top of threadlist:"); shortcut: "t" }
0074             ListElement { description: qsTr("Jump to next thread:"); shortcut: "j" }
0075             ListElement { description: qsTr("Jump to previous thread:"); shortcut: "k" }
0076             ListElement { description: qsTr("Jump to next message:"); shortcut: "n" }
0077             ListElement { description: qsTr("Jump to previous message:"); shortcut: "p" }
0078             ListElement { description: qsTr("Jump to next folder:"); shortcut: "f,n" }
0079             ListElement { description: qsTr("Jump to previous folder:"); shortcut: "f,p" }
0080             ListElement { description: qsTr("Compose new message:"); shortcut: "c" }
0081             ListElement { description: qsTr("Reply to the currently focused message:"); shortcut: "r" }
0082             ListElement { description: qsTr("Delete the currently focused message:"); shortcut: "d" }
0083             ListElement { description: qsTr("Mark the currently focused message as important:"); shortcut: "i" }
0084             ListElement { description: qsTr("Mark the currently focused message as unread:"); shortcut: "u" }
0085             ListElement { description: qsTr("Show this help text:"); shortcut: "?" }
0086         }
0087     }
0088 
0089     Shortcut {
0090         enabled: root.isCurrentView
0091         sequences: ['j']
0092         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextConversation, {})
0093     }
0094     Shortcut {
0095         enabled: root.isCurrentView
0096         sequences: ['k']
0097         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousConversation, {})
0098     }
0099     Shortcut {
0100         enabled: root.isCurrentView
0101         sequences: ['t']
0102         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectTopConversation, {})
0103     }
0104     Shortcut {
0105         enabled: root.isCurrentView
0106         sequences: ['Shift+J']
0107         onActivated: Kube.Fabric.postMessage(Kube.Messages.scrollConversationDown, {})
0108     }
0109     Shortcut {
0110         enabled: root.isCurrentView
0111         sequences: ['Shift+K']
0112         onActivated: Kube.Fabric.postMessage(Kube.Messages.scrollConversationUp, {})
0113     }
0114     Shortcut {
0115         sequences: ['n']
0116         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextMessage, {})
0117     }
0118     Shortcut {
0119         enabled: root.isCurrentView
0120         sequences: ['p']
0121         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousMessage, {})
0122     }
0123     Shortcut {
0124         enabled: root.isCurrentView
0125         sequences: ['f,n']
0126         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextFolder, {})
0127     }
0128     Shortcut {
0129         enabled: root.isCurrentView
0130         sequences: ['f,p']
0131         onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousFolder, {})
0132     }
0133     Shortcut {
0134         enabled: root.isCurrentView
0135         sequences: ['c']
0136         onActivated: Kube.Fabric.postMessage(Kube.Messages.compose, {})
0137     }
0138     Shortcut {
0139         enabled: root.isCurrentView
0140         sequence: "?"
0141         onActivated: root.showHelp()
0142     }
0143 
0144 
0145     Controls1.SplitView {
0146         Layout.fillWidth: true
0147         Layout.fillHeight: true
0148 
0149         Kube.LeftSidebar {
0150             Layout.fillHeight: parent.height
0151             buttons: [
0152                 Kube.PositiveButton {
0153                     objectName: "newMailButton"
0154                     Layout.fillWidth: true
0155                     focus: true
0156                     text: qsTr("New Email")
0157                     onClicked: Kube.Fabric.postMessage(Kube.Messages.compose, {})
0158                 }
0159             ]
0160 
0161             Kube.InlineAccountSwitcher {
0162                 id: accountFolderview
0163                 activeFocusOnTab: true
0164 
0165                 Layout.fillWidth: true
0166                 Layout.fillHeight: true
0167 
0168                 delegate: ColumnLayout {
0169                     id: delegateRoot
0170 
0171                     function currentChanged(isCurrent) {
0172                         if (isCurrent) {
0173                             //Reset important on account switch
0174                             root.important = false
0175                             //Necessary to re-select folder on account change (so the maillist is updated)
0176                             listView.indexSelected(listView.currentIndex)
0177                             //To ensure we always have something selected in the UI as well
0178                             if (!!listView.currentIndex) {
0179                                 listView.selectRootIndex()
0180                             }
0181                         }
0182                     }
0183 
0184                     property Component buttonDelegate: Row {
0185                         Kube.IconButton {
0186                             height: Kube.Units.gridUnit
0187                             padding: 0
0188                             iconName: Kube.Icons.markImportant_inverted
0189                             checked: root.important
0190                             checkable: true
0191                             onClicked: {
0192                                 root.important = checked
0193                                 if (checked) {
0194                                     listView.clearSelection()
0195                                 } else {
0196                                     listView.selectRootIndex()
0197                                 }
0198                             }
0199                         }
0200                         //TODO: edit mode
0201                         // Kube.IconButton {
0202                         //     height: Kube.Units.gridUnit
0203                         //     padding: 0
0204                         //     iconName: Kube.Icons.overflowMenu_inverted
0205                         //     onClicked: listView.editMode = !listView.editMode;
0206                         //     checkable: true
0207                         //     checked: listView.editMode
0208                         // }
0209                     }
0210 
0211                     Kube.FolderListView {
0212                         id: listView
0213                         objectName: "folderListView"
0214                         accountId: delegateRoot.parent.accountId
0215 
0216                         Layout.fillWidth: true
0217                         Layout.fillHeight: true
0218 
0219                         function indexSelected(currentIndex) {
0220                             if (!!currentIndex && currentIndex.valid) {
0221                                 Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder": model.data(currentIndex, Kube.FolderListModel.DomainObject),
0222                                                                                         "trash": model.data(currentIndex, Kube.FolderListModel.Trash)})
0223                             } else {
0224                                 Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder": null,
0225                                                                                         "trash": false})
0226                             }
0227                         }
0228 
0229                         onCurrentIndexChanged: {
0230                             if (delegateRoot.parent.isCurrent) {
0231                                 indexSelected(currentIndex)
0232                             }
0233                         }
0234 
0235                         onDropped: {
0236                             var folder = model.data(index, Kube.FolderListModel.DomainObject)
0237                             Kube.Fabric.postMessage(Kube.Messages.moveToFolder, {"mail": drop.source.mail, "folder": folder})
0238                             drop.accept(Qt.MoveAction)
0239                         }
0240                     }
0241                 }
0242             }
0243         }
0244 
0245         Rectangle {
0246             width: Kube.Units.gridUnit * 18
0247             Layout.fillHeight: parent.height
0248 
0249             color: "transparent"
0250             border.width: 1
0251             border.color: Kube.Colors.buttonColor
0252 
0253             Kube.MailListView  {
0254                 id: mailListView
0255                 objectName: "mailListView"
0256                 anchors.fill: parent
0257                 activeFocusOnTab: true
0258                 Layout.minimumWidth: Kube.Units.gridUnit * 10
0259                 showImportant: root.important
0260                 currentAccount: Kube.Context.currentAccountId
0261                 filter: root.filter
0262                 Kube.Listener {
0263                     filter: Kube.Messages.folderSelection
0264                     onMessageReceived: {
0265                         root.clearSearch()
0266                         mailListView.parentFolder = message.folder
0267                     }
0268                 }
0269                 onCurrentMailChanged: {
0270                     Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail": currentMail})
0271                 }
0272             }
0273         }
0274 
0275         Kube.ConversationView {
0276             id: mailView
0277             objectName: "mailView"
0278             Layout.fillWidth: true
0279             Layout.fillHeight: parent.height
0280             activeFocusOnTab: true
0281             model: Kube.MailListModel {
0282                 id: mailViewModel
0283             }
0284             Kube.Listener {
0285                 filter: Kube.Messages.mailSelection
0286                 onMessageReceived: {
0287                     if (!mailListView.threaded) {
0288                         mailViewModel.filter = {
0289                             "singleMail": message.mail,
0290                             "headersOnly": false,
0291                             "fetchMails": true
0292                         }
0293                     } else {
0294                         mailViewModel.filter = {
0295                             "mail": message.mail,
0296                             "headersOnly": false,
0297                             "fetchMails": true,
0298                             "hideTrash": root.hideTrash,
0299                             "hideNonTrash": root.hideNonTrash
0300                         }
0301                     }
0302                 }
0303             }
0304 
0305             Kube.Listener {
0306                 filter: Kube.Messages.folderSelection
0307                 onMessageReceived: {
0308                     root.hideTrash = !message.trash
0309                     root.hideNonTrash = message.trash
0310                 }
0311             }
0312 
0313         }
0314     }
0315 
0316 }