~ubuntu-branches/debian/jessie/cheese/jessie

« back to all changes in this revision

Viewing changes to libcheese/cheese-avatar-chooser.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2014-04-02 21:39:33 UTC
  • mfrom: (1.5.1) (15.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20140402213933-r0w3gna0pv7q7085
Tags: 3.12.0-1
* New upstream release.
* Revert changes done in 3.10.1-3
  - i.e. lower gnome-desktop build-dependency again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "cheese-widget-private.h"
27
27
#include "cheese-flash.h"
28
28
#include "cheese-avatar-chooser.h"
 
29
#include "cheese-avatar-widget.h"
29
30
#include "um-crop-area.h"
30
31
 
31
32
/**
58
59
 
59
60
struct _CheeseAvatarChooserPrivate
60
61
{
61
 
  GtkWidget *notebook;
62
 
  GtkWidget *camera;
63
 
  GtkWidget *image;
64
 
  GtkWidget *take_button;
65
 
  GtkWidget *take_again_button;
66
 
  CheeseFlash *flash;
67
 
  gulong photo_taken_id;
 
62
  GtkWidget *widget;
68
63
};
69
64
 
70
65
static GParamSpec *properties[PROP_LAST];
71
66
 
72
 
#define CHEESE_AVATAR_CHOOSER_GET_PRIVATE(o)                     \
73
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_AVATAR_CHOOSER, \
74
 
                                CheeseAvatarChooserPrivate))
75
 
 
76
 
G_DEFINE_TYPE (CheeseAvatarChooser, cheese_avatar_chooser, GTK_TYPE_DIALOG);
77
 
 
78
 
/*
79
 
 * cheese_widget_photo_taken_cb:
80
 
 * @camera: a #CheeseCamera
81
 
 * @pixbuf: the #GdkPixbuf of the image that was just taken
82
 
 * @choose: a #CheeseAvatarChooser
83
 
 *
84
 
 * Show the image that was just taken from the camera (as @pixbuf) in the
85
 
 * cropping tool.
86
 
 */
87
 
static void
88
 
cheese_widget_photo_taken_cb (CheeseCamera        *camera,
89
 
                              GdkPixbuf           *pixbuf,
90
 
                              CheeseAvatarChooser *chooser)
91
 
{
92
 
  CheeseAvatarChooserPrivate *priv = chooser->priv;
93
 
  GtkAllocation               allocation;
94
 
 
95
 
  gdk_threads_enter ();
96
 
 
97
 
  gtk_widget_get_allocation (priv->camera, &allocation);
98
 
  gtk_widget_set_size_request (priv->image, allocation.width, allocation.height);
99
 
 
100
 
  um_crop_area_set_picture (UM_CROP_AREA (priv->image), pixbuf);
101
 
  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), IMAGE_PAGE);
102
 
  gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
103
 
                                     GTK_RESPONSE_ACCEPT,
104
 
                                     TRUE);
105
 
  gtk_widget_set_sensitive (priv->take_button, TRUE);
106
 
 
107
 
  gdk_threads_leave ();
108
 
 
109
 
  g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
110
 
}
111
 
 
112
 
/*
113
 
 * take_button_clicked_cb:
114
 
 * @button: the #GtkButton that was clicked
115
 
 * @chooser: the #CheeseAvatarChooser
116
 
 *
117
 
 * Take a photo with the #CheeseCamera of @chooser. When the photo has been
118
 
 * taken, call cheese_widget_photo_taken_cb().
119
 
 */
120
 
static void
121
 
take_button_clicked_cb (GtkButton           *button,
122
 
                        CheeseAvatarChooser *chooser)
123
 
{
124
 
  CheeseAvatarChooserPrivate *priv = chooser->priv;
125
 
  GObject                    *camera;
126
 
 
127
 
  camera = cheese_widget_get_camera (CHEESE_WIDGET (priv->camera));
128
 
  if (priv->photo_taken_id == 0)
129
 
  {
130
 
    gtk_widget_set_sensitive (priv->take_button, FALSE);
131
 
    priv->photo_taken_id = g_signal_connect (G_OBJECT (camera), "photo-taken",
132
 
                                             G_CALLBACK (cheese_widget_photo_taken_cb), chooser);
133
 
  }
134
 
  if (cheese_camera_take_photo_pixbuf (CHEESE_CAMERA (camera)))
135
 
  {
136
 
    cheese_flash_fire (CHEESE_FLASH (priv->flash));
137
 
    ca_gtk_play_for_widget (GTK_WIDGET (chooser), 0,
138
 
                            CA_PROP_EVENT_ID, "camera-shutter",
139
 
                            CA_PROP_MEDIA_ROLE, "event",
140
 
                            CA_PROP_EVENT_DESCRIPTION, _("Shutter sound"),
141
 
                            NULL);
142
 
  }
143
 
  else
144
 
  {
145
 
    g_assert_not_reached ();
146
 
  }
147
 
}
148
 
 
149
 
/*
150
 
 * take_again_button_clicked_cb:
151
 
 * @button: the #GtkButton that was clicked
152
 
 * @chooser: the #CheeseAvatarChooser
153
 
 *
154
 
 * Switch the @chooser back to the camera view, ready to take another photo.
155
 
 */
156
 
static void
157
 
take_again_button_clicked_cb (GtkButton           *button,
158
 
                              CheeseAvatarChooser *chooser)
159
 
{
160
 
  CheeseAvatarChooserPrivate *priv = chooser->priv;
161
 
 
162
 
  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), WIDGET_PAGE);
163
 
  gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
164
 
                                     GTK_RESPONSE_ACCEPT,
165
 
                                     FALSE);
166
 
 
167
 
  um_crop_area_set_picture (UM_CROP_AREA (priv->image), NULL);
168
 
 
169
 
  g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
170
 
}
171
 
 
172
 
/* state_change_cb:
173
 
 * @object: the #CheeseWidget on which the state changed
174
 
 * @param_spec: the (unused) parameter specification
175
 
 * @chooser: a #CheeseAvatarChooser
176
 
 *
177
 
 * Handle state changes on the #CheeseWidget, and update the UI appropriately.
178
 
 */
179
 
static void
180
 
state_change_cb (GObject             *object,
181
 
                 GParamSpec          *param_spec,
182
 
                 CheeseAvatarChooser *chooser)
183
 
{
184
 
  CheeseAvatarChooserPrivate *priv = chooser->priv;
185
 
  CheeseWidgetState           state;
186
 
 
187
 
  g_object_get (object, "state", &state, NULL);
188
 
 
189
 
  switch (state)
190
 
  {
191
 
    case CHEESE_WIDGET_STATE_READY:
192
 
      gtk_widget_set_sensitive (priv->take_button, TRUE);
193
 
      gtk_widget_set_sensitive (priv->take_again_button, TRUE);
194
 
      break;
195
 
    case CHEESE_WIDGET_STATE_ERROR:
196
 
      gtk_widget_set_sensitive (priv->take_button, FALSE);
197
 
      gtk_widget_set_sensitive (priv->take_again_button, FALSE);
198
 
      break;
199
 
    case CHEESE_WIDGET_STATE_NONE:
200
 
      break;
201
 
    default:
202
 
      g_assert_not_reached ();
203
 
  }
204
 
}
205
 
 
206
 
/*
207
 
 * create_page:
208
 
 * @child: the #CheeseWidget to pack into the container
209
 
 * @button: the #GtkButton for taking a photo
210
 
 * @extra: an extra #GtkWidget to pack alongside the @button, or NULL
211
 
 *
212
 
 * Create the widgets for the #CheeseAvatarChooser and pack them into a
213
 
 * container.
214
 
 *
215
 
 * Returns: a #GtkBox containing the individual #CheeseAvatarChooser widgets
216
 
 */
217
 
static GtkWidget *
218
 
create_page (GtkWidget *child,
219
 
             GtkWidget *button,
220
 
             GtkWidget *extra)
221
 
{
222
 
  GtkWidget *vgrid, *hgrid, *align;
223
 
 
224
 
  vgrid = gtk_grid_new ();
225
 
  gtk_grid_attach (GTK_GRID (vgrid),
226
 
                   child, 0, 0, 1, 1);
227
 
  gtk_widget_set_hexpand (child, TRUE);
228
 
  gtk_widget_set_vexpand (child, TRUE);
229
 
  align = gtk_alignment_new (0.5, 0, 0, 0);
230
 
  gtk_widget_set_valign (align, GTK_ALIGN_END);
231
 
  gtk_grid_attach (GTK_GRID (vgrid),
232
 
                   align, 0, 1, 1, 1);
233
 
  hgrid = gtk_grid_new ();
234
 
  gtk_grid_set_column_spacing (GTK_GRID (hgrid), 8);
235
 
  gtk_container_add(GTK_CONTAINER(align), hgrid);
236
 
  gtk_grid_attach (GTK_GRID (hgrid),
237
 
                   button, 0, 0, 1, 1);
238
 
  gtk_widget_set_halign (button, GTK_ALIGN_START);
239
 
  if (extra != NULL)
240
 
  {
241
 
    gtk_grid_attach (GTK_GRID (hgrid),
242
 
                     extra, 1, 0, 1, 1);
243
 
    gtk_widget_set_hexpand (extra, TRUE);
244
 
    gtk_widget_set_vexpand (extra, TRUE);
245
 
  }
246
 
 
247
 
  return vgrid;
 
67
G_DEFINE_TYPE_WITH_PRIVATE (CheeseAvatarChooser, cheese_avatar_chooser, GTK_TYPE_DIALOG);
 
68
 
 
69
static void
 
70
update_select_button (CheeseAvatarWidget  *widget,
 
71
                      GParamSpec          *pspec,
 
72
                      CheeseAvatarChooser *chooser)
 
73
{
 
74
  GdkPixbuf *pixbuf;
 
75
 
 
76
  g_object_get (G_OBJECT (widget), "pixbuf", &pixbuf, NULL);
 
77
  gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
 
78
                                     GTK_RESPONSE_ACCEPT,
 
79
                                     pixbuf != NULL);
 
80
  if (pixbuf)
 
81
    g_object_unref (pixbuf);
248
82
}
249
83
 
250
84
static void
251
85
cheese_avatar_chooser_init (CheeseAvatarChooser *chooser)
252
86
{
253
 
  GtkWidget *frame;
254
 
 
255
 
  CheeseAvatarChooserPrivate *priv = chooser->priv = CHEESE_AVATAR_CHOOSER_GET_PRIVATE (chooser);
256
 
 
257
 
  priv->flash = cheese_flash_new (GTK_WIDGET (chooser));
 
87
  CheeseAvatarChooserPrivate *priv = chooser->priv = cheese_avatar_chooser_get_instance_private (chooser);
258
88
 
259
89
  gtk_dialog_add_buttons (GTK_DIALOG (chooser),
260
 
                          GTK_STOCK_CANCEL,
 
90
                          _("_Cancel"),
261
91
                          GTK_RESPONSE_REJECT,
262
 
                          _("Select"),
 
92
                          _("_Select"),
263
93
                          GTK_RESPONSE_ACCEPT,
264
94
                          NULL);
265
95
  gtk_window_set_title (GTK_WINDOW (chooser), _("Take a Photo"));
268
98
                                     GTK_RESPONSE_ACCEPT,
269
99
                                     FALSE);
270
100
 
271
 
  priv->notebook = gtk_notebook_new ();
272
 
  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
273
 
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
 
101
  g_object_set (G_OBJECT (gtk_dialog_get_action_area (GTK_DIALOG (chooser))), "margin", 8, NULL);
274
102
 
 
103
  priv->widget = cheese_avatar_widget_new ();
 
104
  gtk_widget_show (priv->widget);
275
105
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (chooser))),
276
 
                      priv->notebook,
277
 
                      TRUE, TRUE, 8);
278
 
 
279
 
  /* Camera tab */
280
 
  priv->camera = cheese_widget_new ();
281
 
  g_signal_connect (G_OBJECT (priv->camera), "notify::state",
282
 
                    G_CALLBACK (state_change_cb), chooser);
283
 
  priv->take_button = gtk_button_new_with_mnemonic (_("_Take a Photo"));
284
 
  g_signal_connect (G_OBJECT (priv->take_button), "clicked",
285
 
                    G_CALLBACK (take_button_clicked_cb), chooser);
286
 
  gtk_widget_set_sensitive (priv->take_button, FALSE);
287
 
  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
288
 
                            create_page (priv->camera, priv->take_button, NULL),
289
 
                            gtk_label_new ("webcam"));
290
 
 
291
 
  /* Image tab */
292
 
  priv->image = um_crop_area_new ();
293
 
  frame       = gtk_frame_new (NULL);
294
 
  gtk_container_add (GTK_CONTAINER (frame), priv->image);
295
 
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
296
 
  priv->take_again_button = gtk_button_new_with_mnemonic (_("_Discard photo"));
297
 
  g_signal_connect (G_OBJECT (priv->take_again_button), "clicked",
298
 
                    G_CALLBACK (take_again_button_clicked_cb), chooser);
299
 
  gtk_widget_set_sensitive (priv->take_again_button, FALSE);
300
 
  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
301
 
                            create_page (frame, priv->take_again_button, NULL),
302
 
                            gtk_label_new ("image"));
303
 
 
304
 
  gtk_window_set_default_size (GTK_WINDOW (chooser), 400, 300);
305
 
 
306
 
  gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (chooser)));
307
 
}
308
 
 
309
 
static void
310
 
cheese_avatar_chooser_finalize (GObject *object)
311
 
{
312
 
  CheeseAvatarChooserPrivate *priv = ((CheeseAvatarChooser *) object)->priv;
313
 
 
314
 
  g_clear_object (&priv->flash);
315
 
 
316
 
  G_OBJECT_CLASS (cheese_avatar_chooser_parent_class)->finalize (object);
 
106
                      priv->widget,
 
107
                      TRUE, TRUE, 0);
 
108
 
 
109
  g_signal_connect (G_OBJECT (priv->widget), "notify::pixbuf",
 
110
                    G_CALLBACK (update_select_button), chooser);
 
111
 
317
112
}
318
113
 
319
114
static void
325
120
  switch (prop_id)
326
121
  {
327
122
    case PROP_PIXBUF:
328
 
      g_value_set_object (value, um_crop_area_get_picture (UM_CROP_AREA (priv->image)));
 
123
      g_value_set_object (value, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv->widget)));
329
124
      break;
330
125
    default:
331
126
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338
133
{
339
134
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
340
135
 
341
 
  object_class->finalize     = cheese_avatar_chooser_finalize;
342
136
  object_class->get_property = cheese_avatar_chooser_get_property;
343
137
 
344
138
  /**
353
147
                                                 G_PARAM_READABLE);
354
148
 
355
149
  g_object_class_install_properties (object_class, PROP_LAST, properties);
356
 
 
357
 
  g_type_class_add_private (klass, sizeof (CheeseAvatarChooserPrivate));
358
150
}
359
151
 
360
152
/**
384
176
{
385
177
  g_return_val_if_fail (CHEESE_IS_AVATAR_CHOOSER (chooser), NULL);
386
178
 
387
 
  return um_crop_area_get_picture (UM_CROP_AREA (chooser->priv->image));
 
179
  return cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (chooser->priv->widget));
388
180
}