[gnome-commander] Add scheme member to GnomeCmdCon class for setup of remote GFile object



commit 2d20dd3bd2dd3d5709d0f19cbe351c8f238a2a81
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Dec 11 23:04:19 2021 +0100

    Add scheme member to GnomeCmdCon class for setup of remote GFile object

 src/dialogs/gnome-cmd-con-dialog.cc |  5 ++++-
 src/gnome-cmd-con-remote.cc         |  7 +++----
 src/gnome-cmd-con.cc                |  2 ++
 src/gnome-cmd-con.h                 | 21 +++++++++++++++++++++
 src/gnome-cmd-plain-path.h          |  2 ++
 5 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-con-dialog.cc b/src/dialogs/gnome-cmd-con-dialog.cc
index 8c5d9c91..49189b73 100644
--- a/src/dialogs/gnome-cmd-con-dialog.cc
+++ b/src/dialogs/gnome-cmd-con-dialog.cc
@@ -614,6 +614,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
     {
         g_free(user_name);
         g_free(host);
+        gchar *scheme;
 
         GError *error = nullptr;
 
@@ -622,7 +623,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
             g_uri_split_with_user (
                 dialog->priv->uri_str.c_str(),
                 G_URI_FLAGS_HAS_PASSWORD,
-                nullptr, //scheme
+                &scheme,
                 &user_name,
                 nullptr, //password
                 nullptr, //auth_params
@@ -656,6 +657,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
 
         gnome_cmd_con_set_user_name (con, user_name);
         gnome_cmd_con_set_host_name (con, host);
+        gnome_cmd_con_set_scheme(con, scheme);
         gnome_cmd_con_set_root_path(con, path);
         if (port != -1)
             gnome_cmd_con_set_port(con, port);
@@ -668,6 +670,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
         g_free(user_name);
         g_free(host);
         g_free(path);
+        g_free(scheme);
     }
 
     gtk_widget_destroy (*dialog);
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index 7c6689f8..0ce428e9 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -199,10 +199,9 @@ static GFile *remote_create_gfile (GnomeCmdCon *con, GnomeCmdPath *path)
 {
     g_return_val_if_fail (con->uri != nullptr, nullptr);
 
-    auto *gFileTmp = g_file_new_for_uri (con->uri);
-    auto gFile = g_file_resolve_relative_path (gFileTmp, path->get_path());
-
-    g_object_unref (gFileTmp);
+    auto uri = g_strdup_printf("%s://%s%s", con->scheme, con->hostname, path->get_path());
+    auto gFile = g_file_new_for_uri (uri);
+    g_free(uri);
 
     return gFile;
 }
diff --git a/src/gnome-cmd-con.cc b/src/gnome-cmd-con.cc
index 418a8cdf..dc2178fe 100644
--- a/src/gnome-cmd-con.cc
+++ b/src/gnome-cmd-con.cc
@@ -91,6 +91,7 @@ static void destroy (GtkObject *object)
 
     g_free (con->alias);
     g_free (con->uri);
+    g_free (con->scheme);
 
     delete con->base_path;
     g_string_free (con->root_path, TRUE);
@@ -179,6 +180,7 @@ static void init (GnomeCmdCon *con)
 {
     con->alias = nullptr;
     con->uri = nullptr;
+    con->scheme = nullptr;
     con->method = CON_URI;
 
     con->base_path = nullptr;
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index 25c385eb..99c1da06 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -77,6 +77,7 @@ struct GnomeCmdCon
 
     gchar               *alias;                 // coded as UTF-8
     gchar               *uri;
+    gchar               *scheme;
     ConnectionMethodID  method;
 
     gchar               *username;
@@ -173,6 +174,26 @@ inline void gnome_cmd_con_set_uri (GnomeCmdCon *con, const std::string &uri)
     con->uri = uri.empty() ? NULL : g_strdup (uri.c_str());
 }
 
+inline const gchar *gnome_cmd_con_get_scheme (GnomeCmdCon *con)
+{
+    g_return_val_if_fail (GNOME_CMD_IS_CON (con), NULL);
+    return con->scheme;
+}
+
+inline void gnome_cmd_con_set_scheme (GnomeCmdCon *con, const gchar *scheme = nullptr)
+{
+    g_return_if_fail (GNOME_CMD_IS_CON (con));
+    g_free (con->scheme);
+    con->scheme = g_strdup(scheme);
+}
+
+inline void gnome_cmd_con_set_scheme (GnomeCmdCon *con, const std::string &scheme)
+{
+    g_return_if_fail (GNOME_CMD_IS_CON (con));
+    g_free (con->scheme);
+    con->scheme = scheme.empty() ? NULL : g_strdup (scheme.c_str());
+}
+
 GFile *gnome_cmd_con_create_gfile (GnomeCmdCon *con, GnomeCmdPath *path);
 
 GnomeCmdPath *gnome_cmd_con_create_path (GnomeCmdCon *con, const gchar *path_str);
diff --git a/src/gnome-cmd-plain-path.h b/src/gnome-cmd-plain-path.h
index bb2c0995..386dbd77 100644
--- a/src/gnome-cmd-plain-path.h
+++ b/src/gnome-cmd-plain-path.h
@@ -40,10 +40,12 @@ class GnomeCmdPlainPath: public GnomeCmdPath
   public:
 
     GnomeCmdPlainPath(const GnomeCmdPlainPath &thePath);
+
     explicit GnomeCmdPlainPath(const gchar *plain_path)
     {
       this->path = g_strdup (plain_path);
     }
+
     virtual ~GnomeCmdPlainPath()
     {
       g_free (path);


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