[gnome-commander] Set default value of the connection port to -1, i.e. the value which is not set



commit a2a2e8926c0df064372133525219f788b3bb8f39
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Mon Dec 13 23:27:38 2021 +0100

    Set default value of the connection port to -1, i.e. the value which is not set

 src/dialogs/gnome-cmd-con-dialog.cc |  4 ++--
 src/gnome-cmd-con-remote.cc         |  5 ++---
 src/gnome-cmd-con.cc                |  6 +++++-
 src/gnome-cmd-con.h                 | 10 +++++-----
 4 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-con-dialog.cc b/src/dialogs/gnome-cmd-con-dialog.cc
index 49189b73..725a0677 100644
--- a/src/dialogs/gnome-cmd-con-dialog.cc
+++ b/src/dialogs/gnome-cmd-con-dialog.cc
@@ -604,7 +604,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
             }
 #endif
 
-        if (port)
+        if (port != -1)
             gtk_entry_set_text (GTK_ENTRY (dialog->priv->port_entry), stringify(port).c_str());
     }
 
@@ -649,7 +649,7 @@ gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
             host = g_strdup(gtk_entry_get_text (GTK_ENTRY (dialog->priv->server_entry)));
             path = g_strdup(gtk_entry_get_text (GTK_ENTRY (dialog->priv->folder_entry)));
             auto portChar = gtk_entry_get_text (GTK_ENTRY (dialog->priv->port_entry));
-            port = portChar ? atoi(portChar) : 0;
+            port = portChar ? atoi(portChar) : -1;
         }
 
         auto alias = dialog->priv->alias ? dialog->priv->alias->c_str() : nullptr;
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index 0ce428e9..11bba8ca 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -333,7 +333,7 @@ GnomeCmdConRemote *gnome_cmd_con_remote_new (const gchar *alias, const string &u
 
     gchar *user = nullptr;
     gchar *host = nullptr;
-    gint port = 0;
+    gint port = -1;
     gchar *path = nullptr;
 
     g_uri_split_with_user (
@@ -363,8 +363,7 @@ GnomeCmdConRemote *gnome_cmd_con_remote_new (const gchar *alias, const string &u
     gnome_cmd_con_set_uri (con, uri_str.c_str());
     gnome_cmd_con_set_user_name (con, user);
     gnome_cmd_con_set_host_name (con, host);
-    if (port != -1)
-        gnome_cmd_con_set_port (con, port);
+    gnome_cmd_con_set_port (con, port);
     gnome_cmd_con_set_root_path (con, path);
 
     gnome_cmd_con_remote_set_tooltips (server, host);
diff --git a/src/gnome-cmd-con.cc b/src/gnome-cmd-con.cc
index dc2178fe..2822a4e6 100644
--- a/src/gnome-cmd-con.cc
+++ b/src/gnome-cmd-con.cc
@@ -646,7 +646,7 @@ string &__gnome_cmd_con_make_uri (string &s, const gchar *method, string &server
 }
 
 #ifdef HAVE_SAMBA
-std::string &gnome_cmd_con_make_smb_uri (std::string &uriString, std::string &server, std::string &share, 
std::string &folder, std::string &domain, std::string &user, std::string &password)
+std::string &gnome_cmd_con_make_smb_uri (std::string &uriString, std::string &server, string &port, 
std::string &share, std::string &folder, std::string &domain, std::string &user, std::string &password)
 {
     user = stringify (g_strescape (user.c_str(), nullptr));
     password = stringify (g_strescape (password.c_str(), nullptr));
@@ -675,6 +675,10 @@ std::string &gnome_cmd_con_make_smb_uri (std::string &uriString, std::string &se
         uriString += user + '@';
 
     uriString += server;
+
+    if (!port.empty())
+        uriString += ':' + port;
+
     uriString += "/";
     uriString += folder;
 
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index 99c1da06..576f327f 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -82,7 +82,7 @@ struct GnomeCmdCon
 
     gchar               *username;
     gchar               *hostname;
-    guint16             port{0};
+    gint16              port{-1};
     gchar               *open_msg;
     GnomeCmdPath        *base_path;
     GFileInfo           *base_gFileInfo;
@@ -252,13 +252,13 @@ inline void gnome_cmd_con_set_host_name (GnomeCmdCon *con, const gchar *host)
     con->open_msg = g_strdup_printf (_("Connecting to %s\n"), host ? host : "<?>");
 }
 
-inline void gnome_cmd_con_set_port (GnomeCmdCon *con, guint16 port)
+inline void gnome_cmd_con_set_port (GnomeCmdCon *con, gint16 port)
 {
     g_return_if_fail (GNOME_CMD_IS_CON (con));
     con->port = port;
 }
 
-inline guint16 gnome_cmd_con_get_port (GnomeCmdCon *con)
+inline gint16 gnome_cmd_con_get_port (GnomeCmdCon *con)
 {
     g_return_val_if_fail (GNOME_CMD_IS_CON (con), 0);
     return con->port;
@@ -507,7 +507,7 @@ inline std::string &gnome_cmd_con_make_ftp_uri (std::string &s, std::string &ser
 }
 
 #ifdef HAVE_SAMBA
-std::string &gnome_cmd_con_make_smb_uri (std::string &s, std::string &server, std::string &share, 
std::string &folder, std::string &domain, std::string &user, std::string &password);
+std::string &gnome_cmd_con_make_smb_uri (std::string &s, std::string &server, std::string &port, std::string 
&share, std::string &folder, std::string &domain, std::string &user, std::string &password);
 #endif
 
 inline std::string &gnome_cmd_con_make_dav_uri (std::string &s, std::string &server, std::string &port, 
std::string &folder, std::string &user, std::string &password)
@@ -530,7 +530,7 @@ inline std::string &gnome_cmd_con_make_uri (std::string &s, ConnectionMethodID m
         case CON_SSH:       return gnome_cmd_con_make_ssh_uri (s, server, port, folder, user, password);
 
 #ifdef HAVE_SAMBA
-        case CON_SMB:       return gnome_cmd_con_make_smb_uri (s, server, share, folder, domain, user, 
password);
+        case CON_SMB:       return gnome_cmd_con_make_smb_uri (s, server, port, share, folder, domain, user, 
password);
 #endif
 
         case CON_DAV:       return gnome_cmd_con_make_dav_uri (s, server, port, folder, user, password);


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