comparison pidgin/gtkprefs.c @ 17434:51f19b846fc9

Buttons to add and remove smiley themes.
author Gabriel Schulhof <nix@go-nix.ca>
date Mon, 28 May 2007 23:33:30 +0000
parents f7f4d11d4826
children 3223413a9c80
comparison
equal deleted inserted replaced
17429:043a1139d4e5 17434:51f19b846fc9
617 g_free(name2); 617 g_free(name2);
618 618
619 return ret; 619 return ret;
620 } 620 }
621 621
622 static void request_theme_file_name_cb (gpointer data, char *theme_file_name)
623 {
624 theme_install_theme (theme_file_name, NULL) ;
625 }
626
627 static void
628 add_theme_button_clicked_cb(GtkWidget *button, gpointer null)
629 {
630 purple_request_file (NULL, _("Install Theme"), NULL, FALSE, (GCallback)request_theme_file_name_cb, NULL, NULL, NULL, NULL, NULL) ;
631 }
632
633 static void
634 remove_theme_button_clicked_cb(GtkWidget *button, GtkTreeView *tree_view)
635 {
636 static GtkTreeModel *tm = NULL;
637 static GtkTreeSelection *sel = NULL;
638 static GtkTreeIter itr;
639 static char *theme_path = NULL, *theme_name = NULL, *slash_before_filename = NULL;
640
641 if ((tm = gtk_tree_view_get_model(tree_view)) == NULL) return;
642 if ((sel = gtk_tree_view_get_selection(tree_view)) == NULL) return;
643 if (!gtk_tree_selection_get_selected(sel, NULL, &itr)) return;
644
645 gtk_tree_model_get(tm, &itr, 2, &theme_path, 3, &theme_name, -1);
646
647 if (theme_name) {
648 if (strcmp(theme_name, "none")) {
649 if(theme_path) {
650 g_print ("g_strrstr(\"%s\", \"%s\")\n", theme_path, G_DIR_SEPARATOR_S);
651 if ((slash_before_filename = g_strrstr(theme_path, G_DIR_SEPARATOR_S)) != NULL) {
652 GtkTreeRowReference *theme_rowref;
653 char *dir_file = NULL;
654 GDir *theme_dir = NULL;
655
656 *slash_before_filename = 0;
657 if ((theme_dir = g_dir_open(theme_path, 0, NULL)) != NULL) {
658 while((dir_file = (char *)g_dir_read_name(theme_dir)) != NULL) {
659 if ((dir_file = g_strdup_printf ("%s%s%s", theme_path, G_DIR_SEPARATOR_S, dir_file)) != NULL) {
660 g_print("Deleting file \"%s\"\n", dir_file);
661 #ifdef _WIN32
662 /* UNTESTED ! */
663 DeleteFile(dir_file);
664 #else /* !_WIN32 */
665 unlink(dir_file);
666 #endif /* _WIN32 */
667 g_free(dir_file);
668 }
669 }
670
671 g_dir_close(theme_dir);
672
673 #ifdef _WIN32
674 /* UNTESTED ! */
675 RemoveDirectory(theme_path);
676 #else /* !_WIN32 */
677 rmdir(theme_path);
678 #endif /* _WIN32 */
679
680 /*
681 * Currently theme_refresh_theme_list() is rigged to remove all smiley themes and re-probe them. This is fine,
682 * but for the next minor version we should add a pidgin_themes_remove_smiley_theme(struct smiley_theme *theme)
683 * to gtkthemes.[ch] which will remove an individual theme (IOW the core of the loop in
684 * gtkthemes.c:pidgin_smiley_themes_destroy_all()).
685 */
686 if (previous_smiley_row)
687 gtk_tree_row_reference_free(previous_smiley_row);
688 previous_smiley_row = NULL;
689 if ((theme_rowref = theme_refresh_theme_list()) != NULL)
690 gtk_tree_row_reference_free(theme_rowref);
691
692 } else g_print("Failed to open theme directory\n");
693 } else g_print("Couldn't chop theme file name from path\n");
694 } else g_print("Theme path is NULL\n");
695 } else g_print("Theme name is \"none\"\n");
696 } else g_print("Theme name is NULL!\n");
697
698 g_free(theme_name);
699 g_free(theme_path);
700 }
701
622 static GtkWidget * 702 static GtkWidget *
623 theme_page() 703 theme_page()
624 { 704 {
705 GtkWidget *hbox_buttons;
706 GtkWidget *alignment;
625 GtkWidget *ret; 707 GtkWidget *ret;
626 GtkWidget *sw; 708 GtkWidget *sw;
627 GtkWidget *view; 709 GtkWidget *view;
710 GtkWidget *add_button, *remove_button;
628 GtkCellRenderer *rend; 711 GtkCellRenderer *rend;
629 GtkTreeViewColumn *col; 712 GtkTreeViewColumn *col;
630 GtkTreeSelection *sel; 713 GtkTreeSelection *sel;
631 GtkTreeRowReference *rowref; 714 GtkTreeRowReference *rowref;
632 GtkWidget *label; 715 GtkWidget *label;
691 GtkTreePath *path = gtk_tree_row_reference_get_path(rowref); 774 GtkTreePath *path = gtk_tree_row_reference_get_path(rowref);
692 gtk_tree_row_reference_free(rowref); 775 gtk_tree_row_reference_free(rowref);
693 gtk_tree_selection_select_path(sel, path); 776 gtk_tree_selection_select_path(sel, path);
694 gtk_tree_path_free(path); 777 gtk_tree_path_free(path);
695 } 778 }
779
780 alignment = gtk_alignment_new(1.0, 0.5, 0.0, 1.0);
781 gtk_widget_show(alignment);
782 gtk_box_pack_start(GTK_BOX(ret), alignment, FALSE, TRUE, 0);
783
784 hbox_buttons = gtk_hbox_new(TRUE, PIDGIN_HIG_CAT_SPACE);
785 gtk_widget_show(hbox_buttons);
786 gtk_container_add(GTK_CONTAINER(alignment), hbox_buttons);
787
788 add_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
789 gtk_widget_show(add_button);
790 gtk_box_pack_start(GTK_BOX(hbox_buttons), add_button, FALSE, TRUE, 0);
791 g_signal_connect(G_OBJECT(add_button), "clicked", (GCallback)add_theme_button_clicked_cb, NULL);
792
793 remove_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
794 gtk_widget_show(remove_button);
795 gtk_box_pack_start(GTK_BOX(hbox_buttons), remove_button, FALSE, TRUE, 0);
796 g_signal_connect(G_OBJECT(remove_button), "clicked", (GCallback)remove_theme_button_clicked_cb, view);
696 797
697 gtk_widget_show_all(ret); 798 gtk_widget_show_all(ret);
698 799
699 pidgin_set_accessible_label (view, label); 800 pidgin_set_accessible_label (view, label);
700 801