From 918c67d9d00a140ff91519e4844d66cd481a1a82 Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Wed, 12 Oct 2016 13:49:31 -0400
Subject: [PATCH] save default video device

Now setting the default video device will update the order of the
video preferences and then save the config. This ensures that the
default video device setting persists between dring sessions as
the order of the video preferences in dring.yml is used to determine
the default device when launching dring.

Reviewed-by: Alexandre Viau <alexandre.viau@savoirfairelinux.com>
Change-Id: I7af715c80db58b83eaf4b7584b34ca2279023a2c
Tuleap: #1035
---
 src/client/videomanager.cpp              |  1 +
 src/media/video/video_device_monitor.cpp | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/client/videomanager.cpp b/src/client/videomanager.cpp
index c85a694c02..cc92f9e167 100644
--- a/src/client/videomanager.cpp
+++ b/src/client/videomanager.cpp
@@ -79,6 +79,7 @@ setDefaultDevice(const std::string& name)
 {
     RING_DBG("Setting default device to %s", name.c_str());
     ring::Manager::instance().getVideoManager().videoDeviceMonitor.setDefaultDevice(name);
+    ring::Manager::instance().saveConfig();
 }
 
 std::map<std::string, std::string>
diff --git a/src/media/video/video_device_monitor.cpp b/src/media/video/video_device_monitor.cpp
index d5465fc982..ba1cff48e7 100644
--- a/src/media/video/video_device_monitor.cpp
+++ b/src/media/video/video_device_monitor.cpp
@@ -109,9 +109,20 @@ VideoDeviceMonitor::getMRLForDefaultDevice() const
 void
 VideoDeviceMonitor::setDefaultDevice(const std::string& name)
 {
-    const auto it = findDeviceByName(name);
-    if (it != devices_.end())
-        defaultDevice_ = it->name;
+    const auto itDev = findDeviceByName(name);
+    if (itDev != devices_.end()) {
+        defaultDevice_ = itDev->name;
+
+        // place it at the begining of the prefs
+        auto itPref = findPreferencesByName(name);
+        if (itPref != preferences_.end()) {
+            auto settings = *itPref;
+            preferences_.erase(itPref);
+            preferences_.insert(preferences_.begin(), settings);
+        } else {
+            preferences_.insert(preferences_.begin(), itDev->getSettings());
+        }
+    }
 }
 
 DeviceParams
-- 
GitLab