soc.2008.themes: 6108b8f4: Fixed up a few typos, readability, leaks...

ffdragon at soc.pidgin.im ffdragon at soc.pidgin.im
Sun Jun 29 23:55:44 EDT 2008


-----------------------------------------------------------------
Revision: 6108b8f480f1589e219641d557022940902871cf
Ancestor: 9863839cc1cbdfface64c2083dac9b6ee00d0c8c
Author: ffdragon at soc.pidgin.im
Date: 2008-06-30T03:50:35
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/6108b8f480f1589e219641d557022940902871cf

Modified 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

ChangeLog: 

Fixed up a few typos, readability, leaks, and bugs, all minor and mostly in theme and theme loader classes

-------------- next part --------------
============================================================
--- libpurple/sound-loader.c	020bb6c6c90b5479f5eaf7b0e31bb6d9d03a87d1
+++ libpurple/sound-loader.c	6ec2cede63527ed9d17f1a8b4b98bc7fee1e621c
@@ -37,12 +37,10 @@ purple_sound_loader_build(const gchar *d
 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);
 	g_return_val_if_fail(gdir != NULL, NULL);
@@ -58,11 +56,7 @@ purple_sound_loader_build(const gchar *d
 	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 @@ purple_sound_loader_build(const gchar *d
 			    "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 @@ purple_sound_loader_build(const gchar *d
 		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;
 }
============================================================
--- libpurple/sound-theme.c	279e84b6510b97c6590520ad6861041b8c9f0a49
+++ libpurple/sound-theme.c	a6db34e5e1bcf06f8e4a4d83d2cf2fed10cedc85
@@ -116,7 +116,7 @@ purple_sound_theme_get_type (void)
  * 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(PurpleS
 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 
============================================================
--- libpurple/sound-theme.h	47373d0d77cbdc18479d037488214c1777fdf87f
+++ libpurple/sound-theme.h	1b1f783cd2d3c019492fde177d62f21ba2436096
@@ -77,7 +77,7 @@ GType purple_sound_theme_get_type(void);
  *
  * @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
============================================================
--- libpurple/theme-loader.c	726a2fb4b5571ff1330bdfcfacfff4dd92c021f5
+++ libpurple/theme-loader.c	9dbdab64f13cc2dcc95abc56b37ff07e0545d178
@@ -88,7 +88,8 @@ purple_theme_loader_init(GTypeInstance *
 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 @@ purple_theme_loader_get_type (void)
  *****************************************************************************/
 
 
-gchar *
+const gchar *
 purple_theme_loader_get_type_string (PurpleThemeLoader *theme_loader)
 {
 	PurpleThemeLoaderPrivate *priv = NULL;
@@ -175,7 +176,7 @@ purple_theme_loader_set_type_string(Purp
 	priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
 
 	g_free(priv->type);
-	priv->type = g_strdup (type);
+	priv->type = g_strdup(type);
 }
 
 gpointer
============================================================
--- libpurple/theme-loader.h	4e9302ece03c69349a5fc7fe1cf8fa95a8431a37
+++ libpurple/theme-loader.h	989050d9fd73da1b110407d5db45ac8fa2c542ce
@@ -77,7 +77,7 @@ GType purple_theme_loader_get_type(void)
  *
  * @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
============================================================
--- libpurple/theme-manager.c	df6a74738d8ab1192edd1bff6e81de24a7ad328a
+++ libpurple/theme-manager.c	5f0cb37cf420ac9cbb506d1abe2a6fdf71364bfa
@@ -76,7 +76,7 @@ purple_theme_manager_is_theme_type(gchar
                   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 gc
 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;
 
-	return g_hash_table_lookup(theme_table, 
-				   purple_theme_manager_make_key(name, type));
+	key = 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;
 }
 
 
============================================================
--- libpurple/theme.c	cec9ed7125f02bc4d6920bc15c2cf5ee52293bff
+++ libpurple/theme.c	6d7b9afea74a836452c529725c7e680eae7d8b7a
@@ -37,7 +37,7 @@ typedef struct {
 	gchar *author;
 	gchar *type;
 	gchar *dir;
-	PurpleStoredImage *img;
+	gchar *img;
 } PurpleThemePrivate;
 
 /******************************************************************************
@@ -87,7 +87,7 @@ purple_theme_get_property(GObject *obj, 
 			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_property(GObject *obj, 
 			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 *instanc
 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 @@ purple_theme_finalize(GObject *obj)
 	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 @@ purple_theme_class_init (PurpleThemeClas
 				    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 @@ purple_theme_get_type (void)
  * Public API functions                                                      *
  *****************************************************************************/
 
-gchar *
+const gchar *
 purple_theme_get_name(PurpleTheme *theme)
 {
 	PurpleThemePrivate *priv;
@@ -249,10 +251,10 @@ purple_theme_set_name(PurpleTheme *theme
 	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 @@ purple_theme_set_description(PurpleTheme
 	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 @@ purple_theme_set_author(PurpleTheme *the
 	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 @@ purple_theme_set_type_string(PurpleTheme
 	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 @@ purple_theme_set_dir(PurpleTheme *theme,
 	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 @@ purple_theme_get_image(PurpleTheme *them
 
 	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 @@ purple_theme_set_image(PurpleTheme *them
 
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
-	purple_imgstore_unref(priv->img);
-	priv->img = img;
+	g_free(priv->img);
+	priv->img = g_strdup(img);
 }
============================================================
--- libpurple/theme.h	50f4ec1f82a4366fe7949f0959f251175e59aef9
+++ libpurple/theme.h	0727316e9a97e6f7c7751fa7eb0894d45dd96951
@@ -75,7 +75,7 @@ GType purple_theme_get_type(void);
  *
  * @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 @@ void purple_theme_set_name(PurpleTheme *
  *
  * @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 @@ void purple_theme_set_description(Purple
  *
  * @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 @@ void purple_theme_set_author(PurpleTheme
  *
  * @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 @@ gchar *purple_theme_get_type_string(Purp
  *
  * @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,17 +150,26 @@ void purple_theme_set_dir(PurpleTheme *t
  * 
  * @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
  * 
  * @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_ */
============================================================
--- pidgin/gtkprefs.c	faec9e8c5dd8e92cbb6583d582b017ad6ddc4e87
+++ pidgin/gtkprefs.c	88cb0a1e69377c2c493c99c98a689d86ce452fdf
@@ -558,7 +558,7 @@ pref_set_sound_customized()
 {
 	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,16 +567,25 @@ prefs_themes_sort(PurpleTheme *theme)
 {
 	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");
+		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; 
 
-		pixbuf = pidgin_pixbuf_from_imgstore(purple_theme_get_image(theme));
 		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_themes_init(void)
 	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);


More information about the Commits mailing list