From 748e161b2bf0a150dc0b1064a147e6eb1f0be2ae Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Wed, 11 Aug 2021 10:03:31 -0400
Subject: [PATCH] video: don't start the camera for no reason when it's plugged
 in

When the video device count goes to 1 from 0, previewing is
activated even if we're not in the av settings view. This patch
emits a signal that can be responded to by the settings view.

Gitlab: #489
Change-Id: Id0ed2809015359423ec0f829d8494f598a89c8ea
---
 src/avadapter.cpp                             | 7 ++++---
 src/avadapter.h                               | 2 +-
 src/settingsview/components/AvSettingPage.qml | 9 +++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/avadapter.cpp b/src/avadapter.cpp
index acb8644bd..af66b1480 100644
--- a/src/avadapter.cpp
+++ b/src/avadapter.cpp
@@ -293,10 +293,11 @@ AvAdapter::onVideoDeviceEvent()
         if (deviceEvent == DeviceEvent::Added && currentDeviceListSize == 1) {
             avModel.setDefaultDevice(defaultDevice);
             avModel.setCurrentVideoCaptureDevice(defaultDevice);
-            if (callId.isEmpty())
-                lrcInstance_->renderer()->startPreviewing();
-            else
+            if (callId.isEmpty()) {
+                Q_EMIT videoDeviceAvailable();
+            } else {
                 avModel.switchInputTo(defaultDevice, callId);
+            }
         } else {
             cb();
         }
diff --git a/src/avadapter.h b/src/avadapter.h
index 79d1e0949..aba5736f1 100644
--- a/src/avadapter.h
+++ b/src/avadapter.h
@@ -39,8 +39,8 @@ Q_SIGNALS:
 
     void audioDeviceListChanged(int inputs, int outputs);
     void videoDeviceListChanged(int inputs);
-
     void screenCaptured(int screenNumber, QString source);
+    void videoDeviceAvailable();
 
 protected:
     void safeInit() override {};
diff --git a/src/settingsview/components/AvSettingPage.qml b/src/settingsview/components/AvSettingPage.qml
index cd6555019..0148a769e 100644
--- a/src/settingsview/components/AvSettingPage.qml
+++ b/src/settingsview/components/AvSettingPage.qml
@@ -42,6 +42,15 @@ Rectangle {
 
     color: JamiTheme.secondaryBackgroundColor
 
+    Connections {
+        target: AvAdapter
+
+        function onVideoDeviceAvailable() {
+            if (root.visible)
+                videoSettings.startPreviewing()
+        }
+    }
+
     ColumnLayout {
         id: avSettingsColumnLayout
 
-- 
GitLab