2
* Copyright © 2008 James Liggett <jrliggett@cox.net>
3
* Copyright © 2008 Ryan Zeigler <zeiglerr@gmail.com>
4
* Copyright © 2008 daniel g. siegel <dgsiegel@gnome.org>
6
* Licensed under the GNU General Public License Version 2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include <cheese-camera.h>
26
#include "cheese-prefs-widget.h"
27
#include "cheese-prefs-camera-combo.h"
39
PROP_CAMERA_DEVICE_KEY,
43
typedef struct CheesePrefsCameraComboPrivate
45
gchar *camera_device_key;
46
GtkListStore *list_store;
48
gboolean has_been_synchronized; /* Make sure we don't synchronize if client
49
* sets camera on construction. */
50
} CheesePrefsCameraComboPrivate;
52
#define CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE(o) \
53
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_CAMERA_COMBO, \
54
CheesePrefsCameraComboPrivate))
56
G_DEFINE_TYPE (CheesePrefsCameraCombo, cheese_prefs_camera_combo, CHEESE_TYPE_PREFS_WIDGET);
59
cheese_prefs_camera_combo_init (CheesePrefsCameraCombo *self)
61
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
63
priv->has_been_synchronized = FALSE;
65
priv->camera_device_key = NULL;
66
priv->list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
70
cheese_prefs_camera_combo_finalize (GObject *object)
72
CheesePrefsCameraCombo *self = CHEESE_PREFS_CAMERA_COMBO (object);
73
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
75
g_free (priv->camera_device_key);
76
g_object_unref (priv->list_store);
78
G_OBJECT_CLASS (cheese_prefs_camera_combo_parent_class)->finalize (object);
82
cheese_prefs_camera_combo_selection_changed (GtkComboBox *combo_box, CheesePrefsCameraCombo *self)
84
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
86
/* Put it into gconf */
87
char *new_device = cheese_prefs_camera_combo_get_selected_camera (self);
89
g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->camera_device_key, new_device, NULL);
92
cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
96
cheese_prefs_camera_combo_synchronize (CheesePrefsWidget *prefs_widget)
98
CheesePrefsCameraCombo *self = CHEESE_PREFS_CAMERA_COMBO (prefs_widget);
99
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
101
GtkWidget *combo_box;
102
GPtrArray *camera_devices;
104
CheeseCameraDevice *selected_device;
105
char *gconf_device_name;
108
CheeseCameraDevice *device_ptr;
110
GtkTreeIter active_iter;
113
gboolean found_same_device = FALSE;
115
g_object_get (prefs_widget, "widget", &combo_box, NULL);
117
/* Disconnect to prevent a whole bunch of changed notifications */
118
g_signal_handlers_disconnect_by_func (combo_box, cheese_prefs_camera_combo_selection_changed, prefs_widget);
120
g_object_ref (priv->list_store);
122
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
124
camera_devices = cheese_camera_get_camera_devices (priv->camera);
125
num_devices = cheese_camera_get_num_camera_devices (priv->camera);
126
selected_device = cheese_camera_get_selected_device (priv->camera);
128
/* If the selected device is not the same device as the one in gconf, the
129
* selected device isn't available or was set by --hal-device. Set it now.
130
* Not sure if this is desired behavior */
133
const gchar *devpath = cheese_camera_device_get_device_file (selected_device);
134
g_object_get (prefs_widget->gconf, priv->camera_device_key, &gconf_device_name, NULL);
135
if (!gconf_device_name || strcmp (devpath, gconf_device_name) != 0)
137
g_object_set (prefs_widget->gconf, priv->camera_device_key, devpath, NULL);
139
g_free (gconf_device_name);
141
gtk_list_store_clear (priv->list_store);
143
for (i = 0; i < num_devices; i++)
145
device_ptr = g_ptr_array_index (camera_devices, i);
146
const gchar *devpath = cheese_camera_device_get_device_file (device_ptr);
147
product_name = g_strdup_printf ("%s (%s)",
148
cheese_camera_device_get_name (device_ptr),
150
device_name = g_strdup (devpath);
152
gtk_list_store_append (priv->list_store, &iter);
153
gtk_list_store_set (priv->list_store, &iter, PRODUCT_NAME, product_name,
154
DEVICE_NAME, device_name,
156
g_free (product_name);
157
g_free (device_name);
158
if (device_ptr == selected_device)
161
found_same_device = TRUE;
165
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
166
GTK_TREE_MODEL (priv->list_store));
168
g_object_unref (priv->list_store);
170
if (found_same_device)
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 (cheese_prefs_camera_combo_selection_changed),
179
/* Set sensitive or not depending on whether or not there are camera devices
181
gtk_widget_set_sensitive (combo_box, num_devices > 1);
183
g_ptr_array_unref (camera_devices);
187
cheese_prefs_camera_combo_set_property (GObject *object, guint prop_id,
191
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (object);
195
case PROP_CAMERA_DEVICE_KEY:
196
priv->camera_device_key = g_value_dup_string (value);
199
priv->camera = CHEESE_CAMERA (g_value_get_object (value));
200
if (priv->has_been_synchronized)
201
cheese_prefs_camera_combo_synchronize (CHEESE_PREFS_WIDGET (object));
204
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
210
cheese_prefs_camera_combo_get_property (GObject *object, guint prop_id,
211
GValue *value, GParamSpec *pspec)
213
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (object);
215
g_return_if_fail (CHEESE_IS_PREFS_CAMERA_COMBO (object));
219
case PROP_CAMERA_DEVICE_KEY:
220
g_value_set_string (value, priv->camera_device_key);
223
g_value_set_object (value, priv->camera);
226
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
232
cheese_prefs_camera_combo_class_init (CheesePrefsCameraComboClass *klass)
234
GObjectClass *object_class = G_OBJECT_CLASS (klass);
235
CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
237
g_type_class_add_private (klass, sizeof (CheesePrefsCameraComboPrivate));
239
object_class->finalize = cheese_prefs_camera_combo_finalize;
240
object_class->set_property = cheese_prefs_camera_combo_set_property;
241
object_class->get_property = cheese_prefs_camera_combo_get_property;
242
parent_class->synchronize = cheese_prefs_camera_combo_synchronize;
244
g_object_class_install_property (object_class,
245
PROP_CAMERA_DEVICE_KEY,
246
g_param_spec_string ("camera_device_key",
248
"Camera device gconf key",
250
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
252
g_object_class_install_property (object_class,
254
g_param_spec_object ("camera",
261
CheesePrefsCameraCombo *
262
cheese_prefs_camera_combo_new (GtkWidget *combo_box, CheeseCamera *camera,
263
const gchar *camera_device_key)
265
CheesePrefsCameraCombo *self;
266
GtkCellRenderer *renderer;
267
CheesePrefsCameraComboPrivate *priv;
269
self = g_object_new (CHEESE_TYPE_PREFS_CAMERA_COMBO,
272
"camera_device_key", camera_device_key,
275
priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
277
renderer = gtk_cell_renderer_text_new ();
278
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
279
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box), renderer, "text",
281
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
282
GTK_TREE_MODEL (priv->list_store));
288
cheese_prefs_camera_combo_get_selected_camera (CheesePrefsCameraCombo *camera)
290
CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (camera);
292
GtkTreeIter active_iter;
293
GtkWidget *combo_box;
296
g_object_get (camera, "widget", &combo_box, NULL);
298
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &active_iter);
299
gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &active_iter, DEVICE_NAME, &device, -1);