[gimp] libgimpbase, app: move gimp_file_has_extension() to libgimpbase



commit 6209b1f571ed64ef38acea2d5a803c9648797c45
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 3 20:46:28 2014 +0200

    libgimpbase, app: move gimp_file_has_extension() to libgimpbase
    
    and use it in GimpModuleDB.

 app/core/gimp-utils.c        |   28 ----------------------------
 app/core/gimp-utils.h        |    2 --
 libgimpbase/gimpbase.def     |    1 +
 libgimpbase/gimputils.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 libgimpbase/gimputils.h      |    3 +++
 libgimpmodule/gimpmoduledb.c |    9 +++------
 6 files changed, 49 insertions(+), 36 deletions(-)
---
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index fb43cc0..f6a931c 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -947,34 +947,6 @@ gimp_file_compare (GFile *file1,
     }
 }
 
-gboolean
-gimp_file_has_extension (GFile       *file,
-                         const gchar *extension)
-{
-  gchar    *uri;
-  gint      uri_len;
-  gint      ext_len;
-  gboolean  result = FALSE;
-
-  g_return_val_if_fail (G_IS_FILE (file), FALSE);
-  g_return_val_if_fail (extension != NULL, FALSE);
-
-  uri = g_file_get_uri (file);
-
-  uri_len = strlen (uri);
-  ext_len = strlen (extension);
-
-  if (uri_len && ext_len && (uri_len > ext_len))
-    {
-      if (g_ascii_strcasecmp (uri + uri_len - ext_len, extension) == 0)
-        result = TRUE;
-    }
-
-  g_free (uri);
-
-  return result;
-}
-
 
 /*  debug stuff  */
 
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 33515e6..197eeab 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -102,8 +102,6 @@ void         gimp_constrain_line                   (gdouble          start_x,
 
 gint         gimp_file_compare                     (GFile           *file1,
                                                     GFile           *file2);
-gboolean     gimp_file_has_extension               (GFile           *file,
-                                                    const gchar     *extension);
 
 void         gimp_create_image_from_buffer         (Gimp            *gimp,
                                                     GeglBuffer      *buffer);
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 05b528d..730d86e 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -34,6 +34,7 @@ EXPORTS
        gimp_env_init
        gimp_escape_uline
        gimp_file_get_utf8_name
+       gimp_file_has_extension
        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 5352edf..87eda3d 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -271,6 +271,48 @@ gimp_file_get_utf8_name (GFile *file)
 }
 
 /**
+ * gimp_file_has_extension:
+ * @file:      a #GFile
+ * @extension: an ASCII extension
+ *
+ * This function checks if @file's URI ends with @extension. It behaves
+ * like g_str_has_suffix() on g_file_get_uri(), except that the string
+ * comparison is done case-insensitively using g_ascii_strcasecmp().
+ *
+ * Since: GIMP 2.10
+ *
+ * Return value: %TRUE if @file's URI ends with @extension,
+ *               %FALSE otherwise.
+ **/
+gboolean
+gimp_file_has_extension (GFile       *file,
+                         const gchar *extension)
+{
+  gchar    *uri;
+  gint      uri_len;
+  gint      ext_len;
+  gboolean  result = FALSE;
+
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+  g_return_val_if_fail (extension != NULL, FALSE);
+
+  uri = g_file_get_uri (file);
+
+  uri_len = strlen (uri);
+  ext_len = strlen (extension);
+
+  if (uri_len && ext_len && (uri_len > ext_len))
+    {
+      if (g_ascii_strcasecmp (uri + uri_len - ext_len, extension) == 0)
+        result = TRUE;
+    }
+
+  g_free (uri);
+
+  return result;
+}
+
+/**
  * gimp_strip_uline:
  * @str: underline infested string (or %NULL)
  *
diff --git a/libgimpbase/gimputils.h b/libgimpbase/gimputils.h
index 926045b..20f25c0 100644
--- a/libgimpbase/gimputils.h
+++ b/libgimpbase/gimputils.h
@@ -33,7 +33,10 @@ 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);
+gboolean        gimp_file_has_extension      (GFile        *file,
+                                              const gchar  *extension);
 
 gchar         * gimp_strip_uline             (const gchar  *str) G_GNUC_MALLOC;
 gchar         * gimp_escape_uline            (const gchar  *str) G_GNUC_MALLOC;
diff --git a/libgimpmodule/gimpmoduledb.c b/libgimpmodule/gimpmoduledb.c
index 22121a0..7a06aef 100644
--- a/libgimpmodule/gimpmoduledb.c
+++ b/libgimpmodule/gimpmoduledb.c
@@ -373,13 +373,10 @@ gimp_module_db_load_module (GimpModuleDB *db,
   gchar      *path;
   gboolean    load_inhibit;
 
-  path = g_file_get_path (file);
+  if (! gimp_file_has_extension (file, "." G_MODULE_SUFFIX))
+    return;
 
-  if (! gimp_datafiles_check_extension (path, "." G_MODULE_SUFFIX))
-    {
-      g_free (path);
-      return;
-    }
+  path = g_file_get_path (file);
 
   /* don't load if we already know about it */
   if (gimp_module_db_module_find_by_path (db, path))


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