--- a/pidgin/gtkprefs.c Tue Jun 24 02:06:42 2008 +0000 +++ b/pidgin/gtkprefs.c Fri Jun 27 01:29:59 2008 +0000 @@ -73,6 +73,7 @@ static gboolean prefs_themes_unsorted = TRUE; static GtkListStore *prefs_sound_themes; +static GtkTreeIter prefs_sound_iter; /* * PROTOTYPES @@ -551,40 +552,92 @@ gtk_drag_finish(dc, FALSE, FALSE, t); } +/* sets the current sound theme to customized or NULL */ +static void +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); +} + +/* adds the themes to the theme list from the manager so they can be sisplayed in prefs */ static void prefs_themes_sort(PurpleTheme *theme) { - GdkPixbuf *pixbuf; + GdkPixbuf *pixbuf = NULL; GtkTreeIter iter; + if (PURPLE_IS_SOUND_THEME(theme)){ - /* TODO: string leak? */ + /* TODO: string leaks? */ + gchar *pref = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"); + 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); + gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), 2, NULL, -1); + gdk_pixbuf_unref(pixbuf); + + if (pref && strlen(pref) && !strcmp(purple_theme_get_name(theme), pref)) + prefs_sound_iter = iter; + } } +/* init all the theme variables so that the themes can be sorted later and used by pref pages */ 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); + 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); g_free(filename); - gtk_list_store_append (prefs_sound_themes, &iter); - gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, _("(Default)"), -1); + gtk_list_store_append (prefs_sound_themes, &prefs_sound_iter); + + gtk_list_store_set (prefs_sound_themes, &prefs_sound_iter, 0, pixbuf, 1, _("(Default)"), 2, NULL, -1); gdk_pixbuf_unref (pixbuf); } +/* sets the current sound theme */ +static void +prefs_set_sound_theme(GtkComboBox *combo_box, gpointer user_data) +{ + gint i; + gchar *pref; + gchar *theme_name; + + /* remove "(custom)" */ + gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, NULL, -1); + + g_return_if_fail(gtk_combo_box_get_active_iter(combo_box, &prefs_sound_iter)); + + gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &prefs_sound_iter, 1, &theme_name, -1); + + if (strcmp(theme_name, "(Default)") == 0){ + g_free(theme_name); + theme_name = g_strdup(""); + } + + purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", theme_name); + + for(i=0; i < PURPLE_NUM_SOUNDS; i++){ + pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", + pidgin_sound_get_event_option(i)); + purple_prefs_set_path(pref, ""); + g_free(pref); + } + + gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)")); + + g_free(theme_name); +} + /* Does same as normal sort, except "none" is sorted first */ static gint pidgin_sort_smileys (GtkTreeModel *model, GtkTreeIter *a, @@ -1775,6 +1828,8 @@ g_free(pref); gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)")); + + pref_set_sound_customized(); } static void @@ -1865,6 +1920,8 @@ if (sound_entry) gtk_entry_set_text(GTK_ENTRY(sound_entry), (file && *file != '\0') ? file : _("(default)")); g_value_unset (&val); + + pref_set_sound_customized(); } static GtkWidget * @@ -1974,7 +2031,7 @@ vbox->parent->parent, TRUE, TRUE, 0, GTK_PACK_START); /* SOUND THEMES */ - combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (prefs_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 (); @@ -1984,7 +2041,12 @@ cell_rend = gtk_cell_renderer_text_new (); 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); - + + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &prefs_sound_iter); + g_signal_connect(G_OBJECT(combo_box), "changed", (GCallback)prefs_set_sound_theme, NULL); + + pref_set_sound_customized(); + /* SOUND SELECTION */ sw = gtk_scrolled_window_new(NULL,NULL); gtk_widget_set_size_request(sw, -1, 100);