blob: 350244e4d29e4faaf834738c0942390971af872b [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
ababi76b94aa2020-08-24 17:46:30 +020034 signal conversationSmartListNeedToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, string callState)
ababi69f5dfc2020-08-25 15:07:57 +020035 signal accountComboBoxNeedToShowWelcomePage()
Sébastien Blin1f915762020-08-03 13:27:42 -040036 signal conversationSmartListViewNeedToShowWelcomePage
Sébastien Blin1f915762020-08-03 13:27:42 -040037 signal needToUpdateConversationForAddedContact
38 signal needToAddNewAccount
Sébastien Blin1f915762020-08-03 13:27:42 -040039
40
41 /*
42 * Hack -> force redraw.
43 */
44 function forceReselectConversationSmartListCurrentIndex() {
45 var index = conversationSmartListView.currentIndex
46 conversationSmartListView.currentIndex = -1
47 conversationSmartListView.currentIndex = index
48 }
49
50
51 /*
52 * For contact request conv to be focused correctly.
53 */
54 function setCurrentUidSmartListModelIndex() {
55 conversationSmartListView.currentIndex
56 = conversationSmartListView.model.currentUidSmartListModelIndex(
57 )
58 }
59
60 function updatePendingRequestCount() {
61 pendingRequestCount = ClientWrapper.utilsAdaptor.getTotalPendingRequest()
62 }
63
64 function updateTotalUnreadMessagesCount() {
65 totalUnreadMessagesCount = ClientWrapper.utilsAdaptor.getTotalUnreadMessages()
66 }
67
68 function clearContactSearchBar() {
69 contactSearchBar.clearText()
70 }
71
72 function accountChangedUIReset() {
73 contactSearchBar.clearText()
74 contactSearchBar.setPlaceholderString(
75 JamiTheme.contactSearchBarPlaceHolderConversationText)
76 sidePanelTabBar.converstationTabDown = true
77 sidePanelTabBar.invitationTabDown = false
78 }
79
80 function needToChangeToAccount(accountId, index) {
81 if (index !== -1) {
82 accountComboBox.currentIndex = index
83 ClientWrapper.accountAdaptor.accountChanged(index)
84 accountChangedUIReset()
85 }
86 }
87
88 function refreshAccountComboBox(index = -1) {
Sébastien Blin1f915762020-08-03 13:27:42 -040089
ababi76b94aa2020-08-24 17:46:30 +020090
Sébastien Blin1f915762020-08-03 13:27:42 -040091 /*
92 * To make sure that the ui is refreshed for accountComboBox.
93 * Note: when index in -1, it means to maintain the
94 * current account selection.
95 */
96 var currentIndex = accountComboBox.currentIndex
97 if (accountComboBox.currentIndex === index)
98 accountComboBox.currentIndex = -1
99 accountComboBox.currentIndex = index
100 if (index !== -1)
101 ClientWrapper.accountAdaptor.accountChanged(index)
102 else
103 accountComboBox.currentIndex = currentIndex
104 accountComboBox.update()
105 accountChangedUIReset()
ababi69f5dfc2020-08-25 15:07:57 +0200106 accountComboBox.resetAccountListModel()
Sébastien Blin1f915762020-08-03 13:27:42 -0400107 }
108
109 function deselectConversationSmartList() {
110 ConversationsAdapter.deselectConversation()
111 conversationSmartListView.currentIndex = -1
112 }
113
114 function forceUpdateConversationSmartListView() {
115 conversationSmartListView.updateConversationSmartListView()
116 }
117
Sébastien Blin1f915762020-08-03 13:27:42 -0400118 /*
119 * Intended -> since strange behavior will happen without this for stackview.
120 */
ababidf651a22020-07-30 13:38:57 +0200121 anchors.top: parent.top
ababia284cae2020-08-10 12:33:34 +0200122 anchors.fill: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400123
ababidf651a22020-07-30 13:38:57 +0200124 /*
125 * Search bar container to embed search label
126 */
127 ContactSearchBar {
128 id: contactSearchBar
129 width: sidePanelRect.width - 26
130 height: 35
ababia284cae2020-08-10 12:33:34 +0200131 anchors.top: sidePanelRect.top
ababidf651a22020-07-30 13:38:57 +0200132 anchors.topMargin: 10
133 anchors.left: sidePanelRect.left
134 anchors.leftMargin: 16
135
136 onContactSearchBarTextChanged: {
137 ClientWrapper.utilsAdaptor.setConversationFilter(text)
138 }
139 }
140
Sébastien Blin1f915762020-08-03 13:27:42 -0400141 SidePanelTabBar {
142 id: sidePanelTabBar
ababidf651a22020-07-30 13:38:57 +0200143 anchors.top: contactSearchBar.bottom
144 anchors.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400145 width: sidePanelRect.width
ababidf651a22020-07-30 13:38:57 +0200146 height: tabBarVisible ? 64 : 0
Sébastien Blin1f915762020-08-03 13:27:42 -0400147 }
148
ababi0b686642020-08-18 17:21:28 +0200149 Rectangle {
150 id: searchStatusRect
151
152 visible: lblSearchStatus.text !== ""
153
154 anchors.top: tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom
155 anchors.topMargin: tabBarVisible ? 0 : 10
156 width: parent.width
157 height: 72
158
159 color: "transparent"
160
161 Image {
162 id: searchIcon
163 anchors.left: searchStatusRect.left
164 anchors.leftMargin: 24
165 anchors.verticalCenter: searchStatusRect.verticalCenter
166 width: 24
167 height: 24
168
169 fillMode: Image.PreserveAspectFit
170 mipmap: true
171 source: "qrc:/images/icons/ic_baseline-search-24px.svg"
172 }
173
174 Label {
175 id: lblSearchStatus
176
177 anchors.verticalCenter: searchStatusRect.verticalCenter
178 anchors.left: searchIcon.right
179 anchors.leftMargin: 24
180 width: searchStatusRect.width - searchIcon.width - 24*2 - 8
181 text: ""
182 wrapMode: Text.WordWrap
183 font.pointSize: JamiTheme.menuFontSize
184 }
185
186 MouseArea {
187 id: mouseAreaSearchRect
188
189 anchors.fill: parent
190 hoverEnabled: true
191
192 onReleased: {
193 searchStatusRect.color = JamiTheme.releaseColor
194 }
195
196 onEntered: {
197 searchStatusRect.color = JamiTheme.hoverColor
198 }
199
200 onExited: {
201 searchStatusRect.color = JamiTheme.backgroundColor
202 }
203 }
204 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400205
ababidf651a22020-07-30 13:38:57 +0200206 ConversationSmartListView {
207 id: conversationSmartListView
Sébastien Blin1f915762020-08-03 13:27:42 -0400208
ababi0b686642020-08-18 17:21:28 +0200209 anchors.top: searchStatusRect.visible ? searchStatusRect.bottom : (tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom)
210 anchors.topMargin: (tabBarVisible || searchStatusRect.visible) ? 0 : 10
ababidf651a22020-07-30 13:38:57 +0200211 width: parent.width
ababia284cae2020-08-10 12:33:34 +0200212 height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 :
213 sidePanelRect.height - contactSearchBar.height - 20
Sébastien Blin1f915762020-08-03 13:27:42 -0400214
ababidf651a22020-07-30 13:38:57 +0200215 Connections {
216 target: ConversationsAdapter
Sébastien Blin1f915762020-08-03 13:27:42 -0400217
ababidf651a22020-07-30 13:38:57 +0200218 function onShowChatView(accountId, convUid) {
219 conversationSmartListView.needToShowChatView(accountId,
220 convUid)
Sébastien Blin1f915762020-08-03 13:27:42 -0400221 }
222
ababidf651a22020-07-30 13:38:57 +0200223 function onShowConversationTabs(visible) {
224 tabBarVisible = visible
225 updatePendingRequestCount()
226 updateTotalUnreadMessagesCount()
Sébastien Blin1f915762020-08-03 13:27:42 -0400227 }
ababi0b686642020-08-18 17:21:28 +0200228
229 function onShowSearchStatus(status) {
230 lblSearchStatus.text = status
231 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400232 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400233
ababidf651a22020-07-30 13:38:57 +0200234 onNeedToSelectItems: {
ababi0b686642020-08-18 17:21:28 +0200235 ConversationsAdapter.selectConversation(conversationUid)
ababidf651a22020-07-30 13:38:57 +0200236 }
237
238 onNeedToBackToWelcomePage: {
239 sidePanelRect.conversationSmartListViewNeedToShowWelcomePage()
240 }
241
242 onNeedToAccessMessageWebView: {
243 sidePanelRect.conversationSmartListNeedToAccessMessageWebView(
244 currentUserDisplayName, currentUserAlias,
245 currentUID, callStackViewShouldShow,
ababi76b94aa2020-08-24 17:46:30 +0200246 isAudioOnly, callState)
ababidf651a22020-07-30 13:38:57 +0200247 }
248
249 onNeedToGrabFocus: {
250 contactSearchBar.clearFocus()
251 }
252
253 Component.onCompleted: {
254 ConversationsAdapter.setQmlObject(this)
255 conversationSmartListView.currentIndex = -1
Sébastien Blin1f915762020-08-03 13:27:42 -0400256 }
257 }
258}