Mercurial > pidgin.yaz
changeset 23480:2ccad3a8d9fe
fixed segfault when changing blist themes, changed prefs to not rely on static iter, fixed a few leaks
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Fri, 18 Jul 2008 09:03:40 +0000 |
parents | edb03a8d54bd |
children | fc3600ba68f1 |
files | pidgin/gtkblist.c pidgin/gtkprefs.c pidgin/gtksound.c |
diffstat | 3 files changed, 125 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkblist.c Thu Jul 17 19:40:13 2008 +0000 +++ b/pidgin/gtkblist.c Fri Jul 18 09:03:40 2008 +0000 @@ -5980,7 +5980,7 @@ GtkTreeIter iter; GtkTreePath *path; gboolean expanded; - GdkColor bgcolor; + GdkColor *bgcolor; GdkPixbuf *avatar = NULL; PidginBlistTheme *theme; @@ -5991,13 +5991,13 @@ /*if(theme == NULL){ bgcolor = &(gtkblist->treeview->style->bg[GTK_STATE_ACTIVE]); - +g_print("\nNULL\n"); } else if(purple_blist_node_get_bool(gnode, "collapsed")) bgcolor = (pidgin_blist_theme_get_collapsed_text_info(theme))->color; - else bgcolor = (pidgin_blist_theme_get_expanded_text_info(theme))->color;*/ - - g_print("\n\n\%s\n\n", gdk_color_to_string(&bgcolor)); + else bgcolor = (pidgin_blist_theme_get_expanded_text_info(theme))->color; + +g_print("\n\n\%s\n\n", gdk_color_to_string(&bgcolor));*/ path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); expanded = gtk_tree_view_row_expanded(GTK_TREE_VIEW(gtkblist->treeview), path); @@ -7191,11 +7191,12 @@ pidgin_blist_set_theme(PidginBlistTheme *theme) { PidginBuddyListPrivate *priv = PIDGIN_BUDDY_LIST_GET_PRIVATE(gtkblist); - - g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); - - purple_prefs_set_string(PIDGIN_PREFS_ROOT "/blist/theme", + + if (theme != NULL) + purple_prefs_set_string(PIDGIN_PREFS_ROOT "/blist/theme", purple_theme_get_name(PURPLE_THEME(theme))); + else purple_prefs_set_string(PIDGIN_PREFS_ROOT "/blist/theme", ""); + priv->current_theme = theme; pidgin_blist_refresh(purple_get_blist());
--- a/pidgin/gtkprefs.c Thu Jul 17 19:40:13 2008 +0000 +++ b/pidgin/gtkprefs.c Fri Jul 18 09:03:40 2008 +0000 @@ -73,9 +73,7 @@ static gboolean prefs_themes_unsorted = TRUE; static GtkListStore *prefs_sound_themes; -static GtkTreeIter prefs_sound_iter; static GtkListStore *prefs_blist_themes; -static GtkTreeIter prefs_blist_iter; /* @@ -558,10 +556,27 @@ /* 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); +{ + gboolean custom = pidgin_sound_is_customized(); + const gchar *current_theme = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"); + gchar *theme; + GtkTreeIter iter; + + if (g_str_equal(current_theme, "")) + current_theme = "(Default)"; + + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(prefs_sound_themes), &iter)) { + do { + gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &iter, 1, &theme, -1); + + if (custom && g_str_equal(current_theme, theme)) + gtk_list_store_set(prefs_sound_themes, &iter, 2, "(Custom)", -1); + else gtk_list_store_set(prefs_sound_themes, &iter, 2, NULL, -1); + + g_free(theme); + + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(prefs_sound_themes), &iter)); + } } /* adds the themes to the theme list from the manager so they can be sisplayed in prefs */ @@ -590,9 +605,6 @@ if (pixbuf != NULL) gdk_pixbuf_unref(pixbuf); - if (g_str_equal(purple_theme_get_name(theme), pref)) - prefs_sound_iter = iter; - } else if (PIDGIN_IS_BLIST_THEME(theme)){ pref = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/theme"); @@ -605,14 +617,10 @@ else pixbuf = NULL; gtk_list_store_append (prefs_blist_themes, &iter); - gtk_list_store_set (prefs_blist_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), 2, theme, -1); + gtk_list_store_set (prefs_blist_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), -1); if (pixbuf != NULL) gdk_pixbuf_unref(pixbuf); - - if (g_str_equal(purple_theme_get_name(theme), pref)) - prefs_blist_iter = iter; - } } @@ -622,6 +630,7 @@ { GdkPixbuf *pixbuf = NULL; gchar *filename; + GtkTreeIter iter; filename = g_build_filename(DATADIR, "icons", "hicolor", "16x16", "apps", "pidgin.png", NULL); pixbuf= gdk_pixbuf_new_from_file(filename, NULL); @@ -630,40 +639,43 @@ /* sound themes */ prefs_sound_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING); - 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); + gtk_list_store_append(prefs_sound_themes, &iter); + gtk_list_store_set(prefs_sound_themes, &iter, 0, pixbuf, 1, _("(Default)"), 2, NULL, -1); /* blist themes */ - prefs_blist_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, PIDGIN_TYPE_BLIST_THEME); - - gtk_list_store_append(prefs_blist_themes, &prefs_blist_iter); - gtk_list_store_set(prefs_blist_themes, &prefs_blist_iter, 0, pixbuf, 1, _("(Default)"), 2, NULL, -1); + prefs_blist_themes = gtk_list_store_new(2, GDK_TYPE_PIXBUF, G_TYPE_STRING); + + gtk_list_store_append(prefs_blist_themes, &iter); + gtk_list_store_set(prefs_blist_themes, &iter, 0, pixbuf, 1, _("(Default)"), -1); gdk_pixbuf_unref(pixbuf); } /* sets the current sound theme */ static void -prefs_set_sound_theme(GtkComboBox *combo_box, gpointer user_data) +prefs_set_sound_theme_cb(GtkComboBox *combo_box, gpointer user_data) { gint i; gchar *pref; - gchar *theme_name; + gchar *new_theme; + gboolean sucess; + GtkTreeIter new_iter; - /* 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 (g_str_equal(theme_name, "(Default)")){ - g_free(theme_name); - theme_name = g_strdup(""); + + sucess = gtk_combo_box_get_active_iter(combo_box, &new_iter); + g_return_if_fail(sucess); + + gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &new_iter, 1, &new_theme, -1); + + /* The default theme is stored as NULL */ + if (g_str_equal(new_theme, "(Default)")){ + g_free(new_theme); + new_theme = g_strdup(""); } - purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", theme_name); - + purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", new_theme); + + /* New theme removes all customization */ for(i=0; i < PURPLE_NUM_SOUNDS; i++){ pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", pidgin_sound_get_event_option(i)); @@ -671,9 +683,12 @@ g_free(pref); } + /* gets rid of the "(Custom)" from the last selection */ + pref_set_sound_customized(); + gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)")); - g_free(theme_name); + g_free(new_theme); } /* Does same as normal sort, except "none" is sorted first */ @@ -1054,16 +1069,19 @@ /* sets the current buddy list theme */ static void -prefs_set_blist_theme(GtkComboBox *combo_box, gpointer user_data) +prefs_set_blist_theme_cb(GtkComboBox *combo_box, gpointer user_data) { PidginBlistTheme *theme; + GtkTreeIter iter; + gchar *name = NULL; - g_return_if_fail(gtk_combo_box_get_active_iter(combo_box, &prefs_blist_iter)); - gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &prefs_blist_iter, 1, &theme, -1); - + g_return_if_fail(gtk_combo_box_get_active_iter(combo_box, &iter)); + gtk_tree_model_get(GTK_TREE_MODEL(prefs_blist_themes), &iter, 1, &name, -1); + + theme = PIDGIN_BLIST_THEME(purple_theme_manager_find_theme(name, "blist")); pidgin_blist_set_theme(theme); - g_object_unref(theme); + g_free(name); } @@ -1077,7 +1095,10 @@ GtkWidget *combo_box; GtkCellRenderer *cell_rend; GtkSizeGroup *sg; + GtkTreeIter iter; GList *names = NULL; + gchar *theme; + const gchar *current_theme; ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE); gtk_container_set_border_width(GTK_CONTAINER(ret), PIDGIN_HIG_BORDER); @@ -1097,8 +1118,23 @@ 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_blist_iter); - g_signal_connect(G_OBJECT(combo_box), "changed", (GCallback)prefs_set_blist_theme, NULL); + current_theme = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/theme"); + + if (g_str_equal(current_theme, "")) + current_theme = "(Default)"; + + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(prefs_blist_themes), &iter)) { + do { + gtk_tree_model_get(GTK_TREE_MODEL(prefs_blist_themes), &iter, 1, &theme, -1); + + if (g_str_equal(current_theme, theme)) + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &iter); + + g_free(theme); + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(prefs_blist_themes), &iter)); + } + + g_signal_connect(G_OBJECT(combo_box), "changed", (GCallback)prefs_set_blist_theme_cb, NULL); /* System Tray */ vbox = pidgin_make_frame(ret, _("System Tray Icon")); @@ -2013,8 +2049,8 @@ GtkTreePath *path; GtkWidget *hbox; int j; - const char *file; - char *pref; + const char *file, *current_theme; + char *pref, *theme; GtkCellRenderer *cell_rend; #ifndef _WIN32 GtkWidget *dd; @@ -2106,24 +2142,41 @@ /* 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 (); - 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, "pixbuf", 0, NULL); + gtk_box_pack_start(GTK_BOX (vbox), combo_box, FALSE, FALSE, 0); + + cell_rend = gtk_cell_renderer_pixbuf_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, "pixbuf", 0, NULL); - 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); - - 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", 2, 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(); + 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); + + 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", 2, NULL); + + current_theme = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"); + + if (g_str_equal(current_theme, "")) + current_theme = "(Default)"; + + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(prefs_sound_themes), &iter)) { + do { + gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &iter, 1, &theme, -1); + + if (g_str_equal(current_theme, theme)){ + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &iter); + + if(pidgin_sound_is_customized()) + gtk_list_store_set(prefs_sound_themes, &iter, 2, "(Custom)", -1); + } + + g_free(theme); + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(prefs_sound_themes), &iter)); + } + + g_signal_connect(G_OBJECT(combo_box), "changed", (GCallback)prefs_set_sound_theme_cb, NULL); /* SOUND SELECTION */ sw = gtk_scrolled_window_new(NULL,NULL);
--- a/pidgin/gtksound.c Thu Jul 17 19:40:13 2008 +0000 +++ b/pidgin/gtksound.c Fri Jul 18 09:03:40 2008 +0000 @@ -580,7 +580,7 @@ /* check NULL for sounds that don't have an option, ie buddy pounce */ if (purple_prefs_get_bool(enable_pref)) { char *filename = g_strdup(purple_prefs_get_path(file_pref)); - theme_name = g_strdup(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme")); + theme_name = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"); if (theme_name && strlen(theme_name) && (!filename || !strlen(filename))){ /* Use theme */ g_free(filename); @@ -604,7 +604,6 @@ purple_sound_play_file(filename, NULL); - g_free(theme_name); g_free(filename); }