Hello all, 

This patch fixes a few things which help in changing EWL themes. 

There are three basic parts:

1.  Call ecore_config_load after initializing the ecore_config. This
allows us to load the system configuration... not just use the defaults

COOL STUFF:  this now allows us to write a program like this:

::e_client.c::

#include <Ecore_Config.h>
                                                                             
int main(int argc, char ** argv) {
                                                                                
ecore_config_system_init();
ecore_config_load();
ecore_config_string_set("/ewl/theme/name", argv[1]);
ecore_config_save();
ecore_config_system_shutdown();
return 0;
}

gcc -o client e_client.c `ecore-config --libs --cflags`

Compile the program, and now you can do ./client <theme_name> to
permanently set the EWL theme. (NOTE: we should be able to do this with
examine too, but its busted up pretty bad right now for use with
_system)

2. In ewl_init, whenever there is a fail return the init count minus
one. This seems to have been forgotten in a few places.  

3. In ewl_theme, when we can't load a theme (because the name is
incorrect or something) I hard-coded to fall back to the "default"
theme. 

Another thing, I did not add the ecore_config_save to
ewl_config_shutdown, because i expect we should only be running
ecore_config_save if the program is a configuration manipulation
application. 

Stafford
Index: src/lib/ewl_config.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_config.c,v
retrieving revision 1.2
diff -u -r1.2 ewl_config.c
--- src/lib/ewl_config.c	17 Feb 2005 19:14:54 -0000	1.2
+++ src/lib/ewl_config.c	20 Mar 2005 11:32:19 -0000
@@ -38,6 +38,7 @@
 	DENTER_FUNCTION(DLEVEL_STABLE);
 
 	ecore_config_system_init();
+	ecore_config_load();
 	memset(&ewl_config, 0, sizeof(Ewl_Config));
 	ewl_config_config_read();
 
Index: src/lib/ewl_container.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_container.c,v
retrieving revision 1.2
diff -u -r1.2 ewl_container.c
--- src/lib/ewl_container.c	11 Mar 2005 15:20:53 -0000	1.2
+++ src/lib/ewl_container.c	20 Mar 2005 11:32:22 -0000
@@ -772,24 +772,7 @@
 	DENTER_FUNCTION(DLEVEL_STABLE);
 
 	if (c->child_show && VISIBLE(w) && REALIZED(w)) {
-		Ewl_Object *tmp;
-		printf("Parent: %dx%d\n",
-			ewl_object_preferred_w_get(EWL_OBJECT(c)),
-			ewl_object_preferred_h_get(EWL_OBJECT(c)));
-
-		ecore_list_goto_first(c->children);
-		while ((tmp = ecore_list_next(c->children))) {
-			if (VISIBLE(tmp) && REALIZED(tmp))
-				printf("\tChild: %dx%d\n",
-					ewl_object_preferred_w_get(tmp),
-					ewl_object_preferred_h_get(tmp));
-		}
-
 		c->child_show(c, w);
-
-		printf("Parent: %dx%d\n",
-			ewl_object_preferred_w_get(EWL_OBJECT(c)),
-			ewl_object_preferred_h_get(EWL_OBJECT(c)));
 	}
 
 	/*
Index: src/lib/ewl_misc.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_misc.c,v
retrieving revision 1.4
diff -u -r1.4 ewl_misc.c
--- src/lib/ewl_misc.c	11 Mar 2005 05:22:43 -0000	1.4
+++ src/lib/ewl_misc.c	20 Mar 2005 11:32:26 -0000
@@ -87,6 +87,7 @@
 {
 	DENTER_FUNCTION(DLEVEL_STABLE);
 
+	/* check if we are already initialized */
 	if (++_ewl_init_count > 1)
 		DRETURN_INT(_ewl_init_count, DLEVEL_STABLE);
 
@@ -137,15 +138,15 @@
 #endif
 
 	if (!use_engine) {
-		fprintf(stderr, "ERRR: Cannot open display!\n");
+		fprintf(stderr, "Cannot open display!\n");
 		ewl_shutdown();
-		DRETURN_INT(_ewl_init_count, DLEVEL_STABLE);
+		DRETURN_INT(--_ewl_init_count, DLEVEL_STABLE);
 	}
 
 	if (!ewl_config_init()) {
-		DERROR("Could not init config data....");
+		DERROR("Could not init config data.");
 		ewl_shutdown();
-		DRETURN_INT(_ewl_init_count, DLEVEL_STABLE);
+		DRETURN_INT(--_ewl_init_count, DLEVEL_STABLE);
 	}
 
 	if (print_theme_keys)
@@ -157,17 +158,17 @@
 	}
 
 	if (!ewl_ev_init()) {
-		DERROR("Could not init event data....");
+		DERROR("Could not init event data.");
 		ewl_shutdown();
-		DRETURN_INT(_ewl_init_count, DLEVEL_STABLE);
+		DRETURN_INT(--_ewl_init_count, DLEVEL_STABLE);
 	}
 
 	ewl_callbacks_init();
 
 	if (!ewl_theme_init()) {
-		DERROR("Could not init theme data....");
+		DERROR("Could not init theme data.");
 		ewl_shutdown();
-		DRETURN_INT(_ewl_init_count, DLEVEL_STABLE);
+		DRETURN_INT(--_ewl_init_count, DLEVEL_STABLE);
 	}
 
 	ewl_embed_list = ecore_list_new();
Index: src/lib/ewl_theme.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_theme.c,v
retrieving revision 1.3
diff -u -r1.3 ewl_theme.c
--- src/lib/ewl_theme.c	11 Mar 2005 15:20:54 -0000	1.3
+++ src/lib/ewl_theme.c	20 Mar 2005 11:32:28 -0000
@@ -12,6 +12,7 @@
 static Ecore_Hash *def_theme_data = NULL;
 
 static void ewl_theme_font_path_init(void);
+static char * ewl_theme_path_find(const char * name);
 
 /**
  * @return Returns TRUE on success, FALSE on failure.
@@ -23,10 +24,6 @@
  */
 int ewl_theme_init(void)
 {
-	struct stat     st;
-	char            theme_db_path[PATH_MAX];
-	char           *home;
-	
 	DENTER_FUNCTION(DLEVEL_STABLE);
 
 	/*
@@ -40,13 +37,45 @@
 	 * Retrieve the current theme from the users config.
 	 */
 	if (!theme_name) {
-		theme_name = ewl_config_str_get("/ewl/theme/name");
-		if (!theme_name)
-			theme_name = strdup("default");
+		if(ewl_config.theme.name) {
+			theme_name = strdup(ewl_config.theme.name);
+			theme_path = ewl_theme_path_find(theme_name);
+		}
+	}		
+
+	/*
+	 * Fall back to the default theme.
+	 */	
+	if(!theme_path) {
+		theme_name = strdup("default");
+		theme_path = ewl_theme_path_find(theme_name);
 	}
 
-	if (!theme_name)
+	/*
+	 * If we can't find a theme, no point in continuing further.
+	 */
+	if (!theme_path) {
+		DERROR("No usable theme found, exiting EWL");
 		DRETURN_INT(FALSE, DLEVEL_STABLE);
+	}
+
+	ewl_theme_font_path_init();
+
+	IF_FREE(theme_name);
+
+	DRETURN_INT(TRUE, DLEVEL_STABLE);
+}
+
+/*
+ * Private function for finding the theme path given a theme name, If no theme
+ * of name is found we will return null.
+ */
+static char * ewl_theme_path_find(const char * name) 
+{		
+	struct stat     st;
+	char 	       *theme_found_path = NULL;
+	char 		theme_tmp_path[PATH_MAX];
+	char 	       *home;
 
 	/*
 	 * Get the users home directory. This environment variable should
@@ -57,67 +86,57 @@
 		DERROR("Environment variable HOME not defined\n"
 		       "Try export HOME=/home/user in a bash like environemnt or\n"
 		       "setenv HOME=/home/user in a csh like environment.\n");
-		DRETURN_INT(FALSE, DLEVEL_STABLE);
 	}
 
 	/*
 	 * Build a path to the theme if it is the users home dir and use it if
 	 * available. 
 	 */
-	snprintf(theme_db_path, PATH_MAX, "%s/.e/ewl/themes/%s.eet",
-			home, theme_name);
-	if (((stat(theme_db_path, &st)) == 0) && S_ISREG(st.st_mode)) {
-		theme_path = strdup(theme_db_path);
+	if (home) {
+		snprintf(theme_tmp_path, PATH_MAX, "%s/.e/ewl/themes/%s.eet",
+			home, name);
+		if (((stat(theme_tmp_path, &st)) == 0) && S_ISREG(st.st_mode)) {
+			theme_found_path = strdup(theme_tmp_path);
+		}
 	}
 
 	/*
 	 * No user theme, so we try the system-wide theme.
 	 */
-	if (!theme_path) {
-		snprintf(theme_db_path, PATH_MAX, PACKAGE_DATA_DIR
-				"/themes/%s.eet", theme_name);
-		if (((stat(theme_db_path, &st)) == 0) &&
+	if (!theme_found_path) {
+		snprintf(theme_tmp_path, PATH_MAX, PACKAGE_DATA_DIR
+				"/themes/%s.eet", name);
+		if (((stat(theme_tmp_path, &st)) == 0) &&
 				S_ISREG(st.st_mode)) {
-			theme_path = strdup(theme_db_path);
+			theme_found_path = strdup(theme_tmp_path);
 		}
 	}
 
 	/*
 	 * see if they gave a full path to the theme
 	 */
-	if (!theme_path) {
-		if (theme_name[0] != '/') {
+	if (!theme_found_path) {
+		if (name[0] != '/') {
 			char   *cwd;
 
 			cwd = getenv("PWD");
 			if (cwd != NULL) 
-				snprintf(theme_db_path, PATH_MAX, "%s/%s", cwd, theme_name);
+				snprintf(theme_tmp_path, PATH_MAX, "%s/%s", cwd, name);
 			else
-				snprintf(theme_db_path, PATH_MAX, "%s", theme_name);
+				snprintf(theme_tmp_path, PATH_MAX, "%s", name);
 
 		} else {
-			snprintf(theme_db_path, PATH_MAX, "%s", theme_name);
+			snprintf(theme_tmp_path, PATH_MAX, "%s", name);
 		}
 
-		if (((stat(theme_db_path, &st)) == 0) &&
+		if (((stat(theme_tmp_path, &st)) == 0) &&
 				S_ISREG(st.st_mode)) {
-			theme_path = strdup(theme_db_path);
+			theme_found_path = strdup(theme_tmp_path);
 		}
 	}
 
-	/*
-	 * If we can't find a theme, no point in continuing further.
-	 */
-	if (!theme_path) {
-		DERROR("No usable theme found, exiting EWL");
-		DRETURN_INT(FALSE, DLEVEL_STABLE);
-	}
-
-	ewl_theme_font_path_init();
-
-	IF_FREE(theme_name);
+	return theme_found_path;
 
-	DRETURN_INT(TRUE, DLEVEL_STABLE);
 }
 
 /**

Reply via email to