Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 18020:3c4811489e30
propagate from branch 'im.pidgin.rlaager.merging.for_2_1_0' (head 24ee3feb7b0e68036eebb50b90278e581fea942a)
to branch 'im.pidgin.pidgin.2.1.0' (head 996b7212bd0ff741b6d317a46490f9e903bd624d)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 28 May 2007 08:06:28 +0000 |
parents | c02305ee715a fe8a1051aa0a |
children | fbebe15c91a7 |
comparison
equal
deleted
inserted
replaced
18019:1e674c0886b1 | 18020:3c4811489e30 |
---|---|
59 #include "gtkimhtmltoolbar.h" | 59 #include "gtkimhtmltoolbar.h" |
60 #include "pidginstock.h" | 60 #include "pidginstock.h" |
61 #include "gtkthemes.h" | 61 #include "gtkthemes.h" |
62 #include "gtkutils.h" | 62 #include "gtkutils.h" |
63 | 63 |
64 typedef struct { | |
65 GtkWidget *menu; | |
66 gint default_item; | |
67 } AopMenu; | |
68 | |
64 static guint accels_save_timer = 0; | 69 static guint accels_save_timer = 0; |
65 | 70 |
66 static gboolean | 71 static gboolean |
67 url_clicked_idle_cb(gpointer data) | 72 url_clicked_idle_cb(gpointer data) |
68 { | 73 { |
444 gtk_widget_show(vbox); | 449 gtk_widget_show(vbox); |
445 | 450 |
446 return vbox; | 451 return vbox; |
447 } | 452 } |
448 | 453 |
454 static gpointer | |
455 aop_option_menu_get_selected(GtkWidget *optmenu, GtkWidget **p_item) | |
456 { | |
457 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
458 GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu)); | |
459 if (p_item) | |
460 (*p_item) = item; | |
461 return g_object_get_data(G_OBJECT(item), "aop_per_item_data"); | |
462 } | |
463 | |
449 static void | 464 static void |
450 protocol_menu_cb(GtkWidget *optmenu, GCallback cb) | 465 aop_menu_cb(GtkWidget *optmenu, GCallback cb) |
451 { | 466 { |
452 GtkWidget *menu; | |
453 GtkWidget *item; | 467 GtkWidget *item; |
454 const char *protocol; | 468 gpointer per_item_data; |
455 gpointer user_data; | 469 |
456 | 470 per_item_data = aop_option_menu_get_selected(optmenu, &item); |
457 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 471 |
458 item = gtk_menu_get_active(GTK_MENU(menu)); | 472 if (cb != NULL) { |
459 | 473 ((void (*)(GtkWidget *, gpointer, gpointer))cb)(item, per_item_data, g_object_get_data(G_OBJECT(optmenu), "user_data")); |
460 protocol = g_object_get_data(G_OBJECT(item), "protocol"); | 474 } |
461 | |
462 if (!strcmp(protocol, "prpl-fake")) | |
463 protocol = g_object_get_data(G_OBJECT(item), "real_protocol"); | |
464 | |
465 if (!strcmp(protocol, g_object_get_data(G_OBJECT(optmenu), "last_protocol"))) | |
466 return; | |
467 | |
468 user_data = (g_object_get_data(G_OBJECT(optmenu), "user_data")); | |
469 g_object_set_data(G_OBJECT(optmenu), "last_protocol", (gpointer)protocol); | |
470 | |
471 if (cb != NULL) | |
472 ((void (*)(GtkWidget *, const char *, gpointer))cb)(item, protocol, | |
473 user_data); | |
474 } | 475 } |
475 | 476 |
476 static GtkWidget * | 477 static GtkWidget * |
477 pidgin_protocol_option_menu_item(GtkWidget *menu, GtkSizeGroup *sg, GtkWidget *image, | 478 aop_menu_item_new(GtkSizeGroup *sg, GdkPixbuf *pixbuf, const char *lbl, gpointer per_item_data) |
478 const char *name, const char *id) | |
479 { | 479 { |
480 GtkWidget *item; | 480 GtkWidget *item; |
481 GtkWidget *hbox; | 481 GtkWidget *hbox; |
482 GtkWidget *image; | |
482 GtkWidget *label; | 483 GtkWidget *label; |
483 | 484 |
484 /* Create the item. */ | |
485 item = gtk_menu_item_new(); | 485 item = gtk_menu_item_new(); |
486 | 486 gtk_widget_show(item); |
487 /* Create the hbox. */ | 487 |
488 hbox = gtk_hbox_new(FALSE, 4); | 488 hbox = gtk_hbox_new(FALSE, 4); |
489 gtk_widget_show(hbox); | |
490 | |
491 /* Create the image */ | |
492 if (pixbuf == NULL) | |
493 image = gtk_image_new(); | |
494 else | |
495 image = gtk_image_new_from_pixbuf(pixbuf); | |
496 gtk_widget_show(image); | |
497 | |
498 if (sg) | |
499 gtk_size_group_add_widget(sg, image); | |
500 | |
501 /* Create the label */ | |
502 label = gtk_label_new (lbl); | |
503 gtk_widget_show (label); | |
504 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
505 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
506 | |
489 gtk_container_add(GTK_CONTAINER(item), hbox); | 507 gtk_container_add(GTK_CONTAINER(item), hbox); |
490 gtk_widget_show(hbox); | |
491 | |
492 gtk_size_group_add_widget(sg, image); | |
493 | |
494 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | 508 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); |
495 gtk_widget_show(image); | |
496 | |
497 /* Create the label. */ | |
498 label = gtk_label_new(name); | |
499 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
500 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
501 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 509 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); |
502 gtk_widget_show(label); | 510 |
503 | 511 g_object_set_data(G_OBJECT (item), "aop_per_item_data", per_item_data); |
504 g_object_set_data(G_OBJECT(item), "protocol", (gpointer)id); | 512 |
505 | 513 pidgin_set_accessible_label(item, label); |
506 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
507 gtk_widget_show(item); | |
508 pidgin_set_accessible_label (item, label); | |
509 | 514 |
510 return item; | 515 return item; |
516 } | |
517 | |
518 static GtkWidget * | |
519 aop_option_menu_new(AopMenu *aop_menu, GCallback cb, gpointer user_data) | |
520 { | |
521 GtkWidget *optmenu; | |
522 | |
523 optmenu = gtk_option_menu_new(); | |
524 gtk_widget_show(optmenu); | |
525 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), aop_menu->menu); | |
526 | |
527 if (aop_menu->default_item != -1) | |
528 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), aop_menu->default_item); | |
529 | |
530 g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", aop_menu, (GDestroyNotify)g_free); | |
531 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | |
532 | |
533 g_signal_connect(G_OBJECT(optmenu), "changed", G_CALLBACK(aop_menu_cb), cb); | |
534 | |
535 return optmenu; | |
536 } | |
537 | |
538 static void | |
539 aop_option_menu_replace_menu(GtkWidget *optmenu, AopMenu *new_aop_menu) | |
540 { | |
541 if (gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))) | |
542 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
543 | |
544 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), new_aop_menu->menu); | |
545 | |
546 if (new_aop_menu->default_item != -1) | |
547 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), new_aop_menu->default_item); | |
548 | |
549 g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", new_aop_menu, (GDestroyNotify)g_free); | |
550 } | |
551 | |
552 static void | |
553 aop_option_menu_select_by_data(GtkWidget *optmenu, gpointer data) | |
554 { | |
555 guint idx; | |
556 GList *llItr = NULL; | |
557 | |
558 for (idx = 0, llItr = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children; | |
559 llItr != NULL; | |
560 llItr = llItr->next, idx++) { | |
561 if (data == g_object_get_data(G_OBJECT(llItr->data), "aop_per_item_data")) { | |
562 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), idx); | |
563 break; | |
564 } | |
565 } | |
566 } | |
567 | |
568 static GdkPixbuf * | |
569 get_prpl_pixbuf(PurplePluginProtocolInfo *prpl_info) | |
570 { | |
571 const char *proto_name; | |
572 GdkPixbuf *pixbuf = NULL; | |
573 char *filename; | |
574 char buf[256]; | |
575 | |
576 proto_name = prpl_info->list_icon(NULL, NULL); | |
577 g_return_val_if_fail(proto_name != NULL, NULL); | |
578 | |
579 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
580 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "16", buf, NULL); | |
581 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
582 g_free(filename); | |
583 | |
584 return pixbuf; | |
585 } | |
586 | |
587 static AopMenu * | |
588 create_protocols_menu(const char *default_proto_id) | |
589 { | |
590 AopMenu *aop_menu = NULL; | |
591 PurplePluginProtocolInfo *prpl_info; | |
592 PurplePlugin *plugin; | |
593 GdkPixbuf *pixbuf = NULL; | |
594 GtkSizeGroup *sg; | |
595 GList *p; | |
596 const char *gtalk_name = NULL; | |
597 int i; | |
598 | |
599 aop_menu = g_malloc0(sizeof(AopMenu)); | |
600 aop_menu->default_item = -1; | |
601 aop_menu->menu = gtk_menu_new(); | |
602 gtk_widget_show(aop_menu->menu); | |
603 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
604 | |
605 if (purple_find_prpl("prpl-jabber")) | |
606 gtalk_name = _("Google Talk"); | |
607 | |
608 for (p = purple_plugins_get_protocols(), i = 0; | |
609 p != NULL; | |
610 p = p->next, i++) { | |
611 | |
612 plugin = (PurplePlugin *)p->data; | |
613 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
614 | |
615 if (gtalk_name && strcmp(gtalk_name, plugin->info->name) < 0) { | |
616 char *filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
617 "16", "google-talk.png", NULL); | |
618 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
619 g_free(filename); | |
620 | |
621 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), | |
622 aop_menu_item_new(sg, pixbuf, gtalk_name, "prpl-jabber")); | |
623 | |
624 if (pixbuf) | |
625 g_object_unref(pixbuf); | |
626 | |
627 gtalk_name = NULL; | |
628 } | |
629 | |
630 pixbuf = get_prpl_pixbuf(prpl_info); | |
631 | |
632 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), | |
633 aop_menu_item_new(sg, pixbuf, plugin->info->name, plugin->info->id)); | |
634 | |
635 if (pixbuf) | |
636 g_object_unref(pixbuf); | |
637 | |
638 if (default_proto_id != NULL && !strcmp(plugin->info->id, default_proto_id)) | |
639 aop_menu->default_item = i; | |
640 } | |
641 | |
642 g_object_unref(sg); | |
643 | |
644 return aop_menu; | |
511 } | 645 } |
512 | 646 |
513 GtkWidget * | 647 GtkWidget * |
514 pidgin_protocol_option_menu_new(const char *id, GCallback cb, | 648 pidgin_protocol_option_menu_new(const char *id, GCallback cb, |
515 gpointer user_data) | 649 gpointer user_data) |
516 { | 650 { |
517 PurplePluginProtocolInfo *prpl_info; | 651 return aop_option_menu_new(create_protocols_menu(id), cb, user_data); |
518 PurplePlugin *plugin; | |
519 GtkWidget *optmenu; | |
520 GtkWidget *menu; | |
521 GdkPixbuf *pixbuf; | |
522 GtkWidget *image; | |
523 GList *p; | |
524 GtkSizeGroup *sg; | |
525 char *filename; | |
526 const char *proto_name; | |
527 char buf[256]; | |
528 int i, selected_index = -1; | |
529 const char *gtalk_name = NULL; | |
530 | |
531 if (purple_find_prpl("prpl-jabber")) | |
532 gtalk_name = _("Google Talk"); | |
533 | |
534 optmenu = gtk_option_menu_new(); | |
535 gtk_widget_show(optmenu); | |
536 | |
537 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | |
538 | |
539 menu = gtk_menu_new(); | |
540 gtk_widget_show(menu); | |
541 | |
542 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
543 | |
544 for (p = purple_plugins_get_protocols(), i = 0; | |
545 p != NULL; | |
546 p = p->next, i++) { | |
547 | |
548 plugin = (PurplePlugin *)p->data; | |
549 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
550 | |
551 if (gtalk_name && strcmp(gtalk_name, plugin->info->name) < 0) | |
552 { | |
553 GtkWidget *gtalk_item; | |
554 | |
555 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
556 "16", "google-talk.png", NULL); | |
557 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
558 g_free(filename); | |
559 | |
560 | |
561 if (pixbuf) | |
562 image = gtk_image_new_from_pixbuf(pixbuf); | |
563 else | |
564 image = gtk_image_new(); | |
565 | |
566 gtalk_item = pidgin_protocol_option_menu_item(menu, sg, image, gtalk_name, "prpl-fake"); | |
567 g_object_set_data(G_OBJECT(gtalk_item), "real_protocol", "prpl-jabber"); | |
568 i++; | |
569 | |
570 gtalk_name = NULL; | |
571 } | |
572 | |
573 /* Load the image. */ | |
574 proto_name = prpl_info->list_icon(NULL, NULL); | |
575 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
576 | |
577 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
578 "16", buf, NULL); | |
579 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
580 g_free(filename); | |
581 | |
582 if (pixbuf) | |
583 image = gtk_image_new_from_pixbuf(pixbuf); | |
584 else | |
585 image = gtk_image_new(); | |
586 | |
587 pidgin_protocol_option_menu_item(menu, sg, image, plugin->info->name, plugin->info->id); | |
588 | |
589 if (id != NULL && !strcmp(plugin->info->id, id)) | |
590 { | |
591 g_object_set_data(G_OBJECT(optmenu), "last_protocol", plugin->info->id); | |
592 selected_index = i; | |
593 } | |
594 else if (i == 0) | |
595 { | |
596 /* Ensure we set the protocol even if id is NULL or can't be found. */ | |
597 g_object_set_data(G_OBJECT(optmenu), "last_protocol", plugin->info->id); | |
598 } | |
599 | |
600 if (pixbuf) | |
601 g_object_unref(G_OBJECT(pixbuf)); | |
602 } | |
603 | |
604 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
605 | |
606 if (selected_index != -1) | |
607 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); | |
608 | |
609 g_signal_connect(G_OBJECT(optmenu), "changed", | |
610 G_CALLBACK(protocol_menu_cb), cb); | |
611 | |
612 g_object_unref(sg); | |
613 | |
614 return optmenu; | |
615 } | 652 } |
616 | 653 |
617 PurpleAccount * | 654 PurpleAccount * |
618 pidgin_account_option_menu_get_selected(GtkWidget *optmenu) | 655 pidgin_account_option_menu_get_selected(GtkWidget *optmenu) |
619 { | 656 { |
620 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 657 return (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL); |
621 GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu)); | 658 } |
622 return g_object_get_data(G_OBJECT(item), "account"); | 659 |
623 } | 660 static AopMenu * |
624 | 661 create_account_menu(PurpleAccount *default_account, |
625 static void | 662 PurpleFilterAccountFunc filter_func, gboolean show_all) |
626 account_menu_cb(GtkWidget *optmenu, GCallback cb) | 663 { |
627 { | 664 AopMenu *aop_menu = NULL; |
628 GtkWidget *menu; | |
629 GtkWidget *item; | |
630 PurpleAccount *account; | 665 PurpleAccount *account; |
631 gpointer user_data; | 666 GdkPixbuf *pixbuf = NULL; |
632 | |
633 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
634 item = gtk_menu_get_active(GTK_MENU(menu)); | |
635 | |
636 account = g_object_get_data(G_OBJECT(item), "account"); | |
637 user_data = g_object_get_data(G_OBJECT(optmenu), "user_data"); | |
638 | |
639 if (cb != NULL) | |
640 ((void (*)(GtkWidget *, PurpleAccount *, gpointer))cb)(item, account, | |
641 user_data); | |
642 } | |
643 | |
644 static void | |
645 create_account_menu(GtkWidget *optmenu, PurpleAccount *default_account, | |
646 PurpleFilterAccountFunc filter_func, gboolean show_all) | |
647 { | |
648 PurpleAccount *account; | |
649 GtkWidget *menu; | |
650 GtkWidget *item; | |
651 GtkWidget *image; | |
652 GtkWidget *hbox; | |
653 GtkWidget *label; | |
654 GdkPixbuf *pixbuf; | |
655 GList *list; | 667 GList *list; |
656 GList *p; | 668 GList *p; |
657 GtkSizeGroup *sg; | 669 GtkSizeGroup *sg; |
658 char *filename; | 670 int i; |
659 const char *proto_name; | |
660 char buf[256]; | 671 char buf[256]; |
661 int i, selected_index = -1; | |
662 | 672 |
663 if (show_all) | 673 if (show_all) |
664 list = purple_accounts_get_all(); | 674 list = purple_accounts_get_all(); |
665 else | 675 else |
666 list = purple_connections_get_all(); | 676 list = purple_connections_get_all(); |
667 | 677 |
668 menu = gtk_menu_new(); | 678 aop_menu = g_malloc0(sizeof(AopMenu)); |
669 gtk_widget_show(menu); | 679 aop_menu->default_item = -1; |
670 | 680 aop_menu->menu = gtk_menu_new(); |
681 gtk_widget_show(aop_menu->menu); | |
671 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | 682 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
672 | 683 |
673 for (p = list, i = 0; p != NULL; p = p->next, i++) { | 684 for (p = list, i = 0; p != NULL; p = p->next, i++) { |
674 PurplePluginProtocolInfo *prpl_info = NULL; | 685 PurplePluginProtocolInfo *prpl_info = NULL; |
675 PurplePlugin *plugin; | 686 PurplePlugin *plugin; |
687 continue; | 698 continue; |
688 } | 699 } |
689 | 700 |
690 plugin = purple_find_prpl(purple_account_get_protocol_id(account)); | 701 plugin = purple_find_prpl(purple_account_get_protocol_id(account)); |
691 | 702 |
692 if (plugin != NULL) | 703 if (plugin) |
693 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | 704 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
694 | 705 |
695 /* Create the item. */ | |
696 item = gtk_menu_item_new(); | |
697 | |
698 /* Create the hbox. */ | |
699 hbox = gtk_hbox_new(FALSE, 4); | |
700 gtk_container_add(GTK_CONTAINER(item), hbox); | |
701 gtk_widget_show(hbox); | |
702 | |
703 /* Load the image. */ | 706 /* Load the image. */ |
704 if (prpl_info != NULL) { | 707 if (prpl_info) { |
705 proto_name = prpl_info->list_icon(account, NULL); | 708 pixbuf = get_prpl_pixbuf(prpl_info); |
706 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | 709 |
707 | 710 if (pixbuf) { |
708 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
709 "16", buf, NULL); | |
710 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
711 g_free(filename); | |
712 | |
713 if (pixbuf != NULL) { | |
714 if (purple_account_is_disconnected(account) && show_all && | 711 if (purple_account_is_disconnected(account) && show_all && |
715 purple_connections_get_all()) | 712 purple_connections_get_all()) |
716 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); | 713 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
717 | |
718 image = gtk_image_new_from_pixbuf(pixbuf); | |
719 | |
720 g_object_unref(G_OBJECT(pixbuf)); | |
721 } | 714 } |
722 else | 715 } |
723 image = gtk_image_new(); | |
724 } | |
725 else | |
726 image = gtk_image_new(); | |
727 | |
728 gtk_size_group_add_widget(sg, image); | |
729 | |
730 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
731 gtk_widget_show(image); | |
732 | 716 |
733 if (purple_account_get_alias(account)) { | 717 if (purple_account_get_alias(account)) { |
734 g_snprintf(buf, sizeof(buf), "%s (%s) (%s)", | 718 g_snprintf(buf, sizeof(buf), "%s (%s) (%s)", |
735 purple_account_get_username(account), | 719 purple_account_get_username(account), |
736 purple_account_get_alias(account), | 720 purple_account_get_alias(account), |
739 g_snprintf(buf, sizeof(buf), "%s (%s)", | 723 g_snprintf(buf, sizeof(buf), "%s (%s)", |
740 purple_account_get_username(account), | 724 purple_account_get_username(account), |
741 purple_account_get_protocol_name(account)); | 725 purple_account_get_protocol_name(account)); |
742 } | 726 } |
743 | 727 |
744 /* Create the label. */ | 728 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), |
745 label = gtk_label_new(buf); | 729 aop_menu_item_new(sg, pixbuf, buf, account)); |
746 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | 730 |
747 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 731 if (pixbuf) |
748 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 732 g_object_unref(pixbuf); |
749 gtk_widget_show(label); | 733 |
750 | 734 if (default_account && account == default_account) |
751 g_object_set_data(G_OBJECT(item), "account", account); | 735 aop_menu->default_item = i; |
752 | |
753 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
754 gtk_widget_show(item); | |
755 pidgin_set_accessible_label (item, label); | |
756 | |
757 if (default_account != NULL && account == default_account) | |
758 selected_index = i; | |
759 } | 736 } |
760 | 737 |
761 g_object_unref(sg); | 738 g_object_unref(sg); |
762 | 739 |
763 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | 740 return aop_menu; |
764 | |
765 /* Set the place we should be at. */ | |
766 if (selected_index != -1) | |
767 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); | |
768 } | 741 } |
769 | 742 |
770 static void | 743 static void |
771 regenerate_account_menu(GtkWidget *optmenu) | 744 regenerate_account_menu(GtkWidget *optmenu) |
772 { | 745 { |
773 GtkWidget *menu; | |
774 GtkWidget *item; | |
775 gboolean show_all; | 746 gboolean show_all; |
776 PurpleAccount *account; | 747 PurpleAccount *account; |
777 PurpleFilterAccountFunc filter_func; | 748 PurpleFilterAccountFunc filter_func; |
778 | 749 |
779 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 750 account = (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL); |
780 item = gtk_menu_get_active(GTK_MENU(menu)); | 751 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), "show_all")); |
781 account = g_object_get_data(G_OBJECT(item), "account"); | 752 filter_func = g_object_get_data(G_OBJECT(optmenu), "filter_func"); |
782 | 753 |
783 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), | 754 aop_option_menu_replace_menu(optmenu, create_account_menu(account, filter_func, show_all)); |
784 "show_all")); | |
785 | |
786 filter_func = g_object_get_data(G_OBJECT(optmenu), | |
787 "filter_func"); | |
788 | |
789 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
790 | |
791 create_account_menu(optmenu, account, filter_func, show_all); | |
792 } | 755 } |
793 | 756 |
794 static void | 757 static void |
795 account_menu_sign_on_off_cb(PurpleConnection *gc, GtkWidget *optmenu) | 758 account_menu_sign_on_off_cb(PurpleConnection *gc, GtkWidget *optmenu) |
796 { | 759 { |
813 } | 776 } |
814 | 777 |
815 void | 778 void |
816 pidgin_account_option_menu_set_selected(GtkWidget *optmenu, PurpleAccount *account) | 779 pidgin_account_option_menu_set_selected(GtkWidget *optmenu, PurpleAccount *account) |
817 { | 780 { |
818 GtkWidget *menu; | 781 aop_option_menu_select_by_data(optmenu, account); |
819 GtkWidget *item; | |
820 gboolean show_all; | |
821 PurpleAccount *curaccount; | |
822 PurpleFilterAccountFunc filter_func; | |
823 | |
824 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
825 item = gtk_menu_get_active(GTK_MENU(menu)); | |
826 curaccount = g_object_get_data(G_OBJECT(item), "account"); | |
827 | |
828 if (account == curaccount) | |
829 return; | |
830 | |
831 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), | |
832 "show_all")); | |
833 | |
834 filter_func = g_object_get_data(G_OBJECT(optmenu), | |
835 "filter_func"); | |
836 | |
837 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
838 | |
839 create_account_menu(optmenu, account, filter_func, show_all); | |
840 } | 782 } |
841 | 783 |
842 GtkWidget * | 784 GtkWidget * |
843 pidgin_account_option_menu_new(PurpleAccount *default_account, | 785 pidgin_account_option_menu_new(PurpleAccount *default_account, |
844 gboolean show_all, GCallback cb, | 786 gboolean show_all, GCallback cb, |
846 gpointer user_data) | 788 gpointer user_data) |
847 { | 789 { |
848 GtkWidget *optmenu; | 790 GtkWidget *optmenu; |
849 | 791 |
850 /* Create the option menu */ | 792 /* Create the option menu */ |
851 optmenu = gtk_option_menu_new(); | 793 optmenu = aop_option_menu_new(create_account_menu(default_account, filter_func, show_all), cb, user_data); |
852 gtk_widget_show(optmenu); | |
853 | 794 |
854 g_signal_connect(G_OBJECT(optmenu), "destroy", | 795 g_signal_connect(G_OBJECT(optmenu), "destroy", |
855 G_CALLBACK(account_menu_destroyed_cb), NULL); | 796 G_CALLBACK(account_menu_destroyed_cb), NULL); |
856 | 797 |
857 /* Register the purple sign on/off event callbacks. */ | 798 /* Register the purple sign on/off event callbacks. */ |
869 optmenu); | 810 optmenu); |
870 | 811 |
871 /* Set some data. */ | 812 /* Set some data. */ |
872 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | 813 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); |
873 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all)); | 814 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all)); |
874 g_object_set_data(G_OBJECT(optmenu), "filter_func", | 815 g_object_set_data(G_OBJECT(optmenu), "filter_func", filter_func); |
875 filter_func); | |
876 | |
877 /* Create and set the actual menu. */ | |
878 create_account_menu(optmenu, default_account, filter_func, show_all); | |
879 | |
880 /* And now the last callback. */ | |
881 g_signal_connect(G_OBJECT(optmenu), "changed", | |
882 G_CALLBACK(account_menu_cb), cb); | |
883 | 816 |
884 return optmenu; | 817 return optmenu; |
885 } | 818 } |
886 | 819 |
887 gboolean | 820 gboolean |
1917 g_value_unset(&val); | 1850 g_value_unset(&val); |
1918 | 1851 |
1919 if (account == NULL) | 1852 if (account == NULL) |
1920 return TRUE; | 1853 return TRUE; |
1921 | 1854 |
1922 if (optmenu != NULL) { | 1855 if (optmenu != NULL) |
1923 GList *items; | 1856 aop_option_menu_select_by_data(optmenu, account); |
1924 guint index = 0; | |
1925 pidgin_account_option_menu_set_selected(optmenu, account); | |
1926 items = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children; | |
1927 | |
1928 do { | |
1929 if (account == g_object_get_data(G_OBJECT(items->data), "account")) { | |
1930 /* Set the account in the GUI. */ | |
1931 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), index); | |
1932 return TRUE; | |
1933 } | |
1934 index++; | |
1935 } while ((items = items->next) != NULL); | |
1936 } | |
1937 | 1857 |
1938 return TRUE; | 1858 return TRUE; |
1939 } | 1859 } |
1940 | 1860 |
1941 static void | 1861 static void |