~ubuntu-branches/ubuntu/precise/cheese/precise-proposed

« back to all changes in this revision

Viewing changes to src/cheese-prefs-camera-combo.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher, Jeremy Bicha, Robert Ancell
  • Date: 2011-06-10 11:45:37 UTC
  • mfrom: (1.2.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20110610114537-p9e4zl8m0ehf2b5a
Tags: 3.0.0-0ubuntu1
* Upload to oneiric

[ Jeremy Bicha ]
* Depend on gnome-video-effects since clicking Effects when it is
  not installed results in a segmentation fault.

[ Robert Ancell]
* New upstream version
* debian/control:
  - Use standards version 3.9.1
  - Add build-depends on dh-autoreconf, valac, libclutter-1.0-dev,
    libclutter-gtk-1.0-dev, libclutter-gst-dev, libmx-dev,
    gnome-video-effects-dev, libgee-dev, gnome-common, gobject-introspection, 
    libgirepository1.0-dev, gir1.2-freedesktop, gir1.2-glib-2.0, 
    gir1.2-gstreamer-0.10, gir1.2-clutter-1.0, gir1.2-gdkpixbuf-2.0
  - Drop build-depends on libgconf2-dev, libdbus-1-dev, libdbus-glib-1-dev,
  - Bump build-depends on libglib2.0-dev, libgtk-3-dev,
    libgnome-desktop-3-dev, libgstreamer0.10-dev,
    libgstreamer-plugins-base0.10-dev, libcairo2-dev, libpango1.0-dev,
    librsvg2-dev, libcanberra-gtk3-dev
  - Add new gir1.2-cheese-3.0 package
  - libcheese-gtk18 -> libcheese-gtk19
* debian/cheese.install:
* debian/cheese-common.install:
* debian/libcheese-gtk-dev.install
  - Update for new/changed files
* debian/gir1.2-cheese-3.0.install:
  - Install typelib
* debian/patches/fix-linking.patch:
  - Fix linking issues
* debian/patches/no-gnu-gettext.patch:
  - Don't use both AM_GNU_GETTEXT and IT_PROG_INTLTOOL

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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>
5
 
 *
6
 
 * Licensed under the GNU General Public License Version 2
7
 
 *
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.
12
 
 *
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.
17
 
 *
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/>.
20
 
 */
21
 
 
22
 
#include <string.h>
23
 
#include <glib.h>
24
 
 
25
 
#include <cheese-camera.h>
26
 
#include "cheese-prefs-widget.h"
27
 
#include "cheese-prefs-camera-combo.h"
28
 
 
29
 
enum
30
 
{
31
 
  PRODUCT_NAME,
32
 
  DEVICE_NAME,
33
 
  NUM_COLS
34
 
};
35
 
 
36
 
enum
37
 
{
38
 
  PROP_0,
39
 
  PROP_CAMERA_DEVICE_KEY,
40
 
  PROP_CAMERA
41
 
};
42
 
 
43
 
typedef struct CheesePrefsCameraComboPrivate
44
 
{
45
 
  gchar *camera_device_key;
46
 
  GtkListStore *list_store;
47
 
  CheeseCamera *camera;
48
 
  gboolean has_been_synchronized;  /* Make sure we don't synchronize if client
49
 
                                    * sets camera on construction. */
50
 
} CheesePrefsCameraComboPrivate;
51
 
 
52
 
#define CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE(o)                     \
53
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_PREFS_CAMERA_COMBO, \
54
 
                                CheesePrefsCameraComboPrivate))
55
 
 
56
 
G_DEFINE_TYPE (CheesePrefsCameraCombo, cheese_prefs_camera_combo, CHEESE_TYPE_PREFS_WIDGET);
57
 
 
58
 
static void
59
 
cheese_prefs_camera_combo_init (CheesePrefsCameraCombo *self)
60
 
{
61
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
62
 
 
63
 
  priv->has_been_synchronized = FALSE;
64
 
  priv->camera                = NULL;
65
 
  priv->camera_device_key     = NULL;
66
 
  priv->list_store            = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
67
 
}
68
 
 
69
 
static void
70
 
cheese_prefs_camera_combo_finalize (GObject *object)
71
 
{
72
 
  CheesePrefsCameraCombo        *self = CHEESE_PREFS_CAMERA_COMBO (object);
73
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
74
 
 
75
 
  g_free (priv->camera_device_key);
76
 
  g_object_unref (priv->list_store);
77
 
 
78
 
  G_OBJECT_CLASS (cheese_prefs_camera_combo_parent_class)->finalize (object);
79
 
}
80
 
 
81
 
static void
82
 
cheese_prefs_camera_combo_selection_changed (GtkComboBox *combo_box, CheesePrefsCameraCombo *self)
83
 
{
84
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
85
 
 
86
 
  /* Put it into gconf */
87
 
  char *new_device = cheese_prefs_camera_combo_get_selected_camera (self);
88
 
 
89
 
  g_object_set (CHEESE_PREFS_WIDGET (self)->gconf, priv->camera_device_key, new_device, NULL);
90
 
  g_free (new_device);
91
 
 
92
 
  cheese_prefs_widget_notify_changed (CHEESE_PREFS_WIDGET (self));
93
 
}
94
 
 
95
 
static void
96
 
cheese_prefs_camera_combo_synchronize (CheesePrefsWidget *prefs_widget)
97
 
{
98
 
  CheesePrefsCameraCombo        *self = CHEESE_PREFS_CAMERA_COMBO (prefs_widget);
99
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
100
 
 
101
 
  GtkWidget          *combo_box;
102
 
  GPtrArray          *camera_devices;
103
 
  int                 num_devices;
104
 
  CheeseCameraDevice *selected_device;
105
 
  char               *gconf_device_name;
106
 
  char               *product_name;
107
 
  char               *device_name;
108
 
  CheeseCameraDevice *device_ptr;
109
 
  GtkTreeIter         iter;
110
 
  GtkTreeIter         active_iter;
111
 
  int                 i;
112
 
 
113
 
  gboolean found_same_device = FALSE;
114
 
 
115
 
  g_object_get (prefs_widget, "widget", &combo_box, NULL);
116
 
 
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);
119
 
 
120
 
  g_object_ref (priv->list_store);
121
 
 
122
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), NULL);
123
 
 
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);
127
 
 
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 */
131
 
  if (num_devices > 0)
132
 
  {
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)
136
 
    {
137
 
      g_object_set (prefs_widget->gconf, priv->camera_device_key, devpath, NULL);
138
 
    }
139
 
    g_free (gconf_device_name);
140
 
  }
141
 
  gtk_list_store_clear (priv->list_store);
142
 
 
143
 
  for (i = 0; i < num_devices; i++)
144
 
  {
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),
149
 
                                    devpath);
150
 
    device_name = g_strdup (devpath);
151
 
 
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,
155
 
                        -1);
156
 
    g_free (product_name);
157
 
    g_free (device_name);
158
 
    if (device_ptr == selected_device)
159
 
    {
160
 
      active_iter       = iter;
161
 
      found_same_device = TRUE;
162
 
    }
163
 
  }
164
 
 
165
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
166
 
                           GTK_TREE_MODEL (priv->list_store));
167
 
 
168
 
  g_object_unref (priv->list_store);
169
 
 
170
 
  if (found_same_device)
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 (cheese_prefs_camera_combo_selection_changed),
177
 
                    self);
178
 
 
179
 
  /* Set sensitive or not depending on whether or not there are camera devices
180
 
   * available */
181
 
  gtk_widget_set_sensitive (combo_box, num_devices > 1);
182
 
 
183
 
  g_ptr_array_unref (camera_devices);
184
 
}
185
 
 
186
 
static void
187
 
cheese_prefs_camera_combo_set_property (GObject *object, guint prop_id,
188
 
                                        const GValue *value,
189
 
                                        GParamSpec *pspec)
190
 
{
191
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (object);
192
 
 
193
 
  switch (prop_id)
194
 
  {
195
 
    case PROP_CAMERA_DEVICE_KEY:
196
 
      priv->camera_device_key = g_value_dup_string (value);
197
 
      break;
198
 
    case PROP_CAMERA:
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));
202
 
      break;
203
 
    default:
204
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205
 
      break;
206
 
  }
207
 
}
208
 
 
209
 
static void
210
 
cheese_prefs_camera_combo_get_property (GObject *object, guint prop_id,
211
 
                                        GValue *value, GParamSpec *pspec)
212
 
{
213
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (object);
214
 
 
215
 
  g_return_if_fail (CHEESE_IS_PREFS_CAMERA_COMBO (object));
216
 
 
217
 
  switch (prop_id)
218
 
  {
219
 
    case PROP_CAMERA_DEVICE_KEY:
220
 
      g_value_set_string (value, priv->camera_device_key);
221
 
      break;
222
 
    case PROP_CAMERA:
223
 
      g_value_set_object (value, priv->camera);
224
 
      break;
225
 
    default:
226
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
227
 
      break;
228
 
  }
229
 
}
230
 
 
231
 
static void
232
 
cheese_prefs_camera_combo_class_init (CheesePrefsCameraComboClass *klass)
233
 
{
234
 
  GObjectClass           *object_class = G_OBJECT_CLASS (klass);
235
 
  CheesePrefsWidgetClass *parent_class = CHEESE_PREFS_WIDGET_CLASS (klass);
236
 
 
237
 
  g_type_class_add_private (klass, sizeof (CheesePrefsCameraComboPrivate));
238
 
 
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;
243
 
 
244
 
  g_object_class_install_property (object_class,
245
 
                                   PROP_CAMERA_DEVICE_KEY,
246
 
                                   g_param_spec_string ("camera_device_key",
247
 
                                                        "",
248
 
                                                        "Camera device gconf key",
249
 
                                                        "",
250
 
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
251
 
 
252
 
  g_object_class_install_property (object_class,
253
 
                                   PROP_CAMERA,
254
 
                                   g_param_spec_object ("camera",
255
 
                                                        "",
256
 
                                                        "Camera object",
257
 
                                                        CHEESE_TYPE_CAMERA,
258
 
                                                        G_PARAM_READWRITE));
259
 
}
260
 
 
261
 
CheesePrefsCameraCombo *
262
 
cheese_prefs_camera_combo_new (GtkWidget *combo_box, CheeseCamera *camera,
263
 
                               const gchar *camera_device_key)
264
 
{
265
 
  CheesePrefsCameraCombo        *self;
266
 
  GtkCellRenderer               *renderer;
267
 
  CheesePrefsCameraComboPrivate *priv;
268
 
 
269
 
  self = g_object_new (CHEESE_TYPE_PREFS_CAMERA_COMBO,
270
 
                       "widget", combo_box,
271
 
                       "camera", camera,
272
 
                       "camera_device_key", camera_device_key,
273
 
                       NULL);
274
 
 
275
 
  priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (self);
276
 
 
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",
280
 
                                 PRODUCT_NAME);
281
 
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
282
 
                           GTK_TREE_MODEL (priv->list_store));
283
 
 
284
 
  return self;
285
 
}
286
 
 
287
 
char *
288
 
cheese_prefs_camera_combo_get_selected_camera (CheesePrefsCameraCombo *camera)
289
 
{
290
 
  CheesePrefsCameraComboPrivate *priv = CHEESE_PREFS_CAMERA_COMBO_GET_PRIVATE (camera);
291
 
 
292
 
  GtkTreeIter active_iter;
293
 
  GtkWidget  *combo_box;
294
 
  char       *device;
295
 
 
296
 
  g_object_get (camera, "widget", &combo_box, NULL);
297
 
 
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);
300
 
 
301
 
  return device;
302
 
}