~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to libslab/directory-tile.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libtile.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
6
 
 * Libtile is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libtile is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "directory-tile.h"
22
 
#include "config.h"
23
 
 
24
 
#include <glib/gi18n-lib.h>
25
 
#include <string.h>
26
 
#include <gio/gio.h>
27
 
#include <gdk/gdk.h>
28
 
#include <unistd.h>
29
 
 
30
 
#include "slab-gnome-util.h"
31
 
#include "gnome-utils.h"
32
 
#include "libslab-utils.h"
33
 
 
34
 
#define GCONF_SEND_TO_CMD_KEY       "/desktop/gnome/applications/main-menu/file-area/file_send_to_cmd"
35
 
#define GCONF_ENABLE_DELETE_KEY_DIR "/apps/nautilus/preferences"
36
 
#define GCONF_ENABLE_DELETE_KEY     GCONF_ENABLE_DELETE_KEY_DIR "/enable_delete"
37
 
#define GCONF_CONFIRM_DELETE_KEY    GCONF_ENABLE_DELETE_KEY_DIR "/confirm_trash"
38
 
 
39
 
G_DEFINE_TYPE (DirectoryTile, directory_tile, NAMEPLATE_TILE_TYPE)
40
 
 
41
 
static void directory_tile_finalize (GObject *);
42
 
static void directory_tile_style_set (GtkWidget *, GtkStyle *);
43
 
 
44
 
static void directory_tile_private_setup (DirectoryTile *);
45
 
static void load_image (DirectoryTile *);
46
 
 
47
 
static GtkWidget *create_header (const gchar *);
48
 
 
49
 
static void header_size_allocate_cb (GtkWidget *, GtkAllocation *, gpointer);
50
 
 
51
 
static void open_with_default_trigger (Tile *, TileEvent *, TileAction *);
52
 
static void rename_trigger (Tile *, TileEvent *, TileAction *);
53
 
static void move_to_trash_trigger (Tile *, TileEvent *, TileAction *);
54
 
static void delete_trigger (Tile *, TileEvent *, TileAction *);
55
 
static void send_to_trigger (Tile *, TileEvent *, TileAction *);
56
 
 
57
 
static void rename_entry_activate_cb (GtkEntry *, gpointer);
58
 
static gboolean rename_entry_key_release_cb (GtkWidget *, GdkEventKey *, gpointer);
59
 
static void gconf_enable_delete_cb (GConfClient *, guint, GConfEntry *, gpointer);
60
 
 
61
 
static void disown_spawned_child (gpointer);
62
 
 
63
 
typedef struct
64
 
{
65
 
        gchar *basename;
66
 
        gchar *mime_type;
67
 
        gchar *icon_name;
68
 
        
69
 
        GtkBin *header_bin;
70
 
        GAppInfo *default_app;
71
 
        
72
 
        gboolean image_is_broken;
73
 
        
74
 
        gboolean delete_enabled;
75
 
        guint gconf_conn_id;
76
 
} DirectoryTilePrivate;
77
 
 
78
 
#define DIRECTORY_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DIRECTORY_TILE_TYPE, DirectoryTilePrivate))
79
 
 
80
 
static void directory_tile_class_init (DirectoryTileClass *this_class)
81
 
{
82
 
        GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
83
 
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class);
84
 
 
85
 
        g_obj_class->finalize = directory_tile_finalize;
86
 
 
87
 
        widget_class->style_set = directory_tile_style_set;
88
 
 
89
 
        g_type_class_add_private (this_class, sizeof (DirectoryTilePrivate));
90
 
}
91
 
 
92
 
GtkWidget *
93
 
directory_tile_new (const gchar *in_uri, const gchar *title, const gchar *icon_name, const gchar *mime_type)
94
 
{
95
 
        DirectoryTile *this;
96
 
        DirectoryTilePrivate *priv;
97
 
 
98
 
        gchar *uri;
99
 
        GtkWidget *image;
100
 
        GtkWidget *header;
101
 
        GtkMenu *context_menu;
102
 
 
103
 
        GtkContainer *menu_ctnr;
104
 
        GtkWidget *menu_item;
105
 
 
106
 
        TileAction *action;
107
 
 
108
 
        gchar *basename;
109
 
 
110
 
        gchar *markup;
111
 
 
112
 
        AtkObject *accessible;
113
 
        
114
 
        gchar *filename;
115
 
        gchar *tooltip_text;
116
 
 
117
 
  
118
 
        uri = g_strdup (in_uri);
119
 
 
120
 
        image = gtk_image_new ();
121
 
 
122
 
        if (! title) {
123
 
                markup = g_path_get_basename (uri);
124
 
                basename = g_uri_unescape_string (markup, NULL);
125
 
                g_free (markup);
126
 
        }
127
 
        else
128
 
                basename = g_strdup (title);
129
 
 
130
 
        header = create_header (basename);
131
 
 
132
 
        filename = g_filename_from_uri (uri, NULL, NULL);
133
 
 
134
 
        if (filename)
135
 
                tooltip_text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
136
 
        else
137
 
                tooltip_text = NULL;
138
 
 
139
 
        g_free (filename);
140
 
        
141
 
        context_menu = GTK_MENU (gtk_menu_new ());
142
 
 
143
 
        this = g_object_new (
144
 
                DIRECTORY_TILE_TYPE,
145
 
                "tile-uri",          uri,
146
 
                "nameplate-image",   image,
147
 
                "nameplate-header",  header,
148
 
                "context-menu",      context_menu,
149
 
                NULL);
150
 
        gtk_widget_set_tooltip_text (GTK_WIDGET (this), tooltip_text);
151
 
 
152
 
        g_free (uri);
153
 
        if (tooltip_text)
154
 
                g_free (tooltip_text);
155
 
 
156
 
        priv = DIRECTORY_TILE_GET_PRIVATE (this);
157
 
        priv->basename    = g_strdup (basename);
158
 
        priv->header_bin  = GTK_BIN (header);
159
 
        priv->icon_name   = g_strdup (icon_name);
160
 
        priv->mime_type   = g_strdup (mime_type);
161
 
 
162
 
        directory_tile_private_setup (this);
163
 
 
164
 
        TILE (this)->actions = g_new0 (TileAction *, 6);
165
 
        TILE (this)->n_actions = 6;
166
 
 
167
 
        menu_ctnr = GTK_CONTAINER (TILE (this)->context_menu);
168
 
 
169
 
        /* make open with default action */
170
 
 
171
 
        markup = g_markup_printf_escaped (_("<b>Open</b>"));
172
 
        action = tile_action_new (TILE (this), open_with_default_trigger, markup, TILE_ACTION_OPENS_NEW_WINDOW);
173
 
        g_free (markup);
174
 
 
175
 
        TILE (this)->default_action = action;
176
 
 
177
 
        menu_item = GTK_WIDGET (GTK_WIDGET (tile_action_get_menu_item (action)));
178
 
 
179
 
        TILE (this)->actions [DIRECTORY_TILE_ACTION_OPEN] = action;
180
 
 
181
 
        gtk_container_add (menu_ctnr, menu_item);
182
 
 
183
 
        /* insert separator */
184
 
 
185
 
        menu_item = gtk_separator_menu_item_new ();
186
 
        gtk_container_add (menu_ctnr, menu_item);
187
 
 
188
 
        /* make rename action */
189
 
 
190
 
        action = tile_action_new (TILE (this), rename_trigger, _("Rename..."), 0);
191
 
        TILE (this)->actions[DIRECTORY_TILE_ACTION_RENAME] = action;
192
 
 
193
 
        menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
194
 
        gtk_container_add (menu_ctnr, menu_item);
195
 
 
196
 
        /* make send to action */
197
 
 
198
 
        /* Only allow Send To for local files, ideally this would use something
199
 
         * equivalent to gnome_vfs_uri_is_local, but that method will stat the file and
200
 
         * that can hang in some conditions. */
201
 
 
202
 
        if (!strncmp (TILE (this)->uri, "file://", 7))
203
 
        {
204
 
                action = tile_action_new (TILE (this), send_to_trigger, _("Send To..."),
205
 
                        TILE_ACTION_OPENS_NEW_WINDOW);
206
 
 
207
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
208
 
        }
209
 
        else
210
 
        {
211
 
                action = NULL;
212
 
 
213
 
                menu_item = gtk_menu_item_new_with_label (_("Send To..."));
214
 
                gtk_widget_set_sensitive (menu_item, FALSE);
215
 
        }
216
 
 
217
 
        TILE (this)->actions[DIRECTORY_TILE_ACTION_SEND_TO] = action;
218
 
 
219
 
        gtk_container_add (menu_ctnr, menu_item);
220
 
 
221
 
        /* insert separator */
222
 
 
223
 
        menu_item = gtk_separator_menu_item_new ();
224
 
        gtk_container_add (menu_ctnr, menu_item);
225
 
 
226
 
        /* make move to trash action */
227
 
 
228
 
        action = tile_action_new (TILE (this), move_to_trash_trigger, _("Move to Trash"), 0);
229
 
        TILE (this)->actions[DIRECTORY_TILE_ACTION_MOVE_TO_TRASH] = action;
230
 
 
231
 
        menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
232
 
        gtk_container_add (menu_ctnr, menu_item);
233
 
 
234
 
        /* make delete action */
235
 
 
236
 
        if (priv->delete_enabled)
237
 
        {
238
 
                action = tile_action_new (TILE (this), delete_trigger, _("Delete"), 0);
239
 
                TILE (this)->actions[DIRECTORY_TILE_ACTION_DELETE] = action;
240
 
 
241
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
242
 
                gtk_container_add (menu_ctnr, menu_item);
243
 
        }
244
 
 
245
 
        gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu));
246
 
 
247
 
        load_image (this);
248
 
 
249
 
        accessible = gtk_widget_get_accessible (GTK_WIDGET (this));
250
 
        if (basename)
251
 
          atk_object_set_name (accessible, basename);
252
 
 
253
 
        g_free (basename);
254
 
 
255
 
        return GTK_WIDGET (this);
256
 
}
257
 
 
258
 
static void
259
 
directory_tile_private_setup (DirectoryTile *tile)
260
 
{
261
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
262
 
        GConfClient *client;
263
 
 
264
 
        if (priv->mime_type)
265
 
                priv->default_app = g_app_info_get_default_for_type (priv->mime_type, TRUE);
266
 
        else
267
 
                priv->default_app = NULL;
268
 
 
269
 
        priv->delete_enabled =
270
 
                (gboolean) GPOINTER_TO_INT (get_gconf_value (GCONF_ENABLE_DELETE_KEY));
271
 
 
272
 
        client = gconf_client_get_default ();
273
 
 
274
 
        gconf_client_add_dir (client, GCONF_ENABLE_DELETE_KEY_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL);
275
 
        priv->gconf_conn_id =
276
 
                connect_gconf_notify (GCONF_ENABLE_DELETE_KEY, gconf_enable_delete_cb, tile);
277
 
 
278
 
        g_object_unref (client);
279
 
}
280
 
 
281
 
static void
282
 
directory_tile_init (DirectoryTile *tile)
283
 
{
284
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
285
 
 
286
 
        priv->default_app = NULL;
287
 
        priv->basename = NULL;
288
 
        priv->header_bin = NULL;
289
 
        priv->icon_name = NULL;
290
 
        priv->mime_type = NULL;
291
 
        priv->image_is_broken = TRUE;
292
 
        priv->delete_enabled = FALSE;
293
 
        priv->gconf_conn_id = 0;
294
 
}
295
 
 
296
 
static void
297
 
directory_tile_finalize (GObject *g_object)
298
 
{
299
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (g_object);
300
 
 
301
 
        GConfClient *client;
302
 
 
303
 
        g_free (priv->basename);
304
 
        g_free (priv->icon_name);
305
 
        g_free (priv->mime_type);
306
 
 
307
 
        if (priv->default_app)
308
 
                g_object_unref (priv->default_app);
309
 
    
310
 
        client = gconf_client_get_default ();
311
 
 
312
 
        gconf_client_notify_remove (client, priv->gconf_conn_id);
313
 
        gconf_client_remove_dir (client, GCONF_ENABLE_DELETE_KEY_DIR, NULL);
314
 
 
315
 
        g_object_unref (client);
316
 
 
317
 
        (* G_OBJECT_CLASS (directory_tile_parent_class)->finalize) (g_object);
318
 
}
319
 
 
320
 
static void
321
 
directory_tile_style_set (GtkWidget *widget, GtkStyle *prev_style)
322
 
{
323
 
        load_image (DIRECTORY_TILE (widget));
324
 
}
325
 
 
326
 
static void
327
 
load_image (DirectoryTile *tile)
328
 
{
329
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
330
 
        gchar *icon_name;
331
 
 
332
 
        if (priv->icon_name)
333
 
                icon_name = priv->icon_name;
334
 
        else
335
 
                icon_name = "folder";
336
 
 
337
 
        priv->image_is_broken = slab_load_image (
338
 
                GTK_IMAGE (NAMEPLATE_TILE (tile)->image), GTK_ICON_SIZE_DND, icon_name);
339
 
}
340
 
 
341
 
static GtkWidget *
342
 
create_header (const gchar *name)
343
 
{
344
 
        GtkWidget *header_bin;
345
 
        GtkWidget *header;
346
 
 
347
 
        header = gtk_label_new (name);
348
 
        gtk_label_set_ellipsize (GTK_LABEL (header), PANGO_ELLIPSIZE_END);
349
 
        gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5);
350
 
 
351
 
        header_bin = gtk_alignment_new (0.0, 0.5, 1.0, 0.0);
352
 
        gtk_container_add (GTK_CONTAINER (header_bin), header);
353
 
 
354
 
        g_signal_connect (G_OBJECT (header), "size-allocate", G_CALLBACK (header_size_allocate_cb),
355
 
                NULL);
356
 
 
357
 
        return header_bin;
358
 
}
359
 
 
360
 
static void
361
 
header_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer user_data)
362
 
{
363
 
        gtk_widget_set_size_request (widget, alloc->width, -1);
364
 
}
365
 
 
366
 
static void
367
 
rename_entry_activate_cb (GtkEntry *entry, gpointer user_data)
368
 
{
369
 
        DirectoryTile *tile = DIRECTORY_TILE (user_data);
370
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
371
 
 
372
 
        GFile *src_file;
373
 
        GFile *dst_file;
374
 
 
375
 
        gchar *dirname;
376
 
        gchar *dst_uri;
377
 
        gchar *src_path;
378
 
 
379
 
        GtkWidget *child;
380
 
        GtkWidget *header;
381
 
 
382
 
        gboolean res;
383
 
        GError *error = NULL;
384
 
 
385
 
        if (strlen (gtk_entry_get_text (entry)) < 1)
386
 
                return;
387
 
 
388
 
        src_file = g_file_new_for_uri (TILE (tile)->uri);
389
 
 
390
 
        src_path = g_filename_from_uri (TILE (tile)->uri, NULL, NULL);
391
 
        dirname = g_path_get_dirname (src_path);
392
 
        dst_uri = g_build_filename (dirname, gtk_entry_get_text (entry), NULL);
393
 
        dst_file = g_file_new_for_uri (dst_uri);
394
 
 
395
 
        g_free (dirname);
396
 
        g_free (src_path);
397
 
 
398
 
        res = g_file_move (src_file, dst_file,
399
 
                           G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
400
 
 
401
 
        if (res) {
402
 
                g_free (priv->basename);
403
 
                priv->basename = g_strdup (gtk_entry_get_text (entry));
404
 
        }
405
 
        else {
406
 
                g_warning ("unable to move [%s] to [%s]: %s\n", TILE (tile)->uri, dst_uri,
407
 
                           error->message);
408
 
                g_error_free (error);
409
 
        }
410
 
 
411
 
        g_free (dst_uri);
412
 
        g_object_unref (src_file);
413
 
        g_object_unref (dst_file);
414
 
 
415
 
        header = gtk_label_new (priv->basename);
416
 
        gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5);
417
 
 
418
 
        child = gtk_bin_get_child (priv->header_bin);
419
 
 
420
 
        if (child)
421
 
                gtk_widget_destroy (child);
422
 
 
423
 
        gtk_container_add (GTK_CONTAINER (priv->header_bin), header);
424
 
 
425
 
        gtk_widget_show (header);
426
 
}
427
 
 
428
 
static gboolean
429
 
rename_entry_key_release_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
430
 
{
431
 
        return TRUE;
432
 
}
433
 
 
434
 
static void
435
 
gconf_enable_delete_cb (GConfClient *client, guint conn_id, GConfEntry *entry, gpointer user_data)
436
 
{
437
 
        Tile *tile = TILE (user_data);
438
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (user_data);
439
 
 
440
 
        GtkMenuShell *menu;
441
 
        gboolean delete_enabled;
442
 
 
443
 
        TileAction *action;
444
 
        GtkWidget *menu_item;
445
 
 
446
 
        menu = GTK_MENU_SHELL (tile->context_menu);
447
 
 
448
 
        delete_enabled = gconf_value_get_bool (entry->value);
449
 
 
450
 
        if (delete_enabled == priv->delete_enabled)
451
 
                return;
452
 
 
453
 
        priv->delete_enabled = delete_enabled;
454
 
 
455
 
        if (priv->delete_enabled)
456
 
        {
457
 
                action = tile_action_new (tile, delete_trigger, _("Delete"), 0);
458
 
                tile->actions[DIRECTORY_TILE_ACTION_DELETE] = action;
459
 
 
460
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
461
 
                gtk_menu_shell_insert (menu, menu_item, 7);
462
 
 
463
 
                gtk_widget_show_all (menu_item);
464
 
        }
465
 
        else
466
 
        {
467
 
                g_object_unref (tile->actions[DIRECTORY_TILE_ACTION_DELETE]);
468
 
 
469
 
                tile->actions[DIRECTORY_TILE_ACTION_DELETE] = NULL;
470
 
        }
471
 
}
472
 
 
473
 
static void
474
 
rename_trigger (Tile *tile, TileEvent *event, TileAction *action)
475
 
{
476
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
477
 
 
478
 
        GtkWidget *child;
479
 
        GtkWidget *entry;
480
 
 
481
 
 
482
 
        entry = gtk_entry_new ();
483
 
        gtk_entry_set_text (GTK_ENTRY (entry), priv->basename);
484
 
        gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
485
 
 
486
 
        child = gtk_bin_get_child (priv->header_bin);
487
 
 
488
 
        if (child)
489
 
                gtk_widget_destroy (child);
490
 
 
491
 
        gtk_container_add (GTK_CONTAINER (priv->header_bin), entry);
492
 
 
493
 
        g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (rename_entry_activate_cb), tile);
494
 
 
495
 
        g_signal_connect (G_OBJECT (entry), "key_release_event",
496
 
                G_CALLBACK (rename_entry_key_release_cb), NULL);
497
 
 
498
 
        gtk_widget_show (entry);
499
 
        gtk_widget_grab_focus (entry);
500
 
}
501
 
 
502
 
static void
503
 
move_to_trash_trigger (Tile *tile, TileEvent *event, TileAction *action)
504
 
{
505
 
        GFile *src_file;
506
 
        gboolean res;
507
 
        GError *error = NULL;
508
 
 
509
 
        src_file = g_file_new_for_uri (TILE (tile)->uri);
510
 
 
511
 
        res = g_file_trash (src_file, NULL, &error);
512
 
        if (!res) {
513
 
                g_warning ("unable to move [%s] to the trash: %s\n", TILE (tile)->uri,
514
 
                           error->message);
515
 
                g_error_free (error);
516
 
        }
517
 
 
518
 
        g_object_unref (src_file);
519
 
}
520
 
 
521
 
static void
522
 
delete_trigger (Tile *tile, TileEvent *event, TileAction *action)
523
 
{
524
 
        GtkDialog *confirm_dialog;
525
 
        gint       result;
526
 
 
527
 
        GFile *src_file;
528
 
        gboolean res;
529
 
        GError *error = NULL;
530
 
 
531
 
        if (GPOINTER_TO_INT (libslab_get_gconf_value (GCONF_CONFIRM_DELETE_KEY))) {
532
 
                confirm_dialog = GTK_DIALOG(gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, 
533
 
                                GTK_BUTTONS_NONE, _("Are you sure you want to permanently delete \"%s\"?"), DIRECTORY_TILE_GET_PRIVATE (tile)->basename));
534
 
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(confirm_dialog), _("If you delete an item, it is permanently lost."));
535
 
                                                        
536
 
                gtk_dialog_add_button (confirm_dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
537
 
                gtk_dialog_add_button (confirm_dialog, GTK_STOCK_DELETE, GTK_RESPONSE_YES);
538
 
                gtk_dialog_set_default_response (GTK_DIALOG (confirm_dialog), GTK_RESPONSE_YES);
539
 
 
540
 
                result = gtk_dialog_run (confirm_dialog);
541
 
 
542
 
                gtk_widget_destroy (GTK_WIDGET (confirm_dialog));
543
 
 
544
 
                if (result != GTK_RESPONSE_YES)
545
 
                        return;
546
 
        }
547
 
 
548
 
        src_file = g_file_new_for_uri (TILE (tile)->uri);
549
 
 
550
 
        res = g_file_delete (src_file, NULL, &error);
551
 
 
552
 
        if (!res) {
553
 
                g_warning ("unable to delete [%s]: %s\n", TILE (tile)->uri,
554
 
                           error->message);
555
 
                g_error_free (error);
556
 
        }
557
 
 
558
 
        g_object_unref (src_file);
559
 
}
560
 
 
561
 
static void
562
 
send_to_trigger (Tile *tile, TileEvent *event, TileAction *action)
563
 
{
564
 
        gchar  *cmd;
565
 
        gint    argc;
566
 
        gchar **argv_parsed = NULL;
567
 
        gchar **argv        = NULL;
568
 
 
569
 
        gchar *path;
570
 
        gchar *dirname;
571
 
        gchar *basename;
572
 
 
573
 
        GError *error = NULL;
574
 
 
575
 
        gint i;
576
 
 
577
 
 
578
 
        cmd = (gchar *) get_gconf_value (GCONF_SEND_TO_CMD_KEY);
579
 
 
580
 
        if (! g_shell_parse_argv (cmd, & argc, & argv_parsed, NULL))
581
 
                goto exit;
582
 
 
583
 
        argv = g_new0 (gchar *, argc + 1);
584
 
 
585
 
        path     = g_filename_from_uri (tile->uri, NULL, NULL);
586
 
        dirname  = g_path_get_dirname  (path);
587
 
        basename = g_path_get_basename (path);
588
 
 
589
 
        for (i = 0; i < argc; ++i) {
590
 
                if (strstr (argv_parsed [i], "DIRNAME"))
591
 
                        argv [i] = string_replace_once (argv_parsed [i], "DIRNAME", dirname);
592
 
                else if (strstr (argv_parsed [i], "BASENAME"))
593
 
                        argv [i] = string_replace_once (argv_parsed [i], "BASENAME", basename);
594
 
                else
595
 
                        argv [i] = g_strdup (argv_parsed [i]);
596
 
        }
597
 
 
598
 
        argv [argc] = NULL;
599
 
 
600
 
        g_free (path);
601
 
        g_free (dirname);
602
 
        g_free (basename);
603
 
 
604
 
        g_spawn_async (
605
 
                NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
606
 
                disown_spawned_child, NULL, NULL, & error);
607
 
 
608
 
        if (error) {
609
 
                cmd = g_strjoinv (" ", argv);
610
 
                libslab_handle_g_error (
611
 
                        & error, "%s: can't execute search [%s]\n", G_STRFUNC, cmd);
612
 
                g_free (cmd);
613
 
        }
614
 
 
615
 
        g_strfreev (argv);
616
 
 
617
 
exit:
618
 
 
619
 
        g_free (cmd);
620
 
        g_strfreev (argv_parsed);
621
 
}
622
 
 
623
 
static void
624
 
disown_spawned_child (gpointer user_data)
625
 
{
626
 
        setsid  ();
627
 
        setpgid (0, 0);
628
 
}
629
 
 
630
 
static void
631
 
open_with_default_trigger (Tile *tile, TileEvent *event, TileAction *action)
632
 
{
633
 
        DirectoryTilePrivate *priv = DIRECTORY_TILE_GET_PRIVATE (tile);
634
 
        GList *uris = NULL;
635
 
        gboolean res;
636
 
        GdkAppLaunchContext *launch_context;
637
 
        GError *error = NULL;
638
 
 
639
 
        if (priv->default_app)
640
 
        {
641
 
                uris = g_list_append (uris, TILE (tile)->uri);
642
 
                
643
 
                launch_context = gdk_app_launch_context_new ();
644
 
                gdk_app_launch_context_set_screen (launch_context,
645
 
                                                   gtk_widget_get_screen (GTK_WIDGET (tile)));
646
 
                gdk_app_launch_context_set_timestamp (launch_context,
647
 
                                                      event->time);
648
 
 
649
 
                res = g_app_info_launch_uris (priv->default_app, uris,
650
 
                                              G_APP_LAUNCH_CONTEXT (launch_context),
651
 
                                              &error);
652
 
 
653
 
                if (!res) {
654
 
                        g_warning
655
 
                                ("error: could not launch application with [%s]: %s\n",
656
 
                                 TILE (tile)->uri, error->message);
657
 
                        g_error_free (error);
658
 
                }
659
 
 
660
 
                g_list_free (uris);
661
 
                g_object_unref (launch_context);
662
 
        } else {
663
 
                gchar *cmd;
664
 
                cmd = string_replace_once (
665
 
                        get_slab_gconf_string (SLAB_FILE_MANAGER_OPEN_CMD), "FILE_URI", tile->uri);
666
 
                spawn_process (cmd);
667
 
                g_free (cmd);
668
 
        }
669
 
}