Mercurial > pidgin
comparison src/gtkutils.c @ 5877:f336fc0a7b8b
[gaim-migrate @ 6309]
Added this cool little account drop-down widget, which is only used in
pounces right now.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 15 Jun 2003 03:17:41 +0000 |
parents | 059d95c67cda |
children | d58406d31a1a |
comparison
equal
deleted
inserted
replaced
5876:8d6e5f804325 | 5877:f336fc0a7b8b |
---|---|
639 | 639 |
640 g_object_unref(sg); | 640 g_object_unref(sg); |
641 | 641 |
642 return optmenu; | 642 return optmenu; |
643 } | 643 } |
644 | |
645 static void | |
646 account_menu_cb(GtkWidget *optmenu, GCallback cb) | |
647 { | |
648 GtkWidget *menu; | |
649 GtkWidget *item; | |
650 GaimAccount *account; | |
651 gpointer user_data; | |
652 | |
653 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
654 item = gtk_menu_get_active(GTK_MENU(menu)); | |
655 | |
656 account = g_object_get_data(G_OBJECT(item), "account"); | |
657 user_data = g_object_get_data(G_OBJECT(optmenu), "user_data"); | |
658 | |
659 if (cb != NULL) | |
660 ((void (*)(GtkWidget *, GaimAccount *, gpointer))cb)(item, account, | |
661 user_data); | |
662 } | |
663 | |
664 GtkWidget * | |
665 gaim_gtk_account_option_menu_new(GaimAccount *default_account, | |
666 gboolean show_all, GCallback cb, | |
667 gpointer user_data) | |
668 { | |
669 GaimAccount *account; | |
670 GList *list; | |
671 GtkWidget *hbox; | |
672 GtkWidget *label; | |
673 GtkWidget *optmenu; | |
674 GtkWidget *menu; | |
675 GtkWidget *item; | |
676 GtkWidget *image; | |
677 GdkPixbuf *pixbuf; | |
678 GdkPixbuf *scale; | |
679 GList *p; | |
680 GtkSizeGroup *sg; | |
681 char *filename; | |
682 const char *proto_name; | |
683 char buf[256]; | |
684 int i, selected_index = -1; | |
685 | |
686 optmenu = gtk_option_menu_new(); | |
687 gtk_widget_show(optmenu); | |
688 | |
689 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | |
690 | |
691 menu = gtk_menu_new(); | |
692 gtk_widget_show(menu); | |
693 | |
694 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
695 | |
696 if (show_all) | |
697 list = gaim_accounts_get_all(); | |
698 else | |
699 list = gaim_accounts_get_active(); | |
700 | |
701 for (p = list, i = 0; p != NULL; p = p->next, i++) { | |
702 GaimPluginProtocolInfo *prpl_info = NULL; | |
703 GaimPlugin *plugin; | |
704 | |
705 account = (GaimAccount *)p->data; | |
706 | |
707 plugin = gaim_find_prpl(gaim_account_get_protocol(account)); | |
708 | |
709 if (plugin != NULL) | |
710 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
711 | |
712 /* Create the item. */ | |
713 item = gtk_menu_item_new(); | |
714 | |
715 /* Create the hbox. */ | |
716 hbox = gtk_hbox_new(FALSE, 4); | |
717 gtk_container_add(GTK_CONTAINER(item), hbox); | |
718 gtk_widget_show(hbox); | |
719 | |
720 /* Load the image. */ | |
721 if (prpl_info != NULL) { | |
722 proto_name = prpl_info->list_icon(NULL, NULL); | |
723 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
724 | |
725 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
726 "default", buf, NULL); | |
727 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
728 g_free(filename); | |
729 | |
730 if (pixbuf != NULL) { | |
731 /* Scale and insert the image */ | |
732 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
733 GDK_INTERP_BILINEAR); | |
734 image = gtk_image_new_from_pixbuf(scale); | |
735 | |
736 g_object_unref(G_OBJECT(pixbuf)); | |
737 g_object_unref(G_OBJECT(scale)); | |
738 } | |
739 else | |
740 image = gtk_image_new(); | |
741 } | |
742 else | |
743 image = gtk_image_new(); | |
744 | |
745 gtk_size_group_add_widget(sg, image); | |
746 | |
747 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
748 gtk_widget_show(image); | |
749 | |
750 g_snprintf(buf, sizeof(buf), "%s (%s)", | |
751 gaim_account_get_username(account), plugin->info->name); | |
752 | |
753 /* Create the label. */ | |
754 label = gtk_label_new(buf); | |
755 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
756 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
757 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
758 gtk_widget_show(label); | |
759 | |
760 g_object_set_data(G_OBJECT(item), "account", account); | |
761 | |
762 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
763 gtk_widget_show(item); | |
764 | |
765 if (account == default_account) | |
766 selected_index = i; | |
767 } | |
768 | |
769 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
770 | |
771 if (selected_index != -1) | |
772 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); | |
773 | |
774 g_signal_connect(G_OBJECT(optmenu), "changed", | |
775 G_CALLBACK(account_menu_cb), cb); | |
776 | |
777 g_object_unref(sg); | |
778 | |
779 return optmenu; | |
780 } |