[Xfce4-commits] r29913 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Wed Apr 29 09:42:23 CEST 2009


Author: jannis
Date: 2009-04-29 07:42:23 +0000 (Wed, 29 Apr 2009)
New Revision: 29913

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-file.c
   thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
   thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
   thunar/branches/migration-to-gio/thunar/thunar-shortcuts-icon-renderer.c
   thunar/branches/migration-to-gio/thunar/thunar-shortcuts-model.c
   thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
   thunar/branches/migration-to-gio/thunar/thunar-window.c
Log:
	* thunar/thunar-gio-extensions.{c,h}: Add new function
	  g_volume_is_present() which checks whether the GDrive of a volume
	  has media or not.
	* thunar/thunar-shortcuts-icon-renderer.c: Use GVolume instead of
	  ThunarVfsVolume and create the icon by loading a GtkIconInfo based
	  on the volume GIcon in thunar_shortcuts_renderer_render().
	* thunar/thunar-shortcuts-model.{c,h}: Use GVolumeMonitor and
	  GVolume/GMount instead of ThunarVfsVolumeManager/ThunarVfsVolume
	  everywhere.
	* thunar/thunar-shortcuts-view.c: Rewrite the mount/eject/unmount code
	  to use GVolume/GMount. Need to review this again to make sure it
	  works.
	* thunar/thunar-window.c: Re-implement the mount-pre-unmount signal
	  handler by using GVolumeMonitor/GMount.
	  error handling. Use thunar_file_list_free() instead of iterating over

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-29 07:42:23 UTC (rev 29913)
@@ -1,7 +1,24 @@
+2009-04-29	Jannis Pohlmann <jannis at xfce.org>
+
+	* thunar/thunar-gio-extensions.{c,h}: Add new function
+	  g_volume_is_present() which checks whether the GDrive of a volume
+	  has media or not.
+	* thunar/thunar-shortcuts-icon-renderer.c: Use GVolume instead of 
+	  ThunarVfsVolume and create the icon by loading a GtkIconInfo based
+	  on the volume GIcon in thunar_shortcuts_renderer_render().
+	* thunar/thunar-shortcuts-model.{c,h}: Use GVolumeMonitor and
+	  GVolume/GMount instead of ThunarVfsVolumeManager/ThunarVfsVolume
+	  everywhere. 
+	* thunar/thunar-shortcuts-view.c: Rewrite the mount/eject/unmount code
+	  to use GVolume/GMount. Need to review this again to make sure it
+	  works.
+	* thunar/thunar-window.c: Re-implement the mount-pre-unmount signal
+	  handler by using GVolumeMonitor/GMount.
+
 2009-04-28	Jannis Pohlmann <jannis at xfce.org>
 
 	* thunar/thunar-io-jobs.c, thunar/thunar-io-scan-directory.c: Improve
-	  error handling. Use thunar_file_list_free() instead of iterating over
+	  error handling. Use thunar_file_list_free() instead of iterating over 
 	  the ThunarFile list manually. Make sure to release the
 	  GFileEnumerator in thunar_io_scan_directory(), otherwise unmounting
 	  volumes fails due to open file descriptors.

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -2543,8 +2543,6 @@
 
       /* release our reference */
       g_object_unref (G_OBJECT (file));
-
-      g_debug ("thunar_file_destroy: file is object: %d", G_IS_OBJECT (file));
     }
 }
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -316,3 +316,23 @@
 
   return is_mounted;
 }
+
+
+
+gboolean 
+g_volume_is_present (GVolume *volume)
+{
+  gboolean has_media = FALSE;
+  GDrive  *drive;
+
+  _thunar_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
+
+  drive = g_volume_get_drive (volume);
+  if (drive != NULL)
+    {
+      has_media = g_drive_has_media (drive);
+      g_object_unref (drive);
+    }
+
+  return has_media;
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-29 07:42:23 UTC (rev 29913)
@@ -56,6 +56,7 @@
 
 gboolean g_volume_is_removable       (GVolume     *volume);
 gboolean g_volume_is_mounted         (GVolume     *volume);
+gboolean g_volume_is_present         (GVolume     *volume);
 
 G_END_DECLS
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-icon-renderer.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-icon-renderer.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-icon-renderer.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>.
+ * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -21,6 +22,9 @@
 #include <config.h>
 #endif
 
+#include <gio/gio.h>
+
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-icon-factory.h>
 #include <thunar/thunar-shortcuts-icon-renderer.h>
@@ -66,7 +70,7 @@
 {
   ThunarIconRenderer __parent__;
 
-  ThunarVfsVolume   *volume;
+  GVolume           *volume;
 };
 
 
@@ -124,13 +128,13 @@
   /**
    * ThunarShortcutsIconRenderer:volume:
    *
-   * The #ThunarVfsVolume for which to render an icon or %NULL to fallback
+   * The #GVolume for which to render an icon or %NULL to fallback
    * to the default icon renderering (see #ThunarIconRenderer).
    **/
   g_object_class_install_property (gobject_class,
                                    PROP_VOLUME,
                                    g_param_spec_object ("volume", "volume", "volume",
-                                                        THUNAR_VFS_TYPE_VOLUME,
+                                                        G_TYPE_VOLUME,
                                                         EXO_PARAM_READWRITE));
 }
 
@@ -153,7 +157,7 @@
 
   /* release the volume (if any) */
   if (G_UNLIKELY (shortcuts_icon_renderer->volume != NULL))
-    g_object_unref (G_OBJECT (shortcuts_icon_renderer->volume));
+    g_object_unref (shortcuts_icon_renderer->volume);
 
   (*G_OBJECT_CLASS (thunar_shortcuts_icon_renderer_parent_class)->finalize) (object);
 }
@@ -194,8 +198,8 @@
     {
     case PROP_VOLUME:
       if (G_UNLIKELY (shortcuts_icon_renderer->volume != NULL))
-        g_object_unref (G_OBJECT (shortcuts_icon_renderer->volume));
-      shortcuts_icon_renderer->volume = (gpointer) g_value_dup_object (value);
+        g_object_unref (shortcuts_icon_renderer->volume);
+      shortcuts_icon_renderer->volume = g_value_dup_object (value);
       break;
 
     default:
@@ -216,23 +220,33 @@
                                        GtkCellRendererState flags)
 {
   ThunarShortcutsIconRenderer *shortcuts_icon_renderer = THUNAR_SHORTCUTS_ICON_RENDERER (renderer);
-  ThunarIconFactory           *icon_factory;
   GtkIconTheme                *icon_theme;
   GdkRectangle                 draw_area;
   GdkRectangle                 icon_area;
-  const gchar                 *icon_name;
-  GdkPixbuf                   *icon;
+  GtkIconInfo                 *icon_info;
+  GdkPixbuf                   *icon = NULL;
   GdkPixbuf                   *temp;
+  GIcon                       *gicon;
 
   /* check if we have a volume set */
   if (G_UNLIKELY (shortcuts_icon_renderer->volume != NULL))
     {
       /* load the volume icon */
       icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window));
-      icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);
-      icon_name = thunar_vfs_volume_lookup_icon_name (shortcuts_icon_renderer->volume, icon_theme);
-      icon = thunar_icon_factory_load_icon (icon_factory, icon_name, THUNAR_ICON_RENDERER (renderer)->size, NULL, FALSE);
 
+      /* look up the volume icon info */
+      gicon = g_volume_get_icon (shortcuts_icon_renderer->volume);
+      icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, gicon, cell_area->width, 
+                                                  GTK_ICON_LOOKUP_USE_BUILTIN);
+      g_object_unref (gicon);
+
+      /* try to load the icon */
+      if (G_LIKELY (icon_info != NULL))
+        {
+          icon = gtk_icon_info_load_icon (icon_info, NULL);
+          gtk_icon_info_free (icon_info);
+        }
+
       /* render the icon (if any) */
       if (G_LIKELY (icon != NULL))
         {
@@ -253,7 +267,7 @@
               icon_area.height = gdk_pixbuf_get_height (icon);
             }
 
-          if (!thunar_vfs_volume_is_mounted (shortcuts_icon_renderer->volume))
+          if (!g_volume_is_mounted (shortcuts_icon_renderer->volume))
             {
               /* 50% translucent for unmounted volumes */
               temp = exo_gdk_pixbuf_lucent (icon, 50);
@@ -277,9 +291,6 @@
           /* cleanup */
           g_object_unref (G_OBJECT (icon));
         }
-
-      /* cleanup */
-      g_object_unref (G_OBJECT (icon_factory));
     }
   else
     {

Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-model.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-model.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -122,13 +122,14 @@
                                                                      ThunarShortcutsModel      *model);
 static void               thunar_shortcuts_model_file_destroy       (ThunarFile                *file,
                                                                      ThunarShortcutsModel      *model);
-static void               thunar_shortcuts_model_volume_changed     (ThunarVfsVolume           *volume,
+static void               thunar_shortcuts_model_volume_added       (GVolumeMonitor            *volume_monitor,
+                                                                     GVolume                   *volume,
                                                                      ThunarShortcutsModel      *model);
-static void               thunar_shortcuts_model_volumes_added      (ThunarVfsVolumeManager    *volume_manager,
-                                                                     GList                     *volumes,
+static void               thunar_shortcuts_model_volume_removed     (GVolumeMonitor            *volume_monitor,
+                                                                     GVolume                   *volume,
                                                                      ThunarShortcutsModel      *model);
-static void               thunar_shortcuts_model_volumes_removed    (ThunarVfsVolumeManager    *volume_manager,
-                                                                     GList                     *volumes,
+static void               thunar_shortcuts_model_volume_changed     (GVolumeMonitor            *monitor,
+                                                                     GVolume                   *volume,
                                                                      ThunarShortcutsModel      *model);
 static void               thunar_shortcut_free                      (ThunarShortcut            *shortcut,
                                                                      ThunarShortcutsModel      *model);
@@ -142,21 +143,21 @@
 
 struct _ThunarShortcutsModel
 {
-  GObject __parent__;
+  GObject         __parent__;
 
   /* the model stamp is only used when debugging is
    * enabled, to make sure we don't accept iterators
    * generated by another model.
    */
 #ifndef NDEBUG
-  gint                    stamp;
+  gint            stamp;
 #endif
 
-  GList                  *shortcuts;
-  GList                  *hidden_volumes;
-  ThunarVfsVolumeManager *volume_manager;
+  GList          *shortcuts;
+  GList          *hidden_volumes;
+  GVolumeMonitor *volume_monitor;
 
-  GFileMonitor           *monitor;
+  GFileMonitor   *monitor;
 };
 
 struct _ThunarShortcut
@@ -165,7 +166,7 @@
 
   gchar              *name;
   ThunarFile         *file;
-  ThunarVfsVolume    *volume;
+  GVolume            *volume;
 };
 
 
@@ -265,10 +266,10 @@
 static void
 thunar_shortcuts_model_init (ThunarShortcutsModel *model)
 {
-  ThunarVfsVolume *volume;
   ThunarShortcut  *shortcut;
   GtkTreePath     *path;
   ThunarFile      *file;
+  GVolume         *volume;
   GFile           *bookmarks;
   GFile           *desktop;
   GFile           *home;
@@ -280,10 +281,11 @@
   model->stamp = g_random_int ();
 #endif
 
-  /* connect to the volume manager */
-  model->volume_manager = thunar_vfs_volume_manager_get_default ();
-  g_signal_connect (G_OBJECT (model->volume_manager), "volumes-added", G_CALLBACK (thunar_shortcuts_model_volumes_added), model);
-  g_signal_connect (G_OBJECT (model->volume_manager), "volumes-removed", G_CALLBACK (thunar_shortcuts_model_volumes_removed), model);
+  /* connect to the volume monitor */
+  model->volume_monitor = g_volume_monitor_get ();
+  g_signal_connect (model->volume_monitor, "volume-added", G_CALLBACK (thunar_shortcuts_model_volume_added), model);
+  g_signal_connect (model->volume_monitor, "volume-removed", G_CALLBACK (thunar_shortcuts_model_volume_removed), model);
+  g_signal_connect (model->volume_monitor, "volume-changed", G_CALLBACK (thunar_shortcuts_model_volume_changed), model);
 
   home = g_file_new_for_home ();
 
@@ -350,24 +352,21 @@
   g_list_free (system_paths);
 
   /* prepend the removable media volumes */
-  volumes = thunar_vfs_volume_manager_get_volumes (model->volume_manager);
+  volumes = g_volume_monitor_get_volumes (model->volume_monitor);
   for (lp = volumes; lp != NULL; lp = lp->next)
     {
       /* monitor the volume for changes */
-      volume = THUNAR_VFS_VOLUME (lp->data);
-      g_object_ref (G_OBJECT (volume));
-      g_signal_connect (G_OBJECT (volume), "changed",
-                        G_CALLBACK (thunar_shortcuts_model_volume_changed), model);
+      volume = G_VOLUME (lp->data);
 
       /* we list only present, removable devices here */
-      if (thunar_vfs_volume_is_removable (volume) && thunar_vfs_volume_is_present (volume))
+      if (g_volume_is_removable (volume) && g_volume_is_present (volume))
         {
           /* generate the shortcut (w/o a file, else we might
            * prevent the volume from being unmounted)
            */
           shortcut = _thunar_slice_new0 (ThunarShortcut);
           shortcut->type = THUNAR_SHORTCUT_REMOVABLE_MEDIA;
-          shortcut->volume = volume;
+          shortcut->volume = g_object_ref (volume);
 
           /* link the shortcut to the list */
           thunar_shortcuts_model_add_shortcut (model, shortcut, path);
@@ -375,8 +374,10 @@
         }
       else
         {
-          /* schedule the volume for later checking, not removable or there's no medium present */
-          model->hidden_volumes = g_list_prepend (model->hidden_volumes, volume);
+          /* schedule the volume for later checking, not removable or 
+           * there's no medium present */
+          model->hidden_volumes = g_list_prepend (model->hidden_volumes, 
+                                                  g_object_ref (volume));
         }
     }
 
@@ -409,7 +410,6 @@
 thunar_shortcuts_model_finalize (GObject *object)
 {
   ThunarShortcutsModel *model = THUNAR_SHORTCUTS_MODEL (object);
-  GList                *lp;
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
 
@@ -418,23 +418,19 @@
   g_list_free (model->shortcuts);
 
   /* free all hidden volumes */
-  for (lp = model->hidden_volumes; lp != NULL; lp = lp->next)
-    {
-      g_signal_handlers_disconnect_by_func (G_OBJECT (lp->data), thunar_shortcuts_model_volume_changed, model);
-      g_object_unref (G_OBJECT (lp->data));
-    }
+  g_list_foreach (model->hidden_volumes, (GFunc) g_object_unref, NULL);
   g_list_free (model->hidden_volumes);
 
-  /* detach from the VFS monitor */
+  /* detach from the file monitor */
   if (model->monitor != NULL)
     {
       g_file_monitor_cancel (model->monitor);
-      g_object_unref (G_OBJECT (model->monitor));
+      g_object_unref (model->monitor);
     }
 
-  /* unlink from the volume manager */
-  g_signal_handlers_disconnect_matched (G_OBJECT (model->volume_manager), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model);
-  g_object_unref (G_OBJECT (model->volume_manager));
+  /* unlink from the volume monitor */
+  g_signal_handlers_disconnect_matched (model->volume_monitor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model);
+  g_object_unref (model->volume_monitor);
 
   (*G_OBJECT_CLASS (thunar_shortcuts_model_parent_class)->finalize) (object);
 }
@@ -470,7 +466,7 @@
       return THUNAR_TYPE_FILE;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME:
-      return THUNAR_VFS_TYPE_VOLUME;
+      return G_TYPE_VOLUME;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE:
       return G_TYPE_BOOLEAN;
@@ -537,6 +533,8 @@
 {
   ThunarShortcut *shortcut;
   ThunarFile     *file;
+  GMount         *mount;
+  GFile          *mount_point;
 
   _thunar_return_if_fail (iter->stamp == THUNAR_SHORTCUTS_MODEL (tree_model)->stamp);
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (tree_model));
@@ -549,7 +547,7 @@
     case THUNAR_SHORTCUTS_MODEL_COLUMN_NAME:
       g_value_init (value, G_TYPE_STRING);
       if (G_UNLIKELY (shortcut->volume != NULL))
-        g_value_set_static_string (value, thunar_vfs_volume_get_name (shortcut->volume));
+        g_value_take_string (value, g_volume_get_name (shortcut->volume));
       else if (shortcut->name != NULL)
         g_value_set_static_string (value, shortcut->name);
       else if (shortcut->file != NULL)
@@ -562,10 +560,22 @@
       g_value_init (value, THUNAR_TYPE_FILE);
       if (shortcut->volume != NULL && shortcut->file == NULL)
         {
-          /* try to determine the file on-demand */
-          file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (shortcut->volume), NULL);
-          if (G_LIKELY (file != NULL))
-            g_value_take_object (value, file);
+          /* determine the mount of the volume */
+          mount = g_volume_get_mount (shortcut->volume);
+          
+          if (G_LIKELY (mount != NULL))
+            {
+              /* the volume is mounted, get the mount point */
+              mount_point = g_mount_get_root (mount);
+
+              /* try to allocate/reference a file pointing to the mount point */
+              file = thunar_file_get (mount_point, NULL);
+              g_value_take_object (value, file);
+
+              /* release resources */
+              g_object_unref (mount_point);
+              g_object_unref (mount);
+            }
         }
       else
         {
@@ -574,7 +584,7 @@
       break;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME:
-      g_value_init (value, THUNAR_VFS_TYPE_VOLUME);
+      g_value_init (value, G_TYPE_VOLUME);
       g_value_set_object (value, shortcut->volume);
       break;
 
@@ -1159,16 +1169,19 @@
 
 
 static void
-thunar_shortcuts_model_volume_changed (ThunarVfsVolume      *volume,
+thunar_shortcuts_model_volume_changed (GVolumeMonitor       *volume_monitor,
+                                       GVolume              *volume,
                                        ThunarShortcutsModel *model)
 {
   ThunarShortcut *shortcut = NULL;
-  GtkTreePath     *path;
-  GtkTreeIter      iter;
-  GList           *lp;
-  gint             index;
+  GtkTreePath    *path;
+  GtkTreeIter     iter;
+  GList          *lp;
+  gint            index;
 
-  _thunar_return_if_fail (THUNAR_VFS_IS_VOLUME (volume));
+  _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
+  _thunar_return_if_fail (model->volume_monitor == volume_monitor);
+  _thunar_return_if_fail (G_IS_VOLUME (volume));
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
 
   /* check if the volume is on the hidden list */
@@ -1176,7 +1189,7 @@
   if (lp != NULL)
     {
       /* check if we need to display the volume now */
-      if (thunar_vfs_volume_is_present (volume) && thunar_vfs_volume_is_removable (volume))
+      if (g_volume_is_removable (volume) && g_volume_is_present (volume))
         {
           /* remove the volume from the list of hidden volumes */
           model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp);
@@ -1204,11 +1217,12 @@
   else
     {
       /* lookup the shortcut that contains the given volume */
-      for (index = 0, lp = model->shortcuts; lp != NULL; ++index, lp = lp->next)
+      for (index = 0, lp = model->shortcuts; 
+           shortcut == NULL && lp != NULL; 
+           ++index, lp = lp->next)
         {
-          shortcut = THUNAR_SHORTCUT (lp->data);
-          if (shortcut->volume == volume)
-            break;
+          if (THUNAR_SHORTCUT (lp->data)->volume == volume)
+            shortcut = lp->data;
         }
 
       /* verify that we actually found the shortcut */
@@ -1216,19 +1230,14 @@
       _thunar_assert (shortcut->volume == volume);
 
       /* check if we need to hide the volume now */
-      if (!thunar_vfs_volume_is_present (volume) || !thunar_vfs_volume_is_removable (volume))
+      if (!g_volume_is_removable (volume) || !g_volume_is_present (volume))
         {
-          /* need to ref here, because the file_destroy() handler will drop the refcount. */
-          g_object_ref (G_OBJECT (volume));
-
           /* move the volume to the hidden list */
-          model->hidden_volumes = g_list_prepend (model->hidden_volumes, volume);
+          model->hidden_volumes = g_list_prepend (model->hidden_volumes, 
+                                                  g_object_ref (volume));
 
           /* remove the shortcut from the user interface */
           thunar_shortcuts_model_remove_shortcut (model, shortcut);
-
-          /* need to reconnect to the volume, as the shortcut removal drops the handler */
-          g_signal_connect (G_OBJECT (volume), "changed", G_CALLBACK (thunar_shortcuts_model_volume_changed), model);
         }
       else
         {
@@ -1246,75 +1255,56 @@
 
 
 static void
-thunar_shortcuts_model_volumes_added (ThunarVfsVolumeManager *volume_manager,
-                                      GList                  *volumes,
-                                      ThunarShortcutsModel   *model)
+thunar_shortcuts_model_volume_added (GVolumeMonitor       *volume_monitor,
+                                     GVolume              *volume,
+                                     ThunarShortcutsModel *model)
 {
-  GList *lp;
-
-  _thunar_return_if_fail (THUNAR_VFS_IS_VOLUME_MANAGER (volume_manager));
+  _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
+  _thunar_return_if_fail (model->volume_monitor == volume_monitor);
+  _thunar_return_if_fail (G_IS_VOLUME (volume));
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
-  _thunar_return_if_fail (model->volume_manager == volume_manager);
 
-  /* process all newly added volumes */
-  for (lp = volumes; lp != NULL; lp = lp->next)
-    {
-      /* take a reference on the volume... */
-      g_object_ref (G_OBJECT (lp->data));
+  /* place the volume on the hidden list */
+  model->hidden_volumes = g_list_prepend (model->hidden_volumes, g_object_ref (volume));
 
-      /* ...place the volume on the hidden list... */
-      model->hidden_volumes = g_list_prepend (model->hidden_volumes, lp->data);
-
-      /* ...connect the "changed" signal handler ... */
-      g_signal_connect (G_OBJECT (lp->data), "changed", G_CALLBACK (thunar_shortcuts_model_volume_changed), model);
-
-      /* ...and let the "changed" handler place the volume where appropriate */
-      thunar_shortcuts_model_volume_changed (lp->data, model);
-    }
+  /* let the "changed" handler place the volume where appropriate */
+  thunar_shortcuts_model_volume_changed (volume_monitor, volume, model);
 }
 
 
 
 static void
-thunar_shortcuts_model_volumes_removed (ThunarVfsVolumeManager *volume_manager,
-                                        GList                  *volumes,
-                                        ThunarShortcutsModel   *model)
+thunar_shortcuts_model_volume_removed (GVolumeMonitor       *volume_monitor,
+                                       GVolume              *volume,
+                                       ThunarShortcutsModel *model)
 {
-  GList *hp;
   GList *lp;
 
-  _thunar_return_if_fail (THUNAR_VFS_IS_VOLUME_MANAGER (volume_manager));
+  _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
+  _thunar_return_if_fail (model->volume_monitor == volume_monitor);
+  _thunar_return_if_fail (G_IS_VOLUME (volume));
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
-  _thunar_return_if_fail (model->volume_manager == volume_manager);
   
-  /* process all removed volumes */
-  for (lp = volumes; lp != NULL; lp = lp->next)
+  lp = g_list_find (model->hidden_volumes, volume);
+  if (G_LIKELY (lp != NULL))
     {
-      /* disconnect the "changed" signal handler from the volume */
-      g_signal_handlers_disconnect_by_func (G_OBJECT (lp->data), thunar_shortcuts_model_volume_changed, model);
+      /* remove the volume from the hidden list and drop our reference */
+      model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp);
+      g_object_unref (volume);
+    }
+  else
+    {
+      /* must be an active shortcut then... */
+      for (lp = model->shortcuts; lp != NULL; lp = lp->next)
+        if (THUNAR_SHORTCUT (lp->data)->volume == volume)
+          break;
 
-      /* check if the volume is on the hidden list */
-      hp = g_list_find (model->hidden_volumes, lp->data);
-      if (G_LIKELY (hp != NULL))
-        {
-          /* drop the volume from the hidden list and drop our reference */
-          model->hidden_volumes = g_list_delete_link (model->hidden_volumes, hp);
-          g_object_unref (G_OBJECT (lp->data));
-        }
-      else
-        {
-          /* must be an active shortcut then... */
-          for (hp = model->shortcuts; hp != NULL; hp = hp->next)
-            if (THUNAR_SHORTCUT (hp->data)->volume == lp->data)
-              break;
+      /* something is broken if we don't have a shortcut here */
+      _thunar_assert (lp != NULL);
+      _thunar_assert (THUNAR_SHORTCUT (lp->data)->volume == volume);
 
-          /* something is broken if we don't have a shortcut here */
-          _thunar_assert (hp != NULL);
-          _thunar_assert (THUNAR_SHORTCUT (hp->data)->volume == lp->data);
-
-          /* drop the shortcut from the model */
-          thunar_shortcuts_model_remove_shortcut (model, hp->data);
-        }
+      /* drop the shortcut from the model */
+      thunar_shortcuts_model_remove_shortcut (model, lp->data);
     }
 }
 
@@ -1330,18 +1320,18 @@
       thunar_file_unwatch (shortcut->file);
 
       /* unregister from the file */
-      g_signal_handlers_disconnect_matched (G_OBJECT (shortcut->file),
+      g_signal_handlers_disconnect_matched (shortcut->file,
                                             G_SIGNAL_MATCH_DATA, 0,
                                             0, NULL, NULL, model);
-      g_object_unref (G_OBJECT (shortcut->file));
+      g_object_unref (shortcut->file);
     }
 
   if (G_LIKELY (shortcut->volume != NULL))
     {
-      g_signal_handlers_disconnect_matched (G_OBJECT (shortcut->volume),
+      g_signal_handlers_disconnect_matched (shortcut->volume,
                                             G_SIGNAL_MATCH_DATA, 0,
                                             0, NULL, NULL, model);
-      g_object_unref (G_OBJECT (shortcut->volume));
+      g_object_unref (shortcut->volume);
     }
 
   /* release the shortcut name */
@@ -1402,8 +1392,9 @@
                                       ThunarFile           *file,
                                       GtkTreeIter          *iter)
 {
-  ThunarVfsPath *mount_point;
-  GList         *lp;
+  GMount *mount;
+  GFile  *mount_point;
+  GList  *lp;
   
   _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model), FALSE);
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
@@ -1419,14 +1410,24 @@
         }
 
       /* but maybe we have a mounted(!) volume with a matching mount point */
-      if (THUNAR_SHORTCUT (lp->data)->volume != NULL && thunar_vfs_volume_is_mounted (THUNAR_SHORTCUT (lp->data)->volume))
+      if (THUNAR_SHORTCUT (lp->data)->volume != NULL)
         {
-          /* check if we have a mount point for the volume */
-          mount_point = thunar_vfs_volume_get_mount_point (THUNAR_SHORTCUT (lp->data)->volume);
-          if (G_LIKELY (mount_point != NULL && thunar_vfs_path_equal (mount_point, thunar_file_get_path (file))))
+          mount = g_volume_get_mount (THUNAR_SHORTCUT (lp->data)->volume);
+
+          if (G_LIKELY (mount != NULL))
             {
-              GTK_TREE_ITER_INIT (*iter, model->stamp, lp);
-              return TRUE;
+              mount_point = g_mount_get_root (mount);
+
+              if (G_LIKELY (g_file_equal (mount_point, thunar_file_get_file (file))))
+                {
+                  GTK_TREE_ITER_INIT (*iter, model->stamp, lp);
+                  g_object_unref (mount_point);
+                  g_object_unref (mount);
+                  return TRUE;
+                }
+
+              g_object_unref (mount_point);
+              g_object_unref (mount);
             }
         }
     }

Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -60,73 +61,76 @@
 
 
 
-static void           thunar_shortcuts_view_class_init            (ThunarShortcutsViewClass *klass);
-static void           thunar_shortcuts_view_init                  (ThunarShortcutsView      *view);
-static void           thunar_shortcuts_view_finalize              (GObject                  *object);
-static gboolean       thunar_shortcuts_view_button_press_event    (GtkWidget                *widget,
-                                                                   GdkEventButton           *event);
-static gboolean       thunar_shortcuts_view_button_release_event  (GtkWidget                *widget,
-                                                                   GdkEventButton           *event);
-static void           thunar_shortcuts_view_drag_begin            (GtkWidget                *widget,
-                                                                   GdkDragContext           *context);
-static void           thunar_shortcuts_view_drag_data_received    (GtkWidget                *widget,
-                                                                   GdkDragContext           *context,
-                                                                   gint                      x,
-                                                                   gint                      y,
-                                                                   GtkSelectionData         *selection_data,
-                                                                   guint                     info,
-                                                                   guint                     time);
-static gboolean       thunar_shortcuts_view_drag_drop             (GtkWidget                *widget,
-                                                                   GdkDragContext           *context,
-                                                                   gint                      x,
-                                                                   gint                      y,
-                                                                   guint                     time);
-static gboolean       thunar_shortcuts_view_drag_motion           (GtkWidget                *widget,
-                                                                   GdkDragContext           *context,
-                                                                   gint                      x,
-                                                                   gint                      y,
-                                                                   guint                     time);
-static void           thunar_shortcuts_view_drag_leave            (GtkWidget                *widget,
-                                                                   GdkDragContext           *context,
-                                                                   guint                     time);
-static gboolean       thunar_shortcuts_view_popup_menu            (GtkWidget                *widget);
-static void           thunar_shortcuts_view_row_activated         (GtkTreeView              *tree_view,
-                                                                   GtkTreePath              *path,
-                                                                   GtkTreeViewColumn        *column);
-static void           thunar_shortcuts_view_context_menu          (ThunarShortcutsView      *view,
-                                                                   GdkEventButton           *event,
-                                                                   GtkTreeModel             *model,
-                                                                   GtkTreeIter              *iter);
-static void           thunar_shortcuts_view_remove_activated      (GtkWidget                *item,
-                                                                   ThunarShortcutsView      *view);
-static void           thunar_shortcuts_view_rename_activated      (GtkWidget                *item,
-                                                                   ThunarShortcutsView      *view);
-static void           thunar_shortcuts_view_renamed               (GtkCellRenderer          *renderer,
-                                                                   const gchar              *path_string,
-                                                                   const gchar              *text,
-                                                                   ThunarShortcutsView      *view);
-static GdkDragAction  thunar_shortcuts_view_compute_drop_actions  (ThunarShortcutsView      *view,
-                                                                   GdkDragContext           *context,
-                                                                   gint                      x,
-                                                                   gint                      y,
-                                                                   GtkTreePath             **path_return,
-                                                                   GdkDragAction            *action_return,
-                                                                   GtkTreeViewDropPosition  *position_return);
-static GtkTreePath   *thunar_shortcuts_view_compute_drop_position (ThunarShortcutsView      *view,
-                                                                   gint                      x,
-                                                                   gint                      y);
-static void           thunar_shortcuts_view_drop_uri_list         (ThunarShortcutsView      *view,
-                                                                   GList                    *path_list,
-                                                                   GtkTreePath              *dst_path);
-static void           thunar_shortcuts_view_open                  (ThunarShortcutsView      *view);
-static void           thunar_shortcuts_view_open_in_new_window    (ThunarShortcutsView      *view);
-static void           thunar_shortcuts_view_empty_trash           (ThunarShortcutsView      *view);
-static gboolean       thunar_shortcuts_view_eject                 (ThunarShortcutsView      *view);
-static gboolean       thunar_shortcuts_view_mount                 (ThunarShortcutsView      *view);
-static gboolean       thunar_shortcuts_view_unmount               (ThunarShortcutsView      *view);
-static gboolean       thunar_shortcuts_view_separator_func        (GtkTreeModel             *model,
-                                                                   GtkTreeIter              *iter,
-                                                                   gpointer                  user_data);
+static void           thunar_shortcuts_view_class_init                   (ThunarShortcutsViewClass *klass);
+static void           thunar_shortcuts_view_init                         (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_finalize                     (GObject                  *object);
+static gboolean       thunar_shortcuts_view_button_press_event           (GtkWidget                *widget,
+                                                                          GdkEventButton           *event);
+static gboolean       thunar_shortcuts_view_button_release_event         (GtkWidget                *widget,
+                                                                          GdkEventButton           *event);
+static void           thunar_shortcuts_view_drag_begin                   (GtkWidget                *widget,
+                                                                          GdkDragContext           *context);
+static void           thunar_shortcuts_view_drag_data_received           (GtkWidget                *widget,
+                                                                          GdkDragContext           *context,
+                                                                          gint                      x,
+                                                                          gint                      y,
+                                                                          GtkSelectionData         *selection_data,
+                                                                          guint                     info,
+                                                                          guint                     time);
+static gboolean       thunar_shortcuts_view_drag_drop                    (GtkWidget                *widget,
+                                                                          GdkDragContext           *context,
+                                                                          gint                      x,
+                                                                          gint                      y,
+                                                                          guint                     time);
+static gboolean       thunar_shortcuts_view_drag_motion                  (GtkWidget                *widget,
+                                                                          GdkDragContext           *context,
+                                                                          gint                      x,
+                                                                          gint                      y,
+                                                                          guint                     time);
+static void           thunar_shortcuts_view_drag_leave                   (GtkWidget                *widget,
+                                                                          GdkDragContext           *context,
+                                                                          guint                     time);
+static gboolean       thunar_shortcuts_view_popup_menu                   (GtkWidget                *widget);
+static void           thunar_shortcuts_view_row_activated                (GtkTreeView              *tree_view,
+                                                                          GtkTreePath              *path,
+                                                                          GtkTreeViewColumn        *column);
+static void           thunar_shortcuts_view_context_menu                 (ThunarShortcutsView      *view,
+                                                                          GdkEventButton           *event,
+                                                                          GtkTreeModel             *model,
+                                                                          GtkTreeIter              *iter);
+static void           thunar_shortcuts_view_remove_activated             (GtkWidget                *item,
+                                                                          ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_rename_activated             (GtkWidget                *item,
+                                                                          ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_renamed                      (GtkCellRenderer          *renderer,
+                                                                          const gchar              *path_string,
+                                                                          const gchar              *text,
+                                                                          ThunarShortcutsView      *view);
+static GdkDragAction  thunar_shortcuts_view_compute_drop_actions         (ThunarShortcutsView      *view,
+                                                                          GdkDragContext           *context,
+                                                                          gint                      x,
+                                                                          gint                      y,
+                                                                          GtkTreePath             **path_return,
+                                                                          GdkDragAction            *action_return,
+                                                                          GtkTreeViewDropPosition  *position_return);
+static GtkTreePath   *thunar_shortcuts_view_compute_drop_position        (ThunarShortcutsView      *view,
+                                                                          gint                      x,
+                                                                          gint                      y);
+static void           thunar_shortcuts_view_drop_uri_list                (ThunarShortcutsView      *view,
+                                                                          GList                    *path_list,
+                                                                          GtkTreePath              *dst_path);
+static void           thunar_shortcuts_view_open                         (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_open_selection               (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_open_in_new_window           (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_open_selection_in_new_window (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_empty_trash                  (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_eject                        (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_mount_clicked                (ThunarShortcutsView      *view);
+static void           thunar_shortcuts_view_mount                        (ThunarShortcutsView      *view,
+                                                                          gboolean                  open_in_new_window);
+static gboolean       thunar_shortcuts_view_separator_func               (GtkTreeModel             *model,
+                                                                          GtkTreeIter              *iter,
+                                                                          gpointer                  user_data);
 
 
 
@@ -154,12 +158,10 @@
   guint  drop_occurred : 1;
   GList *drop_file_list;      /* the list of URIs that are contained in the drop data */
 
-#if GTK_CHECK_VERSION(2,8,0)
   /* id of the signal used to queue a resize on the
    * column whenever the shortcuts icon size is changed.
    */
   gint queue_resize_signal_id;
-#endif
 };
 
 
@@ -282,10 +284,8 @@
   gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
 
   /* queue a resize on the column whenever the icon size is changed */
-#if GTK_CHECK_VERSION(2,8,0)
   view->queue_resize_signal_id = g_signal_connect_swapped (G_OBJECT (view->preferences), "notify::shortcuts-icon-size",
                                                            G_CALLBACK (gtk_tree_view_column_queue_resize), column);
-#endif
 
   /* allocate the special icon renderer */
   view->icon_renderer = thunar_shortcuts_icon_renderer_new ();
@@ -341,9 +341,7 @@
   g_object_unref (G_OBJECT (view->provider_factory));
 
   /* disconnect the queue resize signal handler */
-#if GTK_CHECK_VERSION(2,8,0)
   g_signal_handler_disconnect (G_OBJECT (view->preferences), view->queue_resize_signal_id);
-#endif
 
   /* disconnect from the preferences object */
   g_signal_handlers_disconnect_matched (G_OBJECT (view->preferences), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, view);
@@ -788,16 +786,16 @@
                                     GtkTreeModel        *model,
                                     GtkTreeIter         *iter)
 {
-  ThunarVfsVolume *volume;
-  GtkTreePath     *path;
-  ThunarFile      *file;
-  GtkWidget       *image;
-  GtkWidget       *menu;
-  GtkWidget       *item;
-  gboolean         mutable;
-  GtkWidget       *window;
-  GList           *providers, *lp;
-  GList           *actions = NULL, *tmp;
+  GtkTreePath *path;
+  ThunarFile  *file;
+  GtkWidget   *image;
+  GtkWidget   *menu;
+  GtkWidget   *item;
+  GtkWidget   *window;
+  gboolean     mutable;
+  GVolume     *volume;
+  GList       *providers, *lp;
+  GList       *actions = NULL, *tmp;
 
   /* determine the tree path for the given iter */
   path = gtk_tree_model_get_path (model, iter);
@@ -841,13 +839,13 @@
     {
       /* append the "Mount Volume" menu action */
       item = gtk_image_menu_item_new_with_mnemonic (_("_Mount Volume"));
-      gtk_widget_set_sensitive (item, !thunar_vfs_volume_is_mounted (volume));
-      g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_mount), view);
+      gtk_widget_set_sensitive (item, !g_volume_is_mounted (volume));
+      g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_mount_clicked), view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
 
       /* check if the volume is ejectable */
-      if (thunar_vfs_volume_is_ejectable (volume))
+      if (g_volume_is_removable (volume))
         {
           /* append the "Eject Volume" menu action */
           item = gtk_image_menu_item_new_with_mnemonic (_("E_ject Volume"));
@@ -855,15 +853,6 @@
           gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
           gtk_widget_show (item);
         }
-      else
-        {
-          /* append the "Unmount Volume" menu item */
-          item = gtk_image_menu_item_new_with_mnemonic (_("_Unmount Volume"));
-          gtk_widget_set_sensitive (item, thunar_vfs_volume_is_mounted (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 a menu separator */
       item = gtk_separator_menu_item_new ();
@@ -1241,25 +1230,53 @@
   GtkTreeSelection *selection;
   GtkTreeModel     *model;
   GtkTreeIter       iter;
-  ThunarFile       *file;
+  GVolume          *volume;
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
 
-  /* make sure to mount the volume first (if it's a volume) */
-  if (!thunar_shortcuts_view_mount (view))
-    return;
+  /* 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 file for the shortcut at the given tree iterator */
+      gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
 
+      if (G_LIKELY (volume != NULL))
+        {
+          thunar_shortcuts_view_mount (view, FALSE);
+          g_object_unref (volume);
+        }
+      else 
+        {
+          thunar_shortcuts_view_open_selection (view);
+        }
+    }
+}
+
+
+
+static void
+thunar_shortcuts_view_open_selection (ThunarShortcutsView *view)
+{
+  GtkTreeSelection *selection;
+  GtkTreeModel     *model;
+  GtkTreeIter       iter;
+  ThunarFile       *file;
+  
+  _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 file for the shortcut at the given tree iterator */
       gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, -1);
+
       if (G_LIKELY (file != NULL))
         {
           /* invoke the signal to change to that folder */
-          g_signal_emit (G_OBJECT (view), view_signals[SHORTCUT_ACTIVATED], 0, file);
-          g_object_unref (G_OBJECT (file));
+          g_signal_emit (view, view_signals[SHORTCUT_ACTIVATED], 0, file);
+          g_object_unref (file);
         }
     }
 }
@@ -1269,6 +1286,37 @@
 static void
 thunar_shortcuts_view_open_in_new_window (ThunarShortcutsView *view)
 {
+  GtkTreeSelection *selection;
+  GtkTreeModel     *model;
+  GtkTreeIter       iter;
+  GVolume          *volume;
+
+  _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 (volume != NULL)
+        {
+          thunar_shortcuts_view_mount (view, TRUE);
+          g_object_unref (volume);
+        }
+      else
+        {
+          thunar_shortcuts_view_open_selection_in_new_window (view);
+        }
+    }
+}
+
+
+
+static void
+thunar_shortcuts_view_open_selection_in_new_window (ThunarShortcutsView *view)
+{
   ThunarApplication *application;
   GtkTreeSelection  *selection;
   GtkTreeModel      *model;
@@ -1277,23 +1325,21 @@
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
 
-  /* make sure to mount the volume first (if it's a volume) */
-  if (!thunar_shortcuts_view_mount (view))
-    return;
-
   /* 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 file for the shortcut at the given tree iterator */
+      /* determine the volume for the shortcut at the given tree iterator */
       gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, -1);
+
       if (G_LIKELY (file != NULL))
         {
           /* open a new window for the shortcut target folder */
           application = thunar_application_get ();
-          thunar_application_open_window (application, file, gtk_widget_get_screen (GTK_WIDGET (view)));
-          g_object_unref (G_OBJECT (application));
-          g_object_unref (G_OBJECT (file));
+          thunar_application_open_window (application, file, 
+                                          gtk_widget_get_screen (GTK_WIDGET (view)));
+          g_object_unref (application);
+          g_object_unref (file);
         }
     }
 }
@@ -1315,18 +1361,87 @@
 
 
 
-static gboolean
+static void
+thunar_shortcuts_view_eject_finish (GObject      *object,
+                                    GAsyncResult *result,
+                                    gpointer      user_data)
+{
+  ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
+  GtkWidget           *window;
+  GVolume             *volume = G_VOLUME (object);
+  GError              *error = NULL;
+  gchar               *volume_name;
+
+  _thunar_return_if_fail (G_IS_VOLUME (object));
+  _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  /* check if there was an error */
+  if (!g_volume_eject_finish (volume, result, &error))
+    {
+      /* ignore GIO errors already handled */
+      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
+        {
+          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+          /* display an error dialog to inform the user */
+          volume_name = g_volume_get_name (volume);
+          thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), volume_name);
+          g_free (volume_name);
+
+          g_error_free (error);
+        }
+    }
+}
+
+
+
+static void
+thunar_shortcuts_view_unmount_finish (GObject      *object,
+                                      GAsyncResult *result,
+                                      gpointer      user_data)
+{
+  ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
+  GtkWidget           *window;
+  GMount              *mount = G_MOUNT (object);
+  GError              *error = NULL;
+  gchar               *mount_name;
+
+  _thunar_return_if_fail (G_IS_MOUNT (object));
+  _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  /* check if there was an error */
+  if (!g_mount_unmount_finish (mount, result, &error))
+    {
+      /* ignore GIO errors already handled */
+      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
+        {
+          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+          /* display an error dialog to inform the user */
+          mount_name = g_mount_get_name (mount);
+          thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), mount_name);
+          g_free (mount_name);
+
+          g_error_free (error);
+        }
+    }
+}
+
+
+
+static void
 thunar_shortcuts_view_eject (ThunarShortcutsView *view)
 {
   GtkTreeSelection *selection;
-  ThunarVfsVolume  *volume;
   GtkTreeModel     *model;
   GtkTreeIter       iter;
   GtkWidget        *window;
-  gboolean          result = TRUE;
-  GError           *error = NULL;
+  GVolume          *volume;
+  GMount           *mount;
 
-  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
 
   /* determine the selected item */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
@@ -1339,84 +1454,137 @@
           /* determine the toplevel window */
           window = gtk_widget_get_toplevel (GTK_WIDGET (view));
 
-          /* try to eject the volume */
-          result = thunar_vfs_volume_eject (volume, window, &error);
-          if (G_UNLIKELY (!result))
+          /* determine what the appropriate method is: eject or unmount */
+          if (g_volume_can_eject (volume))
             {
-              /* display an error dialog to inform the user */
-              thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), thunar_vfs_volume_get_name (volume));
-              g_error_free (error);
+              /* try to to eject the volume asynchronously */
+              g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL, 
+                              thunar_shortcuts_view_eject_finish, view);
             }
+          else
+            {
+              /* determine the mount of the volume */
+              mount = g_volume_get_mount (volume);
+              if (G_LIKELY (mount != NULL))
+                {
+                  /* the volume is mounted, try to unmount the mount */
+                  g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
+                                   thunar_shortcuts_view_unmount_finish, view);
 
+                  /* release the mount */
+                  g_object_unref (mount);
+                }
+            }
+
           /* cleanup */
-          g_object_unref (G_OBJECT (volume));
+          g_object_unref (volume);
         }
     }
+}
 
-  return result;
+
+
+static void
+thunar_shortcuts_view_mount_clicked (ThunarShortcutsView *view)
+{
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+  thunar_shortcuts_view_mount (view, FALSE);
 }
 
 
 
-static gboolean
-thunar_shortcuts_view_mount (ThunarShortcutsView *view)
+static void
+thunar_shortcuts_view_mount_finish (GObject      *object,
+                                    GAsyncResult *result,
+                                    gpointer      user_data)
 {
-  GtkTreeSelection *selection;
-  ThunarVfsVolume  *volume;
-  GtkTreeModel     *model;
-  GtkTreeIter       iter;
-  GtkWidget        *window;
-  gboolean          result = TRUE;
-  GError           *error = NULL;
+  ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
+  GtkWidget           *window;
+  GVolume             *volume = G_VOLUME (object);
+  GError              *error = NULL;
+  gchar               *volume_name;
 
-  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
+  _thunar_return_if_fail (G_IS_VOLUME (object));
+  _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
+  _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))
+  /* check if there was an error */
+  if (!g_volume_mount_finish (volume, result, &error))
     {
-      /* 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))
+      /* ignore GIO errors already handled */
+      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
         {
-          /* check if the volume isn't already mounted */
-          if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume)))
-            {
-              /* determine the toplevel window */
-              window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
 
-              /* try to mount the volume */
-              result = thunar_vfs_volume_mount (volume, window, &error);
-              if (G_UNLIKELY (!result))
-                {
-                  /* display an error dialog to inform the user */
-                  thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume));
-                  g_error_free (error);
-                }
-            }
+          /* display an error dialog to inform the user */
+          volume_name = g_volume_get_name (volume);
+          thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), volume_name);
+          g_free (volume_name);
 
-          /* cleanup */
-          g_object_unref (G_OBJECT (volume));
+          /* free the error */
+          g_error_free (error);
         }
     }
+  else
+    {
+      thunar_shortcuts_view_open_selection (view);
+    }
+}
 
-  return result;
+
+static void
+thunar_shortcuts_view_mount_new_window_finish (GObject      *object,
+                                               GAsyncResult *result,
+                                               gpointer      user_data)
+{
+  ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data);
+  GtkWidget           *window;
+  GVolume             *volume = G_VOLUME (object);
+  GError              *error = NULL;
+  gchar               *volume_name;
+
+  _thunar_return_if_fail (G_IS_VOLUME (object));
+  _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  /* check if there was an error */
+  if (!g_volume_mount_finish (volume, result, &error))
+    {
+      /* ignore GIO errors which were already handled */
+      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
+        {
+          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+          /* display an error dialog to inform the user */
+          volume_name = g_volume_get_name (volume);
+          thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), volume_name);
+          g_free (volume_name);
+
+          /* free the error */
+          g_error_free (error);
+        }
+    }
+  else
+    {
+      thunar_shortcuts_view_open_selection_in_new_window (view);
+    }
 }
 
 
 
-static gboolean
-thunar_shortcuts_view_unmount (ThunarShortcutsView *view)
+
+static void
+thunar_shortcuts_view_mount (ThunarShortcutsView *view,
+                             gboolean             open_in_new_window)
 {
   GtkTreeSelection *selection;
-  ThunarVfsVolume  *volume;
+  GMountOperation  *mount_operation;
   GtkTreeModel     *model;
   GtkTreeIter       iter;
   GtkWidget        *window;
-  gboolean          result = TRUE;
-  GError           *error = NULL;
+  GVolume          *volume;
 
-  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE);
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
 
   /* determine the selected item */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
@@ -1426,24 +1594,41 @@
       gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
       if (G_UNLIKELY (volume != NULL))
         {
-          /* determine the toplevel window */
-          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
-          /* try to unmount the volume */
-          result = thunar_vfs_volume_unmount (volume, window, &error);
-          if (G_UNLIKELY (!result))
+          if (G_LIKELY (g_volume_is_mounted (volume)))
             {
-              /* display an error dialog to inform the user */
-              thunar_dialogs_show_error (window, error, _("Failed to unmount \"%s\""), thunar_vfs_volume_get_name (volume));
-              g_error_free (error);
+              /* the volume is already mounted, so we can simply open it */
+              if (open_in_new_window)
+                thunar_shortcuts_view_open_selection_in_new_window (view);
+              else
+                thunar_shortcuts_view_open_selection (view);
             }
+          else
+            {
+              /* allocate a GTK+ mount operation for user interaction required during
+               * the mount process */
+              window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+              mount_operation = gtk_mount_operation_new (GTK_WINDOW (window));
 
+              /* try to mount the volume asynchronously */
+              if (open_in_new_window)
+                {
+                  g_volume_mount (volume, G_MOUNT_MOUNT_NONE, mount_operation, NULL,
+                                  thunar_shortcuts_view_mount_new_window_finish, view);
+                }
+              else
+                {
+                  g_volume_mount (volume, G_MOUNT_MOUNT_NONE, mount_operation, NULL,
+                                  thunar_shortcuts_view_mount_finish, view);
+                }
+
+              /* release the mount operation */
+              g_object_unref (mount_operation);
+            }
+
           /* cleanup */
-          g_object_unref (G_OBJECT (volume));
+          g_object_unref (volume);
         }
     }
-
-  return result;
 }
 
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-window.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-28 19:55:34 UTC (rev 29912)
+++ thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-29 07:42:23 UTC (rev 29913)
@@ -197,8 +197,8 @@
 static void     thunar_window_notify_loading              (ThunarView             *view,
                                                            GParamSpec             *pspec,
                                                            ThunarWindow           *window);
-static void     thunar_window_volume_pre_unmount          (ThunarVfsVolumeManager *volume_manager,
-                                                           ThunarVfsVolume        *volume,
+static void     thunar_window_mount_pre_unmount           (GVolumeMonitor         *volume_monitor,
+                                                           GMount                 *mount,
                                                            ThunarWindow           *window);
 static gboolean thunar_window_merge_idle                  (gpointer                user_data);
 static void     thunar_window_merge_idle_destroy          (gpointer                user_data);
@@ -237,8 +237,8 @@
   GtkActionGroup         *action_group;
   GtkUIManager           *ui_manager;
 
-  /* to be able to change folder on "volume-pre-unmount" if required */
-  ThunarVfsVolumeManager *volume_manager;
+  /* to be able to change folder on "mount-pre-unmount" if required */
+  GVolumeMonitor         *volume_monitor;
 
   /* closures for the menu_item_selected()/menu_item_deselected() callbacks */
   GClosure               *menu_item_selected_closure;
@@ -708,9 +708,9 @@
   /* allocate the scroll_to_files mapping */
   window->scroll_to_files = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, g_object_unref);
 
-  /* connect to the volume manager */
-  window->volume_manager = thunar_vfs_volume_manager_get_default ();
-  g_signal_connect (G_OBJECT (window->volume_manager), "volume-pre-unmount", G_CALLBACK (thunar_window_volume_pre_unmount), window);
+  /* connect to the volume monitor */
+  window->volume_monitor = g_volume_monitor_get ();
+  g_signal_connect (window->volume_monitor, "mount-pre-unmount", G_CALLBACK (thunar_window_mount_pre_unmount), window);
 
   /* allocate a closure for the menu_item_selected() callback */
   window->menu_item_selected_closure = g_cclosure_new_object (G_CALLBACK (thunar_window_menu_item_selected), G_OBJECT (window));
@@ -956,24 +956,24 @@
   g_closure_unref (window->menu_item_deselected_closure);
   g_closure_unref (window->menu_item_selected_closure);
 
-  /* disconnect from the volume manager */
-  g_signal_handlers_disconnect_matched (G_OBJECT (window->volume_manager), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
-  g_object_unref (G_OBJECT (window->volume_manager));
+  /* disconnect from the volume monitor */
+  g_signal_handlers_disconnect_matched (window->volume_monitor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
+  g_object_unref (window->volume_monitor);
 
   /* disconnect from the ui manager */
-  g_signal_handlers_disconnect_matched (G_OBJECT (window->ui_manager), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
-  g_object_unref (G_OBJECT (window->ui_manager));
+  g_signal_handlers_disconnect_matched (window->ui_manager, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
+  g_object_unref (window->ui_manager);
 
-  g_object_unref (G_OBJECT (window->action_group));
-  g_object_unref (G_OBJECT (window->icon_factory));
-  g_object_unref (G_OBJECT (window->launcher));
-  g_object_unref (G_OBJECT (window->history));
+  g_object_unref (window->action_group);
+  g_object_unref (window->icon_factory);
+  g_object_unref (window->launcher);
+  g_object_unref (window->history);
 
   /* release our reference on the provider factory */
-  g_object_unref (G_OBJECT (window->provider_factory));
+  g_object_unref (window->provider_factory);
 
   /* release the preferences reference */
-  g_object_unref (G_OBJECT (window->preferences));
+  g_object_unref (window->preferences);
 
   /* release the scroll_to_files hash table */
   g_hash_table_destroy (window->scroll_to_files);
@@ -2395,29 +2395,28 @@
 
 
 static void
-thunar_window_volume_pre_unmount (ThunarVfsVolumeManager *volume_manager,
-                                  ThunarVfsVolume        *volume,
-                                  ThunarWindow           *window)
+thunar_window_mount_pre_unmount (GVolumeMonitor *volume_monitor,
+                                 GMount         *mount,
+                                 ThunarWindow   *window)
 {
-  ThunarVfsPath *path;
-  ThunarFile    *file;
-  GtkAction     *action;
+  ThunarFile *file;
+  GtkAction  *action;
+  GFile      *mount_point;
 
-  _thunar_return_if_fail (THUNAR_VFS_IS_VOLUME_MANAGER (volume_manager));
-  _thunar_return_if_fail (THUNAR_VFS_IS_VOLUME (volume));
+  _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
+  _thunar_return_if_fail (window->volume_monitor == volume_monitor);
+  _thunar_return_if_fail (G_IS_MOUNT (mount));
   _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
 
   /* nothing to do if we don't have a current directory */
   if (G_UNLIKELY (window->current_directory == NULL))
     return;
 
-  /* determine the mount point for the volume */
-  path = thunar_vfs_volume_get_mount_point (volume);
-  if (G_UNLIKELY (path == NULL))
-    return;
+  /* try to get the ThunarFile for the mount point from the file cache */
+  mount_point = g_mount_get_root (mount);
+  file = thunar_file_cache_lookup (mount_point);
+  g_object_unref (mount_point);
 
-  /* check if a ThunarFile is known for the mount point */
-  file = thunar_file_cache_lookup_path (path);
   if (G_UNLIKELY (file == NULL))
     return;
 




More information about the Xfce4-commits mailing list