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 | |
ababi | 76b94aa | 2020-08-24 17:46:30 +0200 | [diff] [blame] | 34 | signal conversationSmartListNeedToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, string callState) |
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 | |
Sébastien Blin | acb1cf0 | 2020-08-17 22:38:19 -0400 | [diff] [blame] | 80 | function refreshAccountComboBox(index) { |
| 81 | ClientWrapper.accountAdaptor.accountChanged(index) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 82 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 83 | accountComboBox.update() |
| 84 | accountChangedUIReset() |
ababi | 69f5dfc | 2020-08-25 15:07:57 +0200 | [diff] [blame] | 85 | accountComboBox.resetAccountListModel() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function deselectConversationSmartList() { |
| 89 | ConversationsAdapter.deselectConversation() |
| 90 | conversationSmartListView.currentIndex = -1 |
| 91 | } |
| 92 | |
| 93 | function forceUpdateConversationSmartListView() { |
Andreas Traczyk | eb53a62 | 2020-09-03 09:24:49 -0400 | [diff] [blame] | 94 | conversationSmartListView.updateListView() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 97 | /* |
| 98 | * Intended -> since strange behavior will happen without this for stackview. |
| 99 | */ |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 100 | anchors.top: parent.top |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 101 | anchors.fill: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 102 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 103 | /* |
| 104 | * Search bar container to embed search label |
| 105 | */ |
| 106 | ContactSearchBar { |
| 107 | id: contactSearchBar |
| 108 | width: sidePanelRect.width - 26 |
| 109 | height: 35 |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 110 | anchors.top: sidePanelRect.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 111 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 120 | SidePanelTabBar { |
| 121 | id: sidePanelTabBar |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 122 | anchors.top: contactSearchBar.bottom |
| 123 | anchors.topMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 124 | width: sidePanelRect.width |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 125 | height: tabBarVisible ? 64 : 0 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 126 | } |
| 127 | |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 128 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 184 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 185 | ConversationSmartListView { |
| 186 | id: conversationSmartListView |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 187 | |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 188 | anchors.top: searchStatusRect.visible ? searchStatusRect.bottom : (tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom) |
| 189 | anchors.topMargin: (tabBarVisible || searchStatusRect.visible) ? 0 : 10 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 190 | width: parent.width |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 191 | height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 : |
| 192 | sidePanelRect.height - contactSearchBar.height - 20 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 193 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 194 | Connections { |
| 195 | target: ConversationsAdapter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 196 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 197 | function onShowChatView(accountId, convUid) { |
| 198 | conversationSmartListView.needToShowChatView(accountId, |
| 199 | convUid) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 200 | } |
| 201 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 202 | function onShowConversationTabs(visible) { |
| 203 | tabBarVisible = visible |
| 204 | updatePendingRequestCount() |
| 205 | updateTotalUnreadMessagesCount() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 206 | } |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 207 | |
| 208 | function onShowSearchStatus(status) { |
| 209 | lblSearchStatus.text = status |
| 210 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 211 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 212 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 213 | onNeedToSelectItems: { |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 214 | ConversationsAdapter.selectConversation(conversationUid) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | onNeedToBackToWelcomePage: { |
| 218 | sidePanelRect.conversationSmartListViewNeedToShowWelcomePage() |
| 219 | } |
| 220 | |
| 221 | onNeedToAccessMessageWebView: { |
| 222 | sidePanelRect.conversationSmartListNeedToAccessMessageWebView( |
| 223 | currentUserDisplayName, currentUserAlias, |
| 224 | currentUID, callStackViewShouldShow, |
ababi | 76b94aa | 2020-08-24 17:46:30 +0200 | [diff] [blame] | 225 | isAudioOnly, callState) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | onNeedToGrabFocus: { |
| 229 | contactSearchBar.clearFocus() |
| 230 | } |
| 231 | |
| 232 | Component.onCompleted: { |
| 233 | ConversationsAdapter.setQmlObject(this) |
| 234 | conversationSmartListView.currentIndex = -1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |