[gnome-commander] Use GIO instead of GnomeVFS for mounting a volume



commit 7f96060b168b8623446918639b87c28179cb1536
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Jun 20 21:00:00 2021 +0200

    Use GIO instead of GnomeVFS for mounting a volume

 src/dialogs/gnome-cmd-file-props-dialog.cc |  10 +-
 src/gnome-cmd-con-device.cc                | 284 +++++++++++++++++++++--------
 src/gnome-cmd-con-device.h                 |   7 +-
 src/gnome-cmd-con.cc                       |  64 ++++++-
 src/gnome-cmd-con.h                        |   4 +
 src/gnome-cmd-data.cc                      | 111 ++++-------
 6 files changed, 321 insertions(+), 159 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-file-props-dialog.cc b/src/dialogs/gnome-cmd-file-props-dialog.cc
index 017b8ddc5..479bfcc28 100644
--- a/src/dialogs/gnome-cmd-file-props-dialog.cc
+++ b/src/dialogs/gnome-cmd-file-props-dialog.cc
@@ -380,15 +380,13 @@ static GtkWidget *create_properties_tab (GnomeCmdFilePropsDialogPrivate *data)
 
         if (GNOME_CMD_IS_CON_DEVICE (con))
         {
-            if (GnomeVFSVolume *vol = gnome_cmd_con_device_get_vfs_volume (GNOME_CMD_CON_DEVICE (con)))
+            if (auto *gMount = gnome_cmd_con_device_get_gmount (GNOME_CMD_CON_DEVICE (con)))
             {
-                gchar *fs_type = gnome_vfs_volume_get_filesystem_type (vol);
-                gchar *dev_path = gnome_vfs_volume_get_device_path (vol);
+                gchar *dev_uuid = g_mount_get_uuid (gMount);
 
-                gchar *s = g_strdup_printf ("%s (%s, %s)", gnome_cmd_con_get_alias (con), dev_path, fs_type);
+                gchar *s = g_strdup_printf ("%s (%s)", gnome_cmd_con_get_alias (con), dev_uuid);
 
-                g_free (fs_type);
-                g_free (dev_path);
+                g_free (dev_uuid);
 
                 label = create_label (dialog, s);
 
diff --git a/src/gnome-cmd-con-device.cc b/src/gnome-cmd-con-device.cc
index 8604ac28d..a32e0ef50 100644
--- a/src/gnome-cmd-con-device.cc
+++ b/src/gnome-cmd-con-device.cc
@@ -44,7 +44,6 @@ struct GnomeCmdConDevicePrivate
     gchar *mountp {nullptr};
     gchar *icon_path {nullptr};
     gboolean autovolume;
-    GnomeVFSVolume *vfsvol;
     GMount *gMount;
     GVolume *gVolume;
 };
@@ -88,8 +87,12 @@ static gboolean is_mounted (GnomeCmdConDevice *dev_con)
 }
 
 
-static void do_legacy_mount(GnomeCmdConDevice *dev_con)
+static void do_legacy_mount(GnomeCmdCon *con)
 {
+    g_return_if_fail (GNOME_CMD_IS_CON_DEVICE (con));
+
+    GnomeCmdConDevice *dev_con = GNOME_CMD_CON_DEVICE (con);
+
     gint ret, estatus;
 
     if (!is_mounted (dev_con))
@@ -144,48 +147,113 @@ static void do_legacy_mount(GnomeCmdConDevice *dev_con)
 }
 
 
-static void do_mount_thread_func (GnomeCmdCon *con)
+static void set_con_mount_succeed(GnomeCmdCon *con)
 {
-    g_return_if_fail (GNOME_CMD_IS_CON_DEVICE (con));
+    con->state = GnomeCmdCon::STATE_OPEN;
+    con->open_result = GnomeCmdCon::OPEN_OK;
+}
 
+
+static void set_con_mount_failed(GnomeCmdCon *con)
+{
+    g_object_unref (con->base_gFileInfo);
+    con->base_gFileInfo = nullptr;
+    con->open_result = GnomeCmdCon::OPEN_FAILED;
+    con->state = GnomeCmdCon::STATE_CLOSED;
+    con->open_failed_msg = con->open_failed_error->message;
+}
+
+
+static void mount_finish_callback(GObject *gVol, GAsyncResult *result, gpointer user_data)
+{
+    GnomeCmdCon *con = GNOME_CMD_CON (user_data);
     GnomeCmdConDevice *dev_con = GNOME_CMD_CON_DEVICE (con);
+    auto gVolume = G_VOLUME(gVol);
+    GError *error = nullptr;
 
-    // If mount point is given, we have mount the device with system calls ('mount')
-    // ToDo: Don't do this anymore...
-    if (dev_con->priv->mountp)
+    if(!g_volume_mount_finish(gVolume, result, &error))
     {
-        do_legacy_mount(dev_con);
+        g_critical("Unable to mount the volume, error: %s", error->message);
+        con->open_failed_error = g_error_copy(error);
+        set_con_mount_failed(con);
+        g_error_free(error);
+        return;
     }
-    else
+    dev_con->priv->gMount = g_volume_get_mount (gVolume);
+    if (!con->base_path)
     {
-        /* ... */
+        set_con_base_path_for_gmount(con, dev_con->priv->gMount);
     }
+    if (!con->base_path)
+    {
+        gnome_cmd_con_set_root_path(con, con->base_path->get_path());
+    }
+    set_con_base_gfileinfo(con);
+    set_con_mount_succeed(con);
+}
+
+static void do_legacy_mount_thread_func(GnomeCmdCon *con)
+{
+    g_return_if_fail (GNOME_CMD_IS_CON_DEVICE (con));
 
-    GnomeVFSURI *uri = gnome_cmd_con_create_uri (con, con->base_path);
-    if (!uri)
+    GError *error = nullptr;
+
+    if (!con->base_path)
+        con->base_path = new GnomeCmdPlainPath(G_DIR_SEPARATOR_S);
+
+    do_legacy_mount(con);
+
+    auto gFile = gnome_cmd_con_create_gfile(con, con->base_path);
+    con->base_gFileInfo = g_file_query_info(gFile,
+                              "*",
+                              G_FILE_QUERY_INFO_NONE,
+                              nullptr,
+                              &error);
+    g_object_unref(gFile);
+    if (error)
+    {
+        con->open_failed_error = g_error_copy(error);
+        set_con_mount_failed(con);
+        g_critical("Unable to mount the volume via legacy mount, error: %s", error->message);
+        g_error_free(error);
         return;
+    }
+
+    set_con_mount_succeed(con);
+    return;
+}
 
-    gchar *uri_str = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
-    con->base_info = gnome_vfs_file_info_new ();
-    GnomeVFSFileInfoOptions infoOpts = (GnomeVFSFileInfoOptions) (GNOME_VFS_FILE_INFO_FOLLOW_LINKS | 
GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE);
-    GnomeVFSResult result = gnome_vfs_get_file_info_uri (uri, con->base_info, infoOpts);
 
-    gnome_vfs_uri_unref (uri);
-    g_free (uri_str);
+static void do_mount (GnomeCmdCon *con)
+{
+    g_return_if_fail (GNOME_CMD_IS_CON_DEVICE (con));
+
+    GnomeCmdConDevice *dev_con = GNOME_CMD_CON_DEVICE (con);
 
-    if (result == GNOME_VFS_OK)
+    // This is a legacy-mount: If mount point is given, we mount the device with system calls ('mount')
+    if (dev_con->priv->mountp)
     {
-        con->state = GnomeCmdCon::STATE_OPEN;
-        con->open_result = GnomeCmdCon::OPEN_OK;
+        auto gThread = g_thread_new (nullptr, (GThreadFunc) do_legacy_mount_thread_func, con);
+        g_thread_unref(gThread);
     }
-    else
+
+    // Check if the volume is already mounted:
+    auto gMount = g_volume_get_mount (dev_con->priv->gVolume);
+    if (gMount)
     {
-        gnome_vfs_file_info_unref (con->base_info);
-        con->base_info = nullptr;
-        con->open_failed_reason = result;
-        con->open_result = GnomeCmdCon::OPEN_FAILED;
-        con->state = GnomeCmdCon::STATE_CLOSED;
+        dev_con->priv->gMount = gMount;
+        set_con_base_path_for_gmount(con, dev_con->priv->gMount);
+        set_con_base_gfileinfo(con);
+        set_con_mount_succeed(con);
+        return;
     }
+    g_volume_mount (dev_con->priv->gVolume,
+        G_MOUNT_MOUNT_NONE,
+        nullptr,
+        nullptr,
+        mount_finish_callback,
+        con);
+
 }
 
 
@@ -195,38 +263,47 @@ static void dev_open (GnomeCmdCon *con)
 
     DEBUG ('m', "Mounting device\n");
 
-    if (!con->base_path)
-        con->base_path = new GnomeCmdPlainPath(G_DIR_SEPARATOR_S);
-
     con->state = GnomeCmdCon::STATE_OPENING;
     con->open_result = GnomeCmdCon::OPEN_IN_PROGRESS;
 
-    g_thread_new (nullptr, (GThreadFunc) do_mount_thread_func, con);
+    do_mount(con);
 }
 
 
-static void dev_vfs_umount_callback (gboolean succeeded, char *error, char *detailed_error, gpointer data)
+static void unmount_callback(GObject *gMnt, GAsyncResult *result, gpointer user_data)
 {
+    GnomeCmdCon *con = GNOME_CMD_CON (user_data);
+    auto gMount = G_MOUNT(gMnt);
+    GError *error = nullptr;
     GtkWidget *msgbox;
 
-    DEBUG('m', "VFS umount callback: %s %s %s\n", succeeded ? "succeeded" : "failed",
-               error ? error : "",
-               detailed_error ? detailed_error : "");
+    if (!g_mount_unmount_with_operation_finish (gMount, result, &error))
+    {
+        DEBUG('m', "unmount_callback: failed %s\n", error->message);
 
-    if (succeeded)
-        msgbox = gtk_message_dialog_new (*main_win,
-                                         GTK_DIALOG_MODAL,
-                                         GTK_MESSAGE_INFO,
-                                         GTK_BUTTONS_OK,
-                                         _("Device is now safe to remove"));
-    else
         msgbox = gtk_message_dialog_new (*main_win,
                                          GTK_DIALOG_MODAL,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_OK,
-                                         _("Cannot unmount the volume:\n%s %s"),
-                                         error ? error : _("Unknown error"),
-                                         detailed_error ? detailed_error: "");
+                                         _("Cannot unmount the volume:\n%s\nError code: %d"),
+                                         error->message,
+                                         error->code);
+        gtk_dialog_run (GTK_DIALOG (msgbox));
+        gtk_widget_destroy (msgbox);
+
+        g_error_free(error);
+        return;
+    }
+
+    con->state = GnomeCmdCon::STATE_CLOSED;
+
+    DEBUG('m', "unmount_callback: succeeded\n");
+
+    msgbox = gtk_message_dialog_new (*main_win,
+                                     GTK_DIALOG_MODAL,
+                                     GTK_MESSAGE_INFO,
+                                     GTK_BUTTONS_OK,
+                                     _("Volume successfuly unmounted"));
 
     gtk_dialog_run (GTK_DIALOG (msgbox));
     gtk_widget_destroy (msgbox);
@@ -250,28 +327,35 @@ static gboolean dev_close (GnomeCmdCon *con)
 
     if (dev_con->priv->autovolume)
     {
-        if (dev_con->priv->vfsvol)
-        {
-            gchar *name;
-            name = gnome_vfs_volume_get_display_name (dev_con->priv->vfsvol);
-            DEBUG ('m', "umounting VFS volume \"%s\"\n", name);
-            g_free (name);
-
-            gnome_vfs_volume_unmount (dev_con->priv->vfsvol, dev_vfs_umount_callback, nullptr);
-        }
+        if (!g_mount_can_unmount(dev_con->priv->gMount))
+            return ret == 0;
+
+        auto gMountName = g_mount_get_name(dev_con->priv->gMount);
+        DEBUG ('m', "umounting GIO mount \"%s\"\n", gMountName);
+        g_free(gMountName);
+        g_mount_unmount_with_operation (dev_con->priv->gMount,
+                            G_MOUNT_UNMOUNT_NONE,
+                            nullptr,
+                            nullptr,
+                            unmount_callback,
+                            con);
     }
     else
     {
-        DEBUG ('m', "umounting %s\n", dev_con->priv->mountp);
-        gchar *cmd = g_strdup_printf ("umount %s", dev_con->priv->mountp);
-        ret = system (cmd);
-        DEBUG ('m', "umount returned %d\n", ret);
-        g_free (cmd);
+        // Legacy unmount
+        if(dev_con->priv->mountp)
+        {
+            DEBUG ('m', "umounting %s\n", dev_con->priv->mountp);
+            gchar *cmd = g_strdup_printf ("umount %s", dev_con->priv->mountp);
+            ret = system (cmd);
+            DEBUG ('m', "umount returned %d\n", ret);
+            g_free (cmd);
+
+            if (ret == 0)
+                con->state = GnomeCmdCon::STATE_CLOSED;
+        }
     }
 
-    if (ret == 0)
-        con->state = GnomeCmdCon::STATE_CLOSED;
-
     return ret == 0;
 }
 
@@ -306,6 +390,16 @@ static GnomeVFSURI *dev_create_uri (GnomeCmdCon *con, GnomeCmdPath *path)
 }
 
 
+static GFile *dev_create_gfile (GnomeCmdCon *con, GnomeCmdPath *unused)
+{
+    g_return_val_if_fail (GNOME_CMD_IS_CON_DEVICE (con), nullptr);
+
+    GnomeCmdConDevice *dev_con = GNOME_CMD_CON_DEVICE (con);
+
+    return g_mount_get_default_location (dev_con->priv->gMount);
+}
+
+
 static GnomeCmdPath *dev_create_path (GnomeCmdCon *con, const gchar *path_str)
 {
     g_return_val_if_fail (GNOME_CMD_IS_CON_DEVICE (con), nullptr);
@@ -323,10 +417,15 @@ static void destroy (GtkObject *object)
 {
     GnomeCmdConDevice *con = GNOME_CMD_CON_DEVICE (object);
 
-    if (con->priv->vfsvol)
+    if (con->priv->gMount)
     {
-        gnome_vfs_volume_unref (con->priv->vfsvol);
-        con->priv->vfsvol = nullptr;
+        g_object_unref(con->priv->gMount);
+        con->priv->gMount = nullptr;
+    }
+    if (con->priv->gVolume)
+    {
+        g_object_unref(con->priv->gVolume);
+        con->priv->gVolume = nullptr;
     }
 
     g_free (con->priv);
@@ -352,6 +451,7 @@ static void class_init (GnomeCmdConDeviceClass *klass)
     con_class->cancel_open = dev_cancel_open;
     con_class->open_is_needed = dev_open_is_needed;
     con_class->create_uri = dev_create_uri;
+    con_class->create_gfile = dev_create_gfile;
     con_class->create_path = dev_create_path;
 }
 
@@ -412,10 +512,12 @@ GnomeCmdConDevice *gnome_cmd_con_device_new (const gchar *alias, const gchar *de
     gnome_cmd_con_device_set_mountp (dev, mountp);
     gnome_cmd_con_device_set_icon_path (dev, icon_path);
     gnome_cmd_con_device_set_autovol(dev, FALSE);
-    gnome_cmd_con_device_set_vfs_volume(dev, nullptr);
+    gnome_cmd_con_device_set_gmount(dev, nullptr);
+    gnome_cmd_con_device_set_gvolume(dev, nullptr);
     gnome_cmd_con_device_set_alias (dev, alias);
 
-    gnome_cmd_con_set_root_path (con, mountp);
+    if (mountp)
+        gnome_cmd_con_set_root_path (con, mountp);
 
     con->open_msg = g_strdup_printf (_("Mounting %s"), alias);
 
@@ -433,7 +535,10 @@ void gnome_cmd_con_device_set_alias (GnomeCmdConDevice *dev, const gchar *alias)
 
     dev->priv->alias = g_strdup (alias);
     GNOME_CMD_CON (dev)->alias = g_strdup (alias);
-    GNOME_CMD_CON (dev)->go_text = g_strdup_printf (_("Go to: %s (%s)"), alias, dev->priv->mountp);
+    if (dev->priv->mountp)
+        GNOME_CMD_CON (dev)->go_text = g_strdup_printf (_("Go to: %s (%s)"), alias, dev->priv->mountp);
+    else
+        GNOME_CMD_CON (dev)->go_text = g_strdup_printf (_("Go to: %s"), alias);
     GNOME_CMD_CON (dev)->open_text = g_strdup_printf (_("Mount: %s"), alias);
     GNOME_CMD_CON (dev)->close_text = g_strdup_printf (_("Unmount: %s"), alias);
 }
@@ -528,20 +633,37 @@ void gnome_cmd_con_device_set_autovol (GnomeCmdConDevice *dev, const gboolean au
 }
 
 
-void gnome_cmd_con_device_set_vfs_volume (GnomeCmdConDevice *dev, GnomeVFSVolume *vfsvol)
+void gnome_cmd_con_device_set_gmount (GnomeCmdConDevice *dev, GMount *gMount)
+{
+    g_return_if_fail (dev != nullptr);
+    g_return_if_fail (dev->priv != nullptr);
+
+    if (dev->priv->gMount)
+    {
+        g_object_unref (dev->priv->gMount);
+        dev->priv->gMount = nullptr;
+    }
+
+    dev->priv->gMount = gMount;
+    if (dev->priv->gMount)
+        g_object_ref(dev->priv->gMount);
+}
+
+
+void gnome_cmd_con_device_set_gvolume (GnomeCmdConDevice *dev, GVolume *gVolume)
 {
     g_return_if_fail (dev != nullptr);
     g_return_if_fail (dev->priv != nullptr);
 
-    if (dev->priv->vfsvol)
+    if (dev->priv->gVolume)
     {
-        gnome_vfs_volume_unref (dev->priv->vfsvol);
-        dev->priv->vfsvol = nullptr;
+        g_object_unref (dev->priv->gVolume);
+        dev->priv->gVolume = nullptr;
     }
 
-    dev->priv->vfsvol = vfsvol;
-    if (dev->priv->vfsvol)
-        gnome_vfs_volume_ref(dev->priv->vfsvol);
+    dev->priv->gVolume = gVolume;
+    if (dev->priv->gVolume)
+        g_object_ref(dev->priv->gVolume);
 }
 
 
@@ -590,10 +712,18 @@ gboolean gnome_cmd_con_device_get_autovol (GnomeCmdConDevice *dev)
 }
 
 
-GnomeVFSVolume *gnome_cmd_con_device_get_vfs_volume (GnomeCmdConDevice *dev)
+GMount *gnome_cmd_con_device_get_gmount (GnomeCmdConDevice *dev)
+{
+    g_return_val_if_fail (dev != nullptr, nullptr);
+    g_return_val_if_fail (dev->priv != nullptr, nullptr);
+
+    return dev->priv->gMount;
+}
+
+GVolume *gnome_cmd_con_device_get_gvolume (GnomeCmdConDevice *dev)
 {
     g_return_val_if_fail (dev != nullptr, nullptr);
     g_return_val_if_fail (dev->priv != nullptr, nullptr);
 
-    return dev->priv->vfsvol;
+    return dev->priv->gVolume;
 }
diff --git a/src/gnome-cmd-con-device.h b/src/gnome-cmd-con-device.h
index 92f1f64bf..515cb9edb 100644
--- a/src/gnome-cmd-con-device.h
+++ b/src/gnome-cmd-con-device.h
@@ -68,5 +68,8 @@ void gnome_cmd_con_device_set_icon_path (GnomeCmdConDevice *dev, const gchar *ic
 gboolean gnome_cmd_con_device_get_autovol (GnomeCmdConDevice *dev);
 void gnome_cmd_con_device_set_autovol (GnomeCmdConDevice *dev, const gboolean autovol);
 
-GnomeVFSVolume *gnome_cmd_con_device_get_vfs_volume (GnomeCmdConDevice *dev);
-void gnome_cmd_con_device_set_vfs_volume (GnomeCmdConDevice *dev, GnomeVFSVolume *vfsvol);
+GMount *gnome_cmd_con_device_get_gmount (GnomeCmdConDevice *dev);
+void gnome_cmd_con_device_set_gmount (GnomeCmdConDevice *dev, GMount *gMount);
+
+GVolume *gnome_cmd_con_device_get_gvolume (GnomeCmdConDevice *dev);
+void gnome_cmd_con_device_set_gvolume (GnomeCmdConDevice *dev, GVolume *gVolume);
diff --git a/src/gnome-cmd-con.cc b/src/gnome-cmd-con.cc
index f8b7f66e3..e38102ec8 100644
--- a/src/gnome-cmd-con.cc
+++ b/src/gnome-cmd-con.cc
@@ -23,6 +23,7 @@
 
 #include "gnome-cmd-includes.h"
 #include "gnome-cmd-con.h"
+#include "gnome-cmd-plain-path.h"
 
 using namespace std;
 
@@ -72,6 +73,10 @@ static void on_open_done (GnomeCmdCon *con)
 static void on_open_failed (GnomeCmdCon *con, const gchar *msg, GnomeVFSResult result)
 {
     // gnome_cmd_con_updated (con);
+    // ToDo: Show error and later on g_error_free con->open_failed_error
+    g_critical("open_failed - error: %s\n", con->open_failed_error->message);
+    g_error_free(con->open_failed_error);
+    con->open_failed_msg = nullptr;
 }
 
 
@@ -93,6 +98,9 @@ static void destroy (GtkObject *object)
     gnome_cmd_pixmap_free (con->open_pixmap);
     g_free (con->close_text);
     g_free (con->close_tooltip);
+    g_object_unref(con->base_gFileInfo);
+    g_error_free(con->open_failed_error);
+    con->open_failed_msg = nullptr;
     gnome_cmd_pixmap_free (con->close_pixmap);
     gnome_cmd_pixmap_free (con->go_pixmap);
 
@@ -197,6 +205,7 @@ static void init (GnomeCmdCon *con)
     con->open_result = GnomeCmdCon::OPEN_NOT_STARTED;
     con->open_failed_reason = GNOME_VFS_OK;
     con->open_failed_msg = nullptr;
+    con->open_failed_error = nullptr;
 
     con->priv = g_new0 (GnomeCmdConPrivate, 1);
     con->priv->default_dir = nullptr;
@@ -270,7 +279,7 @@ static gboolean check_con_open_progress (GnomeCmdCon *con)
             {
                 DEBUG ('m', "GnomeCmdCon::OPEN_FAILED detected\n");
                 DEBUG ('m', "Emitting 'open-failed' signal\n");
-                gtk_signal_emit (GTK_OBJECT (con), signals[OPEN_FAILED], con->open_failed_msg, 
con->open_failed_reason);
+                gtk_signal_emit (GTK_OBJECT (con), signals[OPEN_FAILED], con->open_failed_msg, 
con->open_failed_error->code);
             }
             return FALSE;
 
@@ -283,6 +292,59 @@ static gboolean check_con_open_progress (GnomeCmdCon *con)
 }
 
 
+static void set_con_base_path(GnomeCmdCon *con, GnomeCmdPath *path)
+{
+    g_return_if_fail (con != nullptr);
+    g_return_if_fail (GNOME_CMD_IS_CON (con));
+    g_return_if_fail (path != nullptr);
+
+    if (con->base_path)
+        delete con->base_path;
+
+    con->base_path = path;
+}
+
+
+void set_con_base_path_for_gmount(GnomeCmdCon *con, GMount *gMount)
+{
+    g_return_if_fail (con != nullptr);
+    g_return_if_fail (GNOME_CMD_IS_CON (con));
+    g_return_if_fail (gMount != nullptr);
+    g_return_if_fail (G_IS_MOUNT(gMount));
+
+    auto gFile = g_mount_get_default_location(gMount);
+    auto pathString = g_file_get_path(gFile);
+    g_object_unref(gFile);
+
+    set_con_base_path(con, new GnomeCmdPlainPath(pathString));
+
+    g_free(pathString);
+}
+
+gboolean set_con_base_gfileinfo(GnomeCmdCon *con)
+{
+    g_return_val_if_fail (con != nullptr, FALSE);
+    g_return_val_if_fail (GNOME_CMD_IS_CON (con), FALSE);
+    GError *error = nullptr;
+
+    if (con->base_gFileInfo)
+    {
+        g_object_unref(con->base_gFileInfo);
+        con->base_gFileInfo = nullptr;
+    }
+
+    auto gFile = gnome_cmd_con_create_gfile (con, nullptr);
+    con->base_gFileInfo = g_file_query_info(gFile, "*", G_FILE_QUERY_INFO_NONE, nullptr, &error);
+    g_object_unref(gFile);
+    if (error)
+    {
+        g_critical("set_con_base_gfileinfo: error: %s", error->message);
+        g_error_free(error);
+        return FALSE;
+    }
+    return TRUE;
+}
+
 void gnome_cmd_con_open (GnomeCmdCon *con)
 {
     g_return_if_fail (GNOME_CMD_IS_CON (con));
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index c86b33c47..25808a9ae 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -91,6 +91,7 @@ struct GnomeCmdCon
     gchar               *open_msg;
     GnomeCmdPath        *base_path;
     GnomeVFSFileInfo    *base_info;
+    GFileInfo           *base_gFileInfo;
     GString             *root_path;             // Root path of the connection, used for calculation of 
relative paths
     gboolean            should_remember_dir;
     gboolean            needs_open_visprog;
@@ -111,6 +112,7 @@ struct GnomeCmdCon
 
     OpenResult          open_result;
     GnomeVFSResult      open_failed_reason;
+    GError              *open_failed_error;
     gchar               *open_failed_msg;
 
     GnomeCmdConPrivate  *priv;
@@ -138,6 +140,8 @@ struct GnomeCmdConClass
 
 GtkType gnome_cmd_con_get_type ();
 
+void set_con_base_path_for_gmount(GnomeCmdCon *con, GMount *gMount);
+gboolean set_con_base_gfileinfo(GnomeCmdCon *con);
 
 void gnome_cmd_con_open (GnomeCmdCon *con);
 
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 2d9c57542..a026de2df 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -22,8 +22,6 @@
 #include <config.h>
 #include <glib.h>
 #include <glib/gstdio.h>
-#include <libgnomevfs/gnome-vfs-volume.h>
-#include <libgnomevfs/gnome-vfs-volume-monitor.h>
 
 #include <fstream>
 #include <algorithm>
@@ -2039,22 +2037,9 @@ inline gboolean vfs_is_uri_local (const char *uri)
 }
 
 
-inline void remove_vfs_volume (GnomeVFSVolume *volume)
+inline void remove_gvolume (GVolume *gVolume)
 {
-    char *path, *uri, *localpath;
-
-    if (!gnome_vfs_volume_is_user_visible (volume))
-        return;
-
-    uri = gnome_vfs_volume_get_activation_uri (volume);
-    if (!vfs_is_uri_local (uri))
-    {
-        g_free (uri);
-        return;
-    }
-
-    path = gnome_vfs_volume_get_device_path (volume);
-    localpath = gnome_vfs_get_local_path_from_uri (uri);
+    auto identifier = g_volume_get_identifier(gVolume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
     for (GList *i = gnome_cmd_con_list_get_all_dev (gnome_cmd_data.priv->con_list); i; i = i->next)
     {
@@ -2062,21 +2047,17 @@ inline void remove_vfs_volume (GnomeVFSVolume *volume)
         if (device && gnome_cmd_con_device_get_autovol (device))
         {
             gchar *device_fn = (gchar *) gnome_cmd_con_device_get_device_fn (device);
-            const gchar *mountp = gnome_cmd_con_device_get_mountp (device);
 
-            if ((strcmp(device_fn, path)==0) && (strcmp(mountp, localpath)==0))
+            if ((g_strcmp0(device_fn, identifier)==0))
             {
-                DEBUG('m',"Remove Volume:\ndevice_fn = %s\tmountp = %s\n",
-                device_fn,mountp);
+                DEBUG('m',"Remove Volume: %s\n", device_fn);
                 gnome_cmd_data.priv->con_list->remove(device);
                 break;
             }
         }
     }
 
-    g_free (path);
-    g_free (uri);
-    g_free (localpath);
+    g_free(identifier);
 }
 
 
@@ -2106,96 +2087,80 @@ inline gboolean device_mount_point_exists (GnomeCmdConList *list, const gchar *m
 }
 
 
-static void add_vfs_volume (GnomeVFSVolume *volume)
+static void add_gvolume (GVolume *gVolume)
 {
-    if (!gnome_vfs_volume_is_user_visible (volume))
-        return;
+    g_return_if_fail (gVolume != nullptr);
 
-    char *uri = gnome_vfs_volume_get_activation_uri (volume);
-
-    if (!vfs_is_uri_local (uri))
-    {
-        g_free (uri);
-        return;
-    }
-
-    char *path = gnome_vfs_volume_get_device_path (volume);
-    char *icon = gnome_vfs_volume_get_icon (volume);
-    char *name = gnome_vfs_volume_get_display_name (volume);
-    GnomeVFSDrive *drive = gnome_vfs_volume_get_drive (volume);
+    char *uuid = g_volume_get_uuid (gVolume);
+    auto *gIcon = g_volume_get_icon (gVolume);
+    char *name = g_volume_get_name (gVolume);
+    auto identifier = g_volume_get_identifier(gVolume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
     // Try to load the icon, using current theme
     const gchar *iconpath = nullptr;
     GtkIconTheme *icontheme = gtk_icon_theme_get_default();
     if (icontheme)
     {
-        GtkIconInfo *iconinfo = gtk_icon_theme_lookup_icon (icontheme, icon, 16, 
GTK_ICON_LOOKUP_USE_BUILTIN);
+        GtkIconInfo *iconinfo = gtk_icon_theme_lookup_by_gicon(icontheme, gIcon, 16, 
GTK_ICON_LOOKUP_USE_BUILTIN);
         // This returned string should not be free, see gtk documentation
         if (iconinfo)
             iconpath = gtk_icon_info_get_filename (iconinfo);
     }
 
-    char *localpath = gnome_vfs_get_local_path_from_uri (uri);
-
     DEBUG('m',"name = %s\n", name);
-    DEBUG('m',"path = %s\n", path);
-    DEBUG('m',"uri = %s\n", uri);
-    DEBUG('m',"local = %s\n", localpath);
-    DEBUG('m',"icon = %s (full path = %s)\n", icon, iconpath);
+    DEBUG('m',"device path = %s\n", identifier);
+    DEBUG('m',"uuid = %s\n", uuid);
+    DEBUG('m',"icon path = %s\n", iconpath);
 
     // Don't create a new device connect if one already exists. This can happen if the user manually added 
the same device in "Options|Devices" menu
-    if (!device_mount_point_exists (gnome_cmd_data.priv->con_list, localpath))
+    if (!device_mount_point_exists (gnome_cmd_data.priv->con_list, identifier))
     {
-        GnomeCmdConDevice *ConDev = gnome_cmd_con_device_new (name, path?path:nullptr, localpath, iconpath);
+        GnomeCmdConDevice *ConDev = gnome_cmd_con_device_new (name, identifier, nullptr, iconpath);
         gnome_cmd_con_device_set_autovol (ConDev, TRUE);
-        gnome_cmd_con_device_set_vfs_volume (ConDev, volume);
+        gnome_cmd_con_device_set_gvolume (ConDev, gVolume);
         gnome_cmd_data.priv->con_list->add(ConDev);
     }
     else
-        DEBUG('m', "Device for mountpoint(%s) already exists. AutoVolume not added\n", localpath);
+        DEBUG('m', "Device for mountpoint(%s) already exists. AutoVolume not added\n", identifier);
 
-    g_free (path);
-    g_free (uri);
-    g_free (icon);
+    g_free (uuid);
     g_free (name);
-    g_free (localpath);
+    g_free (identifier);
 
-    gnome_vfs_drive_unref (drive);
+    g_object_unref (gIcon);
+    g_object_unref (gVolume);
 }
 
-
-static void volume_mounted (GnomeVFSVolumeMonitor *volume_monitor, GnomeVFSVolume *volume)
+static void volume_added (GVolumeMonitor *volume_monitor, GVolume *gVolume)
 {
-    add_vfs_volume (volume);
+    add_gvolume (gVolume);
 }
 
-
-static void volume_unmounted (GnomeVFSVolumeMonitor *volume_monitor, GnomeVFSVolume *volume)
+static void volume_removed (GVolumeMonitor *volume_monitor, GVolume *gVolume)
 {
-    remove_vfs_volume (volume);
+    remove_gvolume (gVolume);
 }
 
 inline void set_vfs_volume_monitor ()
 {
-    GnomeVFSVolumeMonitor *monitor = gnome_vfs_get_volume_monitor ();
+    auto monitor = g_volume_monitor_get();
 
-    g_signal_connect (monitor, "volume-mounted", G_CALLBACK (volume_mounted), nullptr);
-    g_signal_connect (monitor, "volume-unmounted", G_CALLBACK (volume_unmounted), nullptr);
+    g_signal_connect (monitor, "volume-added",      G_CALLBACK (volume_added), nullptr);
+    g_signal_connect (monitor, "volume-removed",    G_CALLBACK (volume_removed), nullptr);
 }
 
 
-static void load_vfs_auto_devices ()
+static void load_available_gvolumes ()
 {
-    GnomeVFSVolumeMonitor *monitor = gnome_vfs_get_volume_monitor ();
-    GList *volumes = gnome_vfs_volume_monitor_get_mounted_volumes (monitor);
+    GVolumeMonitor *monitor = g_volume_monitor_get ();
+    GList *gvolumes = g_volume_monitor_get_volumes (monitor);
 
-    for (GList *l = volumes; l; l = l->next)
+    for (GList *l = gvolumes; l; l = l->next)
     {
-        add_vfs_volume ((GnomeVFSVolume *) l->data);
-        gnome_vfs_volume_unref ((GnomeVFSVolume *) l->data);
+        add_gvolume ((GVolume *) l->data);
+        g_object_unref ((GVolume *) l->data);
     }
-    g_list_free (volumes);
-
+    g_list_free (gvolumes);
 }
 
 
@@ -2763,7 +2728,7 @@ void GnomeCmdData::load_devices()
                g_variant_unref(device);
     }
     g_variant_unref(gvDevices);
-    load_vfs_auto_devices ();
+    load_available_gvolumes ();
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]