Am 23.02.2011 08:04, schrieb Yves-Alexis Perez:
On Tue, 2011-02-22 at 17:42 +0100, Harald Judt wrote:
I do not want that; I want the USB flash drive in my list as long as it
is physically attached to the computer. "Eject" is wrong here anyway,
you can't eject it like you can a CD or DVD. How can I revert this
annoying behaviour?

Note that eject does make sense for some usb devices. First, that means
it unmounts all the partitions at once and it stops the power. Secondly,
in some cases (“smart” devices like media player, phones etc.) it's
required to eject and not just unmount.

Ok, you're right, so for _some_ usb devices it does make sense. I used udisks --show-info to investigate some hardware:

Behold:
USB flash drive
    ejectable:                 0
Sansa fuze media player:
    ejectable:                 0
DVD drive:
    ejectable:                 1

So udisks reports it is not ejectable, yet I can eject it because it is removable.

-----
http://hal.freedesktop.org/docs/udisks/udisks.7.html
ID_DRIVE_EJECTABLE:
Whether the media in the drive is physically ejectable. Only set this to 1 (or 0) if the drive truly uses (or doesn't) ejectable media. In particular, it is not necessary to set this for e.g. iPod or Kindle devices where it is necessary to send a command via eject(1) since the desktop user session will offer this option for removable devices regardless of whether they are ejectable. If this property is not set, a heuristic will be used to determine if the media is ejectable (drives using optical, Zip or Jaz media are considered ejectable).
-----

Great, let the others deal with it. I guess "smart" devices etc. don't set "ejectable" to the right value (that would be 1), do they? Will they leave it undefined? I wonder whether thunar could use this property in a better way to decide between ejectable or simply unmount-able. Are there reasons not to do so?

Anyway, I've patched thunar to reactivate the unmount action for both the tree view and the shortcut view. As most of the code is already in place, this was not very difficult, I just had to do a little copy & paste here and there. It adds another entry to the context menu, but does not remove the eject entry. While it's just a hack, duplicates some code, contains unnecessary checks or misses some and therefore is certainly improvable, I'll still attach it to the mail for those who are interested.

Regards,
Harald

--
`Experience is the best teacher.'
diff -Naur Thunar-1.3.0~/po/de.po Thunar-1.3.0/po/de.po
--- Thunar-1.3.0~/po/de.po      2011-01-30 19:37:06.000000000 +0100
+++ Thunar-1.3.0/po/de.po       2011-02-23 15:50:19.852630698 +0100
@@ -2032,6 +2032,11 @@
 msgid "_Mount Volume"
 msgstr "Datenträger _einhängen"
 
+#. append the "Unmount Volume" menu action
+#: ../thunar/thunar-shortcuts-view.c:861 ../thunar/thunar-tree-view.c:1131
+msgid "_Unmount Volume"
+msgstr "Datenträger a_ushängen"
+
 #. append the "Eject Volume" menu action
 #: ../thunar/thunar-shortcuts-view.c:861 ../thunar/thunar-tree-view.c:1131
 msgid "E_ject Volume"
@@ -3675,9 +3680,6 @@
 #~ "Unterstützung für HAL fehlt in thunar-vfs, die\n"
 #~ "Datenträgerverwaltung kann nicht benutzt werden."
 
-#~ msgid "_Unmount Volume"
-#~ msgstr "Datenträger _aushängen"
-
 #~ msgid "Failed to unmount \"%s\""
 #~ msgstr "Der Datenträger »%s« konnte nicht ausgehangen werden"
 
diff -Naur Thunar-1.3.0~/po/en_GB.po Thunar-1.3.0/po/en_GB.po
--- Thunar-1.3.0~/po/en_GB.po   2011-01-30 19:37:06.000000000 +0100
+++ Thunar-1.3.0/po/en_GB.po    2011-02-23 15:48:34.340949776 +0100
@@ -1992,6 +1992,11 @@
 msgid "_Mount Volume"
 msgstr "_Mount Volume"
 
+#. append the "Unmount Volume" menu action
+#: ../thunar/thunar-shortcuts-view.c:861 ../thunar/thunar-tree-view.c:1131
+msgid "_Unmount Volume"
+msgstr "_Unmount Volume"
+
 #. append the "Eject Volume" menu action
 #: ../thunar/thunar-shortcuts-view.c:861 ../thunar/thunar-tree-view.c:1131
 msgid "E_ject Volume"
diff -Naur Thunar-1.3.0~/thunar/thunar-gio-extensions.c 
Thunar-1.3.0/thunar/thunar-gio-extensions.c
--- Thunar-1.3.0~/thunar/thunar-gio-extensions.c        2010-12-06 
10:31:04.000000000 +0100
+++ Thunar-1.3.0/thunar/thunar-gio-extensions.c 2011-02-23 14:35:51.402494011 
+0100
@@ -515,7 +515,30 @@
   return (!is_internal) && (can_eject || can_unmount || is_removable || 
can_mount);
 }
 
+gboolean
+thunar_g_volume_is_unmountable (GVolume *volume)
+{
+  gboolean         can_unmount = FALSE;
+  gboolean         is_internal = FALSE;
+  GMount          *mount;
+
+  /* determine the mount for the volume (if it is mounted at all) */
+  mount = g_volume_get_mount (volume);
+  if (mount != NULL)
+    {
+#ifdef HAVE_GIO_UNIX
+      is_internal = thunar_g_mount_is_internal (mount);
+#endif
+
+      /* check if the volume can be unmounted */
+      can_unmount = g_mount_can_unmount (mount);
 
+      /* release the mount */
+      g_object_unref (mount);
+    }
+
+  return can_unmount;
+}
 
 gboolean
 thunar_g_volume_is_mounted (GVolume *volume)
diff -Naur Thunar-1.3.0~/thunar/thunar-gio-extensions.h 
Thunar-1.3.0/thunar/thunar-gio-extensions.h
--- Thunar-1.3.0~/thunar/thunar-gio-extensions.h        2010-12-04 
16:23:16.000000000 +0100
+++ Thunar-1.3.0/thunar/thunar-gio-extensions.h 2011-02-23 13:33:34.408212871 
+0100
@@ -68,6 +68,7 @@
 void      thunar_g_file_list_free                   (GList             *list);
 
 gboolean  thunar_g_volume_is_removable              (GVolume           
*volume);
+gboolean  thunar_g_volume_is_unmountable            (GVolume           
*volume);
 gboolean  thunar_g_volume_is_mounted                (GVolume           
*volume);
 gboolean  thunar_g_volume_is_present                (GVolume           
*volume);
 
diff -Naur Thunar-1.3.0~/thunar/thunar-shortcuts-view.c 
Thunar-1.3.0/thunar/thunar-shortcuts-view.c
--- Thunar-1.3.0~/thunar/thunar-shortcuts-view.c        2011-01-10 
22:27:01.000000000 +0100
+++ Thunar-1.3.0/thunar/thunar-shortcuts-view.c 2011-02-23 15:43:07.921030586 
+0100
@@ -125,6 +125,7 @@
 static void           thunar_shortcuts_view_open_in_new_window_clicked   
(ThunarShortcutsView      *view);
 static void           thunar_shortcuts_view_empty_trash                  
(ThunarShortcutsView      *view);
 static void           thunar_shortcuts_view_eject                        
(ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_unmount                      
(ThunarShortcutsView      *view);
 static void           thunar_shortcuts_view_mount                        
(ThunarShortcutsView      *view);
 static gboolean       thunar_shortcuts_view_separator_func               
(GtkTreeModel             *model,
                                                                           
GtkTreeIter              *iter,
@@ -857,6 +858,15 @@
       /* check if the volume is present and can be ejected */
       if (thunar_g_volume_is_present (volume) && thunar_g_volume_is_removable 
(volume))
         {
+          /* append the "Unmount Volume" menu action */
+                       if (thunar_g_volume_is_unmountable (volume))
+                         {
+                               item = gtk_image_menu_item_new_with_mnemonic 
(_("_Unmount Volume"));
+                               g_signal_connect_swapped (G_OBJECT (item), 
"activate", G_CALLBACK (thunar_shortcuts_view_unmount), view);
+                               gtk_menu_shell_append (GTK_MENU_SHELL (menu), 
item);
+                               gtk_widget_show (item);
+                         }
+
           /* append the "Eject Volume" menu action */
           item = gtk_image_menu_item_new_with_mnemonic (_("E_ject Volume"));
           g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK 
(thunar_shortcuts_view_eject), view);
@@ -1520,6 +1530,50 @@
 
           /* cleanup */
           g_object_unref (volume);
+        }
+    }
+}
+
+
+
+static void
+thunar_shortcuts_view_unmount (ThunarShortcutsView *view)
+{
+  GtkTreeSelection *selection;
+  GtkTreeModel     *model;
+  GtkTreeIter       iter;
+  GVolume          *volume;
+  GMount           *mount;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  /* determine the selected item */
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+  if (gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      /* determine the volume for the shortcut at the given tree iterator */
+      gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, 
&volume, -1);
+      if (G_UNLIKELY (volume != NULL))
+        {
+              /* determine the mount of the volume */
+              mount = g_volume_get_mount (volume);
+              if (G_LIKELY (mount != NULL))
+                {
+#ifdef HAVE_LIBNOTIFY
+                  thunar_notify_unmount (mount);
+#endif
+
+                  /* the volume is mounted, try to unmount the mount */
+                  g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
+                                   thunar_shortcuts_view_unmount_finish, 
+                                   g_object_ref (view));
+
+                  /* release the mount */
+                  g_object_unref (mount);
+                }
+
+          /* cleanup */
+          g_object_unref (volume);
         }
     }
 }
diff -Naur Thunar-1.3.0~/thunar/thunar-tree-view.c 
Thunar-1.3.0/thunar/thunar-tree-view.c
--- Thunar-1.3.0~/thunar/thunar-tree-view.c     2011-01-26 22:58:54.000000000 
+0100
+++ Thunar-1.3.0/thunar/thunar-tree-view.c      2011-02-23 15:37:28.021279919 
+0100
@@ -151,6 +151,7 @@
 static void                     thunar_tree_view_action_delete                
(ThunarTreeView          *view);
 static void                     thunar_tree_view_action_rename                
(ThunarTreeView          *view);
 static void                     thunar_tree_view_action_eject                 
(ThunarTreeView          *view);
+static void                     thunar_tree_view_action_unmount               
(ThunarTreeView          *view);
 static void                     thunar_tree_view_action_empty_trash           
(ThunarTreeView          *view);
 static void                     thunar_tree_view_action_mount                 
(ThunarTreeView          *view);
 static void                     thunar_tree_view_mount_finish                 
(GObject                 *object,
@@ -1127,6 +1128,15 @@
       /* check if the volume is present and can be ejected */
       if (thunar_g_volume_is_present (volume) && thunar_g_volume_is_removable 
(volume))
         {
+          /* append the "Unmount Volume" menu action */
+                       if (thunar_g_volume_is_unmountable (volume))
+                         {
+                               item = gtk_image_menu_item_new_with_mnemonic 
(_("_Unmount Volume"));
+                               g_signal_connect_swapped (G_OBJECT (item), 
"activate", G_CALLBACK (thunar_tree_view_action_unmount), view);
+                               gtk_menu_shell_append (GTK_MENU_SHELL (menu), 
item);
+                               gtk_widget_show (item);
+                         }
+
           /* append the "Eject Volume" menu action */
           item = gtk_image_menu_item_new_with_mnemonic (_("E_ject Volume"));
           g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK 
(thunar_tree_view_action_eject), view);
@@ -1849,6 +1859,41 @@
       /* release the volume */
       g_object_unref (volume);
     }
+}
+
+
+
+static void
+thunar_tree_view_action_unmount (ThunarTreeView *view)
+{
+  GVolume *volume;
+  GMount  *mount;
+
+  _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
+
+  /* determine the selected volume */
+  volume = thunar_tree_view_get_selected_volume (view);
+  if (G_LIKELY (volume != NULL))
+    {
+               /* determine the mount of the volume */
+               mount = g_volume_get_mount (volume);
+               if (G_LIKELY (mount != NULL))
+            {
+#ifdef HAVE_LIBNOTIFY
+                               thunar_notify_unmount (mount);
+#endif
+
+                               /* the volume is mounted, try to unmount the 
mount */
+                               g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, 
NULL,
+                                                                
thunar_tree_view_action_unmount_finish, 
+                                                                g_object_ref 
(view));
+
+                               /* release the mount */
+                               g_object_unref (mount);
+            }
+      /* release the volume */
+      g_object_unref (volume);
+    }
 }
 
 
_______________________________________________
Thunar-dev mailing list
Thunar-dev@xfce.org
http://foo-projects.org/mailman/listinfo/thunar-dev

Reply via email to