[glib] GLocalFile: add _new_from_dirname_and_basename



commit fd8b45eb6785831d4a3749b31724de6eea74de1a
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Mar 5 21:05:06 2015 -0500

    GLocalFile: add _new_from_dirname_and_basename
    
    Add a new internal constructor for GLocalFile (which itself is private).
    
    This new constructor allows creating a GLocalFile from a dirname and a
    basename, assuming that the dirname is already in canonical form and the
    basename is a regular basename.
    
    This will be used for creating GLocalFile instances from the file
    monitoring code (for signal emissions).

 gio/glocalfile.c |   32 ++++++++++++++++++++++++++++++++
 gio/glocalfile.h |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 846eedb..20e45ab 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -305,6 +305,38 @@ _g_local_file_new (const char *filename)
   return G_FILE (local);
 }
 
+/*< internal >
+ * g_local_file_new_from_dirname_and_basename:
+ * @dirname: an absolute, canonical directory name
+ * @basename: the name of a child inside @dirname
+ *
+ * Creates a #GFile from @dirname and @basename.
+ *
+ * This is more efficient than pasting the fields together for yourself
+ * and creating a #GFile from the result, and also more efficient than
+ * creating a #GFile for the dirname and using g_file_get_child().
+ *
+ * @dirname must be canonical, as per GLocalFile's opinion of what
+ * canonical means.  This means that you should only pass strings that
+ * were returned by _g_local_file_get_filename().
+ *
+ * Returns: a #GFile
+ */
+GFile *
+g_local_file_new_from_dirname_and_basename (const gchar *dirname,
+                                            const gchar *basename)
+{
+  GLocalFile *local;
+
+  g_return_val_if_fail (dirname != NULL, NULL);
+  g_return_val_if_fail (basename && basename[0] && !strchr (basename, '/'), NULL);
+
+  local = g_object_new (G_TYPE_LOCAL_FILE, NULL);
+  local->filename = g_build_filename (dirname, basename, NULL);
+
+  return G_FILE (local);
+}
+
 static gboolean
 g_local_file_is_native (GFile *file)
 {
diff --git a/gio/glocalfile.h b/gio/glocalfile.h
index 8a8035b..e6cf4bf 100644
--- a/gio/glocalfile.h
+++ b/gio/glocalfile.h
@@ -46,6 +46,9 @@ GFile * _g_local_file_new      (const char *filename);
 
 const char * _g_local_file_get_filename (GLocalFile *file);
 
+GFile * g_local_file_new_from_dirname_and_basename (const char *dirname,
+                                                    const char *basename);
+
 G_END_DECLS
 
 #endif /* __G_LOCAL_FILE_H__ */


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