| 741 if (cb != NULL) |
741 if (cb != NULL) |
| 742 ((void (*)(GtkWidget *, GaimAccount *, gpointer))cb)(item, account, |
742 ((void (*)(GtkWidget *, GaimAccount *, gpointer))cb)(item, account, |
| 743 user_data); |
743 user_data); |
| 744 } |
744 } |
| 745 |
745 |
| 746 GtkWidget * |
746 static void |
| 747 gaim_gtk_account_option_menu_new(GaimAccount *default_account, |
747 create_account_menu(GtkWidget *optmenu, GaimAccount *default_account, |
| 748 gboolean show_all, GCallback cb, |
748 gboolean show_all) |
| 749 gpointer user_data) |
|
| 750 { |
749 { |
| 751 GaimAccount *account; |
750 GaimAccount *account; |
| 752 GList *list; |
|
| 753 GtkWidget *hbox; |
|
| 754 GtkWidget *label; |
|
| 755 GtkWidget *optmenu; |
|
| 756 GtkWidget *menu; |
751 GtkWidget *menu; |
| 757 GtkWidget *item; |
752 GtkWidget *item; |
| 758 GtkWidget *image; |
753 GtkWidget *image; |
| |
754 GtkWidget *hbox; |
| |
755 GtkWidget *label; |
| 759 GdkPixbuf *pixbuf; |
756 GdkPixbuf *pixbuf; |
| 760 GdkPixbuf *scale; |
757 GdkPixbuf *scale; |
| |
758 GList *list; |
| 761 GList *p; |
759 GList *p; |
| 762 GtkSizeGroup *sg; |
760 GtkSizeGroup *sg; |
| 763 char *filename; |
761 char *filename; |
| 764 const char *proto_name; |
762 const char *proto_name; |
| 765 char buf[256]; |
763 char buf[256]; |
| 766 int i, selected_index = -1; |
764 int i, selected_index = -1; |
| 767 |
765 |
| 768 optmenu = gtk_option_menu_new(); |
|
| 769 gtk_widget_show(optmenu); |
|
| 770 |
|
| 771 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); |
|
| 772 |
|
| 773 menu = gtk_menu_new(); |
|
| 774 gtk_widget_show(menu); |
|
| 775 |
|
| 776 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
|
| 777 |
|
| 778 if (show_all) |
766 if (show_all) |
| 779 list = gaim_accounts_get_all(); |
767 list = gaim_accounts_get_all(); |
| 780 else |
768 else |
| 781 list = gaim_connections_get_all(); |
769 list = gaim_connections_get_all(); |
| 782 |
770 |
| 783 gaim_debug(GAIM_DEBUG_INFO, "gtkutils", "Populating menu\n"); |
771 menu = gtk_menu_new(); |
| |
772 gtk_widget_show(menu); |
| |
773 |
| |
774 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
| 784 |
775 |
| 785 for (p = list, i = 0; p != NULL; p = p->next, i++) { |
776 for (p = list, i = 0; p != NULL; p = p->next, i++) { |
| 786 GaimPluginProtocolInfo *prpl_info = NULL; |
777 GaimPluginProtocolInfo *prpl_info = NULL; |
| 787 GaimPlugin *plugin; |
778 GaimPlugin *plugin; |
| 788 |
779 |
| 857 |
846 |
| 858 if (default_account != NULL && account == default_account) |
847 if (default_account != NULL && account == default_account) |
| 859 selected_index = i; |
848 selected_index = i; |
| 860 } |
849 } |
| 861 |
850 |
| 862 gaim_debug(GAIM_DEBUG_INFO, "gtkutils", "Done populating menu\n"); |
851 g_object_unref(sg); |
| 863 |
852 |
| 864 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); |
853 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); |
| 865 |
854 |
| |
855 /* Set the place we should be at. */ |
| 866 if (selected_index != -1) |
856 if (selected_index != -1) |
| 867 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); |
857 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); |
| 868 |
858 } |
| |
859 |
| |
860 static void |
| |
861 account_menu_sign_on_off_cb(GaimConnection *gc, GtkWidget *optmenu) |
| |
862 { |
| |
863 GtkWidget *menu; |
| |
864 GtkWidget *item; |
| |
865 gboolean show_all; |
| |
866 GaimAccount *account; |
| |
867 |
| |
868 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); |
| |
869 item = gtk_menu_get_active(GTK_MENU(menu)); |
| |
870 account = g_object_get_data(G_OBJECT(item), "account"); |
| |
871 |
| |
872 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), |
| |
873 "show_all")); |
| |
874 |
| |
875 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); |
| |
876 |
| |
877 create_account_menu(optmenu, account, show_all); |
| |
878 } |
| |
879 |
| |
880 static gboolean |
| |
881 account_menu_destroyed_cb(GtkWidget *optmenu, GdkEvent *event, |
| |
882 void *user_data) |
| |
883 { |
| |
884 gaim_signal_disconnect(optmenu, event_signon, account_menu_sign_on_off_cb); |
| |
885 gaim_signal_disconnect(optmenu, event_signoff, account_menu_sign_on_off_cb); |
| |
886 |
| |
887 return FALSE; |
| |
888 } |
| |
889 |
| |
890 GtkWidget * |
| |
891 gaim_gtk_account_option_menu_new(GaimAccount *default_account, |
| |
892 gboolean show_all, GCallback cb, |
| |
893 gpointer user_data) |
| |
894 { |
| |
895 GtkWidget *optmenu; |
| |
896 |
| |
897 /* Create the option menu */ |
| |
898 optmenu = gtk_option_menu_new(); |
| |
899 gtk_widget_show(optmenu); |
| |
900 |
| |
901 g_signal_connect(G_OBJECT(optmenu), "destroy", |
| |
902 G_CALLBACK(account_menu_destroyed_cb), NULL); |
| |
903 |
| |
904 /* Register the gaim sign on/off event callbacks. */ |
| |
905 gaim_signal_connect(optmenu, event_signon, |
| |
906 account_menu_sign_on_off_cb, optmenu); |
| |
907 gaim_signal_connect(optmenu, event_signoff, |
| |
908 account_menu_sign_on_off_cb, optmenu); |
| |
909 |
| |
910 /* Set some data. */ |
| |
911 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); |
| |
912 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all)); |
| |
913 |
| |
914 /* Create and set the actual menu. */ |
| |
915 create_account_menu(optmenu, default_account, show_all); |
| |
916 |
| |
917 /* And now the last callback. */ |
| 869 g_signal_connect(G_OBJECT(optmenu), "changed", |
918 g_signal_connect(G_OBJECT(optmenu), "changed", |
| 870 G_CALLBACK(account_menu_cb), cb); |
919 G_CALLBACK(account_menu_cb), cb); |
| 871 |
920 |
| 872 g_object_unref(sg); |
|
| 873 |
|
| 874 return optmenu; |
921 return optmenu; |
| 875 } |
922 } |
| 876 |
923 |
| 877 gboolean gaim_gtk_check_if_dir(const char *path, GtkFileSelection *filesel) |
924 gboolean |
| |
925 gaim_gtk_check_if_dir(const char *path, GtkFileSelection *filesel) |
| 878 { |
926 { |
| 879 char *dirname; |
927 char *dirname; |
| 880 |
928 |
| 881 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { |
929 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { |
| 882 /* append a / if needed */ |
930 /* append a / if needed */ |