cssprovider: Move fallback code into _gtk_css_provider_load_named()

This makes sure the full theme loading logic resides in one function and
isn't scattered around.

As a side-effect, the hash table kept by gtk_css_provider_get_named()
will now be populated with fallback themes. This will not be a problem
after the next commit though.
This commit is contained in:
Benjamin Otte 2012-09-19 16:30:27 +02:00
parent 738b453c66
commit b41215bdea
2 changed files with 21 additions and 10 deletions

View File

@ -2792,6 +2792,22 @@ _gtk_css_provider_load_named (GtkCssProvider *provider,
g_free (path);
g_free (dir);
}
else
{
/* Things failed! Fall back! Fall back! */
if (variant)
{
/* If there was a variant, try without */
_gtk_css_provider_load_named (provider, name, NULL);
}
else
{
/* Worst case, fall back to Raleigh */
g_return_if_fail (!g_str_equal (name, "Raleigh")); /* infloop protection */
_gtk_css_provider_load_named (provider, "Raleigh", NULL);
}
}
}
/**

View File

@ -2924,18 +2924,13 @@ settings_update_theme (GtkSettings *settings)
"gtk-application-prefer-dark-theme", &prefer_dark_theme,
NULL);
if (theme_name && *theme_name)
if (!theme_name || !*theme_name)
{
if (prefer_dark_theme)
provider = gtk_css_provider_get_named (theme_name, "dark");
if (!provider)
provider = gtk_css_provider_get_named (theme_name, NULL);
g_free (theme_name);
theme_name = g_strdup ("Raleigh");
}
/* If we didn't find the named theme, fall back */
if (!provider)
provider = gtk_css_provider_get_named ("Raleigh", NULL);
provider = gtk_css_provider_get_named (theme_name, prefer_dark_theme ? "dark" : NULL);
settings_update_provider (priv->screen, &priv->theme_provider, provider);