Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | |
| 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 | */ |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Controls 2.14 |
| 21 | import QtQuick.Layouts 1.14 |
| 22 | import net.jami.Models 1.0 |
| 23 | |
| 24 | import "../../commoncomponents" |
| 25 | |
| 26 | Rectangle { |
| 27 | id: sidePanelRect |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 28 | color: JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 29 | |
| 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) |
ababi | 69f5dfc | 2020-08-25 15:07:57 +0200 | [diff] [blame] | 35 | signal accountComboBoxNeedToShowWelcomePage() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 36 | signal conversationSmartListViewNeedToShowWelcomePage |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 37 | signal needToUpdateConversationForAddedContact |
| 38 | signal needToAddNewAccount |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 39 | |
| 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 89 | |
| 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() |
ababi | 69f5dfc | 2020-08-25 15:07:57 +0200 | [diff] [blame] | 105 | accountComboBox.resetAccountListModel() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | function deselectConversationSmartList() { |
| 109 | ConversationsAdapter.deselectConversation() |
| 110 | conversationSmartListView.currentIndex = -1 |
| 111 | } |
| 112 | |
| 113 | function forceUpdateConversationSmartListView() { |
| 114 | conversationSmartListView.updateConversationSmartListView() |
| 115 | } |
| 116 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 117 | /* |
| 118 | * Intended -> since strange behavior will happen without this for stackview. |
| 119 | */ |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 120 | anchors.top: parent.top |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 121 | anchors.fill: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 122 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 123 | /* |
| 124 | * Search bar container to embed search label |
| 125 | */ |
| 126 | ContactSearchBar { |
| 127 | id: contactSearchBar |
| 128 | width: sidePanelRect.width - 26 |
| 129 | height: 35 |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 130 | anchors.top: sidePanelRect.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 131 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 140 | SidePanelTabBar { |
| 141 | id: sidePanelTabBar |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 142 | anchors.top: contactSearchBar.bottom |
| 143 | anchors.topMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 144 | width: sidePanelRect.width |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 145 | height: tabBarVisible ? 64 : 0 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 146 | } |
| 147 | |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 148 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 204 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 205 | ConversationSmartListView { |
| 206 | id: conversationSmartListView |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 207 | |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 208 | anchors.top: searchStatusRect.visible ? searchStatusRect.bottom : (tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom) |
| 209 | anchors.topMargin: (tabBarVisible || searchStatusRect.visible) ? 0 : 10 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 210 | width: parent.width |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 211 | height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 : |
| 212 | sidePanelRect.height - contactSearchBar.height - 20 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 213 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 214 | Connections { |
| 215 | target: ConversationsAdapter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 216 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 217 | function onShowChatView(accountId, convUid) { |
| 218 | conversationSmartListView.needToShowChatView(accountId, |
| 219 | convUid) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 220 | } |
| 221 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 222 | function onShowConversationTabs(visible) { |
| 223 | tabBarVisible = visible |
| 224 | updatePendingRequestCount() |
| 225 | updateTotalUnreadMessagesCount() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 226 | } |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 227 | |
| 228 | function onShowSearchStatus(status) { |
| 229 | lblSearchStatus.text = status |
| 230 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 231 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 232 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 233 | onNeedToSelectItems: { |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 234 | ConversationsAdapter.selectConversation(conversationUid) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 235 | } |
| 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | } |