Blame SOURCES/0044-cheese-Move-camera_setup-to-cheese-preferences.patch

ecdf9b
From f1dbd7629b18f8078567e34cf3981bfbdc70b5ef Mon Sep 17 00:00:00 2001
ecdf9b
From: Hans de Goede <hdegoede@redhat.com>
ecdf9b
Date: Tue, 18 Jun 2013 11:40:41 +0200
ecdf9b
Subject: [PATCH 44/50] cheese: Move camera_setup to cheese-preferences
ecdf9b
ecdf9b
Since cheese-preferences already tracks how many cameras we have, it can also
ecdf9b
properly do delayed camera setup when going from 0 -> 1 devices while cheese
ecdf9b
is running, and thus is the best place to do the camera setup.
ecdf9b
ecdf9b
As an added bonus this patch uses the new show_error function to properly
ecdf9b
show an error to the user when no devices are found.
ecdf9b
ecdf9b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ecdf9b
---
ecdf9b
 src/cheese-main.vala        | 28 ++++++++++------------------
ecdf9b
 src/cheese-preferences.vala | 24 ++++++++++++++++++++++--
ecdf9b
 src/vapi/cheese-common.vapi |  2 +-
ecdf9b
 3 files changed, 33 insertions(+), 21 deletions(-)
ecdf9b
ecdf9b
diff --git a/src/cheese-main.vala b/src/cheese-main.vala
ecdf9b
index b5ac6cb..761f1b5 100644
ecdf9b
--- a/src/cheese-main.vala
ecdf9b
+++ b/src/cheese-main.vala
ecdf9b
@@ -62,6 +62,12 @@ public class Cheese.Main : Gtk.Application
ecdf9b
     GLib.Object (application_id: app_id, flags: flags);
ecdf9b
   }
ecdf9b
 
ecdf9b
+  private void on_camera_error (string? error)
ecdf9b
+  {
ecdf9b
+    main_window.toggle_camera_actions_sensitivities (false);
ecdf9b
+    main_window.show_error (error);
ecdf9b
+  }
ecdf9b
+
ecdf9b
   /**
ecdf9b
    * Present the existing main window, or create a new one.
ecdf9b
    */
ecdf9b
@@ -147,8 +153,10 @@ public class Cheese.Main : Gtk.Application
ecdf9b
       main_window.key_press_event.connect (on_webcam_key_pressed);
ecdf9b
 
ecdf9b
       main_window.show ();
ecdf9b
-      setup_camera (device);
ecdf9b
+      create_camera (device);
ecdf9b
       preferences_dialog = new PreferencesDialog (camera);
ecdf9b
+      preferences_dialog.camera_error.connect (on_camera_error);
ecdf9b
+      preferences_dialog.setup_camera ();
ecdf9b
     }
ecdf9b
   }
ecdf9b
 
ecdf9b
@@ -157,7 +165,7 @@ public class Cheese.Main : Gtk.Application
ecdf9b
      *
ecdf9b
      * @param uri the uri of the device node to setup, or null
ecdf9b
      */
ecdf9b
-    public void setup_camera (string? uri)
ecdf9b
+    public void create_camera (string? uri)
ecdf9b
     {
ecdf9b
         var settings = new GLib.Settings ("org.gnome.Cheese");
ecdf9b
         string device;
ecdf9b
@@ -177,21 +185,6 @@ public class Cheese.Main : Gtk.Application
ecdf9b
             settings.get_int ("photo-x-resolution"),
ecdf9b
             settings.get_int ("photo-y-resolution"));
ecdf9b
 
ecdf9b
-        try
ecdf9b
-        {
ecdf9b
-            camera.setup (device);
ecdf9b
-        }
ecdf9b
-        catch (Error err)
ecdf9b
-        {
ecdf9b
-            video_preview.hide ();
ecdf9b
-            warning ("Error: %s\n", err.message);
ecdf9b
-            //error_layer.text = err.message;
ecdf9b
-            //error_layer.show ();
ecdf9b
-
ecdf9b
-            //toggle_camera_actions_sensitivities (false);
ecdf9b
-            return;
ecdf9b
-        }
ecdf9b
-
ecdf9b
         value = settings.get_double ("brightness");
ecdf9b
         if (value != 0.0)
ecdf9b
         {
ecdf9b
@@ -218,7 +211,6 @@ public class Cheese.Main : Gtk.Application
ecdf9b
 
ecdf9b
         camera.state_flags_changed.connect (on_camera_state_flags_changed);
ecdf9b
         main_window.set_camera (camera);
ecdf9b
-        camera.play ();
ecdf9b
     }
ecdf9b
 
ecdf9b
     /**
ecdf9b
diff --git a/src/cheese-preferences.vala b/src/cheese-preferences.vala
ecdf9b
index be104a6..30b3d65 100644
ecdf9b
--- a/src/cheese-preferences.vala
ecdf9b
+++ b/src/cheese-preferences.vala
ecdf9b
@@ -111,6 +111,28 @@ public class Cheese.PreferencesDialog : GLib.Object
ecdf9b
   }
ecdf9b
 
ecdf9b
   /**
ecdf9b
+   * Signal raised when there is an error with the camera device
ecdf9b
+   */
ecdf9b
+  public signal void camera_error (string? error);
ecdf9b
+
ecdf9b
+  /**
ecdf9b
+   * Setup the camera device
ecdf9b
+   */
ecdf9b
+  public void setup_camera ()
ecdf9b
+  {
ecdf9b
+    try
ecdf9b
+    {
ecdf9b
+      camera.setup (null);
ecdf9b
+      camera.play ();
ecdf9b
+      camera_changed ();
ecdf9b
+    }
ecdf9b
+    catch (Error err)
ecdf9b
+    {
ecdf9b
+      camera_error (err.message);
ecdf9b
+    }
ecdf9b
+  }
ecdf9b
+
ecdf9b
+  /**
ecdf9b
    * Set up combo box cell renderers.
ecdf9b
    */
ecdf9b
   private void setup_combo_box_models ()
ecdf9b
@@ -161,8 +183,6 @@ public class Cheese.PreferencesDialog : GLib.Object
ecdf9b
     source_combo.sensitive = false;
ecdf9b
 
ecdf9b
     devices.foreach(add_camera_device);
ecdf9b
-
ecdf9b
-    camera_changed ();
ecdf9b
   }
ecdf9b
 
ecdf9b
   /**
ecdf9b
diff --git a/src/vapi/cheese-common.vapi b/src/vapi/cheese-common.vapi
ecdf9b
index e4d4bec..88f47f7 100644
ecdf9b
--- a/src/vapi/cheese-common.vapi
ecdf9b
+++ b/src/vapi/cheese-common.vapi
ecdf9b
@@ -63,7 +63,7 @@ namespace Cheese
ecdf9b
     public void                        toggle_effects_pipeline (bool active);
ecdf9b
     public void                        connect_effect_texture (Cheese.Effect effect, Clutter.Texture texture);
ecdf9b
     public void                        set_video_format (Cheese.VideoFormat format);
ecdf9b
-    public void                        setup (string udi) throws GLib.Error;
ecdf9b
+    public void                        setup (string? udi) throws GLib.Error;
ecdf9b
     public void                        start_video_recording (string filename);
ecdf9b
     public void                        stop ();
ecdf9b
     public void                        stop_video_recording ();
ecdf9b
-- 
ecdf9b
1.8.2.1
ecdf9b