[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Finish implementing the mount/unmount/disconnect context menu actions.

Jannis Pohlmann noreply at xfce.org
Fri Jul 15 21:10:41 CEST 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to d9168021dafd9346401d507e0d844c279479e74c (commit)
       from 1a525b93f6564443c3170eac256601f7f1e984b3 (commit)

commit d9168021dafd9346401d507e0d844c279479e74c
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Jun 14 22:10:16 2011 +0200

    Finish implementing the mount/unmount/disconnect context menu actions.
    
    Mounts only have a "Disconnect" item that unmounts or ejects the mount
    and makes it disappear from the side pane.
    
    Mounted volumes have an "Unmount" context menu item that can be used
    to unmount the volume but have it remain visible in the shortcuts pane
    (unlike in current versions of Thunar). Volumes also have a "Disconnect"
    icon if, and only if, they or their mounts can be ejected (there's a
    difference between unmount and eject in the GIO API, so that's why).
    
    The eject button will always eject and hide the entire mount or device.
    
    I am not sure this will remain the way it is now but for now this shall
    do.

 thunar/thunar-shortcut-row.c   |   59 +++++++++++++++++++++++++++-------------
 thunar/thunar-shortcuts-view.c |   16 +++++++---
 2 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index ae98671..012ca37 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -123,6 +123,9 @@ static void     thunar_shortcut_row_mount_unmount_finish  (GObject
 static void     thunar_shortcut_row_mount_eject_finish    (GObject               *object,
                                                            GAsyncResult          *result,
                                                            gpointer               user_data);
+static void     thunar_shortcut_row_volume_eject_finish   (GObject               *object,
+                                                           GAsyncResult          *result,
+                                                           gpointer               user_data);
 static void     thunar_shortcut_row_poke_volume_finish    (ThunarBrowser         *browser,
                                                            GVolume               *volume,
                                                            ThunarFile            *file,
@@ -946,6 +949,33 @@ thunar_shortcut_row_mount_eject_finish (GObject      *object,
 
 
 static void
+thunar_shortcut_row_volume_eject_finish (GObject      *object,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  ThunarShortcutRow *row = THUNAR_SHORTCUT_ROW (user_data);
+  GVolume           *volume = G_VOLUME (object);
+  GError            *error = NULL;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+  _thunar_return_if_fail (G_IS_VOLUME (volume));
+  _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
+
+  if (!g_volume_eject_with_operation_finish (volume, result, &error))
+    {
+      thunar_dialogs_show_error (GTK_WIDGET (row), error,
+                                 _("Failed to eject \"%s\""),
+                                 row->label);
+      g_error_free (error);
+    }
+
+  /* stop spinning */
+  thunar_shortcut_row_set_spinning (row, FALSE, THUNAR_SHORTCUT_ROW_NORMAL);
+}
+
+
+
+static void
 thunar_shortcut_row_poke_volume_finish (ThunarBrowser *browser,
                                         GVolume       *volume,
                                         ThunarFile    *file,
@@ -1697,30 +1727,21 @@ thunar_shortcut_row_disconnect (ThunarShortcutRow *row)
                                         thunar_shortcut_row_mount_eject_finish,
                                         row);
         }
-      else 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
-        {
-          /* something is out of sync... */
-        }
     }
   else if (row->volume != NULL)
     {
       if (g_volume_can_eject (row->volume))
         {
-          /* try to eject the volume */
-          g_debug ("trying to eject the volume");
+          /* start spinning */
+          thunar_shortcut_row_set_spinning (row, TRUE, THUNAR_SHORTCUT_ROW_EJECTING);
+
+          /* try ejecting the volume */
+          g_volume_eject_with_operation (row->volume,
+                                         G_MOUNT_UNMOUNT_NONE,
+                                         mount_operation,
+                                         row->cancellable,
+                                         thunar_shortcut_row_volume_eject_finish,
+                                         row);
         }
       else
         {
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index e34859b..5938ebd 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -688,6 +688,7 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView *view,
   GtkWidget         *menu;
   GtkWidget         *window;
   GVolume           *volume;
+  GMount            *mount;
   GList             *lp;
   GList             *providers;
   GList             *actions = NULL;
@@ -748,13 +749,13 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView *view,
   if (shortcut_type == THUNAR_SHORTCUT_REGULAR_VOLUME
       || shortcut_type == THUNAR_SHORTCUT_EJECTABLE_VOLUME)
     {
-      /* get the volume from the shortcut row */
+      /* get the volume and mount from the shortcut row */
       volume = thunar_shortcut_row_get_volume (row);
+      mount = g_volume_get_mount (volume);
       
-      /* check if we have a mounted volume */
       /* append the "Mount" item */
       item = gtk_image_menu_item_new_with_mnemonic (_("_Mount"));
-      gtk_widget_set_sensitive (item, !thunar_g_volume_is_mounted (volume));
+      gtk_widget_set_sensitive (item, mount == NULL && g_volume_can_mount (volume));
       g_signal_connect_swapped (item, "activate",
                                 G_CALLBACK (thunar_shortcuts_view_row_mount),
                                 view);
@@ -765,7 +766,7 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView *view,
         {
           /* append the "Unmount" item */
           item = gtk_image_menu_item_new_with_mnemonic (_("_Unmount"));
-          gtk_widget_set_sensitive (item, thunar_g_volume_is_mounted (volume));
+          gtk_widget_set_sensitive (item, mount != NULL && g_mount_can_unmount (mount));
           g_signal_connect_swapped (item, "activate",
                                     G_CALLBACK (thunar_shortcuts_view_row_unmount),
                                     view);
@@ -775,12 +776,17 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView *view,
 
       /* append the "Disconnect" (eject + safely remove drive) item */
       item = gtk_image_menu_item_new_with_mnemonic (_("Disconn_ect"));
-      gtk_widget_set_sensitive (item, thunar_g_volume_is_mounted (volume));
+      gtk_widget_set_sensitive (item, 
+                                (mount != NULL && g_mount_can_eject (mount))
+                                || g_volume_can_eject (volume));
       g_signal_connect_swapped (item, "activate",
                                 G_CALLBACK (thunar_shortcuts_view_row_disconnect),
                                 view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
+
+      if (mount != NULL)
+        g_object_unref (mount);
     }
 
   /* get the ThunarFile from the row */



More information about the Xfce4-commits mailing list