[gtk+/gtk-style-context: 226/251] GtkCssProvider: Add gtk_css_provider_get_named()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 226/251] GtkCssProvider: Add gtk_css_provider_get_named()
- Date: Tue, 12 Oct 2010 02:14:06 +0000 (UTC)
commit 4028142b023fef799251fabad60b5ef1177cca40
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Sep 22 23:39:15 2010 +0200
GtkCssProvider: Add gtk_css_provider_get_named()
This functions loads a CSS file from a installed theme.
gtk/gtkcssprovider.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++--
gtk/gtkcssprovider.h | 2 +
2 files changed, 73 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index a4a1af7..e118c1a 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -2080,8 +2080,25 @@ gtk_css_provider_get_default (void)
return provider;
}
+static gchar *
+css_provider_get_theme_dir (void)
+{
+ const gchar *var;
+ gchar *path;
+
+ var = g_getenv ("GTK_DATA_PREFIX");
+
+ if (var)
+ path = g_build_filename (var, "share", "themes", NULL);
+ else
+ path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
+
+ return path;
+}
+
GtkCssProvider *
-gtk_css_provider_get_named (const gchar *name)
+gtk_css_provider_get_named (const gchar *name,
+ const gchar *variant)
{
static GHashTable *themes = NULL;
GtkCssProvider *provider;
@@ -2093,9 +2110,60 @@ gtk_css_provider_get_named (const gchar *name)
if (!provider)
{
-
+ const gchar *home_dir;
+ gchar *subpath, *path = NULL;
- g_hash_table_insert (themes, g_strdup (name), provider);
+ if (variant)
+ subpath = g_strdup_printf ("gtk-%d.0" G_DIR_SEPARATOR_S "gtk-%s.css", GTK_MAJOR_VERSION, variant);
+ else
+ subpath = g_strdup_printf ("gtk-%d.0" G_DIR_SEPARATOR_S "gtk.css", GTK_MAJOR_VERSION);
+
+ /* First look in the users home directory
+ */
+ home_dir = g_get_home_dir ();
+ if (home_dir)
+ {
+ path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
+
+ if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ {
+ g_free (path);
+ path = NULL;
+ }
+ }
+
+ if (!path)
+ {
+ gchar *theme_dir = css_provider_get_theme_dir ();
+ path = g_build_filename (theme_dir, name, subpath, NULL);
+ g_free (theme_dir);
+
+ if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ {
+ g_free (path);
+ path = NULL;
+ }
+ }
+
+ if (path)
+ {
+ GtkCssProvider *provider;
+ GError *error = NULL;
+
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_path (provider, path, &error);
+
+ if (error)
+ {
+ g_warning ("Could not load named theme \"%s\": %s", name, error->message);
+ g_error_free (error);
+
+ g_object_unref (provider);
+ provider = NULL;
+ }
+ else
+ g_hash_table_insert (themes, g_strdup (name), provider);
+ }
}
return provider;
diff --git a/gtk/gtkcssprovider.h b/gtk/gtkcssprovider.h
index 2b8dd9d..2c6d283 100644
--- a/gtk/gtkcssprovider.h
+++ b/gtk/gtkcssprovider.h
@@ -62,6 +62,8 @@ gboolean gtk_css_provider_load_from_path (GtkCssProvider *css_provider,
GtkCssProvider * gtk_css_provider_get_default (void);
+GtkCssProvider * gtk_css_provider_get_named (const gchar *name,
+ const gchar *variant);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]