blob: 0500a793119e45c6f0db57c1d4d62355c1373976 [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
24import "../../commoncomponents"
25
26Rectangle {
27 id: sidePanelRect
ababidf651a22020-07-30 13:38:57 +020028 color: JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -040029
30 property bool tabBarVisible: true
31 property int pendingRequestCount: 0
32 property int totalUnreadMessagesCount: 0
33
34 signal conversationSmartListNeedToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, string callStateStr)
35 signal accountComboBoxNeedToShowWelcomePage(int index)
36 signal conversationSmartListViewNeedToShowWelcomePage
37 signal accountSignalsReconnect(string accountId)
38 signal needToUpdateConversationForAddedContact
39 signal needToAddNewAccount
Sébastien Blin1f915762020-08-03 13:27:42 -040040
41
42 /*
43 * Hack -> force redraw.
44 */
45 function forceReselectConversationSmartListCurrentIndex() {
46 var index = conversationSmartListView.currentIndex
47 conversationSmartListView.currentIndex = -1
48 conversationSmartListView.currentIndex = index
49 }
50
51
52 /*
53 * For contact request conv to be focused correctly.
54 */
55 function setCurrentUidSmartListModelIndex() {
56 conversationSmartListView.currentIndex
57 = conversationSmartListView.model.currentUidSmartListModelIndex(
58 )
59 }
60
61 function updatePendingRequestCount() {
62 pendingRequestCount = ClientWrapper.utilsAdaptor.getTotalPendingRequest()
63 }
64
65 function updateTotalUnreadMessagesCount() {
66 totalUnreadMessagesCount = ClientWrapper.utilsAdaptor.getTotalUnreadMessages()
67 }
68
69 function clearContactSearchBar() {
70 contactSearchBar.clearText()
71 }
72
73 function accountChangedUIReset() {
74 contactSearchBar.clearText()
75 contactSearchBar.setPlaceholderString(
76 JamiTheme.contactSearchBarPlaceHolderConversationText)
77 sidePanelTabBar.converstationTabDown = true
78 sidePanelTabBar.invitationTabDown = false
79 }
80
81 function needToChangeToAccount(accountId, index) {
82 if (index !== -1) {
83 accountComboBox.currentIndex = index
84 ClientWrapper.accountAdaptor.accountChanged(index)
85 accountChangedUIReset()
86 }
87 }
88
89 function refreshAccountComboBox(index = -1) {
90 accountComboBox.resetAccountListModel()
91
92
93 /*
94 * To make sure that the ui is refreshed for accountComboBox.
95 * Note: when index in -1, it means to maintain the
96 * current account selection.
97 */
98 var currentIndex = accountComboBox.currentIndex
99 if (accountComboBox.currentIndex === index)
100 accountComboBox.currentIndex = -1
101 accountComboBox.currentIndex = index
102 if (index !== -1)
103 ClientWrapper.accountAdaptor.accountChanged(index)
104 else
105 accountComboBox.currentIndex = currentIndex
106 accountComboBox.update()
107 accountChangedUIReset()
108 }
109
110 function deselectConversationSmartList() {
111 ConversationsAdapter.deselectConversation()
112 conversationSmartListView.currentIndex = -1
113 }
114
115 function forceUpdateConversationSmartListView() {
116 conversationSmartListView.updateConversationSmartListView()
117 }
118
ababia284cae2020-08-10 12:33:34 +0200119 function updateSmartList(accountId) {
120 conversationSmartListView.currentIndex = -1
121 conversationSmartListView.updateSmartList(accountId)
122 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400123
124 /*
125 * Intended -> since strange behavior will happen without this for stackview.
126 */
ababidf651a22020-07-30 13:38:57 +0200127 anchors.top: parent.top
ababia284cae2020-08-10 12:33:34 +0200128 anchors.fill: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400129
ababidf651a22020-07-30 13:38:57 +0200130 /*
131 * Search bar container to embed search label
132 */
133 ContactSearchBar {
134 id: contactSearchBar
135 width: sidePanelRect.width - 26
136 height: 35
ababia284cae2020-08-10 12:33:34 +0200137 anchors.top: sidePanelRect.top
ababidf651a22020-07-30 13:38:57 +0200138 anchors.topMargin: 10
139 anchors.left: sidePanelRect.left
140 anchors.leftMargin: 16
141
142 onContactSearchBarTextChanged: {
143 ClientWrapper.utilsAdaptor.setConversationFilter(text)
144 }
145 }
146
Sébastien Blin1f915762020-08-03 13:27:42 -0400147 SidePanelTabBar {
148 id: sidePanelTabBar
ababidf651a22020-07-30 13:38:57 +0200149 anchors.top: contactSearchBar.bottom
150 anchors.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400151 width: sidePanelRect.width
ababidf651a22020-07-30 13:38:57 +0200152 height: tabBarVisible ? 64 : 0
Sébastien Blin1f915762020-08-03 13:27:42 -0400153 }
154
Sébastien Blin1f915762020-08-03 13:27:42 -0400155
ababidf651a22020-07-30 13:38:57 +0200156 ConversationSmartListView {
157 id: conversationSmartListView
Sébastien Blin1f915762020-08-03 13:27:42 -0400158
ababidf651a22020-07-30 13:38:57 +0200159 anchors.top: tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom
160 anchors.topMargin: tabBarVisible ? 0 : 10
161 width: parent.width
ababia284cae2020-08-10 12:33:34 +0200162 height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 :
163 sidePanelRect.height - contactSearchBar.height - 20
Sébastien Blin1f915762020-08-03 13:27:42 -0400164
ababidf651a22020-07-30 13:38:57 +0200165 Connections {
166 target: ConversationsAdapter
Sébastien Blin1f915762020-08-03 13:27:42 -0400167
ababidf651a22020-07-30 13:38:57 +0200168 function onShowChatView(accountId, convUid) {
169 conversationSmartListView.needToShowChatView(accountId,
170 convUid)
Sébastien Blin1f915762020-08-03 13:27:42 -0400171 }
172
ababidf651a22020-07-30 13:38:57 +0200173 function onShowConversationTabs(visible) {
174 tabBarVisible = visible
175 updatePendingRequestCount()
176 updateTotalUnreadMessagesCount()
Sébastien Blin1f915762020-08-03 13:27:42 -0400177 }
178 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400179
ababidf651a22020-07-30 13:38:57 +0200180 onNeedToSelectItems: {
181 ConversationsAdapter.selectConversation(index)
182 }
183
184 onNeedToBackToWelcomePage: {
185 sidePanelRect.conversationSmartListViewNeedToShowWelcomePage()
186 }
187
188 onNeedToAccessMessageWebView: {
189 sidePanelRect.conversationSmartListNeedToAccessMessageWebView(
190 currentUserDisplayName, currentUserAlias,
191 currentUID, callStackViewShouldShow,
192 isAudioOnly, callStateStr)
193 }
194
195 onNeedToGrabFocus: {
196 contactSearchBar.clearFocus()
197 }
198
199 Component.onCompleted: {
200 ConversationsAdapter.setQmlObject(this)
201 conversationSmartListView.currentIndex = -1
Sébastien Blin1f915762020-08-03 13:27:42 -0400202 }
203 }
204}