[gnome-commander] Add the ability to connect to remote mounts via GIO
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Add the ability to connect to remote mounts via GIO
- Date: Wed, 10 Nov 2021 20:51:41 +0000 (UTC)
commit 52a45533986480ec7190d654733ba54d992d116b
Author: Uwe Scholz <u scholz83 gmx de>
Date: Tue Nov 9 23:01:18 2021 +0100
Add the ability to connect to remote mounts via GIO
src/gnome-cmd-con-remote.cc | 101 +++++++++++++++++++++++++++-----------------
src/gnome-cmd-con-smb.cc | 8 ++--
2 files changed, 67 insertions(+), 42 deletions(-)
---
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index 376a0078..f0898eb3 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -24,6 +24,7 @@
#include "gnome-cmd-includes.h"
#include "gnome-cmd-data.h"
#include "gnome-cmd-con-remote.h"
+#include "gnome-cmd-main-win.h"
#include "gnome-cmd-plain-path.h"
#include "imageloader.h"
#include "utils.h"
@@ -34,54 +35,75 @@ using namespace std;
static GnomeCmdConClass *parent_class = nullptr;
-static void get_file_info_func (GnomeCmdCon *con)
+static void set_con_mount_failed(GnomeCmdCon *con)
{
g_return_if_fail(GNOME_CMD_IS_CON(con));
+ con->base_gFileInfo = nullptr;
+ con->open_result = GnomeCmdCon::OPEN_FAILED;
+ con->state = GnomeCmdCon::STATE_CLOSED;
+ con->open_failed_msg = con->open_failed_error->message;
+}
- GError *error = nullptr;
- auto gFile = gnome_cmd_con_create_gfile(con, con->base_path);
-
- auto uri = g_file_get_uri(gFile);
- DEBUG('m', "Connecting to %s\n", uri);
- g_free(uri);
+static void mount_remote_finish_callback(GObject *gobj, GAsyncResult *result, gpointer user_data)
+{
+ auto con = GNOME_CMD_CON(user_data);
+ g_return_if_fail(GNOME_CMD_IS_CON(user_data));
+ g_return_if_fail(gobj != nullptr);
+ auto gFile = G_FILE(gobj);
+ g_return_if_fail(G_IS_FILE(gFile));
- con->base_gFileInfo = g_file_query_info(gFile, "*", G_FILE_QUERY_INFO_NONE, nullptr, &error);
- if (error)
- {
- DEBUG('m', "g_file_query_info error: %s\n", error->message);
- }
- g_object_unref (gFile);
+ GError *error = nullptr;
+ GError *errorQuery = nullptr;
- if (con->state == GnomeCmdCon::STATE_OPENING)
+ // The volume might be mounted already, so we are trying to get some information about the
+ // underlying gFile to decide if we want to raise an error or not
+ g_file_mount_enclosing_volume_finish(gFile, result, &error);
+ con->base_gFileInfo = g_file_query_info(gFile, "*", G_FILE_QUERY_INFO_NONE, nullptr, &errorQuery);
+ if (errorQuery)
{
- DEBUG('m', "State was OPENING, setting flags\n");
- if (!error)
- {
- con->state = GnomeCmdCon::STATE_OPEN;
- con->open_result = GnomeCmdCon::OPEN_OK;
- }
- else
+ auto uriString = g_file_get_uri(gFile);
+ DEBUG('m', "Unable to query information for uri \"%s\", error: %s\n", uriString,
errorQuery->message);
+ g_free(uriString);
+ if (error)
{
- con->state = GnomeCmdCon::STATE_CLOSED;
- con->open_failed_error = g_error_copy(error);
- con->open_result = GnomeCmdCon::OPEN_FAILED;
- con->open_failed_msg = g_strdup (con->open_failed_error->message);
+ DEBUG('m', "... probably because of this error: %s\n", error->message);
g_error_free(error);
}
+ con->open_failed_error = g_error_copy(errorQuery);
+ g_error_free(errorQuery);
+ set_con_mount_failed(con);
+ g_object_unref(gFile);
+ return;
}
- else
- {
- if (con->state == GnomeCmdCon::STATE_CANCELLING)
- DEBUG('m', "The open operation was cancelled, doing nothing\n");
- else
- DEBUG('m', "Strange ConState %d\n", con->state);
- con->state = GnomeCmdCon::STATE_CLOSED;
- }
+
+ con->state = GnomeCmdCon::STATE_OPEN;
+ con->open_result = GnomeCmdCon::OPEN_OK;
+ g_object_unref(gFile);
}
-static gboolean start_get_file_info (GnomeCmdCon *con)
+
+static void mount_func (GnomeCmdCon *con)
{
- g_thread_new (nullptr, (GThreadFunc) get_file_info_func, con);
+ g_return_if_fail(GNOME_CMD_IS_CON(con));
+
+ auto gFile = gnome_cmd_con_create_gfile(con, con->base_path);
+
+ auto uri = g_file_get_uri(gFile);
+ DEBUG('m', "Connecting to %s\n", uri);
+
+ auto gMountOperation = gtk_mount_operation_new ((GtkWindow*) main_win);
+
+ g_file_mount_enclosing_volume (gFile,
+ G_MOUNT_MOUNT_NONE,
+ gMountOperation,
+ nullptr,
+ mount_remote_finish_callback,
+ con);
+}
+
+static gboolean start_mount_func (GnomeCmdCon *con)
+{
+ g_thread_new (nullptr, (GThreadFunc) mount_func, con);
return FALSE;
}
@@ -99,7 +121,7 @@ static void remote_open (GnomeCmdCon *con)
if (!con->base_path)
con->base_path = new GnomeCmdPlainPath(G_DIR_SEPARATOR_S);
- g_timeout_add (1, (GSourceFunc) start_get_file_info, con);
+ g_timeout_add (1, (GSourceFunc) start_mount_func, con);
}
@@ -111,11 +133,14 @@ static void remote_close_callback(GObject *gobj, GAsyncResult *result, gpointer
g_mount_unmount_with_operation_finish(gMount, result, &error);
- if (error)
+ if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CLOSED))
{
gnome_cmd_error_message(_("Disconnect error"), error);
+ g_error_free(error);
return;
}
+ if (error)
+ g_error_free(error);
con->state = GnomeCmdCon::STATE_CLOSED;
con->open_result = GnomeCmdCon::OPEN_NOT_STARTED;
@@ -136,7 +161,7 @@ static gboolean remote_close (GnomeCmdCon *con)
auto gMount = g_file_find_enclosing_mount (gFileTmp, nullptr, &error);
if (error)
{
- g_warning("remote_close - g_file_find_enclosing_mount error: %s", error->message);
+ g_warning("remote_close - g_file_find_enclosing_mount error: %s - %s", uri, error->message);
g_error_free(error);
return false;
}
diff --git a/src/gnome-cmd-con-smb.cc b/src/gnome-cmd-con-smb.cc
index 6bbb99bc..a05c10fb 100644
--- a/src/gnome-cmd-con-smb.cc
+++ b/src/gnome-cmd-con-smb.cc
@@ -40,7 +40,7 @@ struct GnomeCmdConSmbClass
static GnomeCmdConClass *parent_class = nullptr;
-static void get_file_info_func (GnomeCmdCon *con)
+static void mount_func (GnomeCmdCon *con)
{
g_return_if_fail(GNOME_CMD_IS_CON(con));
@@ -102,9 +102,9 @@ static void get_file_info_func (GnomeCmdCon *con)
static gboolean
-start_get_file_info (GnomeCmdCon *con)
+start_mount_func (GnomeCmdCon *con)
{
- g_thread_new (nullptr, (GThreadFunc) get_file_info_func, con);
+ g_thread_new (nullptr, (GThreadFunc) mount_func, con);
return FALSE;
}
@@ -118,7 +118,7 @@ static void smb_open (GnomeCmdCon *con)
con->state = GnomeCmdCon::STATE_OPENING;
con->open_result = GnomeCmdCon::OPEN_IN_PROGRESS;
- g_timeout_add (1, (GSourceFunc) start_get_file_info, con);
+ g_timeout_add (1, (GSourceFunc) start_mount_func, con);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]