From 4a2bf0d61e605dd5128ac35049c124381aaa28b8 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Tue, 19 Oct 2021 17:07:55 -0400
Subject: [PATCH] calls: hide video related features if video disabled

Call controls and features are restrained if video is disabled in account advanced settings.

+ Do not show "accept in video" if there is no video device available

GitLab: #525
Change-Id: Iacc8801c8a302a1b00642a6c31603973ff5f24b6
---
 src/mainview/components/CallActionBar.qml     | 11 +++++--
 .../components/CallViewContextMenu.qml        |  6 ++--
 src/mainview/components/ChatViewHeader.qml    |  6 ++--
 .../components/ConversationListView.qml       |  7 +++--
 .../ConversationSmartListContextMenu.qml      |  5 ++--
 src/mainview/components/InitialCallPage.qml   | 29 +++++++++++++++++--
 .../components/SmartListItemDelegate.qml      |  2 +-
 .../components/AdvancedMediaSettings.qml      |  3 ++
 8 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/src/mainview/components/CallActionBar.qml b/src/mainview/components/CallActionBar.qml
index 3dcece673..ef1001053 100644
--- a/src/mainview/components/CallActionBar.qml
+++ b/src/mainview/components/CallActionBar.qml
@@ -302,6 +302,11 @@ Control {
         function onLocalHandRaisedChanged() { reset() }
         function onIsConferenceCallChanged() { reset() }
     }
+    Connections {
+        target: CurrentAccount
+
+        function onVideoEnabledVideoChanged() { reset() }
+    }
 
     function reset() {
         CallOverlayModel.clearControls()
@@ -309,7 +314,9 @@ Control {
         // centered controls
         CallOverlayModel.addPrimaryControl(muteAudioAction)
         CallOverlayModel.addPrimaryControl(hangupAction)
-        CallOverlayModel.addPrimaryControl(muteVideoAction)
+
+        if (CurrentAccount.videoEnabled_Video)
+            CallOverlayModel.addPrimaryControl(muteVideoAction)
 
         // overflow controls
         CallOverlayModel.addSecondaryControl(audioOutputAction)
@@ -325,7 +332,7 @@ Control {
             CallOverlayModel.addSecondaryControl(callTransferAction)
         }
         CallOverlayModel.addSecondaryControl(chatAction)
-        if (!isSIP)
+        if (CurrentAccount.videoEnabled_Video && !isSIP)
             CallOverlayModel.addSecondaryControl(shareAction)
         CallOverlayModel.addSecondaryControl(recordAction)
         CallOverlayModel.addSecondaryControl(pluginsAction)
diff --git a/src/mainview/components/CallViewContextMenu.qml b/src/mainview/components/CallViewContextMenu.qml
index d3449b110..911a464ae 100644
--- a/src/mainview/components/CallViewContextMenu.qml
+++ b/src/mainview/components/CallViewContextMenu.qml
@@ -113,7 +113,7 @@ ContextMenuAutoLoader {
         GeneralMenuItem {
             id: shareScreen
 
-            canTrigger: AvAdapter.currentRenderingDeviceType !== Video.DeviceType.DISPLAY
+            canTrigger: CurrentAccount.videoEnabled_Video && AvAdapter.currentRenderingDeviceType !== Video.DeviceType.DISPLAY
                         && !isSIP
             itemName: JamiStrings.shareScreen
             iconSource: JamiResources.share_screen_black_24dp_svg
@@ -129,7 +129,7 @@ ContextMenuAutoLoader {
         GeneralMenuItem {
             id: shareScreenArea
 
-            canTrigger: AvAdapter.currentRenderingDeviceType !== Video.DeviceType.DISPLAY
+            canTrigger: CurrentAccount.videoEnabled_Video && AvAdapter.currentRenderingDeviceType !== Video.DeviceType.DISPLAY
                         && !isSIP
             itemName: JamiStrings.shareScreenArea
             iconSource: JamiResources.share_screen_black_24dp_svg
@@ -145,7 +145,7 @@ ContextMenuAutoLoader {
         GeneralMenuItem {
             id: shareFile
 
-            canTrigger: !isSIP
+            canTrigger: CurrentAccount.videoEnabled_Video && !isSIP
             itemName: JamiStrings.shareFile
             iconSource: JamiResources.insert_photo_24dp_svg
             onClicked: {
diff --git a/src/mainview/components/ChatViewHeader.qml b/src/mainview/components/ChatViewHeader.qml
index f2ce5da90..4a25b45bd 100644
--- a/src/mainview/components/ChatViewHeader.qml
+++ b/src/mainview/components/ChatViewHeader.qml
@@ -154,7 +154,7 @@ Rectangle {
             PushButton {
                 id: startAVideoCallButton
 
-                visible: interactionButtonsVisibility
+                visible: CurrentAccount.videoEnabled_Video && interactionButtonsVisibility
 
                 source: JamiResources.videocam_24dp_svg
                 toolTipText: JamiStrings.placeVideoCall
@@ -162,7 +162,9 @@ Rectangle {
                 normalColor: JamiTheme.chatviewBgColor
                 imageColor: JamiTheme.chatviewButtonColor
 
-                onClicked: CallAdapter.placeCall()
+                onClicked: {
+                    CallAdapter.placeCall()
+                }
             }
 
             PushButton {
diff --git a/src/mainview/components/ConversationListView.qml b/src/mainview/components/ConversationListView.qml
index 5b2b34635..f990f5d25 100644
--- a/src/mainview/components/ConversationListView.qml
+++ b/src/mainview/components/ConversationListView.qml
@@ -157,8 +157,11 @@ ListView {
     Shortcut {
         sequence: "Ctrl+Shift+X"
         context: Qt.ApplicationShortcut
-        enabled: root.visible
-        onActivated: CallAdapter.placeCall()
+        enabled: CurrentAccount.videoEnabled_Video && root.visible
+        onActivated: {
+            if (CurrentAccount.videoEnabled_Video)
+                CallAdapter.placeCall()
+        }
     }
 
     Shortcut {
diff --git a/src/mainview/components/ConversationSmartListContextMenu.qml b/src/mainview/components/ConversationSmartListContextMenu.qml
index 80632c164..2a26f0a3c 100644
--- a/src/mainview/components/ConversationSmartListContextMenu.qml
+++ b/src/mainview/components/ConversationSmartListContextMenu.qml
@@ -44,13 +44,14 @@ ContextMenuAutoLoader {
         GeneralMenuItem {
             id: startVideoCallItem
 
-            canTrigger: !hasCall && !readOnly
+            canTrigger: CurrentAccount.videoEnabled_Video && !hasCall && !readOnly
             itemName: JamiStrings.startVideoCall
             iconSource: JamiResources.videocam_24dp_svg
             onClicked: {
                 LRCInstance.selectConversation(responsibleConvUid,
                                                responsibleAccountId)
-                CallAdapter.placeCall()
+                if (CurrentAccount.videoEnabled_Video)
+                    CallAdapter.placeCall()
             }
         },
         GeneralMenuItem {
diff --git a/src/mainview/components/InitialCallPage.qml b/src/mainview/components/InitialCallPage.qml
index 128660c5f..aa7970671 100644
--- a/src/mainview/components/InitialCallPage.qml
+++ b/src/mainview/components/InitialCallPage.qml
@@ -42,11 +42,34 @@ Rectangle {
     ListModel {
         id: incomingControlsModel
         Component.onCompleted: {
-            append({"type": "refuse", "image": JamiResources.round_close_24dp_svg})
-            append({"type": "mic", "image" : JamiResources.place_audiocall_24dp_svg})
-            append({"type": "cam", "image" : JamiResources.videocam_24dp_svg})
+            fillIncomingControls()
         }
     }
+
+    Connections {
+        target: CurrentAccount
+
+        function onVideoEnabledVideoChanged() {
+            fillIncomingControls()
+        }
+    }
+
+    Connections {
+        target: VideoDevices
+
+        function onListSizeChanged() {
+            fillIncomingControls()
+        }
+    }
+
+    function fillIncomingControls() {
+            incomingControlsModel.clear()
+            incomingControlsModel.append({"type": "refuse", "image": JamiResources.round_close_24dp_svg})
+            incomingControlsModel.append({"type": "mic", "image" : JamiResources.place_audiocall_24dp_svg})
+            if (CurrentAccount.videoEnabled_Video && VideoDevices.listSize !== 0)
+                incomingControlsModel.append({"type": "cam", "image" : JamiResources.videocam_24dp_svg})
+    }
+
     ListModel {
         id: outgoingControlsModel
         Component.onCompleted: {
diff --git a/src/mainview/components/SmartListItemDelegate.qml b/src/mainview/components/SmartListItemDelegate.qml
index a5b77f230..95af16d0e 100644
--- a/src/mainview/components/SmartListItemDelegate.qml
+++ b/src/mainview/components/SmartListItemDelegate.qml
@@ -158,7 +158,7 @@ ItemDelegate {
     onClicked: ListView.view.model.select(index)
     onDoubleClicked: {
         ListView.view.model.select(index)
-        if (LRCInstance.currentAccountType === Profile.Type.SIP)
+        if (LRCInstance.currentAccountType === Profile.Type.SIP || !CurrentAccount.videoEnabled_Video)
             CallAdapter.placeAudioOnlyCall()
         else {
             if (!CurrentConversation.readOnly) {
diff --git a/src/settingsview/components/AdvancedMediaSettings.qml b/src/settingsview/components/AdvancedMediaSettings.qml
index cc2e01e67..badf90250 100644
--- a/src/settingsview/components/AdvancedMediaSettings.qml
+++ b/src/settingsview/components/AdvancedMediaSettings.qml
@@ -66,6 +66,9 @@ ColumnLayout {
 
                 Layout.fillWidth: true
                 Layout.fillHeight: true
+                enabled: CurrentAccount.videoEnabled_Video
+
+                opacity: enabled ? 1.0 : 0.5
 
                 mediaType: MediaSettings.VIDEO
             }
-- 
GitLab