blob: c861e980b6039f3864f329411df69d044fc8c30b [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)
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
90 /*
91 * To make sure that the ui is refreshed for accountComboBox.
92 * Note: when index in -1, it means to maintain the
93 * current account selection.
94 */
95 var currentIndex = accountComboBox.currentIndex
96 if (accountComboBox.currentIndex === index)
97 accountComboBox.currentIndex = -1
98 accountComboBox.currentIndex = index
99 if (index !== -1)
100 ClientWrapper.accountAdaptor.accountChanged(index)
101 else
102 accountComboBox.currentIndex = currentIndex
103 accountComboBox.update()
104 accountChangedUIReset()
ababi69f5dfc2020-08-25 15:07:57 +0200105 accountComboBox.resetAccountListModel()
Sébastien Blin1f915762020-08-03 13:27:42 -0400106 }
107
108 function deselectConversationSmartList() {
109 ConversationsAdapter.deselectConversation()
110 conversationSmartListView.currentIndex = -1
111 }
112
113 function forceUpdateConversationSmartListView() {
114 conversationSmartListView.updateConversationSmartListView()
115 }
116
Sébastien Blin1f915762020-08-03 13:27:42 -0400117 /*
118 * Intended -> since strange behavior will happen without this for stackview.
119 */
ababidf651a22020-07-30 13:38:57 +0200120 anchors.top: parent.top
ababia284cae2020-08-10 12:33:34 +0200121 anchors.fill: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400122
ababidf651a22020-07-30 13:38:57 +0200123 /*
124 * Search bar container to embed search label
125 */
126 ContactSearchBar {
127 id: contactSearchBar
128 width: sidePanelRect.width - 26
129 height: 35
ababia284cae2020-08-10 12:33:34 +0200130 anchors.top: sidePanelRect.top
ababidf651a22020-07-30 13:38:57 +0200131 anchors.topMargin: 10
132 anchors.left: sidePanelRect.left
133 anchors.leftMargin: 16
134
135 onContactSearchBarTextChanged: {
136 ClientWrapper.utilsAdaptor.setConversationFilter(text)
137 }
138 }
139
Sébastien Blin1f915762020-08-03 13:27:42 -0400140 SidePanelTabBar {
141 id: sidePanelTabBar
ababidf651a22020-07-30 13:38:57 +0200142 anchors.top: contactSearchBar.bottom
143 anchors.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400144 width: sidePanelRect.width
ababidf651a22020-07-30 13:38:57 +0200145 height: tabBarVisible ? 64 : 0
Sébastien Blin1f915762020-08-03 13:27:42 -0400146 }
147
ababi0b686642020-08-18 17:21:28 +0200148 Rectangle {
149 id: searchStatusRect
150
151 visible: lblSearchStatus.text !== ""
152
153 anchors.top: tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom
154 anchors.topMargin: tabBarVisible ? 0 : 10
155 width: parent.width
156 height: 72
157
158 color: "transparent"
159
160 Image {
161 id: searchIcon
162 anchors.left: searchStatusRect.left
163 anchors.leftMargin: 24
164 anchors.verticalCenter: searchStatusRect.verticalCenter
165 width: 24
166 height: 24
167
168 fillMode: Image.PreserveAspectFit
169 mipmap: true
170 source: "qrc:/images/icons/ic_baseline-search-24px.svg"
171 }
172
173 Label {
174 id: lblSearchStatus
175
176 anchors.verticalCenter: searchStatusRect.verticalCenter
177 anchors.left: searchIcon.right
178 anchors.leftMargin: 24
179 width: searchStatusRect.width - searchIcon.width - 24*2 - 8
180 text: ""
181 wrapMode: Text.WordWrap
182 font.pointSize: JamiTheme.menuFontSize
183 }
184
185 MouseArea {
186 id: mouseAreaSearchRect
187
188 anchors.fill: parent
189 hoverEnabled: true
190
191 onReleased: {
192 searchStatusRect.color = JamiTheme.releaseColor
193 }
194
195 onEntered: {
196 searchStatusRect.color = JamiTheme.hoverColor
197 }
198
199 onExited: {
200 searchStatusRect.color = JamiTheme.backgroundColor
201 }
202 }
203 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400204
ababidf651a22020-07-30 13:38:57 +0200205 ConversationSmartListView {
206 id: conversationSmartListView
Sébastien Blin1f915762020-08-03 13:27:42 -0400207
ababi0b686642020-08-18 17:21:28 +0200208 anchors.top: searchStatusRect.visible ? searchStatusRect.bottom : (tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom)
209 anchors.topMargin: (tabBarVisible || searchStatusRect.visible) ? 0 : 10
ababidf651a22020-07-30 13:38:57 +0200210 width: parent.width
ababia284cae2020-08-10 12:33:34 +0200211 height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 :
212 sidePanelRect.height - contactSearchBar.height - 20
Sébastien Blin1f915762020-08-03 13:27:42 -0400213
ababidf651a22020-07-30 13:38:57 +0200214 Connections {
215 target: ConversationsAdapter
Sébastien Blin1f915762020-08-03 13:27:42 -0400216
ababidf651a22020-07-30 13:38:57 +0200217 function onShowChatView(accountId, convUid) {
218 conversationSmartListView.needToShowChatView(accountId,
219 convUid)
Sébastien Blin1f915762020-08-03 13:27:42 -0400220 }
221
ababidf651a22020-07-30 13:38:57 +0200222 function onShowConversationTabs(visible) {
223 tabBarVisible = visible
224 updatePendingRequestCount()
225 updateTotalUnreadMessagesCount()
Sébastien Blin1f915762020-08-03 13:27:42 -0400226 }
ababi0b686642020-08-18 17:21:28 +0200227
228 function onShowSearchStatus(status) {
229 lblSearchStatus.text = status
230 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400231 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400232
ababidf651a22020-07-30 13:38:57 +0200233 onNeedToSelectItems: {
ababi0b686642020-08-18 17:21:28 +0200234 ConversationsAdapter.selectConversation(conversationUid)
ababidf651a22020-07-30 13:38:57 +0200235 }
236
237 onNeedToBackToWelcomePage: {
238 sidePanelRect.conversationSmartListViewNeedToShowWelcomePage()
239 }
240
241 onNeedToAccessMessageWebView: {
242 sidePanelRect.conversationSmartListNeedToAccessMessageWebView(
243 currentUserDisplayName, currentUserAlias,
244 currentUID, callStackViewShouldShow,
245 isAudioOnly, callStateStr)
246 }
247
248 onNeedToGrabFocus: {
249 contactSearchBar.clearFocus()
250 }
251
252 Component.onCompleted: {
253 ConversationsAdapter.setQmlObject(this)
254 conversationSmartListView.currentIndex = -1
Sébastien Blin1f915762020-08-03 13:27:42 -0400255 }
256 }
257}