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) |
| 35 | signal accountComboBoxNeedToShowWelcomePage(int index) |
| 36 | signal conversationSmartListViewNeedToShowWelcomePage |
| 37 | signal accountSignalsReconnect(string accountId) |
| 38 | signal needToUpdateConversationForAddedContact |
| 39 | signal needToAddNewAccount |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* |
| 43 | * Hack -> force redraw. |
| 44 | */ |
| 45 | function forceReselectConversationSmartListCurrentIndex() { |
| 46 | var index = conversationSmartListView.currentIndex |
| 47 | conversationSmartListView.currentIndex = -1 |
| 48 | conversationSmartListView.currentIndex = index |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /* |
| 53 | * For contact request conv to be focused correctly. |
| 54 | */ |
| 55 | function setCurrentUidSmartListModelIndex() { |
| 56 | conversationSmartListView.currentIndex |
| 57 | = conversationSmartListView.model.currentUidSmartListModelIndex( |
| 58 | ) |
| 59 | } |
| 60 | |
| 61 | function updatePendingRequestCount() { |
| 62 | pendingRequestCount = ClientWrapper.utilsAdaptor.getTotalPendingRequest() |
| 63 | } |
| 64 | |
| 65 | function updateTotalUnreadMessagesCount() { |
| 66 | totalUnreadMessagesCount = ClientWrapper.utilsAdaptor.getTotalUnreadMessages() |
| 67 | } |
| 68 | |
| 69 | function clearContactSearchBar() { |
| 70 | contactSearchBar.clearText() |
| 71 | } |
| 72 | |
| 73 | function accountChangedUIReset() { |
| 74 | contactSearchBar.clearText() |
| 75 | contactSearchBar.setPlaceholderString( |
| 76 | JamiTheme.contactSearchBarPlaceHolderConversationText) |
| 77 | sidePanelTabBar.converstationTabDown = true |
| 78 | sidePanelTabBar.invitationTabDown = false |
| 79 | } |
| 80 | |
| 81 | function needToChangeToAccount(accountId, index) { |
| 82 | if (index !== -1) { |
| 83 | accountComboBox.currentIndex = index |
| 84 | ClientWrapper.accountAdaptor.accountChanged(index) |
| 85 | accountChangedUIReset() |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | function refreshAccountComboBox(index = -1) { |
| 90 | accountComboBox.resetAccountListModel() |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * To make sure that the ui is refreshed for accountComboBox. |
| 95 | * Note: when index in -1, it means to maintain the |
| 96 | * current account selection. |
| 97 | */ |
| 98 | var currentIndex = accountComboBox.currentIndex |
| 99 | if (accountComboBox.currentIndex === index) |
| 100 | accountComboBox.currentIndex = -1 |
| 101 | accountComboBox.currentIndex = index |
| 102 | if (index !== -1) |
| 103 | ClientWrapper.accountAdaptor.accountChanged(index) |
| 104 | else |
| 105 | accountComboBox.currentIndex = currentIndex |
| 106 | accountComboBox.update() |
| 107 | accountChangedUIReset() |
| 108 | } |
| 109 | |
| 110 | function deselectConversationSmartList() { |
| 111 | ConversationsAdapter.deselectConversation() |
| 112 | conversationSmartListView.currentIndex = -1 |
| 113 | } |
| 114 | |
| 115 | function forceUpdateConversationSmartListView() { |
| 116 | conversationSmartListView.updateConversationSmartListView() |
| 117 | } |
| 118 | |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 119 | function updateSmartList(accountId) { |
| 120 | conversationSmartListView.currentIndex = -1 |
| 121 | conversationSmartListView.updateSmartList(accountId) |
| 122 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * Intended -> since strange behavior will happen without this for stackview. |
| 126 | */ |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 127 | anchors.top: parent.top |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 128 | anchors.fill: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 129 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 130 | /* |
| 131 | * Search bar container to embed search label |
| 132 | */ |
| 133 | ContactSearchBar { |
| 134 | id: contactSearchBar |
| 135 | width: sidePanelRect.width - 26 |
| 136 | height: 35 |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 137 | anchors.top: sidePanelRect.top |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 138 | anchors.topMargin: 10 |
| 139 | anchors.left: sidePanelRect.left |
| 140 | anchors.leftMargin: 16 |
| 141 | |
| 142 | onContactSearchBarTextChanged: { |
| 143 | ClientWrapper.utilsAdaptor.setConversationFilter(text) |
| 144 | } |
| 145 | } |
| 146 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 147 | SidePanelTabBar { |
| 148 | id: sidePanelTabBar |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 149 | anchors.top: contactSearchBar.bottom |
| 150 | anchors.topMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 151 | width: sidePanelRect.width |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 152 | height: tabBarVisible ? 64 : 0 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 155 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 156 | ConversationSmartListView { |
| 157 | id: conversationSmartListView |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 158 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 159 | anchors.top: tabBarVisible ? sidePanelTabBar.bottom : contactSearchBar.bottom |
| 160 | anchors.topMargin: tabBarVisible ? 0 : 10 |
| 161 | width: parent.width |
ababi | a284cae | 2020-08-10 12:33:34 +0200 | [diff] [blame] | 162 | height: tabBarVisible ? sidePanelRect.height - sidePanelTabBar.height - contactSearchBar.height - 20 : |
| 163 | sidePanelRect.height - contactSearchBar.height - 20 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 164 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 165 | Connections { |
| 166 | target: ConversationsAdapter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 167 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 168 | function onShowChatView(accountId, convUid) { |
| 169 | conversationSmartListView.needToShowChatView(accountId, |
| 170 | convUid) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 171 | } |
| 172 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 173 | function onShowConversationTabs(visible) { |
| 174 | tabBarVisible = visible |
| 175 | updatePendingRequestCount() |
| 176 | updateTotalUnreadMessagesCount() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 177 | } |
| 178 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 179 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 180 | onNeedToSelectItems: { |
| 181 | ConversationsAdapter.selectConversation(index) |
| 182 | } |
| 183 | |
| 184 | onNeedToBackToWelcomePage: { |
| 185 | sidePanelRect.conversationSmartListViewNeedToShowWelcomePage() |
| 186 | } |
| 187 | |
| 188 | onNeedToAccessMessageWebView: { |
| 189 | sidePanelRect.conversationSmartListNeedToAccessMessageWebView( |
| 190 | currentUserDisplayName, currentUserAlias, |
| 191 | currentUID, callStackViewShouldShow, |
| 192 | isAudioOnly, callStateStr) |
| 193 | } |
| 194 | |
| 195 | onNeedToGrabFocus: { |
| 196 | contactSearchBar.clearFocus() |
| 197 | } |
| 198 | |
| 199 | Component.onCompleted: { |
| 200 | ConversationsAdapter.setQmlObject(this) |
| 201 | conversationSmartListView.currentIndex = -1 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |