changeset 25091:655a37bc0eb0

fixed images to appear in pref menu
author Justin Rodriguez <ffdragon@soc.pidgin.im>
date Tue, 24 Jun 2008 02:06:42 +0000
parents 5a02912e0bac
children cf7625d4d7e0
files libpurple/sound-loader.c libpurple/theme-manager.c libpurple/theme-manager.h pidgin/gtkprefs.c
diffstat 4 files changed, 74 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/sound-loader.c	Sun Jun 22 03:07:07 2008 +0000
+++ b/libpurple/sound-loader.c	Tue Jun 24 02:06:42 2008 +0000
@@ -32,63 +32,62 @@
 /*****************************************************************************
  * Sound Theme Builder                                                      
  *****************************************************************************/
-#define THEME_SUFFIX		".xml"
-#define THEME_NAME		"name"
-#define THEME_AUTHOR		"author"
-#define THEME_IMAGE		"image"
-#define THEME_DESCRIPTION	"description"
-#define THEME_SOUND_EVENT	"event"
-#define THEME_EVENT_NAME	"name"
-#define THEME_EVENT_FILE	"file"
 
 static gpointer
 purple_sound_loader_build(const gchar *dir)
 {
 	xmlnode *root_node, *sub_node;
-	gchar *filename, *filename_full, *image, *data;
+	gchar *filename, *filename_full, *imagefile, *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);
 
-	while ((filename = g_strdup(g_dir_read_name(gdir))) != NULL && ! g_str_has_suffix(filename, THEME_SUFFIX))
+	while ((filename = g_strdup(g_dir_read_name(gdir))) != NULL && ! g_str_has_suffix(filename, ".xml"))
 		g_free(filename);
 	
 	g_return_val_if_fail(filename != NULL, NULL);
 	
 	/* Build the xml tree */
 	filename_full = g_build_filename(dir, filename, NULL);
-	
+
 	root_node = xmlnode_from_file(dir, filename, "sound themes", "sound-loader");
 	g_return_val_if_fail(root_node != NULL, NULL);
 
 	/* Parse the tree */
-	theme = g_object_new(PURPLE_TYPE_SOUND_THEME, "type", "sound", NULL);
-		
-	purple_theme_set_name(PURPLE_THEME(theme), xmlnode_get_attrib(root_node, THEME_NAME));
-	purple_theme_set_author(PURPLE_THEME(theme), xmlnode_get_attrib(root_node, THEME_AUTHOR));
+	/* 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);
+	
+	sub_node = xmlnode_get_child(root_node, "description");
+	data = xmlnode_get_data(sub_node);
 
-	image = g_build_filename(dir, xmlnode_get_attrib(root_node, THEME_IMAGE), NULL);
+	theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
+			    "type", "sound",
+			    "name", xmlnode_get_attrib(root_node, "name"),
+			    "author", xmlnode_get_attrib(root_node, "author"),
+			    "image", preview,
+			    "description", data, NULL);
 	
-	sub_node = xmlnode_get_child(root_node, THEME_DESCRIPTION);
-	data = xmlnode_get_data(sub_node);
-	purple_theme_set_description(PURPLE_THEME(theme), data);
 	xmlnode_free(sub_node);
 
-	while ((sub_node = xmlnode_get_child(root_node, THEME_SOUND_EVENT)) != NULL){
+	while ((sub_node = xmlnode_get_child(root_node, "event")) != NULL){
 		purple_sound_theme_set_file(theme,
-					    xmlnode_get_attrib(root_node, THEME_EVENT_NAME),
-					    xmlnode_get_attrib(root_node, THEME_EVENT_FILE));
+					    xmlnode_get_attrib(root_node, "name"),
+					    xmlnode_get_attrib(root_node, "file"));
 
 		xmlnode_free(sub_node);
 	}
 
+	purple_imgstore_ref(preview);
 	xmlnode_free(root_node);	
 	g_dir_close(gdir);
 	g_free(filename_full);
-	g_free(image);
+	g_free(imagefile);
 	g_free(data);
 	return theme;
 }
--- a/libpurple/theme-manager.c	Sun Jun 22 03:07:07 2008 +0000
+++ b/libpurple/theme-manager.c	Tue Jun 24 02:06:42 2008 +0000
@@ -235,16 +235,16 @@
 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));
 
 	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);
 	
 	g_free(key);	
--- a/libpurple/theme-manager.h	Sun Jun 22 03:07:07 2008 +0000
+++ b/libpurple/theme-manager.h	Tue Jun 24 02:06:42 2008 +0000
@@ -31,7 +31,7 @@
 #include "theme.h"
 #include "theme-loader.h"
 
-typedef void (*PTFunc) (PurpleTheme *theme);
+typedef void (*PTFunc) (PurpleTheme *);
 
 typedef struct _PurpleThemeManager PurpleThemeManager;
 typedef struct _PurpleThemeManagerClass PurpleThemeManagerClass;
--- a/pidgin/gtkprefs.c	Sun Jun 22 03:07:07 2008 +0000
+++ b/pidgin/gtkprefs.c	Tue Jun 24 02:06:42 2008 +0000
@@ -35,6 +35,8 @@
 #include "request.h"
 #include "savedstatuses.h"
 #include "sound.h"
+#include "sound-theme.h"
+#include "theme-manager.h"
 #include "util.h"
 #include "network.h"
 
@@ -69,7 +71,8 @@
 static int notebook_page = 0;
 static GtkTreeRowReference *previous_smiley_row = NULL;
 
-static GtkListStore *sound_themes;
+static gboolean prefs_themes_unsorted = TRUE;
+static GtkListStore *prefs_sound_themes;
 
 /*
  * PROTOTYPES
@@ -548,6 +551,40 @@
 	gtk_drag_finish(dc, FALSE, FALSE, t);
 }
 
+static void
+prefs_themes_sort(PurpleTheme *theme)
+{
+	GdkPixbuf *pixbuf;
+	GtkTreeIter iter;
+	if (PURPLE_IS_SOUND_THEME(theme)){
+		/* TODO: string leak? */
+		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), -1);
+		gdk_pixbuf_unref (pixbuf);
+	}
+}
+
+static void
+prefs_themes_init(void)
+{
+	GdkPixbuf *pixbuf = NULL;
+	GtkTreeIter iter;
+	gchar *filename;
+
+	/* sound themes */
+	prefs_sound_themes = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
+
+	filename = g_build_filename(DATADIR, "icons", "hicolor", "16x16", "apps", "pidgin.png", NULL);
+	pixbuf= gdk_pixbuf_new_from_file (filename, NULL);
+	g_free(filename);
+
+	gtk_list_store_append (prefs_sound_themes, &iter);
+	gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, _("(Default)"), -1);
+
+	gdk_pixbuf_unref (pixbuf);
+}
+
 /* Does same as normal sort, except "none" is sorted first */
 static gint pidgin_sort_smileys (GtkTreeModel	*model,
 						GtkTreeIter		*a,
@@ -1848,7 +1885,6 @@
 	const char *file;
 	char *pref;
 	GtkCellRenderer *cell_rend;
-	GdkPixbuf *pixbuf;
 #ifndef _WIN32
 	GtkWidget *dd;
 	GtkWidget *entry;
@@ -1938,9 +1974,7 @@
 			vbox->parent->parent, TRUE, TRUE, 0, GTK_PACK_START);
 
 	/* SOUND THEMES */
-	sound_themes = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
-
-	combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (sound_themes));
+	combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (prefs_sound_themes));
 	gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0);
 
 	cell_rend = gtk_cell_renderer_pixbuf_new ();
@@ -1951,11 +1985,6 @@
 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell_rend, FALSE);
 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell_rend, "text", 1, NULL);
 	
-	pixbuf = gdk_pixbuf_new_from_file (NULL, NULL);
-	gtk_list_store_append (sound_themes, &iter);
-	gtk_list_store_set (sound_themes, &iter, 0, pixbuf, 1, _("(Default)"), -1);
-	gdk_pixbuf_unref (pixbuf);
-
 	/* SOUND SELECTION */
 	sw = gtk_scrolled_window_new(NULL,NULL);
 	gtk_widget_set_size_request(sw, -1, 100);
@@ -2189,6 +2218,12 @@
 		gtk_window_present(GTK_WINDOW(prefs));
 		return;
 	}
+	
+	/* add everthing in the thmeme manager before the window is loaded */
+	if (prefs_themes_unsorted){
+		purple_theme_manager_for_each_theme(prefs_themes_sort);
+		prefs_themes_unsorted = FALSE;
+	}
 
 	/* copy the preferences to tmp values...
 	 * I liked "take affect immediately" Oh well :-( */
@@ -2284,6 +2319,9 @@
 	purple_prefs_add_path(PIDGIN_PREFS_ROOT "/filelocations/last_open_folder", "");
 	purple_prefs_add_path(PIDGIN_PREFS_ROOT "/filelocations/last_icon_folder", "");
 
+	/* Themes */
+	prefs_themes_init();
+
 	/* Smiley Themes */
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/smileys");
 	purple_prefs_add_string(PIDGIN_PREFS_ROOT "/smileys/theme", "Default");