blob: bf2d6ffb7066bed0214c2600c64492e38c7ea56a [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
Sébastien Blinacb1cf02020-08-17 22:38:19 -040080 function refreshAccountComboBox(index) {
81 ClientWrapper.accountAdaptor.accountChanged(index)
Sébastien Blin1f915762020-08-03 13:27:42 -040082
Sébastien Blin1f915762020-08-03 13:27:42 -040083 accountComboBox.update()
84 accountChangedUIReset()
ababi69f5dfc2020-08-25 15:07:57 +020085 accountComboBox.resetAccountListModel()
Sébastien Blin1f915762020-08-03 13:27:42 -040086 }
87
88 function deselectConversationSmartList() {
89 ConversationsAdapter.deselectConversation()
90 conversationSmartListView.currentIndex = -1
91 }
92
93 function forceUpdateConversationSmartListView() {
Andreas Traczykeb53a622020-09-03 09:24:49 -040094 conversationSmartListView.updateListView()
Sébastien Blin1f915762020-08-03 13:27:42 -040095 }
96
Sébastien Blin1f915762020-08-03 13:27:42 -040097 /*
98 * Intended -> since strange behavior will happen without this for stackview.
99 */
ababidf651a22020-07-30 13:38:57 +0200100 anchors.top: parent.top
ababia284cae2020-08-10 12:33:34 +0200101 anchors.fill: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400102
ababidf651a22020-07-30 13:38:57 +0200103 /*
104 * Search bar container to embed search label
105 */
106 ContactSearchBar {
107 id: contactSearchBar
108 width: sidePanelRect.width - 26
109 height: 35
ababia284cae2020-08-10 12:33:34 +0200110 anchors.top: sidePanelRect.top
ababidf651a22020-07-30 13:38:57 +0200111 anchors.topMargin: 10
112 anchors.left: sidePanelRect.left
113 anchors.leftMargin: 16
114
115 onContactSearchBarTextChanged: {
116 ClientWrapper.utilsAdaptor.setConversationFilter(text)
117 }
118 }
119
Sébastien Blin1f915762020-08-03 13:27:42 -0400120 SidePanelTabBar {
121 id: sidePanelTabBar
ababidf651a22020-07-30 13:38:57 +0200122 anchors.top: contactSearchBar.bottom
123 anchors.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400124 width: sidePanelRect.width
ababidf651a22020-07-30 13:38:57 +0200125 height: tabBarVisible ? 64 : 0
Sébastien Blin1f915762020-08-03 13:27:42 -0400126 }
127
ababi0b686642020-08-18 17:21:28 +0200128 Rectangle {
129 id: searchStatusRect
130
131 visible: lblSearchStatus.text !== ""
132
133 anchors.top: tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom
134 anchors.topMargin: tabBarVisible ? 0 : 10
135 width: parent.width
136 height: 72
137
138 color: "transparent"
139
140 Image {
141 id: searchIcon
142 anchors.left: searchStatusRect.left
143 anchors.leftMargin: 24
144 anchors.verticalCenter: searchStatusRect.verticalCenter
145 width: 24
146 height: 24
147
148 fillMode: Image.PreserveAspectFit
149 mipmap: true
150 source: "qrc:/images/icons/ic_baseline-search-24px.svg"
151 }
152
153 Label {
154 id: lblSearchStatus
155
156 anchors.verticalCenter: searchStatusRect.verticalCenter
157 anchors.left: searchIcon.right
158 anchors.leftMargin: 24
159 width: searchStatusRect.width - searchIcon.width - 24*2 - 8
160 text: ""
161 wrapMode: Text.WordWrap
162 font.pointSize: JamiTheme.menuFontSize
163 }
164
165 MouseArea {
166 id: mouseAreaSearchRect
167
168 anchors.fill: parent
169 hoverEnabled: true
170
171 onReleased: {
172 searchStatusRect.color = JamiTheme.releaseColor
173 }
174
175 onEntered: {
176 searchStatusRect.color = JamiTheme.hoverColor
177 }
178
179 onExited: {
180 searchStatusRect.color = JamiTheme.backgroundColor
181 }
182 }
183 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400184
ababidf651a22020-07-30 13:38:57 +0200185 ConversationSmartListView {
186 id: conversationSmartListView
Sébastien Blin1f915762020-08-03 13:27:42 -0400187
ababi0b686642020-08-18 17:21:28 +0200188 anchors.top: searchStatusRect.visible ? searchStatusRect.bottom : (tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom)
189 anchors.topMargin: (tabBarVisible || searchStatusRect.visible) ? 0 : 10
ababidf651a22020-07-30 13:38:57 +0200190 width: parent.width
ababia284cae2020-08-10 12:33:34 +0200191 height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 :
192 sidePanelRect.height - contactSearchBar.height - 20
Sébastien Blin1f915762020-08-03 13:27:42 -0400193
ababidf651a22020-07-30 13:38:57 +0200194 Connections {
195 target: ConversationsAdapter
Sébastien Blin1f915762020-08-03 13:27:42 -0400196
ababidf651a22020-07-30 13:38:57 +0200197 function onShowChatView(accountId, convUid) {
198 conversationSmartListView.needToShowChatView(accountId,
199 convUid)
Sébastien Blin1f915762020-08-03 13:27:42 -0400200 }
201
ababidf651a22020-07-30 13:38:57 +0200202 function onShowConversationTabs(visible) {
203 tabBarVisible = visible
204 updatePendingRequestCount()
205 updateTotalUnreadMessagesCount()
Sébastien Blin1f915762020-08-03 13:27:42 -0400206 }
ababi0b686642020-08-18 17:21:28 +0200207
208 function onShowSearchStatus(status) {
209 lblSearchStatus.text = status
210 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400211 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400212
ababidf651a22020-07-30 13:38:57 +0200213 onNeedToSelectItems: {
ababi0b686642020-08-18 17:21:28 +0200214 ConversationsAdapter.selectConversation(conversationUid)
ababidf651a22020-07-30 13:38:57 +0200215 }
216
217 onNeedToBackToWelcomePage: {
218 sidePanelRect.conversationSmartListViewNeedToShowWelcomePage()
219 }
220
221 onNeedToAccessMessageWebView: {
222 sidePanelRect.conversationSmartListNeedToAccessMessageWebView(
223 currentUserDisplayName, currentUserAlias,
224 currentUID, callStackViewShouldShow,
ababi76b94aa2020-08-24 17:46:30 +0200225 isAudioOnly, callState)
ababidf651a22020-07-30 13:38:57 +0200226 }
227
228 onNeedToGrabFocus: {
229 contactSearchBar.clearFocus()
230 }
231
232 Component.onCompleted: {
233 ConversationsAdapter.setQmlObject(this)
234 conversationSmartListView.currentIndex = -1
Sébastien Blin1f915762020-08-03 13:27:42 -0400235 }
236 }
237}