[cheese/videobalance: 2/4] Add a first draft of a brightness widget



commit 43d5794db9a52b7df1b4b46a6e02a7c6ca94c1d3
Author: Filippo Argiolas <filippo argiolas gmail com>
Date:   Wed Apr 22 20:48:06 2009 +0200

    Add a first draft of a brightness widget
    
    Add a GtkHScale widget to the preferences dialog, right now it's just for
    testing purposes. I think the whole dialog needs some love.
    Create corresponding cheese-prefs widget.
    Add needed methods for brightness control in cheese-webcam.
---
 data/cheese-prefs.glade             |   63 ++++++++++--
 data/cheese-prefs.ui                |   58 ++++++++++--
 src/Makefile.am                     |    2 +
 src/cheese-prefs-brightness-scale.c |  181 +++++++++++++++++++++++++++++++++++
 src/cheese-prefs-brightness-scale.h |   58 +++++++++++
 src/cheese-prefs-dialog.c           |   11 ++
 src/cheese-webcam.c                 |   27 +++++-
 src/cheese-webcam.h                 |    2 +
 8 files changed, 382 insertions(+), 20 deletions(-)

diff --git a/data/cheese-prefs.glade b/data/cheese-prefs.glade
index e389a0e..7ce85e0 100644
--- a/data/cheese-prefs.glade
+++ b/data/cheese-prefs.glade
@@ -1,13 +1,13 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Tue Jun 17 23:35:53 2008 -->
+<?xml version="1.0"?>
 <glade-interface>
+  <!-- interface-requires gtk+ 2.16 -->
+  <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkDialog" id="cheese_prefs_dialog">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Preferences</property>
-    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="type_hint">dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox1">
@@ -22,7 +22,7 @@
               <widget class="GtkFrame" id="frame2">
                 <property name="visible">True</property>
                 <property name="label_xalign">0</property>
-                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <property name="shadow_type">none</property>
                 <child>
                   <widget class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
@@ -45,13 +45,16 @@
                   </packing>
                 </child>
               </widget>
+              <packing>
+                <property name="position">0</property>
+              </packing>
             </child>
             <child>
               <widget class="GtkFrame" id="frame1">
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="label_xalign">0</property>
-                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <property name="shadow_type">none</property>
                 <child>
                   <widget class="GtkAlignment" id="alignment6">
                     <property name="visible">True</property>
@@ -81,6 +84,38 @@
                 <property name="position">1</property>
               </packing>
             </child>
+            <child>
+              <widget class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Brightness</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">10</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkHScale" id="brightness_scale">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="draw_value">False</property>
+                  </widget>
+                  <packing>
+                    <property name="padding">10</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </widget>
           <packing>
             <property name="expand">False</property>
@@ -92,22 +127,28 @@
           <widget class="GtkHButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <property name="layout_style">end</property>
             <child>
               <widget class="GtkButton" id="button1">
+                <property name="label">gtk-close</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label">gtk-close</property>
                 <property name="use_stock">True</property>
-                <property name="response_id">0</property>
+		<property name="response_id">0</property>
               </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
             </child>
           </widget>
           <packing>
             <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </widget>
diff --git a/data/cheese-prefs.ui b/data/cheese-prefs.ui
index 7ac1f51..5aff923 100644
--- a/data/cheese-prefs.ui
+++ b/data/cheese-prefs.ui
@@ -1,12 +1,13 @@
 <?xml version="1.0"?>
-<!--Generated with glade3 3.4.5 on Tue Jun 17 23:35:53 2008 -->
 <interface>
+  <!-- interface-requires gtk+ 2.16 -->
+  <!-- interface-naming-policy toplevel-contextual -->
   <object class="GtkDialog" id="cheese_prefs_dialog">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Preferences</property>
-    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="type_hint">dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
@@ -21,7 +22,7 @@
               <object class="GtkFrame" id="frame2">
                 <property name="visible">True</property>
                 <property name="label_xalign">0</property>
-                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <property name="shadow_type">none</property>
                 <child>
                   <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
@@ -41,13 +42,16 @@
                   </object>
                 </child>
               </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
             </child>
             <child>
               <object class="GtkFrame" id="frame1">
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="label_xalign">0</property>
-                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <property name="shadow_type">none</property>
                 <child>
                   <object class="GtkAlignment" id="alignment6">
                     <property name="visible">True</property>
@@ -74,6 +78,38 @@
                 <property name="position">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Brightness</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">10</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkHScale" id="brightness_scale">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="draw_value">False</property>
+                  </object>
+                  <packing>
+                    <property name="padding">10</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -85,21 +121,27 @@
           <object class="GtkHButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <property name="layout_style">end</property>
             <child>
               <object class="GtkButton" id="button1">
+                <property name="label">gtk-close</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label">gtk-close</property>
                 <property name="use_stock">True</property>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
diff --git a/src/Makefile.am b/src/Makefile.am
index beb97ff..622b146 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,8 @@ cheese_SOURCES = \
 	cheese-prefs-dialog-widgets.c \
 	cheese-prefs-resolution-combo.h \
 	cheese-prefs-resolution-combo.c \
+	cheese-prefs-brightness-scale.c \
+	cheese-prefs-brightness-scale.h \
 	cheese-prefs-dialog.c \
 	cheese-prefs-dialog.h \
 	cheese-flash.h \
diff --git a/src/cheese-prefs-brightness-scale.c b/src/cheese-prefs-brightness-scale.c
new file mode 100644
index 0000000..ddf2814
--- /dev/null
+++ b/src/cheese-prefs-brightness-scale.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright © 2008 James Liggett <jrliggett cox net>
+ * Copyright © 2008 Ryan Zeigler <zeiglerr gmail com>
+ * Copyright © 2008 daniel g. siegel <dgsiegel gmail com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <glib.h>
+
+#include "cheese-webcam.h"
+#include "cheese-prefs-widget.h"
+#include "cheese-prefs-brightness-scale.h"
+
+enum
+{
+  PROP_0,
+  PROP_WEBCAM
+};
+
+typedef struct CheesePrefsBrightnessScalePrivate
+{
+  gdouble brightness;
+  CheeseWebcam *webcam;
+  gboolean has_been_synchronized;  /* Make sure we don't synchronize if client
+                                    * sets webcam on construction. */
+} CheesePrefsBrightnessScalePrivate;
+
+#define CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE(o)                     \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE, \
+                                CheesePrefsBrightnessScalePrivate))
+
+G_DEFINE_TYPE (CheesePrefsBrightnessScale, cheese_prefs_brightness_scale, CHEESE_TYPE_PREFS_WIDGET);
+
+static void
+cheese_prefs_brightness_scale_init (CheesePrefsBrightnessScale *self)
+{
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+
+  priv->has_been_synchronized = FALSE;
+}
+
+static void
+cheese_prefs_brightness_scale_finalize (GObject *object)
+{
+  CheesePrefsBrightnessScale        *self = CHEESE_PREFS_BRIGHTNESS_SCALE (object);
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+  G_OBJECT_CLASS (cheese_prefs_brightness_scale_parent_class)->finalize (object);
+}
+
+static void
+cheese_prefs_brightness_scale_value_changed (GtkRange *scale, CheesePrefsBrightnessScale *self)
+{
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+  gdouble value = gtk_range_get_value (scale);
+  cheese_webcam_set_brightness (priv->webcam, value);
+#if 0
+
+  g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->brightness_key, value, NULL);
+  g_free (new_device);
+
+#endif
+  cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
+}
+
+static void
+cheese_prefs_brightness_scale_synchronize (CheesePrefsWidget *prefs_widget)
+{
+  CheesePrefsBrightnessScale        *self = CHEESE_PREFS_BRIGHTNESS_SCALE (prefs_widget);
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+
+  GtkWidget          *scale;
+  GtkAdjustment      *adj;
+  gdouble min, max, def;
+
+  g_object_get (prefs_widget, "widget", &scale, NULL);
+  
+  cheese_webcam_get_brightness_range (priv->webcam, &min, &max, &def);
+  g_message ("synchronize %f %f %f", min, max, def);
+
+  adj = gtk_adjustment_new (def, min, max, (max - min)/100.0, 0.0, 0.0);
+  gtk_range_set_adjustment (GTK_RANGE (scale), adj);
+  
+  /* Disconnect to prevent a whole bunch of changed notifications */
+  g_signal_handlers_disconnect_by_func (scale, cheese_prefs_brightness_scale_value_changed, prefs_widget);
+
+  g_signal_connect (G_OBJECT (scale), "value-changed",
+                    G_CALLBACK (cheese_prefs_brightness_scale_value_changed),
+                    self);
+}
+
+static void
+cheese_prefs_brightness_scale_set_property (GObject *object, guint prop_id,
+                                        const GValue *value,
+                                        GParamSpec *pspec)
+{
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (object);
+
+  switch (prop_id)
+  {
+    case PROP_WEBCAM:
+      priv->webcam = CHEESE_WEBCAM (g_value_get_object (value));
+      if (priv->has_been_synchronized)
+        cheese_prefs_brightness_scale_synchronize (CHEESE_PREFS_WIDGET (object));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+cheese_prefs_brightness_scale_get_property (GObject *object, guint prop_id,
+                                        GValue *value, GParamSpec *pspec)
+{
+  CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (object);
+
+  g_return_if_fail (CHEESE_IS_PREFS_BRIGHTNESS_SCALE (object));
+
+  switch (prop_id)
+  {
+    case PROP_WEBCAM:
+      g_value_set_object (value, priv->webcam);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+cheese_prefs_brightness_scale_class_init (CheesePrefsBrightnessScaleClass *klass)
+{
+  GObjectClass           *object_class = G_OBJECT_CLASS (klass);
+  CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (CheesePrefsBrightnessScalePrivate));
+
+  object_class->finalize     = cheese_prefs_brightness_scale_finalize;
+  object_class->set_property = cheese_prefs_brightness_scale_set_property;
+  object_class->get_property = cheese_prefs_brightness_scale_get_property;
+  parent_class->synchronize  = cheese_prefs_brightness_scale_synchronize;
+
+  g_object_class_install_property (object_class,
+                                   PROP_WEBCAM,
+                                   g_param_spec_object ("webcam",
+                                                        "webcam",
+                                                        "Webcam object",
+                                                        CHEESE_TYPE_WEBCAM,
+                                                        G_PARAM_READWRITE));
+}
+
+CheesePrefsBrightnessScale *
+cheese_prefs_brightness_scale_new (GtkWidget *scale, CheeseWebcam *webcam)
+{
+  CheesePrefsBrightnessScale        *self;
+  CheesePrefsBrightnessScalePrivate *priv;
+
+  self = g_object_new (CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE,
+                       "widget", scale,
+                       "webcam", webcam,
+                       NULL);
+
+  priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+
+  return self;
+}
diff --git a/src/cheese-prefs-brightness-scale.h b/src/cheese-prefs-brightness-scale.h
new file mode 100644
index 0000000..b81dfa8
--- /dev/null
+++ b/src/cheese-prefs-brightness-scale.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2008 James Liggett <jrliggett cox net>
+ * Copyright © 2008 Ryan Zeigler <zeiglerr gmail com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CHEESE_PREFS_BRIGHTNESS_SCALE_H_
+#define _CHEESE_PREFS_BRIGHTNESS_SCALE_H_
+
+#include <glib-object.h>
+#include "cheese-prefs-widget.h"
+#include "cheese-webcam.h"
+
+G_BEGIN_DECLS
+
+#define CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE (cheese_prefs_brightness_scale_get_type ())
+#define CHEESE_PREFS_BRIGHTNESS_SCALE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE, \
+                                                                             CheesePrefsBrightnessScale))
+#define CHEESE_PREFS_BRIGHTNESS_SCALE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE, \
+                                                                          CheesePrefsBrightnessScaleClass))
+#define CHEESE_IS_PREFS_BRIGHTNESS_SCALE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE))
+#define CHEESE_IS_PREFS_BRIGHTNESS_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE))
+#define CHEESE_PREFS_BRIGHTNESS_SCALE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE, CheesePrefsBrightnessScaleClass))
+
+typedef struct _CheesePrefsBrightnessScaleClass CheesePrefsBrightnessScaleClass;
+typedef struct _CheesePrefsBrightnessScale CheesePrefsBrightnessScale;
+
+struct _CheesePrefsBrightnessScaleClass
+{
+  CheesePrefsWidgetClass parent_class;
+};
+
+struct _CheesePrefsBrightnessScale
+{
+  CheesePrefsWidget parent_instance;
+};
+
+GType                 cheese_prefs_brightness_scale_get_type (void) G_GNUC_CONST;
+CheesePrefsBrightnessScale *cheese_prefs_brightness_scale_new (GtkWidget    *scale,
+                                                   CheeseWebcam *webcam);
+
+char *cheese_prefs_brightness_scale_get_selected_webcam (CheesePrefsBrightnessScale *webcam);
+
+#endif /* _CHEESE_PREFS_BRIGHTNESS_SCALE_H_ */
diff --git a/src/cheese-prefs-dialog.c b/src/cheese-prefs-dialog.c
index 2e8ec10..cb6dd3d 100644
--- a/src/cheese-prefs-dialog.c
+++ b/src/cheese-prefs-dialog.c
@@ -25,6 +25,7 @@ typedef struct
   GtkWidget *cheese_prefs_dialog;
   GtkWidget *resolution_combo_box;
   GtkWidget *webcam_combo_box;
+  GtkWidget *brightness_scale;
 
   GtkWidget *parent;
   CheeseWebcam *webcam;
@@ -54,6 +55,9 @@ cheese_prefs_dialog_create_dialog (CheesePrefsDialog *prefs_dialog)
                                                                            "resolution_combo_box"));
   prefs_dialog->webcam_combo_box = GTK_WIDGET (gtk_builder_get_object (builder,
                                                                        "webcam_combo_box"));
+  prefs_dialog->brightness_scale = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                                       "brightness_scale"));
+
   gtk_window_set_transient_for (GTK_WINDOW (prefs_dialog->cheese_prefs_dialog),
                                 GTK_WINDOW (prefs_dialog->parent));
 }
@@ -103,6 +107,7 @@ cheese_prefs_dialog_setup_widgets (CheesePrefsDialog *prefs_dialog)
 {
   CheesePrefsWidget *resolution_widget;
   CheesePrefsWidget *webcam_widget;
+  CheesePrefsWidget *brightness_widget;
 
   resolution_widget = CHEESE_PREFS_WIDGET (cheese_prefs_resolution_combo_new (prefs_dialog->resolution_combo_box,
                                                                               prefs_dialog->webcam,
@@ -117,11 +122,17 @@ cheese_prefs_dialog_setup_widgets (CheesePrefsDialog *prefs_dialog)
   webcam_widget = CHEESE_PREFS_WIDGET (cheese_prefs_webcam_combo_new (prefs_dialog->webcam_combo_box,
                                                                       prefs_dialog->webcam,
                                                                       "gconf_prop_webcam"));
+
   g_signal_connect (G_OBJECT (webcam_widget), "changed",
                     G_CALLBACK (cheese_prefs_dialog_on_device_changed),
                     prefs_dialog);
   cheese_prefs_dialog_widgets_add (prefs_dialog->widgets, webcam_widget);
 
+  brightness_widget = CHEESE_PREFS_WIDGET (cheese_prefs_brightness_scale_new (prefs_dialog->brightness_scale,
+                                                                              prefs_dialog->webcam));
+
+  cheese_prefs_dialog_widgets_add (prefs_dialog->widgets, brightness_widget);
+
   cheese_prefs_dialog_widgets_synchronize (prefs_dialog->widgets);
 }
 
diff --git a/src/cheese-webcam.c b/src/cheese-webcam.c
index 17a6c01..337be90 100644
--- a/src/cheese-webcam.c
+++ b/src/cheese-webcam.c
@@ -955,7 +955,6 @@ cheese_webcam_create_video_display_bin (CheeseWebcam *webcam, GError **error)
     return FALSE;
   }
 
-
   if ((tee = gst_element_factory_make ("tee", "tee")) == NULL)
   {
     cheese_webcam_set_error_element_not_found (error, "tee");
@@ -1718,3 +1717,29 @@ cheese_webcam_get_current_video_format (CheeseWebcam *webcam)
 
   return priv->current_format;
 }
+
+void
+cheese_webcam_get_brightness_range (CheeseWebcam *webcam,
+                                    gdouble *min, gdouble *max, gdouble *def)
+{
+  CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
+  GParamSpec *pspec;
+  
+  *min = 0.0;
+  *max = 0.0;
+  *def = 0.0;
+
+  pspec = g_object_class_find_property (
+    G_OBJECT_GET_CLASS (G_OBJECT (priv->video_balance)), "brightness");
+
+  *min = G_PARAM_SPEC_DOUBLE (pspec)->minimum;
+  *max = G_PARAM_SPEC_DOUBLE (pspec)->maximum;
+  *def = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
+}
+
+void
+cheese_webcam_set_brightness (CheeseWebcam *webcam, gdouble value)
+{
+  CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
+  g_object_set (G_OBJECT (priv->video_balance), "brightness", value, NULL);
+}
diff --git a/src/cheese-webcam.h b/src/cheese-webcam.h
index a996c55..45b5fa1 100644
--- a/src/cheese-webcam.h
+++ b/src/cheese-webcam.h
@@ -119,6 +119,8 @@ gboolean           cheese_webcam_switch_webcam_device (CheeseWebcam *webcam);
 GArray *           cheese_webcam_get_video_formats (CheeseWebcam *webcam);
 void               cheese_webcam_set_video_format (CheeseWebcam      *webcam,
                                                    CheeseVideoFormat *format);
+void               cheese_webcam_get_brightness_range (CheeseWebcam *webcam, gdouble *min, gdouble *max, gdouble *def);
+void               cheese_webcam_set_brightness (CheeseWebcam *webcam, gdouble value);
 G_END_DECLS
 
 #endif /* __CHEESE_WEBCAM_H__ */



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