~ubuntu-branches/ubuntu/jaunty/gnome-applets/jaunty-updates

« back to all changes in this revision

Viewing changes to trashapplet/src/trashapplet.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-02-03 17:50:21 UTC
  • mfrom: (1.1.41 upstream)
  • Revision ID: james.westby@ubuntu.com-20090203175021-1krrnemt3lccri4a
Tags: 2.25.90-0ubuntu1
* New upstream version
* debian/patches/09_modemlights_use_new_gst.patch,
  debian/patches/98_autoreconf.patch:
  - new version update
* debian/rules:
  - enable mixer applet

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
 * GNU General Public License for more details.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License
20
20
 * along with this program; if not, write to the Free Software
21
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
28
#include <string.h>
29
29
 
30
30
#include <gtk/gtk.h>
 
31
#include <gdk/gdkkeysyms.h>
31
32
#include <gconf/gconf-client.h>
32
 
#include <libgnome/gnome-help.h>
33
33
#include <gio/gio.h>
34
34
#include <panel-applet.h>
35
 
#include <gnome.h>
36
35
 
37
36
#include "trash-empty.h"
38
37
#include "xstuff.h"
57
56
                           TRASH_TYPE_APPLET, TrashApplet))
58
57
 
59
58
static void trash_applet_do_empty    (BonoboUIComponent *component,
60
 
                                      TrashApplet       *applet,
61
 
                                      const gchar       *cname);
 
59
                                      TrashApplet       *applet,
 
60
                                      const gchar       *cname);
62
61
static void trash_applet_show_about  (BonoboUIComponent *component,
63
 
                                      TrashApplet       *applet,
64
 
                                      const gchar       *cname);
 
62
                                      TrashApplet       *applet,
 
63
                                      const gchar       *cname);
65
64
static void trash_applet_open_folder (BonoboUIComponent *component,
66
 
                                      TrashApplet       *applet,
67
 
                                      const gchar       *cname);
 
65
                                      TrashApplet       *applet,
 
66
                                      const gchar       *cname);
68
67
static void trash_applet_show_help   (BonoboUIComponent *component,
69
 
                                      TrashApplet       *applet,
70
 
                                      const gchar       *cname);
 
68
                                      TrashApplet       *applet,
 
69
                                      const gchar       *cname);
71
70
 
72
71
static const BonoboUIVerb trash_applet_menu_verbs [] = {
73
72
  BONOBO_UI_UNSAFE_VERB ("EmptyTrash", trash_applet_do_empty),
85
84
  GIcon *icon;
86
85
  gint items;
87
86
 
88
 
  /* XXX: this is here for a few weeks so that people building without
89
 
   *      bleeding-edge glib don't have to suffer
90
 
   */
91
 
#ifndef G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT
92
 
#define G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT "trash::item-count"
93
 
#endif
94
 
 
95
87
  info = g_file_query_info (applet->trash,
96
88
                            G_FILE_ATTRIBUTE_STANDARD_ICON","
97
89
                            G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT,
111
103
 
112
104
  if (!g_icon_equal (icon, applet->icon))
113
105
    {
114
 
      char const * const *icon_names;
115
 
 
116
 
      /* TODO: support other types (but by then, probably GtkImage
117
 
       *       will have built-in support for GIcon loading...)
 
106
      /* note: the size is meaningless here,
 
107
       * since we do set_pixel_size() later
118
108
       */
119
 
      g_assert (G_IS_THEMED_ICON (icon));
120
 
 
121
 
      icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
122
 
      gtk_image_set_from_icon_name (GTK_IMAGE (applet->image),
123
 
                                    icon_names[0],
124
 
                                    GTK_ICON_SIZE_MENU);
 
109
      gtk_image_set_from_gicon (GTK_IMAGE (applet->image),
 
110
                                icon, GTK_ICON_SIZE_MENU);
125
111
 
126
112
      if (applet->icon)
127
113
        g_object_unref (applet->icon);
 
114
 
128
115
      applet->icon = g_object_ref (icon);
129
116
    }
130
117
 
151
138
}
152
139
 
153
140
static void
 
141
trash_applet_set_icon_size (TrashApplet *applet,
 
142
                            gint         size)
 
143
{
 
144
  /* copied from button-widget.c in the panel */
 
145
  if (size < 22)
 
146
    size = 16;
 
147
  else if (size < 24)
 
148
    size = 22;
 
149
  else if (size < 32)
 
150
    size = 24;
 
151
  else if (size < 48)
 
152
    size = 32;
 
153
  else
 
154
    size = 48;
 
155
 
 
156
  /* GtkImage already contains a check to do nothing if it's the same */
 
157
  gtk_image_set_pixel_size (applet->image, size);
 
158
}
 
159
 
 
160
static void
154
161
trash_applet_size_allocate (GtkWidget    *widget,
155
 
                            GdkRectangle *allocation)
 
162
                            GdkRectangle *allocation)
156
163
{
157
164
  TrashApplet *applet = TRASH_APPLET (widget);
158
165
 
160
167
  {
161
168
    case PANEL_APPLET_ORIENT_LEFT:
162
169
    case PANEL_APPLET_ORIENT_RIGHT:
163
 
      gtk_image_set_pixel_size (applet->image, allocation->width - 2);
 
170
      trash_applet_set_icon_size (applet, allocation->width);
164
171
      break;
165
172
 
166
173
    case PANEL_APPLET_ORIENT_UP:
167
174
    case PANEL_APPLET_ORIENT_DOWN:
168
 
      gtk_image_set_pixel_size (applet->image, allocation->height - 2);
 
175
      trash_applet_set_icon_size (applet, allocation->height);
169
176
      break;
170
177
  }
171
178
 
236
243
#define PANEL_ENABLE_ANIMATIONS "/apps/panel/global/enable_animations"
237
244
static gboolean
238
245
trash_applet_button_release (GtkWidget      *widget,
239
 
                             GdkEventButton *event)
 
246
                             GdkEventButton *event)
240
247
{
241
248
  TrashApplet *applet = TRASH_APPLET (widget);
242
249
  static GConfClient *client;
244
251
  if (client == NULL)
245
252
    client = gconf_client_get_default ();
246
253
 
247
 
        if (event->button == 1) {
248
 
                if (gconf_client_get_bool (client, PANEL_ENABLE_ANIMATIONS, NULL))
249
 
                        xstuff_zoom_animate (widget, NULL);
250
 
                trash_applet_open_folder (NULL, applet, NULL);
251
 
                return TRUE;
252
 
        }
253
 
        if (GTK_WIDGET_CLASS (trash_applet_parent_class)->button_release_event)
254
 
                return (* GTK_WIDGET_CLASS (trash_applet_parent_class)->button_release_event) (widget, event);
255
 
        else
256
 
                return FALSE;
 
254
  if (event->button == 1)
 
255
    {
 
256
      if (gconf_client_get_bool (client, PANEL_ENABLE_ANIMATIONS, NULL))
 
257
        xstuff_zoom_animate (widget, NULL);
 
258
 
 
259
      trash_applet_open_folder (NULL, applet, NULL);
 
260
 
 
261
      return TRUE;
 
262
    }
 
263
 
 
264
  if (GTK_WIDGET_CLASS (trash_applet_parent_class)->button_release_event)
 
265
    return GTK_WIDGET_CLASS (trash_applet_parent_class)
 
266
        ->button_release_event (widget, event);
 
267
  else
 
268
    return FALSE;
257
269
}
258
270
static gboolean
259
271
trash_applet_key_press (GtkWidget   *widget,
260
 
                        GdkEventKey *event)
 
272
                        GdkEventKey *event)
261
273
{
262
 
        TrashApplet *applet = TRASH_APPLET (widget);
263
 
 
264
 
        switch (event->keyval) {
265
 
        case GDK_KP_Enter:
266
 
        case GDK_ISO_Enter:
267
 
        case GDK_3270_Enter:
268
 
        case GDK_Return:
269
 
        case GDK_space:
270
 
        case GDK_KP_Space:
271
 
                trash_applet_open_folder(NULL, applet, NULL);
272
 
                return TRUE;
273
 
        default:
274
 
                break;
275
 
        }
276
 
        if (GTK_WIDGET_CLASS (trash_applet_parent_class)->key_press_event)
277
 
                return (* GTK_WIDGET_CLASS (trash_applet_parent_class)->key_press_event) (widget, event);
278
 
        else
279
 
                return FALSE;
 
274
  TrashApplet *applet = TRASH_APPLET (widget);
 
275
 
 
276
  switch (event->keyval)
 
277
    {
 
278
     case GDK_KP_Enter:
 
279
     case GDK_ISO_Enter:
 
280
     case GDK_3270_Enter:
 
281
     case GDK_Return:
 
282
     case GDK_space:
 
283
     case GDK_KP_Space:
 
284
      trash_applet_open_folder (NULL, applet, NULL);
 
285
      return TRUE;
 
286
 
 
287
     default:
 
288
      break;
 
289
    }
 
290
 
 
291
  if (GTK_WIDGET_CLASS (trash_applet_parent_class)->key_press_event)
 
292
    return GTK_WIDGET_CLASS (trash_applet_parent_class)
 
293
      ->key_press_event (widget, event);
 
294
  else
 
295
    return FALSE;
280
296
}
281
297
 
282
298
static gboolean
283
299
trash_applet_drag_motion (GtkWidget      *widget,
284
 
                          GdkDragContext *context,
285
 
                          gint            x,
286
 
                          gint            y,
287
 
                          guint           time)
 
300
                          GdkDragContext *context,
 
301
                          gint            x,
 
302
                          gint            y,
 
303
                          guint           time)
288
304
{
289
305
  GList *target;
290
306
 
309
325
static void
310
326
error_dialog (TrashApplet *applet, const gchar *error, ...)
311
327
{
312
 
        va_list args;
313
 
        gchar *error_string;
314
 
        GtkWidget *dialog;
315
 
 
316
 
        g_return_if_fail (error != NULL);
317
 
 
318
 
        va_start (args, error);
319
 
        error_string = g_strdup_vprintf (error, args);
320
 
        va_end (args);
321
 
 
322
 
        dialog = gtk_message_dialog_new (NULL,
323
 
                        GTK_DIALOG_MODAL,
324
 
                        GTK_MESSAGE_ERROR,
325
 
                        GTK_BUTTONS_OK,
326
 
                        "%s",
327
 
                        error_string);
328
 
 
329
 
        g_signal_connect (G_OBJECT (dialog), "response",
330
 
                        G_CALLBACK (gtk_widget_destroy),
331
 
                        NULL);
332
 
 
333
 
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
334
 
        gtk_window_set_screen (GTK_WINDOW(dialog),
335
 
                               gtk_widget_get_screen (GTK_WIDGET (applet)));
336
 
        gtk_widget_show (dialog);
337
 
 
338
 
        g_free (error_string);
 
328
  va_list args;
 
329
  gchar *error_string;
 
330
  GtkWidget *dialog;
 
331
 
 
332
  g_return_if_fail (error != NULL);
 
333
 
 
334
  va_start (args, error);
 
335
  error_string = g_strdup_vprintf (error, args);
 
336
  va_end (args);
 
337
 
 
338
  dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
 
339
                                   GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
340
                                   "%s", error_string);
 
341
 
 
342
  g_signal_connect (G_OBJECT (dialog), "response",
 
343
                    G_CALLBACK (gtk_widget_destroy),
 
344
                    NULL);
 
345
 
 
346
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 
347
  gtk_window_set_screen (GTK_WINDOW(dialog),
 
348
                         gtk_widget_get_screen (GTK_WIDGET (applet)));
 
349
  gtk_widget_show (dialog);
 
350
 
 
351
  g_free (error_string);
339
352
}
340
353
 
341
354
static void
342
355
trash_applet_do_empty (BonoboUIComponent *component,
343
 
                       TrashApplet       *applet,
344
 
                       const gchar       *cname)
 
356
                       TrashApplet       *applet,
 
357
                       const gchar       *cname)
345
358
{
346
359
  trash_empty (GTK_WIDGET (applet));
347
360
}
348
361
 
349
362
static void
350
363
trash_applet_open_folder (BonoboUIComponent *component,
351
 
                          TrashApplet       *applet,
352
 
                          const gchar       *cname)
 
364
                          TrashApplet       *applet,
 
365
                          const gchar       *cname)
353
366
{
354
 
        GdkScreen *screen;
355
 
 
356
 
        /* Open the "trash:" URI with gnome-open */
357
 
        gchar *argv[] = { "gnome-open", "trash:", NULL };
358
 
        GError *err = NULL;
359
 
        gboolean res;   
360
 
 
361
 
        screen = gtk_widget_get_screen (GTK_WIDGET (applet));
362
 
        res = gdk_spawn_on_screen (screen, NULL,
363
 
                                   argv, NULL,
364
 
                                   G_SPAWN_SEARCH_PATH,
365
 
                                   NULL, NULL,
366
 
                                   NULL,
367
 
                                   &err);
368
 
        
369
 
        if (! res) {
370
 
                error_dialog (applet, _("Error while spawning nautilus:\n%s"),
371
 
                              err->message);
372
 
                g_error_free (err);
373
 
        }
 
367
  GError *err = NULL;
 
368
 
 
369
  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (applet)),
 
370
                "trash:",
 
371
                gtk_get_current_event_time (),
 
372
                &err);
 
373
 
 
374
  if (err)
 
375
    {
 
376
      error_dialog (applet, _("Error while spawning nautilus:\n%s"),
 
377
      err->message);
 
378
      g_error_free (err);
 
379
    }
374
380
}
375
381
 
376
382
static void
377
383
trash_applet_show_help (BonoboUIComponent *component,
378
 
                        TrashApplet       *applet,
379
 
                        const gchar       *cname)
 
384
                        TrashApplet       *applet,
 
385
                        const gchar       *cname)
380
386
{
381
 
        GError *err = NULL;
382
 
 
383
 
        /* FIXME - Actually, we need a user guide */
384
 
        gnome_help_display_desktop_on_screen
385
 
                (NULL, "trashapplet", "trashapplet", NULL,
386
 
                 gtk_widget_get_screen (GTK_WIDGET (applet)),
387
 
                 &err);
388
 
 
389
 
        if (err) {
390
 
                error_dialog (applet, _("There was an error displaying help: %s"), err->message);
391
 
                g_error_free (err);
392
 
        }
 
387
  GError *err = NULL;
 
388
 
 
389
  /* FIXME - Actually, we need a user guide */
 
390
  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (applet)),
 
391
                "ghelp:trashapplet",
 
392
                gtk_get_current_event_time (),
 
393
                &err);
 
394
 
 
395
  if (err)
 
396
    {
 
397
      error_dialog (applet,
 
398
                    _("There was an error displaying help: %s"),
 
399
                    err->message);
 
400
      g_error_free (err);
 
401
    }
393
402
}
394
403
 
395
404
 
396
405
static void
397
406
trash_applet_show_about (BonoboUIComponent *component,
398
 
                         TrashApplet       *applet,
399
 
                         const gchar       *cname)
 
407
                         TrashApplet       *applet,
 
408
                         const gchar       *cname)
400
409
{
401
 
        static const char *authors[] = {
402
 
                "Michiel Sikkes <michiel@eyesopened.nl>",
403
 
                "Emmanuele Bassi <ebassi@gmail.com>",
404
 
                "Sebastian Bacher <seb128@canonical.com>",
405
 
                "James Henstridge <james.henstridge@canonical.com>",
406
 
                "Ryan Lortie <desrt@desrt.ca>",
407
 
                NULL
408
 
        };
409
 
        static const char *documenters[] = {
410
 
                "Michiel Sikkes <michiel@eyesopened.nl>",
411
 
                NULL
412
 
        };
 
410
  static const char *authors[] = {
 
411
    "Michiel Sikkes <michiel@eyesopened.nl>",
 
412
    "Emmanuele Bassi <ebassi@gmail.com>",
 
413
    "Sebastian Bacher <seb128@canonical.com>",
 
414
    "James Henstridge <james.henstridge@canonical.com>",
 
415
    "Ryan Lortie <desrt@desrt.ca>",
 
416
    NULL
 
417
  };
 
418
  static const char *documenters[] = {
 
419
    "Michiel Sikkes <michiel@eyesopened.nl>",
 
420
    NULL
 
421
  };
413
422
 
414
 
        gtk_show_about_dialog
415
 
                (NULL,
416
 
                 "version", VERSION,
417
 
                 "copyright", "Copyright \xC2\xA9 2004 Michiel Sikkes,"
418
 
                              "\xC2\xA9 2008 Ryan Lortie",
419
 
                 "comments", _("A GNOME trash bin that lives in your panel. "
420
 
                               "You can use it to view the trash or drag "
421
 
                               "and drop items into the trash."),
422
 
                 "authors", authors,
423
 
                 "documenters", documenters,
424
 
                 "translator-credits", _("translator-credits"),
425
 
                 "logo_icon_name", "user-trash-full",
426
 
                 NULL);
 
423
  gtk_show_about_dialog (NULL,
 
424
                         "version", VERSION,
 
425
                         "copyright", "Copyright \xC2\xA9 2004 Michiel Sikkes,"
 
426
                                      "\xC2\xA9 2008 Ryan Lortie",
 
427
                         "comments", _("A GNOME trash bin that lives in your panel. "
 
428
                                       "You can use it to view the trash or drag "
 
429
                                       "and drop items into the trash."),
 
430
                         "authors", authors,
 
431
                         "documenters", documenters,
 
432
                         "translator-credits", _("translator-credits"),
 
433
                         "logo_icon_name", "user-trash-full",
 
434
                         NULL);
427
435
}
428
436
 
429
437
static gboolean
430
438
confirm_delete_immediately (GtkWidget *parent_view,
431
 
                            gint num_files,
432
 
                            gboolean all)
 
439
                            gint num_files,
 
440
                            gboolean all)
433
441
{
434
 
        GdkScreen *screen;
435
 
        GtkWidget *dialog, *hbox, *vbox, *image, *label;
436
 
        gchar *str, *prompt, *detail;
437
 
        int response;
438
 
 
439
 
        screen = gtk_widget_get_screen (parent_view);
440
 
        
441
 
        dialog = gtk_dialog_new ();
442
 
        gtk_window_set_screen (GTK_WINDOW (dialog), screen);
443
 
        atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
444
 
        gtk_window_set_title (GTK_WINDOW (dialog), _("Delete Immediately?"));
445
 
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
446
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
447
 
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
448
 
 
449
 
        gtk_widget_realize (dialog);
450
 
        gdk_window_set_transient_for (GTK_WIDGET (dialog)->window,
451
 
                                      gdk_screen_get_root_window (screen));
452
 
        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
453
 
 
454
 
        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
455
 
 
456
 
        hbox = gtk_hbox_new (FALSE, 12);
457
 
        gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
458
 
        gtk_widget_show (hbox);
459
 
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
460
 
                            FALSE, FALSE, 0);
461
 
 
462
 
        image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION,
463
 
                                          GTK_ICON_SIZE_DIALOG);
464
 
        gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
465
 
        gtk_widget_show (image);
466
 
        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
467
 
 
468
 
        vbox = gtk_vbox_new (FALSE, 12);
469
 
        gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
470
 
        gtk_widget_show (vbox);
471
 
 
472
 
        if (all) {
473
 
                prompt = _("Cannot move items to trash, do you want to delete them immediately?");
474
 
                detail = g_strdup_printf ("None of the %d selected items can be moved to the Trash", num_files);
475
 
        } else {
476
 
                prompt = _("Cannot move some items to trash, do you want to delete these immediately?");
477
 
                detail = g_strdup_printf ("%d of the selected items cannot be moved to the Trash", num_files);
478
 
        }
479
 
 
480
 
        str = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
481
 
                           prompt, "</span>", NULL);
482
 
        label = gtk_label_new (str);
483
 
        gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
484
 
        gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
485
 
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
486
 
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
487
 
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
488
 
        gtk_widget_show (label);
489
 
        g_free (str);
490
 
 
491
 
        label = gtk_label_new (detail);
492
 
        gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
493
 
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
494
 
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
495
 
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
496
 
        gtk_widget_show (label);
497
 
        g_free (detail);
498
 
 
499
 
        gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL,
500
 
                               GTK_RESPONSE_CANCEL);
501
 
        gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_DELETE,
502
 
                               GTK_RESPONSE_YES);
503
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
504
 
                                         GTK_RESPONSE_YES);
505
 
 
506
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
507
 
 
508
 
        gtk_object_destroy (GTK_OBJECT (dialog));
509
 
 
510
 
        return response == GTK_RESPONSE_YES;
 
442
  GdkScreen *screen;
 
443
  GtkWidget *dialog, *hbox, *vbox, *image, *label;
 
444
  gchar *str, *prompt, *detail;
 
445
  int response;
 
446
 
 
447
  screen = gtk_widget_get_screen (parent_view);
 
448
 
 
449
  dialog = gtk_dialog_new ();
 
450
  gtk_window_set_screen (GTK_WINDOW (dialog), screen);
 
451
  atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
 
452
  gtk_window_set_title (GTK_WINDOW (dialog), _("Delete Immediately?"));
 
453
  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 
454
  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
 
455
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 
456
 
 
457
  gtk_widget_realize (dialog);
 
458
  gdk_window_set_transient_for (GTK_WIDGET (dialog)->window,
 
459
                                gdk_screen_get_root_window (screen));
 
460
  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
461
 
 
462
  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
 
463
 
 
464
  hbox = gtk_hbox_new (FALSE, 12);
 
465
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
 
466
  gtk_widget_show (hbox);
 
467
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
 
468
                      FALSE, FALSE, 0);
 
469
 
 
470
  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION,
 
471
                                    GTK_ICON_SIZE_DIALOG);
 
472
  gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
 
473
  gtk_widget_show (image);
 
474
  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
 
475
 
 
476
  vbox = gtk_vbox_new (FALSE, 12);
 
477
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
 
478
  gtk_widget_show (vbox);
 
479
 
 
480
  if (all)
 
481
    {
 
482
      prompt = _("Cannot move items to trash, do you want to delete them immediately?");
 
483
      detail = g_strdup_printf ("None of the %d selected items can be moved to the Trash", num_files);
 
484
    }
 
485
  else
 
486
    {
 
487
      prompt = _("Cannot move some items to trash, do you want to delete these immediately?");
 
488
      detail = g_strdup_printf ("%d of the selected items cannot be moved to the Trash", num_files);
 
489
    }
 
490
 
 
491
  str = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
 
492
                     prompt, "</span>", NULL);
 
493
  label = gtk_label_new (str);
 
494
  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
 
495
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
496
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
 
497
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
 
498
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 
499
  gtk_widget_show (label);
 
500
  g_free (str);
 
501
 
 
502
  label = gtk_label_new (detail);
 
503
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
504
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
 
505
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
 
506
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 
507
  gtk_widget_show (label);
 
508
  g_free (detail);
 
509
 
 
510
  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL,
 
511
                         GTK_RESPONSE_CANCEL);
 
512
  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_DELETE,
 
513
                         GTK_RESPONSE_YES);
 
514
  gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
515
                                   GTK_RESPONSE_YES);
 
516
 
 
517
  response = gtk_dialog_run (GTK_DIALOG (dialog));
 
518
 
 
519
  gtk_object_destroy (GTK_OBJECT (dialog));
 
520
 
 
521
  return response == GTK_RESPONSE_YES;
511
522
}
512
523
 
513
524
static void
514
525
trash_applet_drag_data_received (GtkWidget        *widget,
515
 
                                 GdkDragContext   *context,
516
 
                                 gint              x,
517
 
                                 gint              y,
518
 
                                 GtkSelectionData *selectiondata,
519
 
                                 guint             info,
520
 
                                 guint             time_)
 
526
                                 GdkDragContext   *context,
 
527
                                 gint              x,
 
528
                                 gint              y,
 
529
                                 GtkSelectionData *selectiondata,
 
530
                                 guint             info,
 
531
                                 guint             time_)
521
532
{
522
 
        gchar **list;
523
 
        gint i;
524
 
        GList *trashed = NULL;
525
 
        GList *untrashable = NULL;
526
 
        GList *l;
527
 
        GError *error = NULL;
528
 
 
529
 
        list = g_uri_list_extract_uris ((gchar *)selectiondata->data);
530
 
 
531
 
        for (i = 0; list[i]; i++) {
532
 
                GFile *file;
533
 
 
534
 
                file = g_file_new_for_uri (list[i]);
535
 
                if (!g_file_trash (file, NULL, NULL)) {
536
 
                        untrashable = g_list_prepend (untrashable, file);
537
 
                }
538
 
                else {
539
 
                        trashed = g_list_prepend (trashed, file);
540
 
                }
541
 
        }
542
 
        
543
 
        if (untrashable) {
544
 
                if (confirm_delete_immediately (widget, 
545
 
                                                g_list_length (untrashable),
546
 
                                                trashed == NULL)) {
547
 
                        for (l = untrashable; l; l = l->next) {
548
 
                                if (!g_file_delete (l->data, NULL, &error)) {
 
533
  gchar **list;
 
534
  gint i;
 
535
  GList *trashed = NULL;
 
536
  GList *untrashable = NULL;
 
537
  GList *l;
 
538
  GError *error = NULL;
 
539
 
 
540
  list = g_uri_list_extract_uris ((gchar *)selectiondata->data);
 
541
 
 
542
  for (i = 0; list[i]; i++)
 
543
    {
 
544
      GFile *file;
 
545
 
 
546
      file = g_file_new_for_uri (list[i]);
 
547
 
 
548
      if (!g_file_trash (file, NULL, NULL))
 
549
        {
 
550
          untrashable = g_list_prepend (untrashable, file);
 
551
        }
 
552
      else
 
553
        {
 
554
          trashed = g_list_prepend (trashed, file);
 
555
        }
 
556
    }
 
557
 
 
558
  if (untrashable)
 
559
    {
 
560
      if (confirm_delete_immediately (widget,
 
561
                                      g_list_length (untrashable),
 
562
                                      trashed == NULL))
 
563
        {
 
564
          for (l = untrashable; l; l = l->next)
 
565
            {
 
566
              if (!g_file_delete (l->data, NULL, &error))
 
567
                {
549
568
/*
550
 
 * FIXME: uncomment me after branched (we're string frozen)
551
 
                                        error_dialog (applet,
552
 
                                                      _("Unable to delete '%s': %s"),
553
 
                                                        g_file_get_uri (l->data),
554
 
                                                        error->message);
 
569
* FIXME: uncomment me after branched (we're string frozen)
 
570
                  error_dialog (applet,
 
571
                                _("Unable to delete '%s': %s"),
 
572
                                g_file_get_uri (l->data),
 
573
                                error->message);
555
574
*/
556
 
                                        g_clear_error (&error);
557
 
                                }       
558
 
                        }
559
 
                }
560
 
        }
561
 
 
562
 
        g_list_foreach (untrashable, (GFunc)g_object_unref, NULL);
563
 
        g_list_free (untrashable);
564
 
        g_list_foreach (trashed, (GFunc)g_object_unref, NULL);
565
 
        g_list_free (trashed);
566
 
 
567
 
        g_strfreev (list);      
568
 
 
569
 
        gtk_drag_finish (context, TRUE, FALSE, time_);
 
575
                                g_clear_error (&error);
 
576
                }
 
577
            }
 
578
        }
 
579
    }
 
580
 
 
581
  g_list_foreach (untrashable, (GFunc)g_object_unref, NULL);
 
582
  g_list_free (untrashable);
 
583
  g_list_foreach (trashed, (GFunc)g_object_unref, NULL);
 
584
  g_list_free (trashed);
 
585
 
 
586
  g_strfreev (list);
 
587
 
 
588
  gtk_drag_finish (context, TRUE, FALSE, time_);
570
589
}
571
590
 
572
591
static void
586
605
static gboolean
587
606
trash_applet_factory (PanelApplet *applet,
588
607
                      const gchar *iid,
589
 
                      gpointer     data)
590
 
{
591
 
        gboolean retval = FALSE;
592
 
 
593
 
        if (!strcmp (iid, "OAFIID:GNOME_Panel_TrashApplet")) {
594
 
                /* Set up the menu */
595
 
                panel_applet_setup_menu_from_file (applet,
596
 
                                                   DATADIR,
597
 
                                                   "GNOME_Panel_TrashApplet.xml",
598
 
                                                   NULL,
599
 
                                                   trash_applet_menu_verbs,
600
 
                                                   applet);
601
 
 
602
 
                gtk_widget_show (GTK_WIDGET (applet));
603
 
 
604
 
                retval = TRUE;
605
 
        }
606
 
 
607
 
        return retval;
608
 
}
609
 
 
610
 
int
611
 
main (int argc, char *argv [])
612
 
{
613
 
        g_thread_init (NULL);
614
 
 
615
 
        /* gettext stuff */
616
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
617
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
618
 
        textdomain (GETTEXT_PACKAGE);
619
 
 
620
 
        gnome_authentication_manager_init();
621
 
 
622
 
        gnome_program_init ("trashapplet", VERSION,
623
 
                            LIBGNOMEUI_MODULE,
624
 
                            argc, argv,
625
 
                            GNOME_CLIENT_PARAM_SM_CONNECT, FALSE,
626
 
                            GNOME_PROGRAM_STANDARD_PROPERTIES,
627
 
                            NULL);
628
 
 
629
 
        gtk_window_set_default_icon_name ("user-trash");
630
 
        g_set_application_name (_("Trash Applet"));
631
 
 
632
 
        return panel_applet_factory_main
633
 
                ("OAFIID:GNOME_Panel_TrashApplet_Factory", TRASH_TYPE_APPLET,
634
 
                 trash_applet_factory, NULL);
635
 
}
 
608
                      gpointer     data)
 
609
{
 
610
  gboolean retval = FALSE;
 
611
 
 
612
  if (!strcmp (iid, "OAFIID:GNOME_Panel_TrashApplet"))
 
613
    {
 
614
      g_set_application_name (_("Trash Applet"));
 
615
 
 
616
      gtk_window_set_default_icon_name ("user-trash");
 
617
 
 
618
      /* Set up the menu */
 
619
      panel_applet_setup_menu_from_file (applet,
 
620
                                         DATADIR,
 
621
                                         "GNOME_Panel_TrashApplet.xml",
 
622
                                         NULL,
 
623
                                         trash_applet_menu_verbs,
 
624
                                         applet);
 
625
 
 
626
      gtk_widget_show (GTK_WIDGET (applet));
 
627
 
 
628
      retval = TRUE;
 
629
  }
 
630
 
 
631
  return retval;
 
632
}
 
633
 
 
634
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_Panel_TrashApplet_Factory",
 
635
                             TRASH_TYPE_APPLET,
 
636
                             "TrashApplet", "0",
 
637
                             trash_applet_factory,
 
638
                             NULL)