[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Implement the disconnect context menu action for mounts.
Jannis Pohlmann
noreply at xfce.org
Mon Jun 13 22:28:01 CEST 2011
Updating branch refs/heads/jannis/new-shortcuts-pane
to 1fe553082e87442099f2750a90fa6d10b6e3d8c4 (commit)
from 9da6496af47367ce9b8b8638188b52c2ba7122f8 (commit)
commit 1fe553082e87442099f2750a90fa6d10b6e3d8c4
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Sun Jun 12 23:47:56 2011 +0200
Implement the disconnect context menu action for mounts.
thunar/thunar-shortcut-row.c | 62 ++++++++++++++++++++++++++++++++++++++++
thunar/thunar-shortcut-row.h | 1 +
thunar/thunar-shortcuts-view.c | 19 ++++++++++++
3 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index 756fb79..504d861 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -1662,3 +1662,65 @@ thunar_shortcut_row_set_icon_size (ThunarShortcutRow *row,
g_object_notify (G_OBJECT (row), "icon-size");
}
+
+
+
+void
+thunar_shortcut_row_disconnect_mount (ThunarShortcutRow *row)
+{
+ GMountOperation *mount_operation;
+ GtkWidget *toplevel;
+
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+ _thunar_return_if_fail (row->shortcut_type == THUNAR_SHORTCUT_STANDALONE_MOUNT);
+
+ if (row->shortcut_type != THUNAR_SHORTCUT_STANDALONE_MOUNT)
+ return;
+
+ if (row->mount == NULL)
+ {
+ /* something is out of sync */
+ return;
+ }
+
+ /* create a mount operation */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (row));
+ mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+ gtk_mount_operation_set_screen (GTK_MOUNT_OPERATION (mount_operation),
+ gtk_widget_get_screen (GTK_WIDGET (row)));
+
+ /* distinguish between mountable and ejectable mounts */
+ if (g_mount_can_unmount (row->mount))
+ {
+ /* start spinning */
+ thunar_shortcut_row_set_spinning (row, TRUE, THUNAR_SHORTCUT_ROW_EJECTING);
+
+ /* try unmounting the mount */
+ g_mount_unmount_with_operation (row->mount,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_operation,
+ row->cancellable,
+ thunar_shortcut_row_mount_unmount_finish,
+ row);
+ }
+ else if (g_mount_can_eject (row->mount))
+ {
+ /* start spinning */
+ thunar_shortcut_row_set_spinning (row, TRUE, THUNAR_SHORTCUT_ROW_EJECTING);
+
+ /* try ejecting the mount */
+ g_mount_eject_with_operation (row->mount,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_operation,
+ row->cancellable,
+ thunar_shortcut_row_mount_eject_finish,
+ row);
+ }
+ else
+ {
+ /* something is out of sync... */
+ }
+
+ /* release the mount operation */
+ g_object_unref (mount_operation);
+}
diff --git a/thunar/thunar-shortcut-row.h b/thunar/thunar-shortcut-row.h
index f69b1f5..e114fec 100644
--- a/thunar/thunar-shortcut-row.h
+++ b/thunar/thunar-shortcut-row.h
@@ -64,6 +64,7 @@ void thunar_shortcut_row_set_icon_size (ThunarShortcutRow *
ThunarIconSize icon_size);
void thunar_shortcut_row_resolve_and_activate (ThunarShortcutRow *row,
gboolean open_in_new_window);
+void thunar_shortcut_row_disconnect_mount (ThunarShortcutRow *row);
G_END_DECLS
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index fcba86f..bf2b7a9 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -108,6 +108,7 @@ static gboolean thunar_shortcuts_view_row_context_menu (Thunar
GtkWidget *widget);
static void thunar_shortcuts_view_row_open (ThunarShortcutsView *view);
static void thunar_shortcuts_view_row_open_new_window (ThunarShortcutsView *view);
+static void thunar_shortcuts_view_row_disconnect_mount (ThunarShortcutsView *view);
static void thunar_shortcuts_view_open (ThunarShortcutsView *view,
ThunarFile *file,
gboolean new_window);
@@ -729,6 +730,9 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView *view,
{
/* append the "Disconnect" item */
item = gtk_image_menu_item_new_with_mnemonic (_("Disconn_ect"));
+ g_signal_connect_swapped (item, "activate",
+ G_CALLBACK (thunar_shortcuts_view_row_disconnect_mount),
+ view);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
@@ -897,6 +901,21 @@ thunar_shortcuts_view_row_open_new_window (ThunarShortcutsView *view)
+static void
+thunar_shortcuts_view_row_disconnect_mount (ThunarShortcutsView *view)
+{
+ ThunarShortcutRow *row;
+
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+ row = thunar_shortcuts_view_get_selected_row (view);
+
+ if (row != NULL)
+ thunar_shortcut_row_disconnect_mount (row);
+}
+
+
+
static ThunarShortcutRow *
thunar_shortcuts_view_get_selected_row (ThunarShortcutsView *view)
{
More information about the Xfce4-commits
mailing list