Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 4 | * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | */ |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 19 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 20 | import QtQuick 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Layouts 1.14 |
| 23 | import net.jami.Models 1.0 |
| 24 | |
| 25 | ListView { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 26 | id: root |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 27 | |
ababi | 76b94aa | 2020-08-24 17:46:30 +0200 | [diff] [blame] | 28 | signal needToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, int callState) |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 29 | signal needToSelectItems(string conversationUid) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 30 | signal needToDeselectItems |
| 31 | signal needToBackToWelcomePage |
| 32 | signal needToGrabFocus |
| 33 | |
| 34 | signal needToShowChatView(string accountId, string convUid) |
| 35 | signal currentIndexIsChanged |
| 36 | signal forceUpdatePotentialInvalidItem |
| 37 | |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 38 | // Refresh all items within the model. |
| 39 | function updateListView() { |
| 40 | root.model.dataChanged( |
| 41 | root.model.index(0, 0), |
| 42 | root.model.index( |
| 43 | root.model.rowCount() - 1, 0)) |
| 44 | root.forceUpdatePotentialInvalidItem() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 47 | ConversationSmartListContextMenu { |
| 48 | id: smartListContextMenu |
| 49 | } |
| 50 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 51 | Connections { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 52 | target: ConversationsAdapter |
| 53 | |
| 54 | function onModelChanged(model) { |
| 55 | root.model = model |
| 56 | } |
| 57 | |
| 58 | // When the model has been sorted, we need to adjust the focus (currentIndex) |
| 59 | // to the previously focused conversation item. |
| 60 | function onModelSorted(uri) { |
| 61 | root.currentIndex = -1 |
| 62 | updateListView() |
| 63 | for (var i = 0; i < count; i++) { |
| 64 | if (root.model.data( |
| 65 | root.model.index(i, 0), 261) === uri) { |
| 66 | root.currentIndex = i |
| 67 | break |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function onUpdateListViewRequested() { |
| 73 | updateListView() |
| 74 | } |
| 75 | |
| 76 | function onNavigateToWelcomePageRequested() { |
| 77 | root.needToBackToWelcomePage() |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | Connections { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 82 | target: CallAdapter |
| 83 | |
| 84 | function onUpdateConversationSmartList() { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 85 | updateListView() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | onCurrentIndexChanged: { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 90 | root.currentIndexIsChanged() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | clip: true |
| 94 | |
| 95 | delegate: ConversationSmartListViewItemDelegate { |
| 96 | id: smartListItemDelegate |
| 97 | } |
| 98 | |
| 99 | ScrollIndicator.vertical: ScrollIndicator {} |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 100 | |
| 101 | Shortcut { |
| 102 | sequence: "Ctrl+Shift+X" |
| 103 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 104 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 105 | onActivated: { |
| 106 | CallAdapter.placeCall() |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | Shortcut { |
| 111 | sequence: "Ctrl+Shift+C" |
| 112 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 113 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 114 | onActivated: { |
| 115 | CallAdapter.placeAudioOnlyCall() |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | Shortcut { |
| 120 | sequence: "Ctrl+Shift+L" |
| 121 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 122 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 123 | onActivated: { |
| 124 | ClientWrapper.utilsAdaptor.clearConversationHistory(ClientWrapper.utilsAdaptor.getCurrAccId(), |
| 125 | ClientWrapper.utilsAdaptor.getCurrConvId()) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | Shortcut { |
| 130 | sequence: "Ctrl+Shift+B" |
| 131 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 132 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 133 | onActivated: { |
| 134 | ClientWrapper.utilsAdaptor.removeConversation(ClientWrapper.utilsAdaptor.getCurrAccId(), |
| 135 | ClientWrapper.utilsAdaptor.getCurrConvId(), true) |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 136 | root.needToBackToWelcomePage() |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
| 140 | Shortcut { |
| 141 | sequence: "Ctrl+Shift+Delete" |
| 142 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 143 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 144 | onActivated: { |
| 145 | ClientWrapper.utilsAdaptor.removeConversation(ClientWrapper.utilsAdaptor.getCurrAccId(), |
| 146 | ClientWrapper.utilsAdaptor.getCurrConvId(), false) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | Shortcut { |
| 151 | sequence: "Ctrl+Down" |
| 152 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 153 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 154 | onActivated: { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 155 | if (currentIndex + 1 >= count) |
| 156 | return |
| 157 | root.currentIndex += 1 |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | Shortcut { |
| 162 | sequence: "Ctrl+Up" |
| 163 | context: Qt.ApplicationShortcut |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 164 | enabled: root.visible |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 165 | onActivated: { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame^] | 166 | if (currentIndex <= 0) |
| 167 | return |
| 168 | root.currentIndex -= 1 |
Sébastien Blin | 214d9ad | 2020-08-13 13:05:17 -0400 | [diff] [blame] | 169 | } |
| 170 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 171 | } |