[cheese/capsrework] Disable camera specific preferences when there is no device



commit 17d3cb52ec709bab6ab06f7399d830c9fe967fb1
Author: Filippo Argiolas <filippo argiolas gmail com>
Date:   Wed Dec 23 08:36:26 2009 +0100

    Disable camera specific preferences when there is no device
    
    Set camera and resolution combo boxes and balance scales insensitive
    when no device is detected

 libcheese/cheese-camera.c        |   39 +++++++++++++++++++++++--------------
 libcheese/cheese-camera.h        |    4 +-
 src/cheese-prefs-balance-scale.c |   18 ++++++++++------
 src/cheese-prefs-camera-combo.c  |    5 +---
 4 files changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index d5f3bd2..9e4d9bf 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -633,6 +633,17 @@ cheese_camera_get_num_camera_devices (CheeseCamera *camera)
   return priv->num_camera_devices;
 }
 
+CheeseCameraDevice *
+cheese_camera_get_selected_device (CheeseCamera *camera)
+{
+  CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
+  if (cheese_camera_get_num_camera_devices (camera) > 0)
+    return CHEESE_CAMERA_DEVICE (
+      g_ptr_array_index (priv->camera_devices, priv->selected_device));
+  else
+    return NULL;
+}
+
 gboolean
 cheese_camera_switch_camera_device (CheeseCamera *camera)
 {
@@ -1125,14 +1136,6 @@ cheese_camera_setup (CheeseCamera *camera, char *id, GError **error)
     g_error ("Unable link pipeline for photo");
 }
 
-int
-cheese_camera_get_selected_device_index (CheeseCamera *camera)
-{
-  CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
-
-  return priv->selected_device;
-}
-
 GPtrArray *
 cheese_camera_get_camera_devices (CheeseCamera *camera)
 {
@@ -1170,10 +1173,12 @@ cheese_camera_set_device_by_dev_udi (CheeseCamera *camera, char *udi)
 GList *
 cheese_camera_get_video_formats (CheeseCamera *camera)
 {
-  CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
-  CheeseCameraDevice  *device = g_ptr_array_index (priv->camera_devices, priv->selected_device);
+  CheeseCameraDevice  *device = cheese_camera_get_selected_device (camera);
 
-  return cheese_camera_device_get_format_list (device);
+  if (device)
+    return cheese_camera_device_get_format_list (device);
+  else
+    return NULL;
 }
 
 gboolean
@@ -1206,7 +1211,7 @@ cheese_camera_get_current_video_format (CheeseCamera *camera)
   return priv->current_format;
 }
 
-void
+gboolean
 cheese_camera_get_balance_property_range (CheeseCamera *camera,
                                           gchar *property,
                                           gdouble *min, gdouble *max, gdouble *def)
@@ -1215,17 +1220,21 @@ cheese_camera_get_balance_property_range (CheeseCamera *camera,
   GParamSpec          *pspec;
 
   *min = 0.0;
-  *max = 0.0;
-  *def = 0.0;
+  *max = 1.0;
+  *def = 0.5;
+
+  if (!GST_IS_ELEMENT (priv->video_balance)) return FALSE;
 
   pspec = g_object_class_find_property (
     G_OBJECT_GET_CLASS (G_OBJECT (priv->video_balance)), property);
 
-  g_return_if_fail (pspec != NULL);
+  g_return_val_if_fail (G_IS_PARAM_SPEC_DOUBLE (pspec), FALSE);
 
   *min = G_PARAM_SPEC_DOUBLE (pspec)->minimum;
   *max = G_PARAM_SPEC_DOUBLE (pspec)->maximum;
   *def = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
+
+  return TRUE;
 }
 
 void
diff --git a/libcheese/cheese-camera.h b/libcheese/cheese-camera.h
index 6680808..b956fb5 100644
--- a/libcheese/cheese-camera.h
+++ b/libcheese/cheese-camera.h
@@ -91,7 +91,7 @@ gboolean           cheese_camera_take_photo (CheeseCamera *camera, char *filenam
 gboolean           cheese_camera_take_photo_pixbuf (CheeseCamera *camera);
 gboolean           cheese_camera_has_camera (CheeseCamera *camera);
 int                cheese_camera_get_num_camera_devices (CheeseCamera *camera);
-int                cheese_camera_get_selected_device_index (CheeseCamera *camera);
+CheeseCameraDevice *cheese_camera_get_selected_device (CheeseCamera *camera);
 GPtrArray *        cheese_camera_get_camera_devices (CheeseCamera *camera);
 void               cheese_camera_set_device_by_dev_file (CheeseCamera *camera, char *file);
 void               cheese_camera_set_device_by_dev_udi (CheeseCamera *camera, char *udi);
@@ -99,7 +99,7 @@ gboolean           cheese_camera_switch_camera_device (CheeseCamera *camera);
 GList     *        cheese_camera_get_video_formats (CheeseCamera *camera);
 void               cheese_camera_set_video_format (CheeseCamera      *camera,
                                                    CheeseVideoFormat *format);
-void cheese_camera_get_balance_property_range (CheeseCamera *camera,
+gboolean cheese_camera_get_balance_property_range (CheeseCamera *camera,
                                                gchar *property,
                                                gdouble *min, gdouble *max, gdouble *def);
 void cheese_camera_set_balance_property (CheeseCamera *camera, gchar *property, gdouble value);
diff --git a/src/cheese-prefs-balance-scale.c b/src/cheese-prefs-balance-scale.c
index bd10946..a2de176 100644
--- a/src/cheese-prefs-balance-scale.c
+++ b/src/cheese-prefs-balance-scale.c
@@ -94,23 +94,27 @@ cheese_prefs_balance_scale_synchronize (CheesePrefsWidget *prefs_widget)
   GtkAdjustment *adj;
   gdouble        min, max, def;
   gdouble        stored_value;
+  gboolean       can_balance;
 
   g_object_get (prefs_widget, "widget", &scale, NULL);
 
-  cheese_camera_get_balance_property_range (priv->camera,
-                                            priv->property_name, &min, &max, &def);
+  /* Disconnect to prevent a whole bunch of changed notifications */
+  g_signal_handlers_disconnect_by_func (scale, cheese_prefs_balance_scale_value_changed, prefs_widget);
+
+  can_balance = cheese_camera_get_balance_property_range (priv->camera,
+                                                          priv->property_name, &min, &max, &def);
 
   adj = GTK_ADJUSTMENT (gtk_adjustment_new (def, min, max, (max - min) / STEPS, 0.0, 0.0));
   gtk_range_set_adjustment (GTK_RANGE (scale), adj);
 
   gtk_scale_add_mark (GTK_SCALE (scale), def, GTK_POS_BOTTOM, NULL);
 
-  g_object_get (CHEESE_PREFS_WIDGET (self)->gconf, priv->gconf_key, &stored_value, NULL);
-
-  gtk_range_set_value (GTK_RANGE (scale), stored_value);
+  gtk_widget_set_sensitive (scale, can_balance);
 
-  /* Disconnect to prevent a whole bunch of changed notifications */
-  g_signal_handlers_disconnect_by_func (scale, cheese_prefs_balance_scale_value_changed, prefs_widget);
+  if (can_balance) {
+    g_object_get (CHEESE_PREFS_WIDGET (self)->gconf, priv->gconf_key, &stored_value, NULL);
+    gtk_range_set_value (GTK_RANGE (scale), stored_value);
+  }
 
   g_signal_connect (G_OBJECT (scale), "value-changed",
                     G_CALLBACK (cheese_prefs_balance_scale_value_changed),
diff --git a/src/cheese-prefs-camera-combo.c b/src/cheese-prefs-camera-combo.c
index 018a4fc..26a6f82 100644
--- a/src/cheese-prefs-camera-combo.c
+++ b/src/cheese-prefs-camera-combo.c
@@ -100,7 +100,6 @@ cheese_prefs_camera_combo_synchronize (CheesePrefsWidget *prefs_widget)
 
   GtkWidget          *combo_box;
   GPtrArray          *camera_devices;
-  int                 selected_device_ind;
   int                 num_devices;
   CheeseCameraDevice *selected_device;
   char               *gconf_device_name;
@@ -123,10 +122,8 @@ cheese_prefs_camera_combo_synchronize (CheesePrefsWidget *prefs_widget)
   gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
 
   camera_devices      = cheese_camera_get_camera_devices (priv->camera);
-  selected_device_ind = cheese_camera_get_selected_device_index (priv->camera);
   num_devices         = cheese_camera_get_num_camera_devices (priv->camera);
-
-  selected_device = g_ptr_array_index (camera_devices, selected_device_ind);
+  selected_device     = cheese_camera_get_selected_device (priv->camera);
 
   /* If the selected device is not the same device as the one in gconf, the
    * selected device isn't available or was set by --hal-device. Set it now.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]