[gimp] libgimpbase: add gimp_file_get_utf8_name()



commit 776a79792de5ad3b20fa616ae4dd7e3569e432a9
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 1 13:18:14 2014 +0200

    libgimpbase: add gimp_file_get_utf8_name()
    
    Which works like gimp_filename_to_utf8() and returns a displayable
    UTF-8 encoded name of a GFile that does not need to be freed, which
    makes a lot of code more readable and compact.

 libgimpbase/gimpbase.def |    1 +
 libgimpbase/gimputils.c  |   36 ++++++++++++++++++++++++++++++++++++
 libgimpbase/gimputils.h  |    1 +
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 94cb4ba..efc4f58 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -31,6 +31,7 @@ EXPORTS
        gimp_enum_value_get_help
        gimp_env_init
        gimp_escape_uline
+       gimp_file_get_utf8_name
        gimp_filename_to_utf8
        gimp_fill_type_get_type
        gimp_flags_get_first_desc
diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c
index 0520632..5352edf 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -233,6 +233,42 @@ gimp_filename_to_utf8 (const gchar *filename)
   return filename_utf8;
 }
 
+/**
+ * gimp_file_get_utf8_name:
+ * @file: a #GFile
+ *
+ * This function works like gimp_filename_to_utf8() and returns
+ * a UTF-8 encoded string that does not need to be freed.
+ *
+ * It converts a #GFile's path or uri to UTF-8 temporarily.  The
+ * return value is a pointer to a string that is guaranteed to be
+ * valid only during the current iteration of the main loop or until
+ * the next call to gimp_file_get_utf8_name().
+ *
+ * The only purpose of this function is to provide an easy way to pass
+ * a #GFile's name to a function that expects an UTF-8 encoded string.
+ *
+ * See g_file_get_parse_name().
+ *
+ * Since: GIMP 2.10
+ *
+ * Return value: A temporarily valid UTF-8 representation of @file's name.
+ *               This string must not be changed or freed.
+ **/
+const gchar *
+gimp_file_get_utf8_name (GFile *file)
+{
+  gchar *name;
+
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+  name = g_file_get_parse_name (file);
+
+  g_object_set_data_full (G_OBJECT (file), "gimp-parse-name", name,
+                          (GDestroyNotify) g_free);
+
+  return name;
+}
 
 /**
  * gimp_strip_uline:
diff --git a/libgimpbase/gimputils.h b/libgimpbase/gimputils.h
index 533ba59..926045b 100644
--- a/libgimpbase/gimputils.h
+++ b/libgimpbase/gimputils.h
@@ -33,6 +33,7 @@ gchar         * gimp_any_to_utf8             (const gchar  *str,
                                               const gchar  *warning_format,
                                               ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
 const gchar   * gimp_filename_to_utf8        (const gchar  *filename);
+const gchar   * gimp_file_get_utf8_name      (GFile        *file);
 
 gchar         * gimp_strip_uline             (const gchar  *str) G_GNUC_MALLOC;
 gchar         * gimp_escape_uline            (const gchar  *str) G_GNUC_MALLOC;


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