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

« back to all changes in this revision

Viewing changes to src/cheese-prefs-resolution-combo.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 © 2008 James Liggett <jrliggett@cox.net>
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 "cheese-prefs-resolution-combo.h"
21
 
 
22
 
typedef struct
23
 
{
24
 
  gchar *x_resolution_key;
25
 
  gchar *y_resolution_key;
26
 
  unsigned int max_x_resolution;
27
 
  unsigned int max_y_resolution;
28
 
  GtkListStore *list_store;
29
 
  CheeseCamera *camera;
30
 
  CheeseVideoFormat *selected_format;
31
 
  gboolean has_been_synchronized;  /* Make sure we don't synchronize if client
32
 
                                    * sets camera on construction. */
33
 
} CheesePrefsResolutionComboPrivate;
34
 
 
35
 
#define CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE(o)                     \
36
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_RESOLUTION_COMBO, \
37
 
                                CheesePrefsResolutionComboPrivate))
38
 
 
39
 
enum
40
 
{
41
 
  PROP_0,
42
 
 
43
 
  PROP_X_RESOLUTION_KEY,
44
 
  PROP_Y_RESOLUTION_KEY,
45
 
  PROP_MAX_X_RESOLUTION,
46
 
  PROP_MAX_Y_RESOLUTION,
47
 
  PROP_CAMERA
48
 
};
49
 
 
50
 
enum
51
 
{
52
 
  COL_NAME,
53
 
  COL_FORMAT,
54
 
  NUM_COLS
55
 
};
56
 
 
57
 
G_DEFINE_TYPE (CheesePrefsResolutionCombo, cheese_prefs_resolution_combo, CHEESE_TYPE_PREFS_WIDGET);
58
 
 
59
 
static void
60
 
cheese_prefs_resolution_combo_init (CheesePrefsResolutionCombo *self)
61
 
{
62
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
63
 
 
64
 
  priv->x_resolution_key      = NULL;
65
 
  priv->y_resolution_key      = NULL;
66
 
  priv->max_x_resolution      = G_MAXUINT;
67
 
  priv->max_y_resolution      = G_MAXUINT;
68
 
  priv->list_store            = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
69
 
  priv->camera                = NULL;
70
 
  priv->selected_format       = NULL;
71
 
  priv->has_been_synchronized = FALSE;
72
 
}
73
 
 
74
 
static void
75
 
cheese_prefs_resolution_combo_finalize (GObject *object)
76
 
{
77
 
  CheesePrefsResolutionCombo        *self = CHEESE_PREFS_RESOLUTION_COMBO (object);
78
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
79
 
 
80
 
  g_free (priv->x_resolution_key);
81
 
  g_free (priv->y_resolution_key);
82
 
  g_object_unref (priv->list_store);
83
 
 
84
 
  G_OBJECT_CLASS (cheese_prefs_resolution_combo_parent_class)->finalize (object);
85
 
}
86
 
 
87
 
static void
88
 
combo_selection_changed (GtkComboBox                *combo_box,
89
 
                         CheesePrefsResolutionCombo *self)
90
 
{
91
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
92
 
 
93
 
  GtkTreeIter        iter;
94
 
  CheeseVideoFormat *format;
95
 
 
96
 
  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter);
97
 
  gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter, COL_FORMAT,
98
 
                      &format, -1);
99
 
 
100
 
  g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->x_resolution_key,
101
 
                format->width, priv->y_resolution_key, format->height, NULL);
102
 
 
103
 
  priv->selected_format = format;
104
 
 
105
 
  cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
106
 
}
107
 
 
108
 
static void
109
 
cheese_prefs_resolution_combo_synchronize (CheesePrefsWidget *prefs_widget)
110
 
{
111
 
  CheesePrefsResolutionCombo        *self = CHEESE_PREFS_RESOLUTION_COMBO (prefs_widget);
112
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
113
 
 
114
 
  GtkWidget               *combo_box;
115
 
  const CheeseVideoFormat *current_format;
116
 
  GList                   *formats;
117
 
  GList                   *l;
118
 
  CheeseVideoFormat       *format;
119
 
  gchar                   *format_name;
120
 
  GtkTreeIter              iter;
121
 
  GtkTreeIter              active_iter;
122
 
  gboolean                 found_resolution;
123
 
 
124
 
  priv->has_been_synchronized = TRUE;
125
 
  found_resolution            = FALSE;
126
 
 
127
 
  /* Don't generate spurious changed events when we set the active resolution */
128
 
  g_object_get (prefs_widget, "widget", &combo_box, NULL);
129
 
  g_signal_handlers_disconnect_by_func (combo_box, combo_selection_changed,
130
 
                                        prefs_widget);
131
 
 
132
 
  g_object_ref (priv->list_store);
133
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
134
 
 
135
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
136
 
  current_format = cheese_camera_get_current_video_format (priv->camera);
137
 
 
138
 
  gtk_list_store_clear (priv->list_store);
139
 
  formats = cheese_camera_get_video_formats (priv->camera);
140
 
 
141
 
  for (l = formats; l != NULL; l = l->next)
142
 
  {
143
 
    format      = l->data;
144
 
    format_name = g_strdup_printf ("%i x %i", format->width, format->height);
145
 
 
146
 
    if (format->width <= priv->max_x_resolution &&
147
 
        format->height <= priv->max_y_resolution)
148
 
    {
149
 
      gtk_list_store_append (priv->list_store, &iter);
150
 
      gtk_list_store_set (priv->list_store, &iter,
151
 
                          COL_NAME, format_name,
152
 
                          COL_FORMAT, format,
153
 
                          -1);
154
 
 
155
 
      g_free (format_name);
156
 
 
157
 
      if ((format->width == current_format->width) &&
158
 
          (format->height == current_format->height))
159
 
      {
160
 
        active_iter      = iter;
161
 
        found_resolution = TRUE;
162
 
      }
163
 
    }
164
 
  }
165
 
 
166
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
167
 
                           GTK_TREE_MODEL (priv->list_store));
168
 
  g_object_unref (priv->list_store);
169
 
 
170
 
  if (found_resolution)
171
 
    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &active_iter);
172
 
  else
173
 
    gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
174
 
 
175
 
  g_signal_connect (G_OBJECT (combo_box), "changed",
176
 
                    G_CALLBACK (combo_selection_changed),
177
 
                    self);
178
 
 
179
 
  gtk_widget_set_sensitive (combo_box, formats != NULL);
180
 
  g_list_free (formats);
181
 
  g_list_free (l);
182
 
}
183
 
 
184
 
static void
185
 
cheese_prefs_resolution_combo_set_property (GObject *object, guint prop_id,
186
 
                                            const GValue *value,
187
 
                                            GParamSpec *pspec)
188
 
{
189
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (object);
190
 
 
191
 
  g_return_if_fail (CHEESE_IS_PREFS_RESOLUTION_COMBO (object));
192
 
 
193
 
  switch (prop_id)
194
 
  {
195
 
    case PROP_X_RESOLUTION_KEY:
196
 
      priv->x_resolution_key = g_value_dup_string (value);
197
 
      break;
198
 
    case PROP_Y_RESOLUTION_KEY:
199
 
      priv->y_resolution_key = g_value_dup_string (value);
200
 
      break;
201
 
    case PROP_MAX_X_RESOLUTION:
202
 
      priv->max_x_resolution = g_value_get_uint (value);
203
 
      break;
204
 
    case PROP_MAX_Y_RESOLUTION:
205
 
      priv->max_y_resolution = g_value_get_uint (value);
206
 
      break;
207
 
    case PROP_CAMERA:
208
 
      priv->camera = CHEESE_CAMERA (g_value_get_object (value));
209
 
 
210
 
      /* If the camera changes the resolutions change too. But only change the
211
 
       * data if we've been synchronized once already. If this property is set
212
 
       * on construction, we would synchronize twice--once when the property is
213
 
       * set, and again when the dialog syncs when it's created. */
214
 
      if (priv->has_been_synchronized)
215
 
        cheese_prefs_resolution_combo_synchronize (CHEESE_PREFS_WIDGET (object));
216
 
 
217
 
      break;
218
 
    default:
219
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220
 
      break;
221
 
  }
222
 
}
223
 
 
224
 
static void
225
 
cheese_prefs_resolution_combo_get_property (GObject *object, guint prop_id,
226
 
                                            GValue *value, GParamSpec *pspec)
227
 
{
228
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (object);
229
 
 
230
 
  g_return_if_fail (CHEESE_IS_PREFS_RESOLUTION_COMBO (object));
231
 
 
232
 
  switch (prop_id)
233
 
  {
234
 
    case PROP_X_RESOLUTION_KEY:
235
 
      g_value_set_string (value, priv->x_resolution_key);
236
 
      break;
237
 
    case PROP_Y_RESOLUTION_KEY:
238
 
      g_value_set_string (value, priv->y_resolution_key);
239
 
      break;
240
 
    case PROP_MAX_X_RESOLUTION:
241
 
      g_value_set_uint (value, priv->max_x_resolution);
242
 
      break;
243
 
    case PROP_MAX_Y_RESOLUTION:
244
 
      g_value_set_uint (value, priv->max_y_resolution);
245
 
      break;
246
 
    case PROP_CAMERA:
247
 
      g_value_set_object (value, priv->camera);
248
 
      break;
249
 
    default:
250
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251
 
      break;
252
 
  }
253
 
}
254
 
 
255
 
static void
256
 
cheese_prefs_resolution_combo_class_init (CheesePrefsResolutionComboClass *klass)
257
 
{
258
 
  GObjectClass           *object_class = G_OBJECT_CLASS (klass);
259
 
  CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
260
 
 
261
 
  g_type_class_add_private (klass, sizeof (CheesePrefsResolutionComboPrivate));
262
 
 
263
 
  object_class->finalize     = cheese_prefs_resolution_combo_finalize;
264
 
  object_class->set_property = cheese_prefs_resolution_combo_set_property;
265
 
  object_class->get_property = cheese_prefs_resolution_combo_get_property;
266
 
  parent_class->synchronize  = cheese_prefs_resolution_combo_synchronize;
267
 
 
268
 
  g_object_class_install_property (object_class,
269
 
                                   PROP_X_RESOLUTION_KEY,
270
 
                                   g_param_spec_string ("x_resolution_key",
271
 
                                                        "",
272
 
                                                        "GConf key for X resolution",
273
 
                                                        "",
274
 
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
275
 
 
276
 
  g_object_class_install_property (object_class,
277
 
                                   PROP_Y_RESOLUTION_KEY,
278
 
                                   g_param_spec_string ("y_resolution_key",
279
 
                                                        "",
280
 
                                                        "GConf key for Y resolution",
281
 
                                                        "",
282
 
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
283
 
 
284
 
  g_object_class_install_property (object_class,
285
 
                                   PROP_MAX_X_RESOLUTION,
286
 
                                   g_param_spec_uint ("max_x_resolution",
287
 
                                                      "",
288
 
                                                      "Maximum supported X resolution",
289
 
                                                      0,
290
 
                                                      G_MAXUINT,
291
 
                                                      G_MAXUINT,
292
 
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
293
 
 
294
 
  g_object_class_install_property (object_class,
295
 
                                   PROP_MAX_Y_RESOLUTION,
296
 
                                   g_param_spec_uint ("max_y_resolution",
297
 
                                                      "",
298
 
                                                      "Maximum supported Y resolution",
299
 
                                                      0,
300
 
                                                      G_MAXUINT,
301
 
                                                      G_MAXUINT,
302
 
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
303
 
 
304
 
  g_object_class_install_property (object_class,
305
 
                                   PROP_CAMERA,
306
 
                                   g_param_spec_object ("camera",
307
 
                                                        "",
308
 
                                                        "Camera object",
309
 
                                                        CHEESE_TYPE_CAMERA,
310
 
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
311
 
}
312
 
 
313
 
CheesePrefsResolutionCombo *
314
 
cheese_prefs_resolution_combo_new (GtkWidget *combo_box, CheeseCamera *camera,
315
 
                                   const gchar *x_resolution_key,
316
 
                                   const gchar *y_resolution_key,
317
 
                                   unsigned int max_x_resolution,
318
 
                                   unsigned int max_y_resolution)
319
 
{
320
 
  CheesePrefsResolutionCombo        *self;
321
 
  GtkCellRenderer                   *renderer;
322
 
  CheesePrefsResolutionComboPrivate *priv;
323
 
 
324
 
  self = g_object_new (CHEESE_TYPE_PREFS_RESOLUTION_COMBO,
325
 
                       "widget", combo_box,
326
 
                       "camera", camera,
327
 
                       "x_resolution_key", x_resolution_key,
328
 
                       "y_resolution_key", y_resolution_key,
329
 
                       NULL);
330
 
 
331
 
  if (max_x_resolution > 0 &&
332
 
      max_y_resolution > 0)
333
 
  {
334
 
    g_object_set (self,
335
 
                  "max_x_resolution", max_x_resolution,
336
 
                  "max_y_resolution", max_y_resolution,
337
 
                  NULL);
338
 
  }
339
 
 
340
 
  priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
341
 
 
342
 
  renderer = gtk_cell_renderer_text_new ();
343
 
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
344
 
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box), renderer, "text",
345
 
                                 COL_NAME);
346
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
347
 
                           GTK_TREE_MODEL (priv->list_store));
348
 
 
349
 
  return self;
350
 
}
351
 
 
352
 
CheeseVideoFormat *
353
 
cheese_prefs_resolution_combo_get_selected_format (CheesePrefsResolutionCombo *resolution_combo)
354
 
{
355
 
  CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (resolution_combo);
356
 
 
357
 
  return priv->selected_format;
358
 
}