[gnome-commander] Add method for retrieving a GFile object for a file in a GnomeCmdDir
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Add method for retrieving a GFile object for a file in a GnomeCmdDir
- Date: Fri, 29 Oct 2021 21:19:44 +0000 (UTC)
commit a0e998ecd93b19106de42fa0f4ae31f72731bc40
Author: Uwe Scholz <u scholz83 gmx de>
Date: Fri Oct 29 22:50:34 2021 +0200
Add method for retrieving a GFile object for a file in a GnomeCmdDir
src/gnome-cmd-con-remote.cc | 2 +-
src/gnome-cmd-dir.cc | 36 ++++++++++++++++++++++++++++++++++++
src/gnome-cmd-dir.h | 1 +
3 files changed, 38 insertions(+), 1 deletion(-)
---
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index 2cfaa381..f8f2ecfd 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -153,7 +153,7 @@ static GnomeCmdPath *remote_create_path (GnomeCmdCon *con, const gchar *path_str
static void destroy (GtkObject *object)
{
- GnomeCmdConRemote *con_remote = GNOME_CMD_CON_REMOTE (object);
+ auto con_remote = GNOME_CMD_CON_REMOTE (object);
gnome_cmd_pixmap_free (con_remote->parent.go_pixmap);
gnome_cmd_pixmap_free (con_remote->parent.open_pixmap);
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index 38a7c9d1..22d4aa4f 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -624,6 +624,42 @@ gchar *gnome_cmd_dir_get_uri_str (GnomeCmdDir *dir)
return dir_str;
}
+/**
+ * This function returns a GFile object which is the result of the URI construction of
+ * two URI's: the connection URI, which is the private member of GnomeCmdDir,
+ * and the given filename string.
+ */
+GFile *gnome_cmd_dir_get_gfile_for_con_and_filename(GnomeCmdDir *dir, const gchar *filename)
+{
+ auto conUri = gnome_cmd_con_get_uri(dir->priv->con);
+ if (!conUri) // is usually set for a remote connection
+ {
+ return nullptr;
+ }
+
+ GError *error = nullptr;
+ auto gnomeCmdDirPath = gnome_cmd_dir_get_path(dir);
+ auto dirLastCharacter = gnomeCmdDirPath->get_path()[strlen(gnomeCmdDirPath->get_path())-1];
+ auto mergedDirAndFileNameString = dirLastCharacter != G_DIR_SEPARATOR
+ ? g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", gnomeCmdDirPath->get_path(), filename)
+ : g_strdup_printf("%s%s", gnomeCmdDirPath->get_path(), filename);
+ auto fullFileNameUri = g_uri_resolve_relative (
+ conUri,
+ mergedDirAndFileNameString,
+ G_URI_FLAGS_NONE,
+ &error);
+ if (error)
+ {
+ g_warning ("get_gfile_for_merged_paths error: %s", error->message);
+ g_error_free(error);
+ return nullptr;
+ }
+ auto gFile = g_file_new_for_uri(fullFileNameUri);
+ g_free(mergedDirAndFileNameString);
+ g_free(fullFileNameUri);
+ return gFile;
+}
+
GFile *gnome_cmd_dir_get_child_gfile (GnomeCmdDir *dir, const gchar *filename)
{
diff --git a/src/gnome-cmd-dir.h b/src/gnome-cmd-dir.h
index b83b5fa5..14ce06ca 100644
--- a/src/gnome-cmd-dir.h
+++ b/src/gnome-cmd-dir.h
@@ -128,6 +128,7 @@ 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);
+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);
GFile *gnome_cmd_dir_get_absolute_path_gfile (GnomeCmdDir *dir, std::string absolute_filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]