soc.2008.themes: f3b38e0c: fixed images to appear in pref menu
ffdragon at soc.pidgin.im
ffdragon at soc.pidgin.im
Mon Jun 23 22:10:39 EDT 2008
-----------------------------------------------------------------
Revision: f3b38e0cf2855a8c22a1949257165b7ffa9f4358
Ancestor: 433e0b3c65aead850f53278b185580a1318780f8
Author: ffdragon at soc.pidgin.im
Date: 2008-06-24T02:06:42
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/f3b38e0cf2855a8c22a1949257165b7ffa9f4358
Modified files:
libpurple/sound-loader.c libpurple/theme-manager.c
libpurple/theme-manager.h pidgin/gtkprefs.c
ChangeLog:
fixed images to appear in pref menu
-------------- next part --------------
============================================================
--- libpurple/sound-loader.c 94a8f37d733a4b99981dbec558abacb7b894c452
+++ libpurple/sound-loader.c ea4b70da389b2a2eba8c738d3d5b0c056423fe70
@@ -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;
}
============================================================
--- libpurple/theme-manager.c 00151c44c19305b8bffb43ea5abc0e36e7f46de5
+++ libpurple/theme-manager.c 6ef952f65becd723b3212d865d8c411f8a307d52
@@ -235,16 +235,16 @@ purple_theme_manager_add_theme(PurpleThe
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);
============================================================
--- libpurple/theme-manager.h 846f834899f35dfb017af9abc2c153dc5ee97dd0
+++ libpurple/theme-manager.h 20b160dd0fc5a67964f480510dc989ac4e9b72ad
@@ -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;
============================================================
--- pidgin/gtkprefs.c e57374abd5d039e2db3d92708e23305d176340cf
+++ pidgin/gtkprefs.c 6caf8a9c8df904cef72904bea02ef887080da7d7
@@ -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 GtkTreeRowReference *previous_smi
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 @@ theme_dnd_recv(GtkWidget *widget, GdkDra
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 @@ sound_page(void)
const char *file;
char *pref;
GtkCellRenderer *cell_rend;
- GdkPixbuf *pixbuf;
#ifndef _WIN32
GtkWidget *dd;
GtkWidget *entry;
@@ -1938,9 +1974,7 @@ sound_page(void)
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 @@ sound_page(void)
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 @@ void pidgin_prefs_show(void)
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 @@ pidgin_prefs_init(void)
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");
More information about the Commits
mailing list