ab12a32
From a1805cadf3e6f7396a323c26e391cd91c28c829f Mon Sep 17 00:00:00 2001
9b94ca0
From: Hans de Goede <hdegoede@redhat.com>
9b94ca0
Date: Tue, 18 Jun 2013 11:59:55 +0200
ab12a32
Subject: [PATCH 06/11] cheese: Properly deal with going from 0 -> 1 devices
9b94ca0
9b94ca0
Before this patch cheese showed a "No device found" message when started
9b94ca0
without any devices connected, and would keep showing this after the user
9b94ca0
plugged in a webcam. The new cam also could not be selected from the
9b94ca0
preferences dialog.
9b94ca0
9b94ca0
After this patch cheese will automatically switch to showing video from a
9b94ca0
newly plugged in webcam (when it had no devices before).
9b94ca0
9b94ca0
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
9b94ca0
---
9b94ca0
 src/cheese-application.vala |  1 +
9b94ca0
 src/cheese-preferences.vala | 28 +++++++++++++++++++++++++---
9b94ca0
 2 files changed, 26 insertions(+), 3 deletions(-)
9b94ca0
9b94ca0
diff --git a/src/cheese-application.vala b/src/cheese-application.vala
ab12a32
index aa62a2e..fbb1145 100644
9b94ca0
--- a/src/cheese-application.vala
9b94ca0
+++ b/src/cheese-application.vala
ab12a32
@@ -368,6 +368,7 @@ public class Cheese.Application : Gtk.Application
9b94ca0
                 mode.set_enabled (false);
9b94ca0
                 shoot.set_enabled (false);
9b94ca0
 
9b94ca0
+                preferences_dialog.camera_stop ();
9b94ca0
                 main_window.camera_state_change_null ();
9b94ca0
                 break;
9b94ca0
             default:
9b94ca0
diff --git a/src/cheese-preferences.vala b/src/cheese-preferences.vala
ab12a32
index a73bb46..06929f5 100644
9b94ca0
--- a/src/cheese-preferences.vala
9b94ca0
+++ b/src/cheese-preferences.vala
ab12a32
@@ -24,6 +24,8 @@ using Gtk;
ab12a32
 public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
 {
9b94ca0
   private Cheese.Camera camera;
9b94ca0
+  private bool camera_is_setup;
9b94ca0
+  private bool camera_is_playing;
9b94ca0
 
9b94ca0
   private GLib.Settings settings;
9b94ca0
 
ab12a32
@@ -122,8 +124,16 @@ public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
   {
9b94ca0
     try
9b94ca0
     {
9b94ca0
-      camera.setup (null);
9b94ca0
-      camera.play ();
9b94ca0
+      if (!camera_is_setup)
9b94ca0
+      {
9b94ca0
+          camera.setup (null);
9b94ca0
+          camera_is_setup = true;
9b94ca0
+      }
9b94ca0
+      if (!camera_is_playing)
9b94ca0
+      {
9b94ca0
+        camera.play ();
9b94ca0
+        camera_is_playing = true;
9b94ca0
+      }
9b94ca0
       camera_changed ();
9b94ca0
     }
9b94ca0
     catch (Error err)
ab12a32
@@ -133,6 +143,14 @@ public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
   }
9b94ca0
 
9b94ca0
   /**
9b94ca0
+   * Call this when the gstreamer pipe transitions to NULL
9b94ca0
+   */
9b94ca0
+  public void camera_stop ()
9b94ca0
+  {
9b94ca0
+    camera_is_playing = false;
9b94ca0
+  }
9b94ca0
+
9b94ca0
+  /**
9b94ca0
    * Set up combo box cell renderers.
9b94ca0
    */
9b94ca0
   private void setup_combo_box_models ()
ab12a32
@@ -268,7 +286,7 @@ public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
     combo.model.get (iter, 1, out dev);
9b94ca0
     camera.set_device_by_device_node (dev.get_device_node ());
9b94ca0
     camera.switch_camera_device ();
9b94ca0
-    camera_changed ();
9b94ca0
+    camera_play ();
9b94ca0
   }
9b94ca0
 
9b94ca0
   /**
ab12a32
@@ -529,6 +547,7 @@ public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
   {
9b94ca0
     TreeIter iter;
9b94ca0
     Cheese.CameraDevice dev = (Cheese.CameraDevice) device;
9b94ca0
+    bool was_empty = camera_model.iter_n_children (null) == 0;
9b94ca0
 
9b94ca0
     camera_model.append (out iter);
9b94ca0
     camera_model.set (iter,
ab12a32
@@ -537,6 +556,9 @@ public class Cheese.PreferencesDialog : GLib.Object
9b94ca0
 
ab12a32
     if (camera_model.iter_n_children (null) > 1)
9b94ca0
       source_combo.sensitive = true;
9b94ca0
+
9b94ca0
+    if (was_empty)
9b94ca0
+      source_combo.set_active_iter (iter);
9b94ca0
   }
9b94ca0
 
9b94ca0
   /**
9b94ca0
-- 
9b94ca0
1.8.3.1
9b94ca0