app: keep the theme directories around a GFiles

and change gimp_get_theme_dir() to return a GFile.
This commit is contained in:
Michael Natterer 2014-07-17 10:09:19 +02:00
parent 32f29db8b0
commit 14c39816d8
8 changed files with 78 additions and 60 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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),

View File

@ -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);

View File

@ -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);
path = g_build_filename (themes_get_theme_dir (gimp, gui_config->theme),
file, NULL);
if (! g_file_test (path, G_FILE_TEST_EXISTS))
if (! g_file_query_exists (file, NULL))
{
g_free (path);
g_object_unref (file);
path = g_build_filename (themes_get_theme_dir (gimp, NULL),
file, NULL);
file = g_object_ref (themes_get_theme_dir (gimp, NULL));
component = first_component;
va_start (args, first_component);
do
{
GFile *tmp = g_file_get_child (file, component);
g_object_unref (file);
file = tmp;
}
while ((component = va_arg (args, gchar *)));
va_end (args);
}
g_free (file);
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");
esc_gtkrc_theme = g_strescape (gtkrc_theme, NULL);
esc_gtkrc_user = g_strescape (gtkrc_user, NULL);
tmp = g_file_get_path (gtkrc_theme);
esc_gtkrc_theme = g_strescape (tmp, NULL);
g_free (tmp);
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

View File

@ -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__ */

View File

@ -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);

View File

@ -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
);