Mercurial > pidgin.yaz
changeset 11557:1e7c0773380f
[gaim-migrate @ 13819]
Fix smiley theme selection being lost when gaim is restarted. We now save the smiley theme name instead of path as the pref. Avoid leaking a GtkTreeRowReference.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 20 Sep 2005 21:47:57 +0000 |
parents | 7fbf5e4e8f5f |
children | 19941a47405c |
files | src/gtkprefs.c src/gtkthemes.c src/gtkthemes.h |
diffstat | 3 files changed, 83 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkprefs.c Mon Sep 19 16:18:50 2005 +0000 +++ b/src/gtkprefs.c Tue Sep 20 21:47:57 2005 +0000 @@ -66,7 +66,7 @@ static GtkWidget *debugbutton = NULL; static int notebook_page = 0; static GtkTreeIter plugin_iter; -GtkTreeRowReference *previous_smiley_row; +static GtkTreeRowReference *previous_smiley_row = NULL; /* * PROTOTYPES @@ -451,6 +451,9 @@ debugbutton = NULL; notebook_page = 0; smiley_theme_store = NULL; + if (previous_smiley_row) + gtk_tree_row_reference_free(previous_smiley_row); + previous_smiley_row = NULL; for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) { @@ -458,57 +461,59 @@ } } -static void smiley_sel (GtkTreeSelection *sel, GtkTreeModel *model) { +static void smiley_sel(GtkTreeSelection *sel, GtkTreeModel *model) { GtkTreeIter iter; - const char *filename; - char *description; + const char *themename; + char *description; GValue val = { 0, }; - GtkTreePath *path, - *oldpath; - struct smiley_theme *new_theme, - *old_theme; - - - if (! gtk_tree_selection_get_selected (sel, &model, &iter)) + GtkTreePath *path, *oldpath; + struct smiley_theme *new_theme, *old_theme; + + if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return; old_theme = current_smiley_theme; - gtk_tree_model_get_value (model, &iter, 2, &val); + gtk_tree_model_get_value(model, &iter, 3, &val); path = gtk_tree_model_get_path(model, &iter); - filename = g_value_get_string(&val); - gaim_prefs_set_string("/gaim/gtk/smileys/theme", filename); + themename = g_value_get_string(&val); + gaim_prefs_set_string("/gaim/gtk/smileys/theme", themename); g_value_unset (&val); + /* current_smiley_theme is set in callback for the above pref change */ new_theme = current_smiley_theme; description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n" "<span size='smaller' foreground='white'>%s</span>", new_theme->name, new_theme->author, new_theme->desc); - gtk_list_store_set(smiley_theme_store,&iter,1,description,-1); + gtk_list_store_set(smiley_theme_store, &iter, 1, description, -1); g_free(description); - oldpath = gtk_tree_row_reference_get_path(previous_smiley_row); - if(gtk_tree_model_get_iter(model, &iter, oldpath)){ - description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n" + if (new_theme != old_theme && previous_smiley_row) { + oldpath = gtk_tree_row_reference_get_path(previous_smiley_row); + if (gtk_tree_model_get_iter(model, &iter, oldpath)) { + description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n" "<span size='smaller' foreground='dim grey'>%s</span>", old_theme->name, old_theme->author, old_theme->desc); - gtk_list_store_set(smiley_theme_store,&iter,1,description,-1); - g_free(description); + gtk_list_store_set(smiley_theme_store, &iter, 1, + description, -1); + g_free(description); + } + gtk_tree_path_free(oldpath); } - gtk_tree_path_free(oldpath); - - gtk_tree_row_reference_free(previous_smiley_row); + if (previous_smiley_row) + gtk_tree_row_reference_free(previous_smiley_row); previous_smiley_row = gtk_tree_row_reference_new(model, path); gtk_tree_path_free(path); } -static GtkTreePath *theme_refresh_theme_list() +static GtkTreeRowReference *theme_refresh_theme_list() { GdkPixbuf *pixbuf; GSList *themes; GtkTreeIter iter; - GtkTreePath *path = NULL; - int ind = 0; - + GtkTreeRowReference *row_ref = NULL; + + if (previous_smiley_row) + gtk_tree_row_reference_free(previous_smiley_row); previous_smiley_row = NULL; gaim_gtkthemes_smiley_theme_probe(); @@ -516,7 +521,6 @@ if (!(themes = smiley_themes)) return NULL; - gtk_list_store_clear(smiley_theme_store); while (themes) { @@ -544,16 +548,19 @@ g_free(description); themes = themes->next; - if (current_smiley_theme && !strcmp(theme->path, current_smiley_theme->path)) { - /* path = gtk_tree_path_new_from_indices(ind); */ - char *iwishihadgtk2_2 = g_strdup_printf("%d", ind); - path = gtk_tree_path_new_from_string(iwishihadgtk2_2); - g_free(iwishihadgtk2_2); + + /* If this is the currently selected theme, + * we will need to select it. Grab the row reference. */ + if (theme == current_smiley_theme) { + GtkTreePath *path = gtk_tree_model_get_path( + GTK_TREE_MODEL(smiley_theme_store), &iter); + row_ref = gtk_tree_row_reference_new( + GTK_TREE_MODEL(smiley_theme_store), path); + gtk_tree_path_free(path); } - ind++; } - return path; + return row_ref; } static void theme_install_theme(char *path, char *extn) { @@ -562,7 +569,7 @@ #endif gchar *destdir; gchar *tail; - GtkTreePath *themepath = NULL; + GtkTreeRowReference *theme_rowref; /* Just to be safe */ g_strchomp(path); @@ -602,9 +609,9 @@ #endif g_free(destdir); - themepath = theme_refresh_theme_list(); - if (themepath != NULL) - gtk_tree_path_free(themepath); + theme_rowref = theme_refresh_theme_list(); + if (theme_rowref != NULL) + gtk_tree_row_reference_free(theme_rowref); } static void @@ -707,7 +714,7 @@ GtkCellRenderer *rend; GtkTreeViewColumn *col; GtkTreeSelection *sel; - GtkTreePath *path = NULL; + GtkTreeRowReference *rowref; GtkWidget *label; GtkTargetEntry te[3] = {{"text/plain", 0, 0},{"text/uri-list", 0, 1},{"STRING", 0, 2}}; @@ -730,7 +737,7 @@ gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0); smiley_theme_store = gtk_list_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - path = theme_refresh_theme_list(); + rowref = theme_refresh_theme_list(); view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(smiley_theme_store)); @@ -742,11 +749,6 @@ rend = gtk_cell_renderer_pixbuf_new(); sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - if(path) { - gtk_tree_selection_select_path(sel, path); - gtk_tree_path_free(path); - } - /* Custom sort so "none" theme is at top of list */ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(smiley_theme_store), 3, gaim_sort_smileys, NULL, NULL); @@ -771,6 +773,13 @@ g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(smiley_sel), NULL); + if (rowref) { + GtkTreePath *path = gtk_tree_row_reference_get_path(rowref); + gtk_tree_row_reference_free(rowref); + gtk_tree_selection_select_path(sel, path); + gtk_tree_path_free(path); + } + gtk_widget_show_all(ret); gaim_set_accessible_label (view, label); @@ -2260,8 +2269,16 @@ smiley_theme_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) { - if (!strcmp(name, "/gaim/gtk/smileys/theme")) - gaim_gtkthemes_load_smiley_theme((const char *)value, TRUE); + const char *themename = value; + GSList *themes; + + for (themes = smiley_themes; themes; themes = themes->next) { + struct smiley_theme *smile = themes->data; + if (smile->name && strcmp(themename, smile->name) == 0) { + gaim_gtkthemes_load_smiley_theme(smile->path, TRUE); + break; + } + } } void @@ -2310,7 +2327,7 @@ /* Smiley Themes */ gaim_prefs_add_none("/gaim/gtk/smileys"); - gaim_prefs_add_string("/gaim/gtk/smileys/theme", "default"); + gaim_prefs_add_string("/gaim/gtk/smileys/theme", "Default"); /* Smiley Callbacks */ gaim_prefs_connect_callback(prefs, "/gaim/gtk/smileys/theme",
--- a/src/gtkthemes.c Mon Sep 19 16:18:50 2005 +0000 +++ b/src/gtkthemes.c Tue Sep 20 21:47:57 2005 +0000 @@ -269,11 +269,24 @@ void gaim_gtkthemes_init() { - if (current_smiley_theme == NULL) { - gaim_gtkthemes_smiley_theme_probe(); - if (smiley_themes != NULL) { - struct smiley_theme *smile = smiley_themes->data; + GSList *l; + const char *current_theme = + gaim_prefs_get_string("/gaim/gtk/smileys/theme"); + + gaim_gtkthemes_smiley_theme_probe(); + + for (l = smiley_themes; l; l = l->next) { + struct smiley_theme *smile = l->data; + if (smile->name && strcmp(current_theme, smile->name) == 0) { gaim_gtkthemes_load_smiley_theme(smile->path, TRUE); + break; } } + + /* If we still don't have a smiley theme, choose the first one */ + if (!current_smiley_theme && smiley_themes) { + struct smiley_theme *smile = smiley_themes->data; + gaim_gtkthemes_load_smiley_theme(smile->path, TRUE); + } + }
--- a/src/gtkthemes.h Mon Sep 19 16:18:50 2005 +0000 +++ b/src/gtkthemes.h Tue Sep 20 21:47:57 2005 +0000 @@ -42,7 +42,6 @@ extern struct smiley_theme *current_smiley_theme; extern GSList *smiley_themes; -extern GtkTreeRowReference *previous_smiley_row; extern void gaim_gtkthemes_init(); gboolean gaim_gtkthemes_smileys_disabled();