libpurple/theme-manager.c

branch
next.minor
changeset 25875
a98b16817658
parent 25005
e86ff053dd10
child 26778
42e6ec9c8320
--- a/libpurple/theme-manager.c	Sat Jan 24 03:11:09 2009 +0000
+++ b/libpurple/theme-manager.c	Sun Jan 25 22:55:23 2009 +0000
@@ -1,5 +1,5 @@
 /*
- * Themes for LibPurple
+ * Themes for libpurple
  *
  * Pidgin is the legal property of its developers, whose names are too numerous
  * to list here.  Please refer to the COPYRIGHT file distributed with this
@@ -18,8 +18,8 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
- *
  */
+
 #include <glib.h>
 #include <string.h>
 
@@ -34,66 +34,66 @@
 static GHashTable *theme_table = NULL;
 
 /*****************************************************************************
- * GObject Stuff                                                     
+ * GObject Stuff
  ****************************************************************************/
 
-GType 
+GType
 purple_theme_manager_get_type(void)
 {
-  static GType type = 0;
-  if (type == 0) {
-    static const GTypeInfo info = {
-      sizeof (PurpleThemeManagerClass),
-      NULL,   /* base_init */
-      NULL,   /* base_finalize */
-      NULL,   /* class_init */
-      NULL,   /* class_finalize */
-      NULL,   /* class_data */
-      sizeof (PurpleThemeManager),
-      0,      /* n_preallocs */
-      NULL,    /* instance_init */
-      NULL,   /* Value Table */
-    };
-    type = g_type_register_static(G_TYPE_OBJECT,
-                                   "PurpleThemeManager",
-                                   &info, 0);
-  }
-  return type;
+	static GType type = 0;
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleThemeManagerClass),
+			NULL, /* base_init */
+			NULL, /* base_finalize */
+			NULL, /* class_init */
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof(PurpleThemeManager),
+			0, /* n_preallocs */
+			NULL, /* instance_init */
+			NULL, /* Value Table */
+		};
+		type = g_type_register_static(G_TYPE_OBJECT,
+				"PurpleThemeManager", &info, 0);
+	}
+	return type;
 }
 
 /******************************************************************************
  * Helpers
  *****************************************************************************/
+
 /* makes a key of <type> + '/' + <name> */
 static gchar *
 purple_theme_manager_make_key(const gchar *name, const gchar *type)
 {
 	g_return_val_if_fail(name && *name, NULL);
-	g_return_val_if_fail(type && *type, NULL);		
+	g_return_val_if_fail(type && *type, NULL);
 	return g_strconcat(type, "/", name, NULL);
 }
 
-/* returns TRUE if theme is of type "user_data" */ 
+/* returns TRUE if theme is of type "user_data" */
 static gboolean
 purple_theme_manager_is_theme_type(gchar *key,
-                  gpointer value,
-                  gchar *user_data)
+		gpointer value,
+		gchar *user_data)
 {
 	return g_str_has_prefix(key, g_strconcat(user_data, "/", NULL));
 }
 
 static gboolean
 purple_theme_manager_is_theme(gchar *key,
-                  gpointer value,
-                  gchar *user_data)
+		gpointer value,
+		gchar *user_data)
 {
 	return PURPLE_IS_THEME(value);
 }
 
 static void
 purple_theme_manager_function_wrapper(gchar *key,
-                  		      gpointer value,
-                		      PTFunc user_data)
+		gpointer value,
+		PTFunc user_data)
 {
 	if (PURPLE_IS_THEME(value))
 		(* user_data)(value);
@@ -102,7 +102,6 @@
 static void
 purple_theme_manager_build_dir(const gchar *root)
 {
-
 	gchar *purple_dir, *theme_dir;
 	const gchar *name = NULL, *type = NULL;
 	GDir *rdir, *tdir;
@@ -114,25 +113,25 @@
 		return;
 
 	/* Parses directory by root/name/purple/type */
-	while((name = g_dir_read_name(rdir))) {
+	while ((name = g_dir_read_name(rdir))) {
 		purple_dir = g_build_filename(root, name, "purple", NULL);
 		tdir = g_dir_open(purple_dir, 0, NULL);
-	
-		if(!tdir) {
+
+		if (!tdir) {
 			g_free(purple_dir);
 
 			continue;
 		}
 
-		while((type = g_dir_read_name(tdir))) {
-			if((loader = g_hash_table_lookup(theme_table, type))) {
+		while ((type = g_dir_read_name(tdir))) {
+			if ((loader = g_hash_table_lookup(theme_table, type))) {
 				PurpleTheme *theme = NULL;
 
 				theme_dir = g_build_filename(purple_dir, type, NULL);
 
 				theme = purple_theme_loader_build(loader, theme_dir);
 
-				if(PURPLE_IS_THEME(theme))
+				if (PURPLE_IS_THEME(theme))
 					purple_theme_manager_add_theme(theme);
 			}
 		}
@@ -145,28 +144,25 @@
 }
 
 /*****************************************************************************
- * Public API functions                                                      *
+ * Public API functions
  *****************************************************************************/
 
 void
 purple_theme_manager_init(void)
 {
 	theme_table = g_hash_table_new_full(g_str_hash,
-	       	                             g_str_equal,
-	       	                             g_free,
-	       	                             g_object_unref);
+			g_str_equal, g_free, g_object_unref);
 }
 
-void 
-purple_theme_manager_refresh()
+void
+purple_theme_manager_refresh(void)
 {
 	gchar *path = NULL;
 	const gchar *xdg = NULL;
 	gint i = 0;
 
 	g_hash_table_foreach_remove(theme_table,
-                	            (GHRFunc) purple_theme_manager_is_theme,
-                	            NULL);
+			(GHRFunc) purple_theme_manager_is_theme, NULL);
 
 	/* Add themes from ~/.purple */
 	path = g_build_filename(purple_user_dir(), "themes", NULL);
@@ -174,7 +170,7 @@
 	g_free(path);
 
 	/* look for XDG_DATA_HOME.  If we don't have it use ~/.local, and add it */
-	if((xdg = g_getenv("XDG_DATA_HOME")) != NULL)
+	if ((xdg = g_getenv("XDG_DATA_HOME")) != NULL)
 		path = g_build_filename(xdg, "themes", NULL);
 	else
 		path = g_build_filename(purple_home_dir(), ".local", "themes", NULL);
@@ -184,10 +180,10 @@
 
 	/* now dig through XDG_DATA_DIRS and add those too */
 	xdg = g_getenv("XDG_DATA_DIRS");
-	if(xdg) {
+	if (xdg) {
 		gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0);
 
-		for(i = 0; xdg_dirs[i]; i++) {
+		for (i = 0; xdg_dirs[i]; i++) {
 			path = g_build_filename(xdg_dirs[i], "themes", NULL);
 			purple_theme_manager_build_dir(path);
 			g_free(path);
@@ -197,13 +193,12 @@
 	}
 }
 
-void 
-purple_theme_manager_uninit()
+void
+purple_theme_manager_uninit(void)
 {
 	g_hash_table_destroy(theme_table);
 }
 
-
 void
 purple_theme_manager_register_type(PurpleThemeLoader *loader)
 {
@@ -215,7 +210,7 @@
 	g_return_if_fail(type);
 
 	/* if something is already there do nothing */
-	if (! g_hash_table_lookup(theme_table, type)) 
+	if (!g_hash_table_lookup(theme_table, type))
 		g_hash_table_insert(theme_table, type, loader);
 }
 
@@ -229,19 +224,18 @@
 	type = purple_theme_loader_get_type_string(loader);
 	g_return_if_fail(type);
 
-	if (g_hash_table_lookup(theme_table, type) == loader){
-
+	if (g_hash_table_lookup(theme_table, type) == loader)
+	{
 		g_hash_table_remove(theme_table, type);
 
 		g_hash_table_foreach_remove(theme_table,
-                	                    (GHRFunc)purple_theme_manager_is_theme_type,
-                	                    (gpointer)type);		
-	}/* only free if given registered loader */
+				(GHRFunc)purple_theme_manager_is_theme_type, (gpointer)type);
+	} /* only free if given registered loader */
 }
 
 PurpleTheme *
 purple_theme_manager_find_theme(const gchar *name,
-				const gchar *type)
+		const gchar *type)
 {
 	gchar *key;
 	PurpleTheme *theme;
@@ -257,21 +251,20 @@
 	return theme;
 }
 
-
-void 
+void
 purple_theme_manager_add_theme(PurpleTheme *theme)
 {
 	gchar *key;
-	
+
 	g_return_if_fail(PURPLE_IS_THEME(theme));
 
 	key = purple_theme_manager_make_key(purple_theme_get_name(theme),
-			  		    purple_theme_get_type_string(theme));
+			purple_theme_get_type_string(theme));
 
 	g_return_if_fail(key);
 
 	/* if something is already there do nothing */
-	if (g_hash_table_lookup(theme_table, key) == NULL) 
+	if (g_hash_table_lookup(theme_table, key) == NULL)
 		g_hash_table_insert(theme_table, key, theme);
 }
 
@@ -283,22 +276,20 @@
 	g_return_if_fail(PURPLE_IS_THEME(theme));
 
 	key = purple_theme_manager_make_key(purple_theme_get_name(theme),
-				  	    purple_theme_get_type_string(theme));
+			purple_theme_get_type_string(theme));
 
 	g_return_if_fail(key);
 
-	g_hash_table_remove(theme_table, key);	
+	g_hash_table_remove(theme_table, key);
 
-	g_free(key);	
+	g_free(key);
 }
 
-void 
+void
 purple_theme_manager_for_each_theme(PTFunc func)
 {
 	g_return_if_fail(func);
 
 	g_hash_table_foreach(theme_table,
-			     (GHFunc) purple_theme_manager_function_wrapper,
-			     func);
+			(GHFunc) purple_theme_manager_function_wrapper, func);
 }
-

mercurial