blob: 0513f6fd4ee3f4d461685d2427be45609b8be42b [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
2/*
3 * Copyright (C) 2020 by Savoir-faire Linux
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
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 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import net.jami.Models 1.0
23
24ListView {
25 id: conversationSmartListView
26
27 signal needToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, string callStateStr)
28 signal needToSelectItems(int index)
29 signal needToDeselectItems
30 signal needToBackToWelcomePage
31 signal needToGrabFocus
32
33 signal needToShowChatView(string accountId, string convUid)
34 signal currentIndexIsChanged
35 signal forceUpdatePotentialInvalidItem
36
37
38 /*
39 * When model is sorted, we need to reset to focus (currentIndex)
40 * to the real conversation that we focused.
41 */
42 function modelSorted(contactURIToCompare) {
43 var conversationSmartListViewModel = conversationSmartListView.model
44 conversationSmartListView.currentIndex = -1
45 updateConversationSmartListView()
46 for (var i = 0; i < count; i++) {
47 if (conversationSmartListViewModel.data(
48 conversationSmartListViewModel.index(i, 0),
49 261) === contactURIToCompare) {
50 conversationSmartListView.currentIndex = i
51 break
52 }
53 }
54 }
55
56
57 /*
58 * Refresh all item within model.
59 */
60 function updateConversationSmartListView() {
61 var conversationSmartListViewModel = conversationSmartListView.model
62 conversationSmartListViewModel.dataChanged(
63 conversationSmartListViewModel.index(0, 0),
64 conversationSmartListViewModel.index(
65 conversationSmartListViewModel.rowCount() - 1, 0))
66 conversationSmartListView.forceUpdatePotentialInvalidItem()
67 }
68
69 function setModel(model) {
70 conversationSmartListView.model = model
71 }
72
73 function backToWelcomePage() {
74 conversationSmartListView.needToBackToWelcomePage()
75 }
76
77
78 /*
79 * Update smartlist to accountId.
80 */
81 function updateSmartList(accountId) {
82 conversationSmartListView.model.setAccount(accountId)
83 }
84
85 Connections {
86 target: CallAdapter
87
88 function onUpdateConversationSmartList() {
89 updateConversationSmartListView()
90 }
91 }
92
93 onCurrentIndexChanged: {
94 conversationSmartListView.currentIndexIsChanged()
95 }
96
97 clip: true
98
99 delegate: ConversationSmartListViewItemDelegate {
100 id: smartListItemDelegate
101 }
102
103 ScrollIndicator.vertical: ScrollIndicator {}
104}