finch/libgnt/gntstyle.c

branch
soc.2007.finchfeat
changeset 19307
0027732ddb26
parent 18615
e93a1eb0fad7
parent 18847
409cb01a636e
child 19314
472ad9489d68
--- a/finch/libgnt/gntstyle.c	Thu Jul 19 10:35:11 2007 +0000
+++ b/finch/libgnt/gntstyle.c	Sun Jul 22 01:28:19 2007 +0000
@@ -49,13 +49,18 @@
 char *gnt_style_get_from_name(const char *group, const char *key)
 {
 #if GLIB_CHECK_VERSION(2,6,0)
+	const char *prg = g_get_prgname();
+	if ((group == NULL || *group == '\0') && prg &&
+			g_key_file_has_group(gkfile, prg))
+		group = prg;
+	if (!group)
+		group = "general";
 	return g_key_file_get_value(gkfile, group, key, NULL);
 #endif
 }
 
 gboolean gnt_style_get_bool(GntStyle style, gboolean def)
 {
-	int i;
 	const char * str;
 
 	if (bool_styles[style] != -1)
@@ -63,11 +68,20 @@
 	
 	str = gnt_style_get(style);
 
+	bool_styles[style] = str ? gnt_style_parse_bool(str) : def;
+	return bool_styles[style];
+}
+
+gboolean gnt_style_parse_bool(const char *str)
+{
+	gboolean def = FALSE;
+	int i;
+
 	if (str)
 	{
-		if (strcmp(str, "false") == 0)
+		if (g_ascii_strcasecmp(str, "false") == 0)
 			def = FALSE;
-		else if (strcmp(str, "true") == 0)
+		else if (g_ascii_strcasecmp(str, "true") == 0)
 			def = TRUE;
 		else if (sscanf(str, "%d", &i) == 1)
 		{
@@ -77,9 +91,7 @@
 				def = FALSE;
 		}
 	}
-
-	bool_styles[style] = def;
-	return bool_styles[style];
+	return def;
 }
 
 static void
@@ -134,8 +146,8 @@
 		int j;
 		GntWS *ws;
 		gchar **titles;
-		char *group = calloc(12, 1);
-		g_sprintf(group, "Workspace-%d", i);
+		char group[32];
+		g_snprintf(group, sizeof(group), "Workspace-%d", i);
 		name = g_key_file_get_value(gkfile, group, "name", NULL);
 		if (!name)
 			return;
@@ -157,7 +169,6 @@
 				g_hash_table_replace(wm->title_places, g_strdup(titles[j]), ws);
 			g_strfreev(titles);
 		}
-		g_free(group);
 	}
 #endif
 }

mercurial