~ubuntu-branches/debian/sid/cheese/sid

« back to all changes in this revision

Viewing changes to src/cheese-prefs-balance-scale.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-07-17 21:04:16 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110717210416-nt5qi659qei7a2yy
Tags: 3.0.1-2
* debian/control.in:
  - Change gir1.2-cheese-3.0 Section to libs
  - Make library packages depend against cheese-common package
  - Make cheese package recommends against hicolor-icon-theme
  - Move gst Dependency to libcheese package
* debian/patches/0002-fix-linking.patch: Add missing library to fix linking
* debian/watch:
  - Switch to .bz2 tarballs.
  - Bump version to 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
3
 
 *
4
 
 * Licensed under the GNU General Public License Version 2
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <string.h>
21
 
#include <glib.h>
22
 
 
23
 
#include <cheese-camera.h>
24
 
#include "cheese-prefs-widget.h"
25
 
#include "cheese-prefs-balance-scale.h"
26
 
 
27
 
#define STEPS 20.0
28
 
 
29
 
enum
30
 
{
31
 
  PROP_0,
32
 
  PROP_PROPERTY_NAME,
33
 
  PROP_GCONF_KEY,
34
 
  PROP_CAMERA
35
 
};
36
 
 
37
 
typedef struct CheesePrefsBalanceScalePrivate
38
 
{
39
 
  CheeseCamera *camera;
40
 
  gchar *property_name;
41
 
  gchar *gconf_key;
42
 
  gboolean has_been_synchronized;  /* Make sure we don't synchronize if client
43
 
                                    * sets camera on construction. */
44
 
} CheesePrefsBalanceScalePrivate;
45
 
 
46
 
#define CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE(o)                     \
47
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_BALANCE_SCALE, \
48
 
                                CheesePrefsBalanceScalePrivate))
49
 
 
50
 
G_DEFINE_TYPE (CheesePrefsBalanceScale, cheese_prefs_balance_scale, CHEESE_TYPE_PREFS_WIDGET);
51
 
 
52
 
static void
53
 
cheese_prefs_balance_scale_init (CheesePrefsBalanceScale *self)
54
 
{
55
 
  CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
56
 
 
57
 
  priv->property_name         = NULL;
58
 
  priv->gconf_key             = NULL;
59
 
  priv->has_been_synchronized = FALSE;
60
 
}
61
 
 
62
 
static void
63
 
cheese_prefs_balance_scale_finalize (GObject *object)
64
 
{
65
 
  CheesePrefsBalanceScale        *self = CHEESE_PREFS_BALANCE_SCALE (object);
66
 
  CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
67
 
 
68
 
  g_free (priv->property_name);
69
 
  g_free (priv->gconf_key);
70
 
 
71
 
  G_OBJECT_CLASS (cheese_prefs_balance_scale_parent_class)->finalize (object);
72
 
}
73
 
 
74
 
static void
75
 
cheese_prefs_balance_scale_value_changed (GtkRange *scale, CheesePrefsBalanceScale *self)
76
 
{
77
 
  CheesePrefsBalanceScalePrivate *priv  = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
78
 
  gdouble                         value = gtk_range_get_value (scale);
79
 
 
80
 
  cheese_camera_set_balance_property (priv->camera, priv->property_name, value);
81
 
 
82
 
  g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->gconf_key, value, NULL);
83
 
 
84
 
  cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
85
 
}
86
 
 
87
 
static void
88
 
cheese_prefs_balance_scale_synchronize (CheesePrefsWidget *prefs_widget)
89
 
{
90
 
  CheesePrefsBalanceScale        *self = CHEESE_PREFS_BALANCE_SCALE (prefs_widget);
91
 
  CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
92
 
 
93
 
  GtkWidget     *scale;
94
 
  GtkAdjustment *adj;
95
 
  gdouble        min, max, def;
96
 
  gdouble        stored_value;
97
 
  gboolean       can_balance;
98
 
 
99
 
  g_object_get (prefs_widget, "widget", &scale, NULL);
100
 
 
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);
103
 
 
104
 
  can_balance = cheese_camera_get_balance_property_range (priv->camera,
105
 
                                                          priv->property_name, &min, &max, &def);
106
 
 
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);
109
 
 
110
 
  gtk_scale_add_mark (GTK_SCALE (scale), def, GTK_POS_BOTTOM, NULL);
111
 
 
112
 
  gtk_widget_set_sensitive (scale, can_balance);
113
 
 
114
 
  if (can_balance)
115
 
  {
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);
118
 
  }
119
 
 
120
 
  g_signal_connect (G_OBJECT (scale), "value-changed",
121
 
                    G_CALLBACK (cheese_prefs_balance_scale_value_changed),
122
 
                    self);
123
 
}
124
 
 
125
 
static void
126
 
cheese_prefs_balance_scale_set_property (GObject *object, guint prop_id,
127
 
                                         const GValue *value,
128
 
                                         GParamSpec *pspec)
129
 
{
130
 
  CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (object);
131
 
 
132
 
  switch (prop_id)
133
 
  {
134
 
    case PROP_PROPERTY_NAME:
135
 
      priv->property_name = g_value_dup_string (value);
136
 
      break;
137
 
    case PROP_GCONF_KEY:
138
 
      priv->gconf_key = g_value_dup_string (value);
139
 
      break;
140
 
    case PROP_CAMERA:
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));
144
 
      break;
145
 
    default:
146
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147
 
      break;
148
 
  }
149
 
}
150
 
 
151
 
static void
152
 
cheese_prefs_balance_scale_get_property (GObject *object, guint prop_id,
153
 
                                         GValue *value, GParamSpec *pspec)
154
 
{
155
 
  CheesePrefsBalanceScalePrivate *priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (object);
156
 
 
157
 
  g_return_if_fail (CHEESE_IS_PREFS_BALANCE_SCALE (object));
158
 
 
159
 
  switch (prop_id)
160
 
  {
161
 
    case PROP_PROPERTY_NAME:
162
 
      g_value_set_string (value, priv->property_name);
163
 
      break;
164
 
    case PROP_GCONF_KEY:
165
 
      g_value_set_string (value, priv->gconf_key);
166
 
      break;
167
 
    case PROP_CAMERA:
168
 
      g_value_set_object (value, priv->camera);
169
 
      break;
170
 
    default:
171
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172
 
      break;
173
 
  }
174
 
}
175
 
 
176
 
static void
177
 
cheese_prefs_balance_scale_class_init (CheesePrefsBalanceScaleClass *klass)
178
 
{
179
 
  GObjectClass           *object_class = G_OBJECT_CLASS (klass);
180
 
  CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
181
 
 
182
 
  g_type_class_add_private (klass, sizeof (CheesePrefsBalanceScalePrivate));
183
 
 
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;
188
 
 
189
 
  g_object_class_install_property (object_class,
190
 
                                   PROP_PROPERTY_NAME,
191
 
                                   g_param_spec_string ("property_name",
192
 
                                                        "",
193
 
                                                        "Property this widget will control in the videobalance element",
194
 
                                                        "",
195
 
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
196
 
 
197
 
  g_object_class_install_property (object_class,
198
 
                                   PROP_GCONF_KEY,
199
 
                                   g_param_spec_string ("gconf_key",
200
 
                                                        "",
201
 
                                                        "GConf key for balance",
202
 
                                                        "",
203
 
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
204
 
 
205
 
  g_object_class_install_property (object_class,
206
 
                                   PROP_CAMERA,
207
 
                                   g_param_spec_object ("camera",
208
 
                                                        "camera",
209
 
                                                        "Camera object",
210
 
                                                        CHEESE_TYPE_CAMERA,
211
 
                                                        G_PARAM_READWRITE));
212
 
}
213
 
 
214
 
CheesePrefsBalanceScale *
215
 
cheese_prefs_balance_scale_new (GtkWidget    *scale,
216
 
                                CheeseCamera *camera,
217
 
                                const gchar  *property,
218
 
                                const gchar  *gconf_key)
219
 
{
220
 
  CheesePrefsBalanceScale        *self;
221
 
  CheesePrefsBalanceScalePrivate *priv;
222
 
 
223
 
  self = g_object_new (CHEESE_TYPE_PREFS_BALANCE_SCALE,
224
 
                       "widget", scale,
225
 
                       "camera", camera,
226
 
                       "property_name", property,
227
 
                       "gconf_key", gconf_key,
228
 
                       NULL);
229
 
 
230
 
  priv = CHEESE_PREFS_BALANCE_SCALE_GET_PRIVATE (self);
231
 
 
232
 
  return self;
233
 
}