changeset 23472:fbf72bbd1084

Fixed up a few typos, readability, leaks, and bugs, all minor and mostly in theme and theme loader classes
author Justin Rodriguez <ffdragon@soc.pidgin.im>
date Mon, 30 Jun 2008 03:50:35 +0000
parents ef66901f74f5
children 60d3ba8c9047
files libpurple/sound-loader.c libpurple/sound-theme.c libpurple/sound-theme.h libpurple/theme-loader.c libpurple/theme-loader.h libpurple/theme-manager.c libpurple/theme.c libpurple/theme.h pidgin/gtkprefs.c
diffstat 9 files changed, 89 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/sound-loader.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/sound-loader.c	Mon Jun 30 03:50:35 2008 +0000
@@ -37,11 +37,9 @@
 purple_sound_loader_build(const gchar *dir)
 {
 	xmlnode *root_node, *sub_node;
-	gchar *filename, *filename_full, *imagefile, *data;
+	gchar *filename, *filename_full, *data;
 	GDir *gdir;
 	PurpleSoundTheme *theme;
-	PurpleStoredImage *preview;
-
 
 	/* Find the theme file */
 	gdir = g_dir_open(dir, 0, NULL);
@@ -58,11 +56,7 @@
 	root_node = xmlnode_from_file(dir, filename, "sound themes", "sound-loader");
 	g_return_val_if_fail(root_node != NULL, NULL);
 
-	/* Parse the tree */
-	/* TODO: fix image and add description */
-	imagefile = g_build_filename(dir, xmlnode_get_attrib(root_node, "image"), NULL);
-	preview = purple_imgstore_new_from_file(imagefile);
-	
+	/* Parse the tree */	
 	sub_node = xmlnode_get_child(root_node, "description");
 	data = xmlnode_get_data(sub_node);
 
@@ -70,7 +64,7 @@
 			    "type", "sound",
 			    "name", xmlnode_get_attrib(root_node, "name"),
 			    "author", xmlnode_get_attrib(root_node, "author"),
-			    "image", preview,
+			    "image", xmlnode_get_attrib(root_node, "image"),
 			    "directory", dir,
 			    "description", data, NULL);
 	
@@ -83,11 +77,9 @@
 		xmlnode_free(sub_node);
 	}
 
-	purple_imgstore_ref(preview);
 	xmlnode_free(root_node);	
 	g_dir_close(gdir);
 	g_free(filename_full);
-	g_free(imagefile);
 	g_free(data);
 	return theme;
 }
--- a/libpurple/sound-theme.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/sound-theme.c	Mon Jun 30 03:50:35 2008 +0000
@@ -116,7 +116,7 @@
  * Public API functions                                                      
  *****************************************************************************/
 
-gchar *
+const gchar *
 purple_sound_theme_get_file(PurpleSoundTheme *theme,
 			    const gchar *event)
 {
@@ -133,18 +133,15 @@
 purple_sound_theme_get_file_full(PurpleSoundTheme *theme,
 				 const gchar *event)
 {
-	gchar *dir, *filename, *full;
+	gchar *filename;
 
 	g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL);
 
-	dir = purple_theme_get_dir(PURPLE_THEME(theme));
 	filename = purple_sound_theme_get_file(theme, event);
 	
 	g_return_val_if_fail(filename, NULL);
 
-	full = g_build_filename(dir, filename, NULL);
-
-	return full;
+	return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme)), filename, NULL);
 }
 
 void 
--- a/libpurple/sound-theme.h	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/sound-theme.h	Mon Jun 30 03:50:35 2008 +0000
@@ -77,7 +77,7 @@
  *
  * @returns the filename of the sound event
  */
-gchar *purple_sound_theme_get_file(PurpleSoundTheme *theme,
+const gchar *purple_sound_theme_get_file(PurpleSoundTheme *theme,
 				   const gchar *event);
 /**
  * Returns a copy of the directory and filename for the sound event
--- a/libpurple/theme-loader.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/theme-loader.c	Mon Jun 30 03:50:35 2008 +0000
@@ -88,7 +88,8 @@
 purple_theme_loader_init(GTypeInstance *instance,
 			gpointer klass)
 {
-	(PURPLE_THEME_LOADER(instance))->priv = g_new0(PurpleThemeLoaderPrivate, 1);
+	PurpleThemeLoader *loader = PURPLE_THEME_LOADER(instance);
+	loader->priv = g_new0(PurpleThemeLoaderPrivate, 1);
 }
 
 static void
@@ -153,7 +154,7 @@
  *****************************************************************************/
 
 
-gchar *
+const gchar *
 purple_theme_loader_get_type_string (PurpleThemeLoader *theme_loader)
 {
 	PurpleThemeLoaderPrivate *priv = NULL;
@@ -175,7 +176,7 @@
 	priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
 
 	g_free(priv->type);
-	priv->type = g_strdup (type);
+	priv->type = g_strdup(type);
 }
 
 gpointer
--- a/libpurple/theme-loader.h	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/theme-loader.h	Mon Jun 30 03:50:35 2008 +0000
@@ -77,7 +77,7 @@
  *
  * @returns 		the string represting this type
  */
-gchar *purple_theme_loader_get_type_string(PurpleThemeLoader *self);
+const gchar *purple_theme_loader_get_type_string(PurpleThemeLoader *self);
 
 /**
  * Creates a new PurpleTheme
--- a/libpurple/theme-manager.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/theme-manager.c	Mon Jun 30 03:50:35 2008 +0000
@@ -76,7 +76,7 @@
                   gpointer value,
                   gchar *user_data)
 {
-	return g_str_has_prefix (key, g_strconcat(user_data, "/", NULL));
+	return g_str_has_prefix(key, g_strconcat(user_data, "/", NULL));
 }
 
 static gboolean
@@ -223,11 +223,18 @@
 purple_theme_manager_find_theme(const gchar *name,
 				const gchar *type)
 {
-	g_return_val_if_fail(name, NULL);
-	g_return_val_if_fail(type, NULL);
+	gchar *key;
+	PurpleTheme *theme;
+
+	key = purple_theme_manager_make_key(name, type);
 
-	return g_hash_table_lookup(theme_table, 
-				   purple_theme_manager_make_key(name, type));
+	g_return_val_if_fail(key, NULL);
+
+	theme = g_hash_table_lookup(theme_table, key);
+
+	g_free(key);
+
+	return theme;
 }
 
 
--- a/libpurple/theme.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/theme.c	Mon Jun 30 03:50:35 2008 +0000
@@ -37,7 +37,7 @@
 	gchar *author;
 	gchar *type;
 	gchar *dir;
-	PurpleStoredImage *img;
+	gchar *img;
 } PurpleThemePrivate;
 
 /******************************************************************************
@@ -87,7 +87,7 @@
 			g_value_set_string(value, purple_theme_get_dir(theme));
 			break;
 		case PROP_IMAGE:
-			g_value_set_pointer(value, purple_theme_get_image(theme));
+			g_value_set_string(value, purple_theme_get_image(theme));
 			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
@@ -118,7 +118,7 @@
 			purple_theme_set_dir(theme, g_value_get_string(value));
 			break;
 		case PROP_IMAGE:
-			purple_theme_set_image(theme, g_value_get_pointer(value));
+			purple_theme_set_image(theme, g_value_get_string(value));
 			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
@@ -130,7 +130,8 @@
 purple_theme_init(GTypeInstance *instance,
 			gpointer klass)
 {
-	(PURPLE_THEME(instance))->priv = g_new0(PurpleThemePrivate, 1);
+	PurpleTheme *theme = PURPLE_THEME(instance);
+	theme->priv = g_new0(PurpleThemePrivate, 1);
 }
 
 static void
@@ -144,7 +145,7 @@
 	g_free(priv->author);
 	g_free(priv->type);
 	g_free(priv->dir);
-	purple_imgstore_unref(priv->img);
+	g_free(priv->img);
 
 	G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
@@ -192,8 +193,9 @@
 				    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 	g_object_class_install_property(obj_class, PROP_DIR, pspec);
 	/* PREVIEW IMAGE */
-	pspec = g_param_spec_pointer("image", "Image",
+	pspec = g_param_spec_string("image", "Image",
 				    "A preview image of the theme",
+				    NULL,
 				    G_PARAM_READWRITE);
 	g_object_class_install_property(obj_class, PROP_IMAGE, pspec);
 }
@@ -228,7 +230,7 @@
  * Public API functions                                                      *
  *****************************************************************************/
 
-gchar *
+const gchar *
 purple_theme_get_name(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -249,10 +251,10 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->name);
-	priv->name = g_strdup (name);
+	priv->name = g_strdup(name);
 }
 
-gchar *
+const gchar *
 purple_theme_get_description(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -273,10 +275,10 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->description);
-	priv->description = g_strdup (description);
+	priv->description = g_strdup(description);
 }
 
-gchar *
+const gchar *
 purple_theme_get_author(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -297,10 +299,10 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->author);
-	priv->author = g_strdup (author);
+	priv->author = g_strdup(author);
 }
 
-gchar *
+const gchar *
 purple_theme_get_type_string(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -322,10 +324,10 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->type);
-	priv->type = g_strdup (type);
+	priv->type = g_strdup(type);
 }
 
-gchar *
+const gchar *
 purple_theme_get_dir(PurpleTheme *theme) 
 {
 	PurpleThemePrivate *priv;
@@ -346,10 +348,10 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->dir);
-	priv->dir = g_strdup (dir);
+	priv->dir = g_strdup(dir);
 }
 
-PurpleStoredImage *
+const gchar *
 purple_theme_get_image(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -358,11 +360,21 @@
 
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
-	return purple_imgstore_ref(priv->img);
+	return priv->img;
+}
+
+gchar *
+purple_theme_get_image_full(PurpleTheme *theme)
+{
+	const gchar *filename = purple_theme_get_image(theme);
+	
+	g_return_val_if_fail(filename, NULL);
+
+	return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme)), filename, NULL);
 }
 
 void 
-purple_theme_set_image(PurpleTheme *theme, PurpleStoredImage *img)
+purple_theme_set_image(PurpleTheme *theme, const gchar *img)
 {	
 	PurpleThemePrivate *priv;
 
@@ -370,6 +382,6 @@
 
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
-	purple_imgstore_unref(priv->img);
-	priv->img = img;
+	g_free(priv->img);
+	priv->img = g_strdup(img);
 }
--- a/libpurple/theme.h	Fri Jun 27 21:01:47 2008 +0000
+++ b/libpurple/theme.h	Mon Jun 30 03:50:35 2008 +0000
@@ -75,7 +75,7 @@
  *
  * @return The string representating the name of the theme
  */
-gchar *purple_theme_get_name(PurpleTheme *theme);
+const gchar *purple_theme_get_name(PurpleTheme *theme);
 
 /**
  * Sets the name of the PurpleTheme object
@@ -92,7 +92,7 @@
  *
  * @return A short description of the theme
  */
-gchar *purple_theme_get_description(PurpleTheme *theme);
+const gchar *purple_theme_get_description(PurpleTheme *theme);
 
 /**
  * Sets the description of the PurpleTheme object
@@ -109,7 +109,7 @@
  *
  * @return The author of the theme
  */
-gchar *purple_theme_get_author(PurpleTheme *theme);
+const gchar *purple_theme_get_author(PurpleTheme *theme);
 
 /**
  * Sets the author of the PurpleTheme object
@@ -126,7 +126,7 @@
  *
  * @return The string represtenting the type
  */
-gchar *purple_theme_get_type_string(PurpleTheme *theme);
+const gchar *purple_theme_get_type_string(PurpleTheme *theme);
 
 /**
  * Returns the directory of the PurpleTheme object
@@ -135,7 +135,7 @@
  *
  * @return The string represtenting the theme directory 
  */
-gchar *purple_theme_get_dir(PurpleTheme *theme);
+const gchar *purple_theme_get_dir(PurpleTheme *theme);
 
 /**
  * Sets the directory of the PurpleTheme object
@@ -150,9 +150,18 @@
  * 
  * @param theme 	the purple theme
  *
- * @return The PurpleStoredImage preview of the PurpleTheme object
+ * @return The image preview of the PurpleTheme object
  */
-PurpleStoredImage *purple_theme_get_image(PurpleTheme *theme);
+const gchar *purple_theme_get_image(PurpleTheme *theme);
+
+/**
+ * Returns the image preview and directory of the PurpleTheme object
+ * 
+ * @param theme 	the purple theme
+ *
+ * @return The image preview of the PurpleTheme object
+ */
+gchar *purple_theme_get_image_full(PurpleTheme *theme);
 
 /**
  * Sets the directory of the PurpleTheme object
@@ -160,7 +169,7 @@
  * @param theme 	the purple theme
  * @param img		the image preview of the PurpleTheme object
  */
-void purple_theme_set_image(PurpleTheme *theme, PurpleStoredImage *img);
+void purple_theme_set_image(PurpleTheme *theme, const gchar *img);
 
 G_END_DECLS
 #endif /* _PURPLE_THEME_H_ */
--- a/pidgin/gtkprefs.c	Fri Jun 27 21:01:47 2008 +0000
+++ b/pidgin/gtkprefs.c	Mon Jun 30 03:50:35 2008 +0000
@@ -558,7 +558,7 @@
 {
 	if (pidgin_sound_is_customized())
 		gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, "(Custom)", -1);
-	else    gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, NULL, -1);
+	else gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, NULL, -1);
 }
 
 /* adds the themes to the theme list from the manager so they can be sisplayed in prefs */
@@ -567,15 +567,24 @@
 {
 	GdkPixbuf *pixbuf = NULL;
 	GtkTreeIter iter;
+	gchar *image_full;
 	
 	if (PURPLE_IS_SOUND_THEME(theme)){
 		/* TODO: string leaks? */
-		gchar *pref = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme");
-
-		pixbuf = pidgin_pixbuf_from_imgstore(purple_theme_get_image(theme));
+		const gchar *pref = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme");
+		
+		image_full = purple_theme_get_image_full(theme);
+		if (image_full != NULL){
+			pixbuf = gdk_pixbuf_new_from_file(image_full, NULL);
+			g_free(image_full);
+		}
+		else pixbuf = NULL; 
+
 		gtk_list_store_append (prefs_sound_themes, &iter);
 		gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), 2, NULL, -1);
-		gdk_pixbuf_unref(pixbuf);
+
+		if (pixbuf != NULL)
+			gdk_pixbuf_unref(pixbuf);
 
 		if (pref && strlen(pref) && !strcmp(purple_theme_get_name(theme), pref))
 			prefs_sound_iter = iter;
@@ -594,7 +603,7 @@
 	prefs_sound_themes = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
 
 	filename = g_build_filename(DATADIR, "icons", "hicolor", "16x16", "apps", "pidgin.png", NULL);
-	pixbuf= gdk_pixbuf_new_from_file (filename, NULL);
+	pixbuf= gdk_pixbuf_new_from_file(filename, NULL);
 	g_free(filename);
 
 	gtk_list_store_append (prefs_sound_themes, &prefs_sound_iter);