blob: 1d61c5bb3dd377d9368fae7db32991067d76f4ca [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
Andreas Traczykeb53a622020-09-03 09:24:49 -04004 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Sébastien Blin1f915762020-08-03 13:27:42 -04005 *
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 Traczykeb53a622020-09-03 09:24:49 -040019
Sébastien Blin1f915762020-08-03 13:27:42 -040020import QtQuick 2.14
21import QtQuick.Controls 2.14
22import QtQuick.Layouts 1.14
23import net.jami.Models 1.0
24
25ListView {
Andreas Traczykeb53a622020-09-03 09:24:49 -040026 id: root
Sébastien Blin1f915762020-08-03 13:27:42 -040027
ababi76b94aa2020-08-24 17:46:30 +020028 signal needToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, int callState)
ababi0b686642020-08-18 17:21:28 +020029 signal needToSelectItems(string conversationUid)
Sébastien Blin1f915762020-08-03 13:27:42 -040030 signal needToDeselectItems
31 signal needToBackToWelcomePage
32 signal needToGrabFocus
33
34 signal needToShowChatView(string accountId, string convUid)
35 signal currentIndexIsChanged
36 signal forceUpdatePotentialInvalidItem
37
Andreas Traczykeb53a622020-09-03 09:24:49 -040038 // 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 Blin1f915762020-08-03 13:27:42 -040045 }
46
Ming Rui Zhang96808872020-08-27 12:59:09 -040047 ConversationSmartListContextMenu {
48 id: smartListContextMenu
49 }
50
Sébastien Blin1f915762020-08-03 13:27:42 -040051 Connections {
Andreas Traczykeb53a622020-09-03 09:24:49 -040052 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 Blin1f915762020-08-03 13:27:42 -040082 target: CallAdapter
83
84 function onUpdateConversationSmartList() {
Andreas Traczykeb53a622020-09-03 09:24:49 -040085 updateListView()
Sébastien Blin1f915762020-08-03 13:27:42 -040086 }
87 }
88
89 onCurrentIndexChanged: {
Andreas Traczykeb53a622020-09-03 09:24:49 -040090 root.currentIndexIsChanged()
Sébastien Blin1f915762020-08-03 13:27:42 -040091 }
92
93 clip: true
94
95 delegate: ConversationSmartListViewItemDelegate {
96 id: smartListItemDelegate
97 }
98
99 ScrollIndicator.vertical: ScrollIndicator {}
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400100
101 Shortcut {
102 sequence: "Ctrl+Shift+X"
103 context: Qt.ApplicationShortcut
Andreas Traczykeb53a622020-09-03 09:24:49 -0400104 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400105 onActivated: {
106 CallAdapter.placeCall()
107 }
108 }
109
110 Shortcut {
111 sequence: "Ctrl+Shift+C"
112 context: Qt.ApplicationShortcut
Andreas Traczykeb53a622020-09-03 09:24:49 -0400113 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400114 onActivated: {
115 CallAdapter.placeAudioOnlyCall()
116 }
117 }
118
119 Shortcut {
120 sequence: "Ctrl+Shift+L"
121 context: Qt.ApplicationShortcut
Andreas Traczykeb53a622020-09-03 09:24:49 -0400122 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400123 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 Traczykeb53a622020-09-03 09:24:49 -0400132 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400133 onActivated: {
134 ClientWrapper.utilsAdaptor.removeConversation(ClientWrapper.utilsAdaptor.getCurrAccId(),
135 ClientWrapper.utilsAdaptor.getCurrConvId(), true)
Andreas Traczykeb53a622020-09-03 09:24:49 -0400136 root.needToBackToWelcomePage()
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400137 }
138 }
139
140 Shortcut {
141 sequence: "Ctrl+Shift+Delete"
142 context: Qt.ApplicationShortcut
Andreas Traczykeb53a622020-09-03 09:24:49 -0400143 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400144 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 Traczykeb53a622020-09-03 09:24:49 -0400153 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400154 onActivated: {
Andreas Traczykeb53a622020-09-03 09:24:49 -0400155 if (currentIndex + 1 >= count)
156 return
157 root.currentIndex += 1
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400158 }
159 }
160
161 Shortcut {
162 sequence: "Ctrl+Up"
163 context: Qt.ApplicationShortcut
Andreas Traczykeb53a622020-09-03 09:24:49 -0400164 enabled: root.visible
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400165 onActivated: {
Andreas Traczykeb53a622020-09-03 09:24:49 -0400166 if (currentIndex <= 0)
167 return
168 root.currentIndex -= 1
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400169 }
170 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400171}