[cheese/videobalance: 4/4] Store brightness in gconf
- From: Filippo Argiolas <fargiolas src gnome org>
- To: svn-commits-list gnome org
- Subject: [cheese/videobalance: 4/4] Store brightness in gconf
- Date: Wed, 22 Apr 2009 16:34:08 -0400 (EDT)
commit c8c1f7efeb9d104cc8dafdc8e86589df306d67c2
Author: Filippo Argiolas <filippo argiolas gmail com>
Date: Wed Apr 22 22:24:59 2009 +0200
Store brightness in gconf
Store brightness level in the correspondent gconf setting and restore it
on startup
---
src/cheese-prefs-brightness-scale.c | 42 +++++++++++++++++++++++++++-------
src/cheese-prefs-brightness-scale.h | 3 +-
src/cheese-prefs-dialog.c | 2 +-
src/cheese-window.c | 10 ++++++-
4 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/src/cheese-prefs-brightness-scale.c b/src/cheese-prefs-brightness-scale.c
index ddf2814..09b06a9 100644
--- a/src/cheese-prefs-brightness-scale.c
+++ b/src/cheese-prefs-brightness-scale.c
@@ -26,15 +26,18 @@
#include "cheese-prefs-widget.h"
#include "cheese-prefs-brightness-scale.h"
+#define STEPS 20.0
+
enum
{
PROP_0,
+ PROP_BRIGHTNESS_KEY,
PROP_WEBCAM
};
typedef struct CheesePrefsBrightnessScalePrivate
{
- gdouble brightness;
+ gchar *brightness_key;
CheeseWebcam *webcam;
gboolean has_been_synchronized; /* Make sure we don't synchronize if client
* sets webcam on construction. */
@@ -50,7 +53,7 @@ static void
cheese_prefs_brightness_scale_init (CheesePrefsBrightnessScale *self)
{
CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
-
+ priv->brightness_key = NULL;
priv->has_been_synchronized = FALSE;
}
@@ -59,6 +62,9 @@ cheese_prefs_brightness_scale_finalize (GObject *object)
{
CheesePrefsBrightnessScale *self = CHEESE_PREFS_BRIGHTNESS_SCALE (object);
CheesePrefsBrightnessScalePrivate *priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
+
+ g_free (priv->brightness_key);
+
G_OBJECT_CLASS (cheese_prefs_brightness_scale_parent_class)->finalize (object);
}
@@ -68,12 +74,9 @@ cheese_prefs_brightness_scale_value_changed (GtkRange *scale, CheesePrefsBrightn
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));
}
@@ -86,14 +89,18 @@ cheese_prefs_brightness_scale_synchronize (CheesePrefsWidget *prefs_widget)
GtkWidget *scale;
GtkAdjustment *adj;
gdouble min, max, def;
+ gdouble stored_value;
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);
+ adj = GTK_ADJUSTMENT (gtk_adjustment_new (def, min, max, (max - min)/STEPS, 0.0, 0.0));
gtk_range_set_adjustment (GTK_RANGE (scale), adj);
+
+ g_object_get (CHEESE_PREFS_WIDGET (self)->gconf, priv->brightness_key, &stored_value, NULL);
+
+ gtk_range_set_value (GTK_RANGE (scale), stored_value);
/* Disconnect to prevent a whole bunch of changed notifications */
g_signal_handlers_disconnect_by_func (scale, cheese_prefs_brightness_scale_value_changed, prefs_widget);
@@ -112,6 +119,9 @@ cheese_prefs_brightness_scale_set_property (GObject *object, guint prop_id,
switch (prop_id)
{
+ case PROP_BRIGHTNESS_KEY:
+ priv->brightness_key = g_value_dup_string (value);
+ break;
case PROP_WEBCAM:
priv->webcam = CHEESE_WEBCAM (g_value_get_object (value));
if (priv->has_been_synchronized)
@@ -133,6 +143,9 @@ cheese_prefs_brightness_scale_get_property (GObject *object, guint prop_id,
switch (prop_id)
{
+ case PROP_BRIGHTNESS_KEY:
+ g_value_set_string (value, priv->brightness_key);
+ break;
case PROP_WEBCAM:
g_value_set_object (value, priv->webcam);
break;
@@ -156,6 +169,14 @@ cheese_prefs_brightness_scale_class_init (CheesePrefsBrightnessScaleClass *klass
parent_class->synchronize = cheese_prefs_brightness_scale_synchronize;
g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_KEY,
+ g_param_spec_string ("brightness_key",
+ "",
+ "GConf key for brightness",
+ "",
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class,
PROP_WEBCAM,
g_param_spec_object ("webcam",
"webcam",
@@ -165,7 +186,9 @@ cheese_prefs_brightness_scale_class_init (CheesePrefsBrightnessScaleClass *klass
}
CheesePrefsBrightnessScale *
-cheese_prefs_brightness_scale_new (GtkWidget *scale, CheeseWebcam *webcam)
+cheese_prefs_brightness_scale_new (GtkWidget *scale,
+ CheeseWebcam *webcam,
+ const gchar *brightness_key)
{
CheesePrefsBrightnessScale *self;
CheesePrefsBrightnessScalePrivate *priv;
@@ -173,6 +196,7 @@ cheese_prefs_brightness_scale_new (GtkWidget *scale, CheeseWebcam *webcam)
self = g_object_new (CHEESE_TYPE_PREFS_BRIGHTNESS_SCALE,
"widget", scale,
"webcam", webcam,
+ "brightness_key", brightness_key,
NULL);
priv = CHEESE_PREFS_BRIGHTNESS_SCALE_GET_PRIVATE (self);
diff --git a/src/cheese-prefs-brightness-scale.h b/src/cheese-prefs-brightness-scale.h
index b81dfa8..a5ed5e5 100644
--- a/src/cheese-prefs-brightness-scale.h
+++ b/src/cheese-prefs-brightness-scale.h
@@ -51,7 +51,8 @@ struct _CheesePrefsBrightnessScale
GType cheese_prefs_brightness_scale_get_type (void) G_GNUC_CONST;
CheesePrefsBrightnessScale *cheese_prefs_brightness_scale_new (GtkWidget *scale,
- CheeseWebcam *webcam);
+ CheeseWebcam *webcam,
+ const gchar *brightness_key);
char *cheese_prefs_brightness_scale_get_selected_webcam (CheesePrefsBrightnessScale *webcam);
diff --git a/src/cheese-prefs-dialog.c b/src/cheese-prefs-dialog.c
index cb6dd3d..9b5c6c0 100644
--- a/src/cheese-prefs-dialog.c
+++ b/src/cheese-prefs-dialog.c
@@ -129,7 +129,7 @@ cheese_prefs_dialog_setup_widgets (CheesePrefsDialog *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));
+ prefs_dialog->webcam,"gconf_prop_brightness"));
cheese_prefs_dialog_widgets_add (prefs_dialog->widgets, brightness_widget);
diff --git a/src/cheese-window.c b/src/cheese-window.c
index e931488..0ed7c7a 100644
--- a/src/cheese-window.c
+++ b/src/cheese-window.c
@@ -1852,12 +1852,16 @@ setup_camera (CheeseWindow *cheese_window)
char *webcam_device = NULL;
int x_resolution;
int y_resolution;
+ gdouble brightness;
GtkWidget *message_area;
GError *error;
- g_object_get (cheese_window->gconf, "gconf_prop_x_resolution", &x_resolution,
- "gconf_prop_y_resolution", &y_resolution, "gconf_prop_webcam", &webcam_device, NULL);
+ g_object_get (cheese_window->gconf,
+ "gconf_prop_x_resolution", &x_resolution,
+ "gconf_prop_y_resolution", &y_resolution,
+ "gconf_prop_webcam", &webcam_device,
+ "gconf_prop_brightness", &brightness, NULL);
gdk_threads_enter ();
cheese_window->webcam = cheese_webcam_new (cheese_window->screen,
@@ -1908,6 +1912,8 @@ setup_camera (CheeseWindow *cheese_window)
cheese_webcam_set_effect (cheese_window->webcam,
cheese_effect_chooser_get_selection (CHEESE_EFFECT_CHOOSER (cheese_window->effect_chooser)));
+ cheese_webcam_set_brightness (cheese_window->webcam, brightness);
+
cheese_webcam_play (cheese_window->webcam);
gdk_threads_enter ();
gtk_notebook_set_current_page (GTK_NOTEBOOK (cheese_window->notebook), 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]