2
* Copyright © 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
4
* Licensed under the GNU General Public License Version 2
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <cheese-camera.h>
24
#include "cheese-prefs-widget.h"
25
#include "cheese-prefs-balance-scale.h"
37
typedef struct CheesePrefsBalanceScalePrivate
42
gboolean has_been_synchronized; /* Make sure we don't synchronize if client
43
* sets camera on construction. */
44
} CheesePrefsBalanceScalePrivate;
46
#define CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE(o) \
47
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_BALANCE_SCALE, \
48
CheesePrefsBalanceScalePrivate))
50
G_DEFINE_TYPE (CheesePrefsBalanceScale, cheese_prefs_balance_scale, CHEESE_TYPE_PREFS_WIDGET);
53
cheese_prefs_balance_scale_init (CheesePrefsBalanceScale *self)
55
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
57
priv->property_name = NULL;
58
priv->gconf_key = NULL;
59
priv->has_been_synchronized = FALSE;
63
cheese_prefs_balance_scale_finalize (GObject *object)
65
CheesePrefsBalanceScale *self = CHEESE_PREFS_BALANCE_SCALE (object);
66
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
68
g_free (priv->property_name);
69
g_free (priv->gconf_key);
71
G_OBJECT_CLASS (cheese_prefs_balance_scale_parent_class)->finalize (object);
75
cheese_prefs_balance_scale_value_changed (GtkRange *scale, CheesePrefsBalanceScale *self)
77
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
78
gdouble value = gtk_range_get_value (scale);
80
cheese_camera_set_balance_property (priv->camera, priv->property_name, value);
82
g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->gconf_key, value, NULL);
84
cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
88
cheese_prefs_balance_scale_synchronize (CheesePrefsWidget *prefs_widget)
90
CheesePrefsBalanceScale *self = CHEESE_PREFS_BALANCE_SCALE (prefs_widget);
91
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
95
gdouble min, max, def;
99
g_object_get (prefs_widget, "widget", &scale, NULL);
101
/* Disconnect to prevent a whole bunch of changed notifications */
102
g_signal_handlers_disconnect_by_func (scale, cheese_prefs_balance_scale_value_changed, prefs_widget);
104
can_balance = cheese_camera_get_balance_property_range (priv->camera,
105
priv->property_name, &min, &max, &def);
107
adj = GTK_ADJUSTMENT (gtk_adjustment_new (def, min, max, (max - min) / STEPS, 0.0, 0.0));
108
gtk_range_set_adjustment (GTK_RANGE (scale), adj);
110
gtk_scale_add_mark (GTK_SCALE (scale), def, GTK_POS_BOTTOM, NULL);
112
gtk_widget_set_sensitive (scale, can_balance);
116
g_object_get (CHEESE_PREFS_WIDGET (self)->gconf, priv->gconf_key, &stored_value, NULL);
117
gtk_range_set_value (GTK_RANGE (scale), stored_value);
120
g_signal_connect (G_OBJECT (scale), "value-changed",
121
G_CALLBACK (cheese_prefs_balance_scale_value_changed),
126
cheese_prefs_balance_scale_set_property (GObject *object, guint prop_id,
130
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (object);
134
case PROP_PROPERTY_NAME:
135
priv->property_name = g_value_dup_string (value);
138
priv->gconf_key = g_value_dup_string (value);
141
priv->camera = CHEESE_CAMERA (g_value_get_object (value));
142
if (priv->has_been_synchronized)
143
cheese_prefs_balance_scale_synchronize (CHEESE_PREFS_WIDGET (object));
146
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152
cheese_prefs_balance_scale_get_property (GObject *object, guint prop_id,
153
GValue *value, GParamSpec *pspec)
155
CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (object);
157
g_return_if_fail (CHEESE_IS_PREFS_BALANCE_SCALE (object));
161
case PROP_PROPERTY_NAME:
162
g_value_set_string (value, priv->property_name);
165
g_value_set_string (value, priv->gconf_key);
168
g_value_set_object (value, priv->camera);
171
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
177
cheese_prefs_balance_scale_class_init (CheesePrefsBalanceScaleClass *klass)
179
GObjectClass *object_class = G_OBJECT_CLASS (klass);
180
CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
182
g_type_class_add_private (klass, sizeof (CheesePrefsBalanceScalePrivate));
184
object_class->finalize = cheese_prefs_balance_scale_finalize;
185
object_class->set_property = cheese_prefs_balance_scale_set_property;
186
object_class->get_property = cheese_prefs_balance_scale_get_property;
187
parent_class->synchronize = cheese_prefs_balance_scale_synchronize;
189
g_object_class_install_property (object_class,
191
g_param_spec_string ("property_name",
193
"Property this widget will control in the videobalance element",
195
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
197
g_object_class_install_property (object_class,
199
g_param_spec_string ("gconf_key",
201
"GConf key for balance",
203
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
205
g_object_class_install_property (object_class,
207
g_param_spec_object ("camera",
214
CheesePrefsBalanceScale *
215
cheese_prefs_balance_scale_new (GtkWidget *scale,
216
CheeseCamera *camera,
217
const gchar *property,
218
const gchar *gconf_key)
220
CheesePrefsBalanceScale *self;
221
CheesePrefsBalanceScalePrivate *priv;
223
self = g_object_new (CHEESE_TYPE_PREFS_BALANCE_SCALE,
226
"property_name", property,
227
"gconf_key", gconf_key,
230
priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);