[gimp] app: keep the theme directories around a GFiles



commit 14c39816d820ad3dd8a6f27318bea758db21e78b
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 17 10:09:19 2014 +0200

    app: keep the theme directories around a GFiles
    
    and change gimp_get_theme_dir() to return a GFile.

 app/core/gimp-gui.c              |    2 +-
 app/core/gimp-gui.h              |    4 +-
 app/dialogs/preferences-dialog.c |    8 ++--
 app/gui/gui-vtable.c             |    4 +-
 app/gui/themes.c                 |   90 +++++++++++++++++++++----------------
 app/gui/themes.h                 |   18 ++++----
 app/pdb/gimprc-cmds.c            |    5 ++-
 tools/pdbgen/pdb/gimprc.pdb      |    5 ++-
 8 files changed, 77 insertions(+), 59 deletions(-)
---
diff --git a/app/core/gimp-gui.c b/app/core/gimp-gui.c
index 83a638a..b355c23 100644
--- a/app/core/gimp-gui.c
+++ b/app/core/gimp-gui.c
@@ -254,7 +254,7 @@ gimp_get_user_time (Gimp *gimp)
   return 0;
 }
 
-const gchar *
+GFile *
 gimp_get_theme_dir (Gimp *gimp)
 {
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
diff --git a/app/core/gimp-gui.h b/app/core/gimp-gui.h
index 5d076fe..63cb241 100644
--- a/app/core/gimp-gui.h
+++ b/app/core/gimp-gui.h
@@ -48,7 +48,7 @@ struct _GimpGui
                                              gint                *monitor);
   guint32        (* get_user_time)          (Gimp                *gimp);
 
-  const gchar  * (* get_theme_dir)          (Gimp                *gimp);
+  GFile        * (* get_theme_dir)          (Gimp                *gimp);
 
   GimpObject   * (* get_window_strategy)    (Gimp                *gimp);
   GimpObject   * (* get_empty_display)      (Gimp                *gimp);
@@ -152,7 +152,7 @@ gchar        * gimp_get_display_name       (Gimp                *gimp,
                                             GObject            **screen,
                                             gint                *monitor);
 guint32        gimp_get_user_time          (Gimp                *gimp);
-const gchar  * gimp_get_theme_dir          (Gimp                *gimp);
+GFile        * gimp_get_theme_dir          (Gimp                *gimp);
 
 gboolean       gimp_pdb_dialog_new         (Gimp                *gimp,
                                             GimpContext         *context,
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index cf8bb28..57eb7a7 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1510,12 +1510,13 @@ prefs_dialog_new (Gimp       *gimp,
 
     for (i = 0; i < n_themes; i++)
       {
-        GtkTreeIter iter;
+        GtkTreeIter  iter;
+        GFile       *theme_dir = themes_get_theme_dir (gimp, themes[i]);
 
         gtk_list_store_append (list_store, &iter);
         gtk_list_store_set (list_store, &iter,
                             0, themes[i],
-                            1, themes_get_theme_dir (gimp, themes[i]),
+                            1, gimp_file_get_utf8_name (theme_dir),
                             -1);
 
         if (GIMP_GUI_CONFIG (object)->theme &&
@@ -1533,8 +1534,7 @@ prefs_dialog_new (Gimp       *gimp,
           }
       }
 
-    if (themes)
-      g_strfreev (themes);
+    g_strfreev (themes);
 
     g_signal_connect (sel, "changed",
                       G_CALLBACK (prefs_theme_select_callback),
diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c
index 31b41dd..11ae9d4 100644
--- a/app/gui/gui-vtable.c
+++ b/app/gui/gui-vtable.c
@@ -102,7 +102,7 @@ static gchar        * gui_get_display_name       (Gimp                *gimp,
                                                   GObject            **screen,
                                                   gint                *monitor);
 static guint32        gui_get_user_time          (Gimp                *gimp);
-static const gchar  * gui_get_theme_dir          (Gimp                *gimp);
+static GFile        * gui_get_theme_dir          (Gimp                *gimp);
 static GimpObject   * gui_get_window_strategy    (Gimp                *gimp);
 static GimpObject   * gui_get_empty_display      (Gimp                *gimp);
 static GimpObject   * gui_display_get_by_ID      (Gimp                *gimp,
@@ -291,7 +291,7 @@ gui_get_user_time (Gimp *gimp)
   return 0;
 }
 
-static const gchar *
+static GFile *
 gui_get_theme_dir (Gimp *gimp)
 {
   return themes_get_theme_dir (gimp, GIMP_GUI_CONFIG (gimp->config)->theme);
diff --git a/app/gui/themes.c b/app/gui/themes.c
index 3e0a6fd..d3df21a 100644
--- a/app/gui/themes.c
+++ b/app/gui/themes.c
@@ -71,7 +71,7 @@ themes_init (Gimp *gimp)
   themes_hash = g_hash_table_new_full (g_str_hash,
                                        g_str_equal,
                                        g_free,
-                                       g_free);
+                                       g_object_unref);
 
   if (config->theme_path)
     {
@@ -143,7 +143,7 @@ themes_list_themes (Gimp *gimp,
   return NULL;
 }
 
-const gchar *
+GFile *
 themes_get_theme_dir (Gimp        *gimp,
                       const gchar *theme_name)
 {
@@ -155,51 +155,57 @@ themes_get_theme_dir (Gimp        *gimp,
   return g_hash_table_lookup (themes_hash, theme_name);
 }
 
-gchar *
+GFile *
 themes_get_theme_file (Gimp        *gimp,
                        const gchar *first_component,
                        ...)
 {
   GimpGuiConfig *gui_config;
-  gchar         *file;
-  gchar         *component;
-  gchar         *path;
+  GFile         *file;
+  const gchar   *component;
   va_list        args;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
   g_return_val_if_fail (first_component != NULL, NULL);
 
-  file = g_strdup (first_component);
+  gui_config = GIMP_GUI_CONFIG (gimp->config);
+
+  file      = g_object_ref (themes_get_theme_dir (gimp, gui_config->theme));
+  component = first_component;
 
   va_start (args, first_component);
 
-  while ((component = va_arg (args, gchar *)))
+  do
     {
-      gchar *tmp;
-
-      tmp = g_build_filename (file, component, NULL);
-      g_free (file);
+      GFile *tmp = g_file_get_child (file, component);
+      g_object_unref (file);
       file = tmp;
     }
+  while ((component = va_arg (args, gchar *)));
 
   va_end (args);
 
-  gui_config = GIMP_GUI_CONFIG (gimp->config);
+  if (! g_file_query_exists (file, NULL))
+    {
+      g_object_unref (file);
 
-  path = g_build_filename (themes_get_theme_dir (gimp, gui_config->theme),
-                           file, NULL);
+      file      = g_object_ref (themes_get_theme_dir (gimp, NULL));
+      component = first_component;
 
-  if (! g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      g_free (path);
+      va_start (args, first_component);
 
-      path = g_build_filename (themes_get_theme_dir (gimp, NULL),
-                               file, NULL);
-    }
+      do
+        {
+          GFile *tmp = g_file_get_child (file, component);
+          g_object_unref (file);
+          file = tmp;
+        }
+      while ((component = va_arg (args, gchar *)));
 
-  g_free (file);
+      va_end (args);
+    }
 
-  return path;
+  return file;
 }
 
 
@@ -232,26 +238,32 @@ themes_apply_theme (Gimp        *gimp,
     }
   else
     {
-      const gchar *theme_dir = themes_get_theme_dir (gimp, theme_name);
-      gchar       *gtkrc_theme;
-      gchar       *gtkrc_user;
-      gchar       *esc_gtkrc_theme;
-      gchar       *esc_gtkrc_user;
+      GFile *theme_dir = themes_get_theme_dir (gimp, theme_name);
+      GFile *gtkrc_theme;
+      GFile *gtkrc_user;
+      gchar *esc_gtkrc_theme;
+      gchar *esc_gtkrc_user;
+      gchar *tmp;
 
       if (theme_dir)
         {
-          gtkrc_theme = g_build_filename (theme_dir, "gtkrc", NULL);
+          gtkrc_theme = g_file_get_child (theme_dir, "gtkrc");
         }
       else
         {
           /*  get the hardcoded default theme gtkrc  */
-          gtkrc_theme = g_strdup (gimp_gtkrc ());
+          gtkrc_theme = g_file_new_for_path (gimp_gtkrc ());
         }
 
-      gtkrc_user = gimp_personal_rc_file ("gtkrc");
+      gtkrc_user = gimp_personal_rc_gfile ("gtkrc");
+
+      tmp = g_file_get_path (gtkrc_theme);
+      esc_gtkrc_theme = g_strescape (tmp, NULL);
+      g_free (tmp);
 
-      esc_gtkrc_theme = g_strescape (gtkrc_theme, NULL);
-      esc_gtkrc_user  = g_strescape (gtkrc_user, NULL);
+      tmp = g_file_get_path (gtkrc_user);
+      esc_gtkrc_user = g_strescape (tmp, NULL);
+      g_free (tmp);
 
       if (! gimp_output_stream_printf
             (output, NULL, NULL, &error,
@@ -265,9 +277,10 @@ themes_apply_theme (Gimp        *gimp,
              "include \"%s\"\n"
              "\n"
              "# end of themerc\n",
-             gtkrc_user,
+             gimp_file_get_utf8_name (gtkrc_user),
              esc_gtkrc_theme,
-             esc_gtkrc_user))
+             esc_gtkrc_user) ||
+          ! g_output_stream_close (output, NULL, &error))
         {
           gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR,
                         _("Error writing '%s': %s"),
@@ -277,9 +290,8 @@ themes_apply_theme (Gimp        *gimp,
 
       g_free (esc_gtkrc_theme);
       g_free (esc_gtkrc_user);
-      g_free (gtkrc_theme);
-      g_free (gtkrc_user);
-
+      g_object_unref (gtkrc_theme);
+      g_object_unref (gtkrc_user);
       g_object_unref (output);
     }
 
@@ -299,7 +311,7 @@ themes_directories_foreach (const GimpDatafileData *file_data,
 
   g_hash_table_insert (themes_hash,
                        g_strdup (file_data->basename),
-                       g_strdup (file_data->filename));
+                       g_file_new_for_path (file_data->filename));
 }
 
 static void
diff --git a/app/gui/themes.h b/app/gui/themes.h
index ad8edb3..b80ecf1 100644
--- a/app/gui/themes.h
+++ b/app/gui/themes.h
@@ -19,16 +19,16 @@
 #define __THEMES_H__
 
 
-void           themes_init           (Gimp        *gimp);
-void           themes_exit           (Gimp        *gimp);
+void     themes_init           (Gimp        *gimp);
+void     themes_exit           (Gimp        *gimp);
 
-gchar       ** themes_list_themes    (Gimp        *gimp,
-                                      gint        *n_themes);
-const gchar  * themes_get_theme_dir  (Gimp        *gimp,
-                                      const gchar *theme_name);
-gchar        * themes_get_theme_file (Gimp        *gimp,
-                                      const gchar *first_component,
-                                      ...) G_GNUC_NULL_TERMINATED;
+gchar ** themes_list_themes    (Gimp        *gimp,
+                                gint        *n_themes);
+GFile  * themes_get_theme_dir  (Gimp        *gimp,
+                                const gchar *theme_name);
+GFile  * themes_get_theme_file (Gimp        *gimp,
+                                const gchar *first_component,
+                                ...) G_GNUC_NULL_TERMINATED;
 
 
 #endif /* __THEMES_H__ */
diff --git a/app/pdb/gimprc-cmds.c b/app/pdb/gimprc-cmds.c
index f387f3a..a742acb 100644
--- a/app/pdb/gimprc-cmds.c
+++ b/app/pdb/gimprc-cmds.c
@@ -184,7 +184,10 @@ get_theme_dir_invoker (GimpProcedure         *procedure,
   GimpValueArray *return_vals;
   gchar *theme_dir = NULL;
 
-  theme_dir = g_strdup (gimp_get_theme_dir (gimp));
+  GFile *file = gimp_get_theme_dir (gimp);
+
+  if (file)
+    theme_dir = g_file_get_path (file);
 
   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
   g_value_take_string (gimp_value_array_index (return_vals, 1), theme_dir);
diff --git a/tools/pdbgen/pdb/gimprc.pdb b/tools/pdbgen/pdb/gimprc.pdb
index 585bb4b..18019a1 100644
--- a/tools/pdbgen/pdb/gimprc.pdb
+++ b/tools/pdbgen/pdb/gimprc.pdb
@@ -184,7 +184,10 @@ sub get_theme_dir {
     %invoke = (
        code => <<'CODE'
 {
-  theme_dir = g_strdup (gimp_get_theme_dir (gimp));
+  GFile *file = gimp_get_theme_dir (gimp);
+
+  if (file)
+    theme_dir = g_file_get_path (file);
 }
 CODE
     );


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