1
/* vi:set et ai sw=2 sts=2 ts=2: */
3
3
* Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org>
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License as published by the Free
7
* Software Foundation; either version 2 of the License, or (at your option)
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
* You should have received a copy of the GNU General Public License along with
16
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
* Place, Suite 330, Boston, MA 02111-1307 USA
19
* Inspired by the shortcuts list as found in the GtkFileChooser, which was
20
* developed for Gtk+ by Red Hat, Inc.
4
* Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
23
22
#ifdef HAVE_CONFIG_H
62
static void thunar_shortcuts_view_class_init (ThunarShortcutsViewClass *klass);
63
static void thunar_shortcuts_view_init (ThunarShortcutsView *view);
64
static void thunar_shortcuts_view_finalize (GObject *object);
65
static gboolean thunar_shortcuts_view_button_press_event (GtkWidget *widget,
66
GdkEventButton *event);
67
static gboolean thunar_shortcuts_view_button_release_event (GtkWidget *widget,
68
GdkEventButton *event);
69
static void thunar_shortcuts_view_drag_begin (GtkWidget *widget,
70
GdkDragContext *context);
71
static void thunar_shortcuts_view_drag_data_received (GtkWidget *widget,
72
GdkDragContext *context,
75
GtkSelectionData *selection_data,
78
static gboolean thunar_shortcuts_view_drag_drop (GtkWidget *widget,
79
GdkDragContext *context,
83
static gboolean thunar_shortcuts_view_drag_motion (GtkWidget *widget,
84
GdkDragContext *context,
88
static void thunar_shortcuts_view_drag_leave (GtkWidget *widget,
89
GdkDragContext *context,
91
static gboolean thunar_shortcuts_view_popup_menu (GtkWidget *widget);
92
static void thunar_shortcuts_view_row_activated (GtkTreeView *tree_view,
94
GtkTreeViewColumn *column);
95
static void thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
96
GdkEventButton *event,
99
static void thunar_shortcuts_view_remove_activated (GtkWidget *item,
100
ThunarShortcutsView *view);
101
static void thunar_shortcuts_view_rename_activated (GtkWidget *item,
102
ThunarShortcutsView *view);
103
static void thunar_shortcuts_view_renamed (GtkCellRenderer *renderer,
104
const gchar *path_string,
106
ThunarShortcutsView *view);
107
static GdkDragAction thunar_shortcuts_view_compute_drop_actions (ThunarShortcutsView *view,
108
GdkDragContext *context,
111
GtkTreePath **path_return,
112
GdkDragAction *action_return,
113
GtkTreeViewDropPosition *position_return);
114
static GtkTreePath *thunar_shortcuts_view_compute_drop_position (ThunarShortcutsView *view,
117
static void thunar_shortcuts_view_drop_uri_list (ThunarShortcutsView *view,
119
GtkTreePath *dst_path);
120
static void thunar_shortcuts_view_open (ThunarShortcutsView *view);
121
static void thunar_shortcuts_view_open_in_new_window (ThunarShortcutsView *view);
122
static void thunar_shortcuts_view_empty_trash (ThunarShortcutsView *view);
123
static gboolean thunar_shortcuts_view_eject (ThunarShortcutsView *view);
124
static gboolean thunar_shortcuts_view_mount (ThunarShortcutsView *view);
125
static gboolean thunar_shortcuts_view_unmount (ThunarShortcutsView *view);
126
static gboolean thunar_shortcuts_view_separator_func (GtkTreeModel *model,
66
static void thunar_shortcuts_view_finalize (GObject *object);
67
static gboolean thunar_shortcuts_view_button_press_event (GtkWidget *widget,
68
GdkEventButton *event);
69
static gboolean thunar_shortcuts_view_button_release_event (GtkWidget *widget,
70
GdkEventButton *event);
71
static void thunar_shortcuts_view_drag_begin (GtkWidget *widget,
72
GdkDragContext *context);
73
static void thunar_shortcuts_view_drag_data_received (GtkWidget *widget,
74
GdkDragContext *context,
77
GtkSelectionData *selection_data,
80
static gboolean thunar_shortcuts_view_drag_drop (GtkWidget *widget,
81
GdkDragContext *context,
85
static gboolean thunar_shortcuts_view_drag_motion (GtkWidget *widget,
86
GdkDragContext *context,
90
static void thunar_shortcuts_view_drag_leave (GtkWidget *widget,
91
GdkDragContext *context,
93
static gboolean thunar_shortcuts_view_popup_menu (GtkWidget *widget);
94
static void thunar_shortcuts_view_row_activated (GtkTreeView *tree_view,
96
GtkTreeViewColumn *column);
97
static void thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
98
GdkEventButton *event,
101
static void thunar_shortcuts_view_remove_activated (GtkWidget *item,
102
ThunarShortcutsView *view);
103
static void thunar_shortcuts_view_rename_activated (GtkWidget *item,
104
ThunarShortcutsView *view);
105
static void thunar_shortcuts_view_renamed (GtkCellRenderer *renderer,
106
const gchar *path_string,
108
ThunarShortcutsView *view);
109
static GdkDragAction thunar_shortcuts_view_compute_drop_actions (ThunarShortcutsView *view,
110
GdkDragContext *context,
113
GtkTreePath **path_return,
114
GdkDragAction *action_return,
115
GtkTreeViewDropPosition *position_return);
116
static GtkTreePath *thunar_shortcuts_view_compute_drop_position (ThunarShortcutsView *view,
119
static void thunar_shortcuts_view_drop_uri_list (ThunarShortcutsView *view,
121
GtkTreePath *dst_path);
122
static void thunar_shortcuts_view_open_clicked (ThunarShortcutsView *view);
123
static void thunar_shortcuts_view_open (ThunarShortcutsView *view,
124
gboolean new_window);
125
static void thunar_shortcuts_view_open_in_new_window_clicked (ThunarShortcutsView *view);
126
static void thunar_shortcuts_view_empty_trash (ThunarShortcutsView *view);
127
static void thunar_shortcuts_view_eject (ThunarShortcutsView *view);
128
static void thunar_shortcuts_view_mount (ThunarShortcutsView *view);
129
static gboolean thunar_shortcuts_view_separator_func (GtkTreeModel *model,
179
static GObjectClass *thunar_shortcuts_view_parent_class;
180
static guint view_signals[LAST_SIGNAL];
185
thunar_shortcuts_view_get_type (void)
187
static GType type = G_TYPE_INVALID;
189
if (G_UNLIKELY (type == G_TYPE_INVALID))
191
static const GTypeInfo info =
193
sizeof (ThunarShortcutsViewClass),
196
(GClassInitFunc) thunar_shortcuts_view_class_init,
199
sizeof (ThunarShortcutsView),
201
(GInstanceInitFunc) thunar_shortcuts_view_init,
205
type = g_type_register_static (GTK_TYPE_TREE_VIEW, I_("ThunarShortcutsView"), &info, 0);
181
static guint view_signals[LAST_SIGNAL];
185
G_DEFINE_TYPE_WITH_CODE (ThunarShortcutsView, thunar_shortcuts_view, GTK_TYPE_TREE_VIEW,
186
G_IMPLEMENT_INTERFACE (THUNAR_TYPE_BROWSER, NULL))
393
374
else if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS
394
375
&& (event->state & gtk_accelerator_get_default_mod_mask ()) == 0)
377
/* check if we clicked the eject button area */
378
gint icon_width, icon_height, column_width;
379
column_width = gtk_tree_view_column_get_width (gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0));
380
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
381
if (event->x >= column_width - icon_width - 3)
383
/* check if that shortcut actually has an eject button */
384
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
385
if (gtk_tree_model_get_iter (model, &iter, path))
387
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT, &eject_icon, -1);
388
if (strlen (eject_icon) > 0)
389
view->pressed_eject_button = 1;
395
g_debug("thunar_shortcuts_view_button_press_event(): x: %f, y: %f; my width: %i, eject width: %i, eject: %i",
396
event->x, event->y, column_width, icon_width, view->pressed_eject_button);
396
399
/* remember the button as pressed and handle it in the release handler */
397
400
view->pressed_button = event->button;
400
405
/* release the path */
415
420
/* check if we have an event matching the pressed button state */
416
421
if (G_LIKELY (view->pressed_button == (gint) event->button))
423
if (view->pressed_eject_button)
424
thunar_shortcuts_view_eject (view);
418
426
/* check if we should simply open or open in new window */
419
427
if (G_LIKELY (event->button == 1))
420
thunar_shortcuts_view_open (view);
428
thunar_shortcuts_view_open (view, FALSE);
421
429
else if (G_UNLIKELY (event->button == 2))
422
thunar_shortcuts_view_open_in_new_window (view);
430
thunar_shortcuts_view_open (view, TRUE);
425
433
/* reset the pressed button state */
426
434
view->pressed_button = -1;
435
view->pressed_eject_button = 0;
428
437
/* call the parent's release event handler */
429
438
return (*GTK_WIDGET_CLASS (thunar_shortcuts_view_parent_class)->button_release_event) (widget, event);
1202
1200
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1203
1201
for (lp = path_list; lp != NULL; lp = lp->next)
1205
file = thunar_file_get_for_path (lp->data, &error);
1203
file = thunar_file_get (lp->data, &error);
1206
1204
if (G_UNLIKELY (file == NULL))
1209
1207
/* make sure, that only directories gets added to the shortcuts list */
1210
1208
if (G_UNLIKELY (!thunar_file_is_directory (file)))
1212
uri_string = thunar_vfs_path_dup_string (lp->data);
1213
display_string = g_filename_display_name (uri_string);
1214
1210
g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR,
1215
1211
_("The path \"%s\" does not refer to a directory"),
1217
g_object_unref (G_OBJECT (file));
1218
g_free (display_string);
1219
g_free (uri_string);
1212
thunar_file_get_display_name (file));
1213
g_object_unref (file);
1223
1217
thunar_shortcuts_model_add (THUNAR_SHORTCUTS_MODEL (model), path, file);
1224
g_object_unref (G_OBJECT (file));
1218
g_object_unref (file);
1225
1219
gtk_tree_path_next (path);
1244
thunar_shortcuts_view_open (ThunarShortcutsView *view)
1238
thunar_shortcuts_view_open_clicked (ThunarShortcutsView *view)
1240
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1241
thunar_shortcuts_view_open (view, FALSE);
1247
thunar_shortcuts_view_poke_file_finish (ThunarBrowser *browser,
1249
ThunarFile *target_file,
1253
ThunarApplication *application;
1254
gboolean new_window = GPOINTER_TO_UINT (user_data);
1256
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
1257
_thunar_return_if_fail (THUNAR_IS_FILE (file));
1263
/* open a new window for the target folder */
1264
application = thunar_application_get ();
1265
thunar_application_open_window (application, target_file,
1266
gtk_widget_get_screen (GTK_WIDGET (browser)), NULL);
1267
g_object_unref (application);
1271
/* invoke the signal to change to that folder */
1272
g_signal_emit (browser, view_signals[SHORTCUT_ACTIVATED], 0, target_file);
1277
thunar_dialogs_show_error (GTK_WIDGET (browser), error, _("Failed to open \"%s\""),
1278
thunar_file_get_display_name (file));
1285
thunar_shortcuts_view_poke_volume_finish (ThunarBrowser *browser,
1287
ThunarFile *mount_point,
1291
gboolean new_window = GPOINTER_TO_UINT (user_data);
1294
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
1295
_thunar_return_if_fail (G_IS_VOLUME (volume));
1299
thunar_browser_poke_file (browser, mount_point, GTK_WIDGET (browser),
1300
thunar_shortcuts_view_poke_file_finish,
1301
GUINT_TO_POINTER (new_window));
1305
volume_name = g_volume_get_name (volume);
1306
thunar_dialogs_show_error (GTK_WIDGET (browser), error,
1307
_("Failed to mount \"%s\""), volume_name);
1308
g_free (volume_name);
1315
thunar_shortcuts_view_open (ThunarShortcutsView *view,
1316
gboolean new_window)
1246
1318
GtkTreeSelection *selection;
1247
1319
GtkTreeModel *model;
1248
1320
GtkTreeIter iter;
1249
1321
ThunarFile *file;
1251
1324
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1253
/* make sure to mount the volume first (if it's a volume) */
1254
if (!thunar_shortcuts_view_mount (view))
1257
1326
/* determine the selected item */
1258
1327
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1329
/* avoid dealing with invalid selections */
1330
if (!GTK_IS_TREE_SELECTION (selection))
1259
1333
if (gtk_tree_selection_get_selected (selection, &model, &iter))
1261
1335
/* determine the file for the shortcut at the given tree iterator */
1262
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, -1);
1263
if (G_LIKELY (file != NULL))
1265
/* invoke the signal to change to that folder */
1266
g_signal_emit (G_OBJECT (view), view_signals[SHORTCUT_ACTIVATED], 0, file);
1267
g_object_unref (G_OBJECT (file));
1336
gtk_tree_model_get (model, &iter,
1337
THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file,
1338
THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume,
1341
if (G_LIKELY (volume != NULL))
1343
thunar_browser_poke_volume (THUNAR_BROWSER (view), volume, view,
1344
thunar_shortcuts_view_poke_volume_finish,
1345
GUINT_TO_POINTER (new_window));
1347
else if (file != NULL)
1349
thunar_browser_poke_file (THUNAR_BROWSER (view), file, view,
1350
thunar_shortcuts_view_poke_file_finish,
1351
GUINT_TO_POINTER (new_window));
1355
g_object_unref (file);
1358
g_object_unref (volume);
1275
thunar_shortcuts_view_open_in_new_window (ThunarShortcutsView *view)
1365
thunar_shortcuts_view_open_in_new_window_clicked (ThunarShortcutsView *view)
1277
ThunarApplication *application;
1278
GtkTreeSelection *selection;
1279
GtkTreeModel *model;
1283
1367
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1285
/* make sure to mount the volume first (if it's a volume) */
1286
if (!thunar_shortcuts_view_mount (view))
1289
/* determine the selected item */
1290
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1291
if (gtk_tree_selection_get_selected (selection, &model, &iter))
1293
/* determine the file for the shortcut at the given tree iterator */
1294
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, -1);
1295
if (G_LIKELY (file != NULL))
1297
/* open a new window for the shortcut target folder */
1298
application = thunar_application_get ();
1299
thunar_application_open_window (application, file, gtk_widget_get_screen (GTK_WIDGET (view)));
1300
g_object_unref (G_OBJECT (application));
1301
g_object_unref (G_OBJECT (file));
1368
thunar_shortcuts_view_open (view, TRUE);
1315
1380
/* empty the trash bin (asking the user first) */
1316
1381
application = thunar_application_get ();
1317
thunar_application_empty_trash (application, GTK_WIDGET (view));
1382
thunar_application_empty_trash (application, GTK_WIDGET (view), NULL);
1318
1383
g_object_unref (G_OBJECT (application));
1389
thunar_shortcuts_view_eject_finish (GObject *object,
1390
GAsyncResult *result,
1393
ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
1395
GVolume *volume = G_VOLUME (object);
1396
GError *error = NULL;
1399
_thunar_return_if_fail (G_IS_VOLUME (object));
1400
_thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
1401
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1403
/* check if there was an error */
1404
if (!g_volume_eject_finish (volume, result, &error))
1406
/* ignore GIO errors already handled */
1407
if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
1409
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
1411
/* display an error dialog to inform the user */
1412
volume_name = g_volume_get_name (volume);
1413
thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), volume_name);
1414
g_free (volume_name);
1416
g_error_free (error);
1420
#ifdef HAVE_LIBNOTIFY
1421
thunar_notify_eject_finish (volume);
1424
g_object_unref (view);
1430
thunar_shortcuts_view_unmount_finish (GObject *object,
1431
GAsyncResult *result,
1434
ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
1436
GMount *mount = G_MOUNT (object);
1437
GError *error = NULL;
1440
_thunar_return_if_fail (G_IS_MOUNT (object));
1441
_thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
1442
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1444
/* check if there was an error */
1445
if (!g_mount_unmount_finish (mount, result, &error))
1447
/* ignore GIO errors already handled */
1448
if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
1450
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
1452
/* display an error dialog to inform the user */
1453
mount_name = g_mount_get_name (mount);
1454
thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), mount_name);
1455
g_free (mount_name);
1457
g_error_free (error);
1461
#ifdef HAVE_LIBNOTIFY
1462
thunar_notify_unmount_finish (mount);
1465
g_object_unref (view);
1324
1471
thunar_shortcuts_view_eject (ThunarShortcutsView *view)
1326
1473
GtkTreeSelection *selection;
1327
ThunarVfsVolume *volume;
1328
1474
GtkTreeModel *model;
1329
1475
GtkTreeIter iter;
1331
gboolean result = TRUE;
1332
GError *error = NULL;
1334
_thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
1479
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1336
1481
/* determine the selected item */
1337
1482
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1341
1486
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
1342
1487
if (G_UNLIKELY (volume != NULL))
1344
/* determine the toplevel window */
1345
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
1347
/* try to eject the volume */
1348
result = thunar_vfs_volume_eject (volume, window, &error);
1349
if (G_UNLIKELY (!result))
1351
/* display an error dialog to inform the user */
1352
thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), thunar_vfs_volume_get_name (volume));
1353
g_error_free (error);
1489
/* determine what the appropriate method is: eject or unmount */
1490
if (g_volume_can_eject (volume))
1492
#ifdef HAVE_LIBNOTIFY
1493
thunar_notify_eject (volume);
1496
/* try to to eject the volume asynchronously */
1497
g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL,
1498
thunar_shortcuts_view_eject_finish,
1499
g_object_ref (view));
1503
/* determine the mount of the volume */
1504
mount = g_volume_get_mount (volume);
1505
if (G_LIKELY (mount != NULL))
1507
#ifdef HAVE_LIBNOTIFY
1508
thunar_notify_unmount (mount);
1511
/* the volume is mounted, try to unmount the mount */
1512
g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
1513
thunar_shortcuts_view_unmount_finish,
1514
g_object_ref (view));
1516
/* release the mount */
1517
g_object_unref (mount);
1357
g_object_unref (G_OBJECT (volume));
1522
g_object_unref (volume);
1530
thunar_shortcuts_view_poke_volume_mount_finish (ThunarBrowser *browser,
1532
ThunarFile *mount_point,
1538
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
1539
_thunar_return_if_fail (G_IS_VOLUME (volume));
1543
volume_name = g_volume_get_name (volume);
1544
thunar_dialogs_show_error (GTK_WIDGET (browser), error,
1545
_("Failed to mount \"%s\""), volume_name);
1546
g_free (volume_name);
1367
1554
thunar_shortcuts_view_mount (ThunarShortcutsView *view)
1369
1556
GtkTreeSelection *selection;
1370
ThunarVfsVolume *volume;
1371
GtkTreeModel *model;
1374
gboolean result = TRUE;
1375
GError *error = NULL;
1377
_thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
1379
/* determine the selected item */
1380
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1381
if (gtk_tree_selection_get_selected (selection, &model, &iter))
1383
/* determine the volume for the shortcut at the given tree iterator */
1384
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
1385
if (G_UNLIKELY (volume != NULL))
1387
/* check if the volume isn't already mounted */
1388
if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume)))
1390
/* determine the toplevel window */
1391
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
1393
/* try to mount the volume */
1394
result = thunar_vfs_volume_mount (volume, window, &error);
1395
if (G_UNLIKELY (!result))
1397
/* display an error dialog to inform the user */
1398
thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume));
1399
g_error_free (error);
1404
g_object_unref (G_OBJECT (volume));
1414
thunar_shortcuts_view_unmount (ThunarShortcutsView *view)
1416
GtkTreeSelection *selection;
1417
ThunarVfsVolume *volume;
1418
GtkTreeModel *model;
1421
gboolean result = TRUE;
1422
GError *error = NULL;
1424
_thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
1426
/* determine the selected item */
1427
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1428
if (gtk_tree_selection_get_selected (selection, &model, &iter))
1430
/* determine the volume for the shortcut at the given tree iterator */
1431
gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
1432
if (G_UNLIKELY (volume != NULL))
1434
/* determine the toplevel window */
1435
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
1437
/* try to unmount the volume */
1438
result = thunar_vfs_volume_unmount (volume, window, &error);
1439
if (G_UNLIKELY (!result))
1441
/* display an error dialog to inform the user */
1442
thunar_dialogs_show_error (window, error, _("Failed to unmount \"%s\""), thunar_vfs_volume_get_name (volume));
1443
g_error_free (error);
1447
g_object_unref (G_OBJECT (volume));
1557
GtkTreeModel *model;
1561
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
1563
/* determine the selected item */
1564
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1566
/* avoid dealing with invalid selections */
1567
if (!GTK_IS_TREE_SELECTION (selection))
1570
if (gtk_tree_selection_get_selected (selection, &model, &iter))
1572
/* determine the file for the shortcut at the given tree iterator */
1573
gtk_tree_model_get (model, &iter,
1574
THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume,
1577
if (G_LIKELY (volume != NULL))
1579
thunar_browser_poke_volume (THUNAR_BROWSER (view), volume, view,
1580
thunar_shortcuts_view_poke_volume_mount_finish,
1582
g_object_unref (volume);