comparison src/gtkprefs.c @ 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 ec2335d98b83
children 9b3833da6840
comparison
equal deleted inserted replaced
11556:7fbf5e4e8f5f 11557:1e7c0773380f
64 64
65 static GtkWidget *prefs = NULL; 65 static GtkWidget *prefs = NULL;
66 static GtkWidget *debugbutton = NULL; 66 static GtkWidget *debugbutton = NULL;
67 static int notebook_page = 0; 67 static int notebook_page = 0;
68 static GtkTreeIter plugin_iter; 68 static GtkTreeIter plugin_iter;
69 GtkTreeRowReference *previous_smiley_row; 69 static GtkTreeRowReference *previous_smiley_row = NULL;
70 70
71 /* 71 /*
72 * PROTOTYPES 72 * PROTOTYPES
73 */ 73 */
74 static int prefs_notebook_add_page(const char*, GdkPixbuf*, 74 static int prefs_notebook_add_page(const char*, GdkPixbuf*,
449 prefs = NULL; 449 prefs = NULL;
450 sound_entry = NULL; 450 sound_entry = NULL;
451 debugbutton = NULL; 451 debugbutton = NULL;
452 notebook_page = 0; 452 notebook_page = 0;
453 smiley_theme_store = NULL; 453 smiley_theme_store = NULL;
454 if (previous_smiley_row)
455 gtk_tree_row_reference_free(previous_smiley_row);
456 previous_smiley_row = NULL;
454 457
455 for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) 458 for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next)
456 { 459 {
457 delete_plugin_prefs(l->data); 460 delete_plugin_prefs(l->data);
458 } 461 }
459 } 462 }
460 463
461 static void smiley_sel (GtkTreeSelection *sel, GtkTreeModel *model) { 464 static void smiley_sel(GtkTreeSelection *sel, GtkTreeModel *model) {
462 GtkTreeIter iter; 465 GtkTreeIter iter;
463 const char *filename; 466 const char *themename;
464 char *description; 467 char *description;
465 GValue val = { 0, }; 468 GValue val = { 0, };
466 GtkTreePath *path, 469 GtkTreePath *path, *oldpath;
467 *oldpath; 470 struct smiley_theme *new_theme, *old_theme;
468 struct smiley_theme *new_theme, 471
469 *old_theme; 472 if (!gtk_tree_selection_get_selected(sel, &model, &iter))
470
471
472 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
473 return; 473 return;
474 474
475 old_theme = current_smiley_theme; 475 old_theme = current_smiley_theme;
476 gtk_tree_model_get_value (model, &iter, 2, &val); 476 gtk_tree_model_get_value(model, &iter, 3, &val);
477 path = gtk_tree_model_get_path(model, &iter); 477 path = gtk_tree_model_get_path(model, &iter);
478 filename = g_value_get_string(&val); 478 themename = g_value_get_string(&val);
479 gaim_prefs_set_string("/gaim/gtk/smileys/theme", filename); 479 gaim_prefs_set_string("/gaim/gtk/smileys/theme", themename);
480 g_value_unset (&val); 480 g_value_unset (&val);
481 481
482 /* current_smiley_theme is set in callback for the above pref change */
482 new_theme = current_smiley_theme; 483 new_theme = current_smiley_theme;
483 description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n" 484 description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n"
484 "<span size='smaller' foreground='white'>%s</span>", 485 "<span size='smaller' foreground='white'>%s</span>",
485 new_theme->name, new_theme->author, new_theme->desc); 486 new_theme->name, new_theme->author, new_theme->desc);
486 gtk_list_store_set(smiley_theme_store,&iter,1,description,-1); 487 gtk_list_store_set(smiley_theme_store, &iter, 1, description, -1);
487 g_free(description); 488 g_free(description);
488 489
489 oldpath = gtk_tree_row_reference_get_path(previous_smiley_row); 490 if (new_theme != old_theme && previous_smiley_row) {
490 if(gtk_tree_model_get_iter(model, &iter, oldpath)){ 491 oldpath = gtk_tree_row_reference_get_path(previous_smiley_row);
491 description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n" 492 if (gtk_tree_model_get_iter(model, &iter, oldpath)) {
493 description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n"
492 "<span size='smaller' foreground='dim grey'>%s</span>", 494 "<span size='smaller' foreground='dim grey'>%s</span>",
493 old_theme->name, old_theme->author, old_theme->desc); 495 old_theme->name, old_theme->author, old_theme->desc);
494 gtk_list_store_set(smiley_theme_store,&iter,1,description,-1); 496 gtk_list_store_set(smiley_theme_store, &iter, 1,
495 g_free(description); 497 description, -1);
496 } 498 g_free(description);
497 gtk_tree_path_free(oldpath); 499 }
498 500 gtk_tree_path_free(oldpath);
499 gtk_tree_row_reference_free(previous_smiley_row); 501 }
502 if (previous_smiley_row)
503 gtk_tree_row_reference_free(previous_smiley_row);
500 previous_smiley_row = gtk_tree_row_reference_new(model, path); 504 previous_smiley_row = gtk_tree_row_reference_new(model, path);
501 gtk_tree_path_free(path); 505 gtk_tree_path_free(path);
502 } 506 }
503 507
504 static GtkTreePath *theme_refresh_theme_list() 508 static GtkTreeRowReference *theme_refresh_theme_list()
505 { 509 {
506 GdkPixbuf *pixbuf; 510 GdkPixbuf *pixbuf;
507 GSList *themes; 511 GSList *themes;
508 GtkTreeIter iter; 512 GtkTreeIter iter;
509 GtkTreePath *path = NULL; 513 GtkTreeRowReference *row_ref = NULL;
510 int ind = 0; 514
511 515 if (previous_smiley_row)
516 gtk_tree_row_reference_free(previous_smiley_row);
512 previous_smiley_row = NULL; 517 previous_smiley_row = NULL;
513 518
514 gaim_gtkthemes_smiley_theme_probe(); 519 gaim_gtkthemes_smiley_theme_probe();
515 520
516 if (!(themes = smiley_themes)) 521 if (!(themes = smiley_themes))
517 return NULL; 522 return NULL;
518
519 523
520 gtk_list_store_clear(smiley_theme_store); 524 gtk_list_store_clear(smiley_theme_store);
521 525
522 while (themes) { 526 while (themes) {
523 struct smiley_theme *theme = themes->data; 527 struct smiley_theme *theme = themes->data;
542 if (pixbuf != NULL) 546 if (pixbuf != NULL)
543 g_object_unref(G_OBJECT(pixbuf)); 547 g_object_unref(G_OBJECT(pixbuf));
544 548
545 g_free(description); 549 g_free(description);
546 themes = themes->next; 550 themes = themes->next;
547 if (current_smiley_theme && !strcmp(theme->path, current_smiley_theme->path)) { 551
548 /* path = gtk_tree_path_new_from_indices(ind); */ 552 /* If this is the currently selected theme,
549 char *iwishihadgtk2_2 = g_strdup_printf("%d", ind); 553 * we will need to select it. Grab the row reference. */
550 path = gtk_tree_path_new_from_string(iwishihadgtk2_2); 554 if (theme == current_smiley_theme) {
551 g_free(iwishihadgtk2_2); 555 GtkTreePath *path = gtk_tree_model_get_path(
556 GTK_TREE_MODEL(smiley_theme_store), &iter);
557 row_ref = gtk_tree_row_reference_new(
558 GTK_TREE_MODEL(smiley_theme_store), path);
559 gtk_tree_path_free(path);
552 } 560 }
553 ind++; 561 }
554 } 562
555 563 return row_ref;
556 return path;
557 } 564 }
558 565
559 static void theme_install_theme(char *path, char *extn) { 566 static void theme_install_theme(char *path, char *extn) {
560 #ifndef _WIN32 567 #ifndef _WIN32
561 gchar *command, *escaped; 568 gchar *command, *escaped;
562 #endif 569 #endif
563 gchar *destdir; 570 gchar *destdir;
564 gchar *tail; 571 gchar *tail;
565 GtkTreePath *themepath = NULL; 572 GtkTreeRowReference *theme_rowref;
566 573
567 /* Just to be safe */ 574 /* Just to be safe */
568 g_strchomp(path); 575 g_strchomp(path);
569 576
570 /* I dont know what you are, get out of here */ 577 /* I dont know what you are, get out of here */
600 607
601 g_free(command); 608 g_free(command);
602 #endif 609 #endif
603 g_free(destdir); 610 g_free(destdir);
604 611
605 themepath = theme_refresh_theme_list(); 612 theme_rowref = theme_refresh_theme_list();
606 if (themepath != NULL) 613 if (theme_rowref != NULL)
607 gtk_tree_path_free(themepath); 614 gtk_tree_row_reference_free(theme_rowref);
608 } 615 }
609 616
610 static void 617 static void
611 theme_got_url(void *data, const char *themedata, size_t len) 618 theme_got_url(void *data, const char *themedata, size_t len)
612 { 619 {
705 GtkWidget *sw; 712 GtkWidget *sw;
706 GtkWidget *view; 713 GtkWidget *view;
707 GtkCellRenderer *rend; 714 GtkCellRenderer *rend;
708 GtkTreeViewColumn *col; 715 GtkTreeViewColumn *col;
709 GtkTreeSelection *sel; 716 GtkTreeSelection *sel;
710 GtkTreePath *path = NULL; 717 GtkTreeRowReference *rowref;
711 GtkWidget *label; 718 GtkWidget *label;
712 GtkTargetEntry te[3] = {{"text/plain", 0, 0},{"text/uri-list", 0, 1},{"STRING", 0, 2}}; 719 GtkTargetEntry te[3] = {{"text/plain", 0, 0},{"text/uri-list", 0, 1},{"STRING", 0, 2}};
713 720
714 ret = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); 721 ret = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE);
715 gtk_container_set_border_width (GTK_CONTAINER (ret), GAIM_HIG_BORDER); 722 gtk_container_set_border_width (GTK_CONTAINER (ret), GAIM_HIG_BORDER);
728 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); 735 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
729 736
730 gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0); 737 gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0);
731 smiley_theme_store = gtk_list_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); 738 smiley_theme_store = gtk_list_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
732 739
733 path = theme_refresh_theme_list(); 740 rowref = theme_refresh_theme_list();
734 741
735 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(smiley_theme_store)); 742 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(smiley_theme_store));
736 743
737 gtk_drag_dest_set(view, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, te, 744 gtk_drag_dest_set(view, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, te,
738 sizeof(te) / sizeof(GtkTargetEntry) , GDK_ACTION_COPY | GDK_ACTION_MOVE); 745 sizeof(te) / sizeof(GtkTargetEntry) , GDK_ACTION_COPY | GDK_ACTION_MOVE);
739 746
740 g_signal_connect(G_OBJECT(view), "drag_data_received", G_CALLBACK(theme_dnd_recv), smiley_theme_store); 747 g_signal_connect(G_OBJECT(view), "drag_data_received", G_CALLBACK(theme_dnd_recv), smiley_theme_store);
741 748
742 rend = gtk_cell_renderer_pixbuf_new(); 749 rend = gtk_cell_renderer_pixbuf_new();
743 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); 750 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
744
745 if(path) {
746 gtk_tree_selection_select_path(sel, path);
747 gtk_tree_path_free(path);
748 }
749 751
750 /* Custom sort so "none" theme is at top of list */ 752 /* Custom sort so "none" theme is at top of list */
751 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(smiley_theme_store), 753 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(smiley_theme_store),
752 3, gaim_sort_smileys, NULL, NULL); 754 3, gaim_sort_smileys, NULL, NULL);
753 755
768 gtk_tree_view_append_column (GTK_TREE_VIEW(view), col); 770 gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
769 g_object_unref(G_OBJECT(smiley_theme_store)); 771 g_object_unref(G_OBJECT(smiley_theme_store));
770 gtk_container_add(GTK_CONTAINER(sw), view); 772 gtk_container_add(GTK_CONTAINER(sw), view);
771 773
772 g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(smiley_sel), NULL); 774 g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(smiley_sel), NULL);
775
776 if (rowref) {
777 GtkTreePath *path = gtk_tree_row_reference_get_path(rowref);
778 gtk_tree_row_reference_free(rowref);
779 gtk_tree_selection_select_path(sel, path);
780 gtk_tree_path_free(path);
781 }
773 782
774 gtk_widget_show_all(ret); 783 gtk_widget_show_all(ret);
775 784
776 gaim_set_accessible_label (view, label); 785 gaim_set_accessible_label (view, label);
777 786
2258 2267
2259 static void 2268 static void
2260 smiley_theme_pref_cb(const char *name, GaimPrefType type, gpointer value, 2269 smiley_theme_pref_cb(const char *name, GaimPrefType type, gpointer value,
2261 gpointer data) 2270 gpointer data)
2262 { 2271 {
2263 if (!strcmp(name, "/gaim/gtk/smileys/theme")) 2272 const char *themename = value;
2264 gaim_gtkthemes_load_smiley_theme((const char *)value, TRUE); 2273 GSList *themes;
2274
2275 for (themes = smiley_themes; themes; themes = themes->next) {
2276 struct smiley_theme *smile = themes->data;
2277 if (smile->name && strcmp(themename, smile->name) == 0) {
2278 gaim_gtkthemes_load_smiley_theme(smile->path, TRUE);
2279 break;
2280 }
2281 }
2265 } 2282 }
2266 2283
2267 void 2284 void
2268 gaim_gtk_prefs_init(void) 2285 gaim_gtk_prefs_init(void)
2269 { 2286 {
2308 gaim_prefs_add_string("/gaim/gtk/filelocations/last_open_folder", ""); 2325 gaim_prefs_add_string("/gaim/gtk/filelocations/last_open_folder", "");
2309 gaim_prefs_add_string("/gaim/gtk/filelocations/last_icon_folder", ""); 2326 gaim_prefs_add_string("/gaim/gtk/filelocations/last_icon_folder", "");
2310 2327
2311 /* Smiley Themes */ 2328 /* Smiley Themes */
2312 gaim_prefs_add_none("/gaim/gtk/smileys"); 2329 gaim_prefs_add_none("/gaim/gtk/smileys");
2313 gaim_prefs_add_string("/gaim/gtk/smileys/theme", "default"); 2330 gaim_prefs_add_string("/gaim/gtk/smileys/theme", "Default");
2314 2331
2315 /* Smiley Callbacks */ 2332 /* Smiley Callbacks */
2316 gaim_prefs_connect_callback(prefs, "/gaim/gtk/smileys/theme", 2333 gaim_prefs_connect_callback(prefs, "/gaim/gtk/smileys/theme",
2317 smiley_theme_pref_cb, NULL); 2334 smiley_theme_pref_cb, NULL);
2318 } 2335 }