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

« back to all changes in this revision

Viewing changes to src/cheese-window.vala

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-02-07 00:39:22 UTC
  • mto: (15.1.2 experimental) (1.6.1)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20120207003922-gr3zub1aeli4nomr
Tags: upstream-3.3.5
ImportĀ upstreamĀ versionĀ 3.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
using Gee;
30
30
using CanberraGtk;
31
31
 
 
32
[DBus(name = "org.freedesktop.PackageKit.Modify")]
 
33
interface PkProxy : GLib.Object {
 
34
        public abstract async void install_package_names (uint xid, string[] packages_names, string interaction) throws IOError;
 
35
}
 
36
 
32
37
const int FULLSCREEN_TIMEOUT_INTERVAL = 5 * 1000;
33
38
const int EFFECTS_PER_PAGE            = 9;
 
39
const string SENDTO_EXEC = "nautilus-sendto";
34
40
 
35
41
public class Cheese.MainWindow : Gtk.Window
36
42
{
85
91
  private Gtk.Action       countdown_action;
86
92
  private Gtk.Action       effects_page_prev_action;
87
93
  private Gtk.Action       effects_page_next_action;
 
94
  private Gtk.Action       share_action;
 
95
  private Gtk.ActionGroup  main_actions;
88
96
 
89
97
  private bool is_fullscreen;
90
98
  private bool is_wide_mode;
106
114
 
107
115
  private Cheese.Effect selected_effect;
108
116
 
 
117
  private Cheese.ShareableMedia shareable_media;
 
118
 
 
119
  /**
 
120
   * Responses from the delete files confirmation dialog.
 
121
   *
 
122
   * @param SKIP skip a single file
 
123
   * @param SKIP_ALL skill all following files
 
124
   */
 
125
  enum DeleteResponse
 
126
  {
 
127
    SKIP = 1,
 
128
    SKIP_ALL = 2
 
129
  }
 
130
 
109
131
  /**
110
132
   * Destroy the main window, and shutdown the application, when quitting.
111
133
   *
157
179
    if (event.type == Gdk.EventType.BUTTON_PRESS)
158
180
    {
159
181
      if (event.button == 3)
160
 
      {
161
 
        thumbnail_popup.popup (null, thumb_view, null, event.button, event.time);
162
 
      }
 
182
        thumbnail_popup.popup (null, thumb_view, null, event.button, event.time);
163
183
    }
164
184
    else
165
185
    if (event.type == Gdk.EventType.2BUTTON_PRESS)
199
219
                                                      Gtk.DialogFlags.DESTROY_WITH_PARENT,
200
220
                                                      Gtk.MessageType.ERROR,
201
221
                                                      Gtk.ButtonsType.OK,
202
 
                                                      "Could not open %s",
 
222
                                                      _("Could not open %s"),
203
223
                                                      filename);
204
224
 
205
225
      error_dialog.run ();
208
228
  }
209
229
 
210
230
  /**
211
 
   * Delete the requested image in the thumbview from storage.
 
231
   * Delete the requested image or images in the thumbview from storage.
212
232
   *
213
 
   * A confirmation dialog is shown to the user before deleting the file.
 
233
   * A confirmation dialog is shown to the user before deleting any files.
214
234
   *
215
235
   * @param action the action that emitted the signal
216
236
   */
217
237
  [CCode (instance_pos = -1)]
218
238
  public void on_file_delete (Gtk.Action action)
219
239
  {
220
 
    File file;
221
240
    int response;
222
 
    MessageDialog confirmation_dialog;
223
 
 
224
 
    GLib.List<GLib.File> files = thumb_view.get_selected_images_list ();
225
 
 
226
 
    for (int i = 0; i < files.length (); i++)
 
241
    int error_response;
 
242
    bool skip_all_errors = false;
 
243
 
 
244
    var files = thumb_view.get_selected_images_list ();
 
245
    var files_length = files.length ();
 
246
 
 
247
    var confirmation_dialog = new MessageDialog.with_markup (this,
 
248
      Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
 
249
      Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
 
250
      GLib.ngettext("Are you sure you want to permanently delete the file?",
 
251
        "Are you sure you want to permanently delete %d files?",
 
252
        files_length), files_length);
 
253
    confirmation_dialog.add_button (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
 
254
    confirmation_dialog.add_button (Gtk.Stock.DELETE, Gtk.ResponseType.ACCEPT);
 
255
    confirmation_dialog.format_secondary_text ("%s",
 
256
      GLib.ngettext("If you delete an item, it will be permanently lost",
 
257
        "If you delete the items, they will be permanently lost",
 
258
        files_length));
 
259
 
 
260
    response = confirmation_dialog.run ();
 
261
    if (response == Gtk.ResponseType.ACCEPT)
227
262
    {
228
 
      file = files<GLib.File>.nth (i).data;
229
 
      if (file == null)
230
 
        return;
231
 
 
232
 
      confirmation_dialog = new MessageDialog.with_markup (this,
233
 
                                                           Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
234
 
                                                           Gtk.MessageType.WARNING,
235
 
                                                           Gtk.ButtonsType.NONE,
236
 
                                                           "Are you sure you want to permanently delete the file \"%s\"?",
237
 
                                                           file.get_basename ());
238
 
      confirmation_dialog.add_button (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
239
 
      confirmation_dialog.add_button (Gtk.Stock.DELETE, Gtk.ResponseType.ACCEPT);
240
 
      confirmation_dialog.format_secondary_text ("%s", "If you delete an item, it will be permanently lost");
241
 
      response = confirmation_dialog.run ();
242
 
      confirmation_dialog.destroy ();
243
 
      if (response == Gtk.ResponseType.ACCEPT)
 
263
      foreach (var file in files)
244
264
      {
 
265
        if (file == null)
 
266
          return;
 
267
 
245
268
        try
246
269
        {
247
270
          file.delete (null);
248
271
        }
249
272
        catch (Error err)
250
273
        {
251
 
          MessageDialog error_dialog = new MessageDialog (this,
252
 
                                                          Gtk.DialogFlags.MODAL |
253
 
                                                          Gtk.DialogFlags.DESTROY_WITH_PARENT,
254
 
                                                          Gtk.MessageType.ERROR,
255
 
                                                          Gtk.ButtonsType.OK,
256
 
                                                          "Could not delete %s",
257
 
                                                          file.get_path ());
258
 
 
259
 
          error_dialog.run ();
260
 
          error_dialog.destroy ();
 
274
          warning ("Unable to delete file: %s", err.message);
 
275
 
 
276
          if (!skip_all_errors) {
 
277
            var error_dialog = new MessageDialog (this,
 
278
              Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
 
279
              Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE,
 
280
              "Could not delete %s", file.get_path ());
 
281
 
 
282
            error_dialog.add_button (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
 
283
            error_dialog.add_button ("Skip", DeleteResponse.SKIP);
 
284
            error_dialog.add_button ("Skip all", DeleteResponse.SKIP_ALL);
 
285
 
 
286
            error_response = error_dialog.run ();
 
287
            if (error_response == DeleteResponse.SKIP_ALL) {
 
288
              skip_all_errors = true;
 
289
            } else if (error_response == Gtk.ResponseType.CANCEL) {
 
290
              break;
 
291
            }
 
292
 
 
293
            error_dialog.destroy ();
 
294
          }
261
295
        }
262
296
      }
263
297
    }
 
298
    confirmation_dialog.destroy ();
264
299
  }
265
300
 
266
301
  /**
294
329
                                                        Gtk.DialogFlags.DESTROY_WITH_PARENT,
295
330
                                                        Gtk.MessageType.ERROR,
296
331
                                                        Gtk.ButtonsType.OK,
297
 
                                                        "Could not move %s to trash",
 
332
                                                        _("Could not move %s to trash"),
298
333
                                                        file.get_path ());
299
334
 
300
335
        error_dialog.run ();
341
376
  }
342
377
 
343
378
  /**
 
379
   * Share the selected file(s) in the thumbview.
 
380
   *
 
381
   * A dialog is shown to the user, where the technology for sharing the
 
382
   * image or video can be selected.
 
383
   *
 
384
   * @param action the action that emitted the signal
 
385
   */
 
386
  [CCode (instance_pos = -1)]
 
387
  public void on_share_files (Gtk.Action action)
 
388
  {
 
389
    bool nautilus_sendto_installed = Environment.find_program_in_path (SENDTO_EXEC) != null;
 
390
 
 
391
    if (!nautilus_sendto_installed)
 
392
      install_packages ((obj, res) => {
 
393
                        install_packages.end (res);
 
394
                        get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.LEFT_PTR));
 
395
                       });
 
396
    else
 
397
      shareable_media.share_files (thumb_view.get_selected_images_list ());
 
398
  }
 
399
 
 
400
  /**
 
401
   * Install nautilus-sendto runtime dependency.
 
402
   *
 
403
   */
 
404
  private async void install_packages ()
 
405
  {
 
406
    get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.WATCH));
 
407
 
 
408
    try {
 
409
      PkProxy pk_proxy = yield GLib.Bus.get_proxy (BusType.SESSION,
 
410
                                                   "org.freedesktop.PackageKit",
 
411
                                                   "/org/freedesktop/PackageKit");
 
412
 
 
413
      string[] packages = { "nautilus-sendto" };
 
414
 
 
415
      yield pk_proxy.install_package_names ((uint) Gdk.X11Window.get_xid (this.get_window ()),
 
416
                                            packages,
 
417
                                            ""); // Use interaction defaults.
 
418
    } catch (IOError error) {
 
419
      critical ("D-Bus error: %s\n", error.message);
 
420
    }
 
421
  }
 
422
 
 
423
  /**
344
424
   * Save the selected file in the thumbview to an alternate storage location.
345
425
   *
346
426
   * A file chooser dialog is shown to the user, asking where the file should
359
439
    if (filename == null)
360
440
      return;                    /* Nothing selected. */
361
441
 
362
 
    save_as_dialog = new FileChooserDialog ("Save File",
 
442
    save_as_dialog = new FileChooserDialog (_("Save File"),
363
443
                                            this,
364
444
                                            Gtk.FileChooserAction.SAVE,
365
445
                                            Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
393
473
                                                        Gtk.DialogFlags.DESTROY_WITH_PARENT,
394
474
                                                        Gtk.MessageType.ERROR,
395
475
                                                        Gtk.ButtonsType.OK,
396
 
                                                        "Could not save %s",
 
476
                                                        _("Could not save %s"),
397
477
                                                        target_filename);
398
478
 
399
479
        error_dialog.run ();
906
986
    {
907
987
      camera.start_video_recording (fileutil.get_new_media_filename (this.current_mode));
908
988
      take_action_button_label.label = "<b>" + _("Stop _Recording") + "</b>";
909
 
      take_action_button.tooltip_text = "Stop recording";
 
989
      take_action_button.tooltip_text = _("Stop recording");
910
990
      take_action_button_image.set_from_stock (Gtk.Stock.MEDIA_STOP, Gtk.IconSize.BUTTON);
911
991
      this.is_recording = true;
912
992
      this.disable_mode_change ();
935
1015
      this.disable_mode_change ();
936
1016
      effects_toggle_action.sensitive = false;
937
1017
      take_action_button_label.label  = "<b>" + _("Stop _Taking Pictures") + "</b>";
938
 
      take_action_button.tooltip_text = "Stop taking pictures";
 
1018
      take_action_button.tooltip_text = _("Stop taking pictures");
939
1019
      burst_take_photo ();
940
1020
 
941
1021
      /* Use the countdown duration if it is greater than the burst delay, plus
1370
1450
    buttons_area                      = gtk_builder.get_object ("buttons_area") as Gtk.Box;
1371
1451
    thumbnail_popup                   = gtk_builder.get_object ("thumbnail_popup") as Gtk.Menu;
1372
1452
 
 
1453
    main_actions             = gtk_builder.get_object ("main_actions") as Gtk.ActionGroup;
1373
1454
    take_photo_action        = gtk_builder.get_object ("take_photo") as Gtk.Action;
1374
1455
    take_video_action        = gtk_builder.get_object ("take_video") as Gtk.Action;
1375
1456
    take_burst_action        = gtk_builder.get_object ("take_burst") as Gtk.Action;
1382
1463
    fullscreen_action        = gtk_builder.get_object ("fullscreen") as Gtk.ToggleAction;
1383
1464
    effects_page_next_action = gtk_builder.get_object ("effects_page_next") as Gtk.Action;
1384
1465
    effects_page_prev_action = gtk_builder.get_object ("effects_page_prev") as Gtk.Action;
 
1466
    share_action             = gtk_builder.get_object ("share") as Gtk.Action;
 
1467
 
 
1468
    shareable_media = new Cheese.ShareableMedia (this);
 
1469
    main_actions.pre_activate.connect(on_action_pre_activated);
1385
1470
 
1386
1471
    /* Array contains all 'buttons', for easier manipulation
1387
1472
     * IMPORTANT: IF ANOTHER BUTTON IS ADDED UNDER THE VIEWPORT, ADD IT TO THIS ARRAY */
1457
1542
  }
1458
1543
 
1459
1544
  /**
 
1545
   * Decide which actions will be sensitive or insensitive.
 
1546
   *
 
1547
   * @param action the action that emitted the signal.
 
1548
   */
 
1549
  public void on_action_pre_activated (Gtk.Action action)
 
1550
  {
 
1551
     if (strcmp (action.get_name(), "edit_action") == 0)
 
1552
     {
 
1553
        if (thumb_view.get_selected_images_list () == null)
 
1554
           share_action.set_sensitive (false);
 
1555
        else
 
1556
           share_action.set_sensitive (true);
 
1557
     }
 
1558
  }
 
1559
 
 
1560
  /**
1460
1561
   * Setup the camera listed in GSettings.
1461
1562
   *
1462
1563
   * @param uri the uri of the device node to setup, or null