[gnome-commander] Let the directory URI string end with a directory separator if desired



commit 357b73d564ae0a729678018a2ed026e983c473d8
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Wed Jan 5 16:28:55 2022 +0100

    Let the directory URI string end with a directory separator if desired

 src/gnome-cmd-dir.cc | 19 +++++++++++++++----
 src/gnome-cmd-dir.h  |  2 +-
 2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index f2f6035f..2aa44738 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -628,15 +628,26 @@ GFile *gnome_cmd_dir_get_gfile (GnomeCmdDir *dir)
 }
 
 
-gchar *gnome_cmd_dir_get_uri_str (GnomeCmdDir *dir)
+gchar *gnome_cmd_dir_get_uri_str (GnomeCmdDir *dir, gboolean withTrailingSlash)
 {
     g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), nullptr);
 
-    GFile *gFile = gnome_cmd_dir_get_gfile (dir);
+    auto gFile = gnome_cmd_dir_get_gfile (dir);
 
-    gchar *dir_str = g_file_get_uri (gFile);
+    g_return_val_if_fail(G_IS_FILE(gFile), nullptr);
 
-    return dir_str;
+    auto dirString = g_file_get_uri (gFile);
+
+    if (withTrailingSlash)
+    {
+        auto tmpString = dirString[strlen(dirString)-1] == G_DIR_SEPARATOR
+            ? g_strdup(dirString)
+            : g_strdup_printf("%s%s", dirString, G_DIR_SEPARATOR_S);
+        g_free(dirString);
+        dirString = tmpString;
+    }
+
+    return dirString;
 }
 
 /**
diff --git a/src/gnome-cmd-dir.h b/src/gnome-cmd-dir.h
index 5447e175..f5d98bf3 100644
--- a/src/gnome-cmd-dir.h
+++ b/src/gnome-cmd-dir.h
@@ -126,7 +126,7 @@ void gnome_cmd_dir_update_path (GnomeCmdDir *dir);
 gchar *gnome_cmd_dir_get_display_path (GnomeCmdDir *dir);
 
 GFile       *gnome_cmd_dir_get_gfile (GnomeCmdDir *dir);
-gchar       *gnome_cmd_dir_get_uri_str (GnomeCmdDir *dir);
+gchar       *gnome_cmd_dir_get_uri_str (GnomeCmdDir *dir, gboolean withTrailingSlash = false);
 
 GFile *gnome_cmd_dir_get_gfile_for_con_and_filename(GnomeCmdDir *dir, const gchar *filename);
 GFile *gnome_cmd_dir_get_child_gfile (GnomeCmdDir *dir, const gchar *filename);


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