[Xfce4-commits] [apps/xfdashboard] 01/01: Allow user to override CSS files of theme to apply user's favourites settings.

noreply at xfce.org noreply at xfce.org
Wed Jun 7 11:52:18 CEST 2017


This is an automated email from the git hooks/post-receive script.

n   o   m   a   d       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfdashboard.

commit 7be223df1fc3378691ee851dc7fcc0de3ea312d7
Author: Stephan Haller <nomad at froevel.de>
Date:   Wed Jun 7 11:48:45 2017 +0200

    Allow user to override CSS files of theme to apply user's favourites settings.
    
    Changed the way and order how CSS files of themes are loaded:
    
    - First the CSS resources define in theme's theme file (xfdashboard.theme) are loaded
    - Then user's global stylesheet ($HOME/.config/xfdashboard/themes/global.css) is loaded if it exists
    - At last user's theme related stylesheet ($HOME/.config/xfdashboard/themes/user-[THEME_NAME].css) is loaded if it exists
    
    This commit addresses issue GH #152 to make user's changes to one or all themes more convienient.
---
 libxfdashboard/theme.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 122 insertions(+), 3 deletions(-)

diff --git a/libxfdashboard/theme.c b/libxfdashboard/theme.c
index 8415bd1..831ee63 100644
--- a/libxfdashboard/theme.c
+++ b/libxfdashboard/theme.c
@@ -60,6 +60,9 @@ struct _XfdashboardThemePrivate
 	XfdashboardThemeCSS			*styling;
 	XfdashboardThemeLayout		*layout;
 	XfdashboardThemeEffects		*effects;
+
+	gchar						*userThemeStyleFile;
+	gchar						*userGlobalStyleFile;
 };
 
 /* Properties */
@@ -82,6 +85,7 @@ static GParamSpec* XfdashboardThemeProperties[PROP_LAST]={ 0, };
 #define XFDASHBOARD_THEME_SUBPATH						"xfdashboard-1.0"
 #define XFDASHBOARD_THEME_FILE							"xfdashboard.theme"
 #define XFDASHBOARD_THEME_GROUP							"Xfdashboard Theme"
+#define XFDASHBOARD_USER_GLOBAL_CSS_FILE				"global.css"
 
 /* Load theme file and all listed resources in this file */
 static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
@@ -177,7 +181,10 @@ static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
 		return(FALSE);
 	}
 
-	/* Create CSS parser and load style resources */
+	/* Create CSS parser, load style resources first and user stylesheets (theme
+	 * unrelated "global.css" and theme related "user-[THEME_NAME].css" in this
+	 * order) at last to allow user to override theme styles.
+	 */
 	resources=g_key_file_get_string_list(themeKeyFile,
 											XFDASHBOARD_THEME_GROUP,
 											"Style",
@@ -203,6 +210,12 @@ static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
 		resourceFile=g_build_filename(priv->themePath, *resource, NULL);
 
 		/* Try to load style resource */
+		XFDASHBOARD_DEBUG(self, THEME,
+							"Loading CSS file %s for theme %s with priority %d",
+							resourceFile,
+							priv->themeName,
+							counter);
+
 		if(!xfdashboard_theme_css_add_file(priv->styling, resourceFile, counter, &error))
 		{
 			/* Set error */
@@ -226,6 +239,56 @@ static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
 	}
 	g_strfreev(resources);
 
+	if(priv->userGlobalStyleFile)
+	{
+		XFDASHBOARD_DEBUG(self, THEME,
+							"Loading user's global CSS file %s for theme %s with priority %d",
+							priv->userGlobalStyleFile,
+							priv->themeName,
+							counter);
+
+		/* Load user's theme unrelated (global) stylesheet as it exists */
+		if(!xfdashboard_theme_css_add_file(priv->styling, priv->userGlobalStyleFile, counter, &error))
+		{
+			/* Set error */
+			g_propagate_error(outError, error);
+
+			/* Release allocated resources */
+			if(themeKeyFile) g_key_file_free(themeKeyFile);
+
+			/* Return FALSE to indicate error */
+			return(FALSE);
+		}
+
+		/* Increase counter used for CSS priority for next user CSS file */
+		counter++;
+	}
+
+	if(priv->userThemeStyleFile)
+	{
+		XFDASHBOARD_DEBUG(self, THEME,
+							"Loading user's theme CSS file %s for theme %s with priority %d",
+							priv->userThemeStyleFile,
+							priv->themeName,
+							counter);
+
+		/* Load user's theme related stylesheet as it exists */
+		if(!xfdashboard_theme_css_add_file(priv->styling, priv->userThemeStyleFile, counter, &error))
+		{
+			/* Set error */
+			g_propagate_error(outError, error);
+
+			/* Release allocated resources */
+			if(themeKeyFile) g_key_file_free(themeKeyFile);
+
+			/* Return FALSE to indicate error */
+			return(FALSE);
+		}
+
+		/* Increase counter used for CSS priority for next user CSS file */
+		counter++;
+	}
+
 	/* Create XML parser and load layout resources */
 	resources=g_key_file_get_string_list(themeKeyFile,
 											XFDASHBOARD_THEME_GROUP,
@@ -250,7 +313,12 @@ static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
 		/* Get path and file for style resource */
 		resourceFile=g_build_filename(priv->themePath, *resource, NULL);
 
-		/* Try to load style resource */
+		/* Try to load layout resource */
+		XFDASHBOARD_DEBUG(self, THEME,
+							"Loading XML layout file %s for theme %s",
+							resourceFile,
+							priv->themeName);
+
 		if(!xfdashboard_theme_layout_add_file(priv->layout, resourceFile, &error))
 		{
 			/* Set error */
@@ -300,10 +368,15 @@ static gboolean _xfdashboard_theme_load_resources(XfdashboardTheme *self,
 		resource=resources;
 		while(*resource)
 		{
-			/* Get path and file for style resource */
+			/* Get path and file for effect resource */
 			resourceFile=g_build_filename(priv->themePath, *resource, NULL);
 
 			/* Try to load style resource */
+			XFDASHBOARD_DEBUG(self, THEME,
+								"Loading XML effects file %s for theme %s",
+								resourceFile,
+								priv->themeName);
+
 			if(!xfdashboard_theme_effects_add_file(priv->effects, resourceFile, &error))
 			{
 				/* Set error */
@@ -440,6 +513,8 @@ static void _xfdashboard_theme_set_theme_name(XfdashboardTheme *self, const gcha
 {
 	XfdashboardThemePrivate		*priv;
 	gchar						*themePath;
+	gchar						*resourceFile;
+	gchar						*userThemeStylesheet;
 
 	g_return_if_fail(XFDASHBOARD_IS_THEME(self));
 	g_return_if_fail(inThemeName && *inThemeName);
@@ -479,6 +554,36 @@ static void _xfdashboard_theme_set_theme_name(XfdashboardTheme *self, const gcha
 	priv->layout=xfdashboard_theme_layout_new();
 	priv->effects=xfdashboard_theme_effects_new();
 
+	/* Check for user resource files */
+	resourceFile=g_build_filename(g_get_user_config_dir(), "xfdashboard", "themes", XFDASHBOARD_USER_GLOBAL_CSS_FILE, NULL);
+	if(g_file_test(resourceFile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+	{
+		priv->userGlobalStyleFile=g_strdup(resourceFile);
+	}
+		else
+		{
+			XFDASHBOARD_DEBUG(self, THEME,
+								"No user global stylesheet found at %s for theme %s - skipping",
+								resourceFile,
+								priv->themeName);
+		}
+	g_free(resourceFile);
+
+	userThemeStylesheet=g_strdup_printf("user-%s.css", priv->themeName);
+	resourceFile=g_build_filename(g_get_user_config_dir(), "xfdashboard", "themes", userThemeStylesheet, NULL);
+	if(g_file_test(resourceFile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+	{
+		priv->userThemeStyleFile=g_strdup(resourceFile);
+	}
+		else
+		{
+			XFDASHBOARD_DEBUG(self, THEME,
+								"No user theme stylesheet found at %s for theme %s - skipping",
+								resourceFile,
+								priv->themeName);
+		}
+	g_free(resourceFile);
+
 	/* Release allocated resources */
 	if(themePath) g_free(themePath);
 }
@@ -520,6 +625,18 @@ static void _xfdashboard_theme_dispose(GObject *inObject)
 		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardThemeProperties[PROP_COMMENT]);
 	}
 
+	if(priv->userThemeStyleFile)
+	{
+		g_free(priv->userThemeStyleFile);
+		priv->userThemeStyleFile=NULL;
+	}
+
+	if(priv->userGlobalStyleFile)
+	{
+		g_free(priv->userGlobalStyleFile);
+		priv->userGlobalStyleFile=NULL;
+	}
+
 	if(priv->styling)
 	{
 		g_object_unref(priv->styling);
@@ -657,6 +774,8 @@ void xfdashboard_theme_init(XfdashboardTheme *self)
 	priv->themePath=NULL;
 	priv->themeDisplayName=NULL;
 	priv->themeComment=NULL;
+	priv->userThemeStyleFile=NULL;
+	priv->userGlobalStyleFile=NULL;
 	priv->styling=NULL;
 	priv->layout=NULL;
 	priv->effects=NULL;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list