2
* Copyright © 2008 James Liggett <jrliggett@cox.net>
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/>.
20
#include "cheese-prefs-resolution-combo.h"
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;
30
CheeseVideoFormat *selected_format;
31
gboolean has_been_synchronized; /* Make sure we don't synchronize if client
32
* sets camera on construction. */
33
} CheesePrefsResolutionComboPrivate;
35
#define CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE(o) \
36
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_RESOLUTION_COMBO, \
37
CheesePrefsResolutionComboPrivate))
43
PROP_X_RESOLUTION_KEY,
44
PROP_Y_RESOLUTION_KEY,
45
PROP_MAX_X_RESOLUTION,
46
PROP_MAX_Y_RESOLUTION,
57
G_DEFINE_TYPE (CheesePrefsResolutionCombo, cheese_prefs_resolution_combo, CHEESE_TYPE_PREFS_WIDGET);
60
cheese_prefs_resolution_combo_init (CheesePrefsResolutionCombo *self)
62
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
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);
70
priv->selected_format = NULL;
71
priv->has_been_synchronized = FALSE;
75
cheese_prefs_resolution_combo_finalize (GObject *object)
77
CheesePrefsResolutionCombo *self = CHEESE_PREFS_RESOLUTION_COMBO (object);
78
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
80
g_free (priv->x_resolution_key);
81
g_free (priv->y_resolution_key);
82
g_object_unref (priv->list_store);
84
G_OBJECT_CLASS (cheese_prefs_resolution_combo_parent_class)->finalize (object);
88
combo_selection_changed (GtkComboBox *combo_box,
89
CheesePrefsResolutionCombo *self)
91
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
94
CheeseVideoFormat *format;
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,
100
g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->x_resolution_key,
101
format->width, priv->y_resolution_key, format->height, NULL);
103
priv->selected_format = format;
105
cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
109
cheese_prefs_resolution_combo_synchronize (CheesePrefsWidget *prefs_widget)
111
CheesePrefsResolutionCombo *self = CHEESE_PREFS_RESOLUTION_COMBO (prefs_widget);
112
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
114
GtkWidget *combo_box;
115
const CheeseVideoFormat *current_format;
118
CheeseVideoFormat *format;
121
GtkTreeIter active_iter;
122
gboolean found_resolution;
124
priv->has_been_synchronized = TRUE;
125
found_resolution = FALSE;
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,
132
g_object_ref (priv->list_store);
133
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
135
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
136
current_format = cheese_camera_get_current_video_format (priv->camera);
138
gtk_list_store_clear (priv->list_store);
139
formats = cheese_camera_get_video_formats (priv->camera);
141
for (l = formats; l != NULL; l = l->next)
144
format_name = g_strdup_printf ("%i x %i", format->width, format->height);
146
if (format->width <= priv->max_x_resolution &&
147
format->height <= priv->max_y_resolution)
149
gtk_list_store_append (priv->list_store, &iter);
150
gtk_list_store_set (priv->list_store, &iter,
151
COL_NAME, format_name,
155
g_free (format_name);
157
if ((format->width == current_format->width) &&
158
(format->height == current_format->height))
161
found_resolution = TRUE;
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);
170
if (found_resolution)
171
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &active_iter);
173
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
175
g_signal_connect (G_OBJECT (combo_box), "changed",
176
G_CALLBACK (combo_selection_changed),
179
gtk_widget_set_sensitive (combo_box, formats != NULL);
180
g_list_free (formats);
185
cheese_prefs_resolution_combo_set_property (GObject *object, guint prop_id,
189
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (object);
191
g_return_if_fail (CHEESE_IS_PREFS_RESOLUTION_COMBO (object));
195
case PROP_X_RESOLUTION_KEY:
196
priv->x_resolution_key = g_value_dup_string (value);
198
case PROP_Y_RESOLUTION_KEY:
199
priv->y_resolution_key = g_value_dup_string (value);
201
case PROP_MAX_X_RESOLUTION:
202
priv->max_x_resolution = g_value_get_uint (value);
204
case PROP_MAX_Y_RESOLUTION:
205
priv->max_y_resolution = g_value_get_uint (value);
208
priv->camera = CHEESE_CAMERA (g_value_get_object (value));
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));
219
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225
cheese_prefs_resolution_combo_get_property (GObject *object, guint prop_id,
226
GValue *value, GParamSpec *pspec)
228
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (object);
230
g_return_if_fail (CHEESE_IS_PREFS_RESOLUTION_COMBO (object));
234
case PROP_X_RESOLUTION_KEY:
235
g_value_set_string (value, priv->x_resolution_key);
237
case PROP_Y_RESOLUTION_KEY:
238
g_value_set_string (value, priv->y_resolution_key);
240
case PROP_MAX_X_RESOLUTION:
241
g_value_set_uint (value, priv->max_x_resolution);
243
case PROP_MAX_Y_RESOLUTION:
244
g_value_set_uint (value, priv->max_y_resolution);
247
g_value_set_object (value, priv->camera);
250
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
256
cheese_prefs_resolution_combo_class_init (CheesePrefsResolutionComboClass *klass)
258
GObjectClass *object_class = G_OBJECT_CLASS (klass);
259
CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
261
g_type_class_add_private (klass, sizeof (CheesePrefsResolutionComboPrivate));
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;
268
g_object_class_install_property (object_class,
269
PROP_X_RESOLUTION_KEY,
270
g_param_spec_string ("x_resolution_key",
272
"GConf key for X resolution",
274
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
276
g_object_class_install_property (object_class,
277
PROP_Y_RESOLUTION_KEY,
278
g_param_spec_string ("y_resolution_key",
280
"GConf key for Y resolution",
282
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
284
g_object_class_install_property (object_class,
285
PROP_MAX_X_RESOLUTION,
286
g_param_spec_uint ("max_x_resolution",
288
"Maximum supported X resolution",
292
G_PARAM_READABLE | G_PARAM_WRITABLE));
294
g_object_class_install_property (object_class,
295
PROP_MAX_Y_RESOLUTION,
296
g_param_spec_uint ("max_y_resolution",
298
"Maximum supported Y resolution",
302
G_PARAM_READABLE | G_PARAM_WRITABLE));
304
g_object_class_install_property (object_class,
306
g_param_spec_object ("camera",
310
G_PARAM_READABLE | G_PARAM_WRITABLE));
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)
320
CheesePrefsResolutionCombo *self;
321
GtkCellRenderer *renderer;
322
CheesePrefsResolutionComboPrivate *priv;
324
self = g_object_new (CHEESE_TYPE_PREFS_RESOLUTION_COMBO,
327
"x_resolution_key", x_resolution_key,
328
"y_resolution_key", y_resolution_key,
331
if (max_x_resolution > 0 &&
332
max_y_resolution > 0)
335
"max_x_resolution", max_x_resolution,
336
"max_y_resolution", max_y_resolution,
340
priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (self);
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",
346
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
347
GTK_TREE_MODEL (priv->list_store));
353
cheese_prefs_resolution_combo_get_selected_format (CheesePrefsResolutionCombo *resolution_combo)
355
CheesePrefsResolutionComboPrivate *priv = CHEESE_PREFS_RESOLUTION_COMBO_GET_PRIVATE (resolution_combo);
357
return priv->selected_format;