Mercurial > pidgin
comparison pidgin/gtkutils.c @ 17758:012aaa301a30
Remove code duplication for prpl-icon creation.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 25 May 2007 03:32:46 +0000 |
parents | d48026a5f9dd |
children | 2f8d77356268 |
comparison
equal
deleted
inserted
replaced
17757:a307926a3432 | 17758:012aaa301a30 |
---|---|
493 pidgin_set_accessible_label (item, label); | 493 pidgin_set_accessible_label (item, label); |
494 | 494 |
495 return item; | 495 return item; |
496 } | 496 } |
497 | 497 |
498 static GdkPixbuf * | |
499 pidgin_create_prpl_icon_from_prpl(PurplePlugin *prpl, PidginPrplIconSize size, PurpleAccount *account) | |
500 { | |
501 PurplePluginProtocolInfo *prpl_info; | |
502 const char *protoname = NULL; | |
503 char buf[MAXPATHLEN]; | |
504 char *filename = NULL; | |
505 GdkPixbuf *pixbuf; | |
506 | |
507 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
508 if (prpl_info->list_icon == NULL) | |
509 return NULL; | |
510 | |
511 protoname = prpl_info->list_icon(account, NULL); | |
512 if (protoname == NULL) | |
513 return NULL; | |
514 | |
515 /* | |
516 * Status icons will be themeable too, and then it will look up | |
517 * protoname from the theme | |
518 */ | |
519 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
520 | |
521 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
522 size == PIDGIN_PRPL_ICON_SMALL ? "16" : | |
523 size == PIDGIN_PRPL_ICON_MEDIUM ? "22" : "48", | |
524 buf, NULL); | |
525 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
526 g_free(filename); | |
527 | |
528 return pixbuf; | |
529 } | |
530 | |
498 GtkWidget * | 531 GtkWidget * |
499 pidgin_protocol_option_menu_new(const char *id, GCallback cb, | 532 pidgin_protocol_option_menu_new(const char *id, GCallback cb, |
500 gpointer user_data) | 533 gpointer user_data) |
501 { | 534 { |
502 PurplePluginProtocolInfo *prpl_info; | 535 PurplePluginProtocolInfo *prpl_info; |
506 GdkPixbuf *pixbuf; | 539 GdkPixbuf *pixbuf; |
507 GtkWidget *image; | 540 GtkWidget *image; |
508 GList *p; | 541 GList *p; |
509 GtkSizeGroup *sg; | 542 GtkSizeGroup *sg; |
510 char *filename; | 543 char *filename; |
511 const char *proto_name; | |
512 char buf[256]; | |
513 int i, selected_index = -1; | 544 int i, selected_index = -1; |
514 const char *gtalk_name = NULL; | 545 const char *gtalk_name = NULL; |
515 | 546 |
516 if (purple_find_prpl("prpl-jabber")) | 547 if (purple_find_prpl("prpl-jabber")) |
517 gtalk_name = _("Google Talk"); | 548 gtalk_name = _("Google Talk"); |
554 | 585 |
555 gtalk_name = NULL; | 586 gtalk_name = NULL; |
556 } | 587 } |
557 | 588 |
558 /* Load the image. */ | 589 /* Load the image. */ |
559 proto_name = prpl_info->list_icon(NULL, NULL); | 590 pixbuf = pidgin_create_prpl_icon_from_prpl(plugin, PIDGIN_PRPL_ICON_SMALL, NULL); |
560 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
561 | |
562 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
563 "16", buf, NULL); | |
564 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
565 g_free(filename); | |
566 | 591 |
567 if (pixbuf) | 592 if (pixbuf) |
568 image = gtk_image_new_from_pixbuf(pixbuf); | 593 image = gtk_image_new_from_pixbuf(pixbuf); |
569 else | 594 else |
570 image = gtk_image_new(); | 595 image = gtk_image_new(); |
636 GtkWidget *image; | 661 GtkWidget *image; |
637 GtkWidget *hbox; | 662 GtkWidget *hbox; |
638 GtkWidget *label; | 663 GtkWidget *label; |
639 GdkPixbuf *pixbuf; | 664 GdkPixbuf *pixbuf; |
640 GList *list; | 665 GList *list; |
641 GList *p; | |
642 GtkSizeGroup *sg; | 666 GtkSizeGroup *sg; |
643 char *filename; | |
644 const char *proto_name; | |
645 char buf[256]; | 667 char buf[256]; |
646 int i, selected_index = -1; | 668 int i, selected_index = -1; |
647 | 669 |
648 if (show_all) | 670 if (show_all) |
649 list = purple_accounts_get_all(); | 671 list = purple_accounts_get_all(); |
653 menu = gtk_menu_new(); | 675 menu = gtk_menu_new(); |
654 gtk_widget_show(menu); | 676 gtk_widget_show(menu); |
655 | 677 |
656 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | 678 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
657 | 679 |
658 for (p = list, i = 0; p != NULL; p = p->next, i++) { | 680 for (i = 0; list != NULL; list = list->next, i++) { |
659 PurplePluginProtocolInfo *prpl_info = NULL; | |
660 PurplePlugin *plugin; | |
661 | 681 |
662 if (show_all) | 682 if (show_all) |
663 account = (PurpleAccount *)p->data; | 683 account = (PurpleAccount *)list->data; |
664 else { | 684 else { |
665 PurpleConnection *gc = (PurpleConnection *)p->data; | 685 PurpleConnection *gc = (PurpleConnection *)list->data; |
666 | 686 |
667 account = purple_connection_get_account(gc); | 687 account = purple_connection_get_account(gc); |
668 } | 688 } |
669 | 689 |
670 if (filter_func && !filter_func(account)) { | 690 if (filter_func && !filter_func(account)) { |
671 i--; | 691 i--; |
672 continue; | 692 continue; |
673 } | 693 } |
674 | |
675 plugin = purple_find_prpl(purple_account_get_protocol_id(account)); | |
676 | |
677 if (plugin != NULL) | |
678 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
679 | 694 |
680 /* Create the item. */ | 695 /* Create the item. */ |
681 item = gtk_menu_item_new(); | 696 item = gtk_menu_item_new(); |
682 | 697 |
683 /* Create the hbox. */ | 698 /* Create the hbox. */ |
684 hbox = gtk_hbox_new(FALSE, 4); | 699 hbox = gtk_hbox_new(FALSE, 4); |
685 gtk_container_add(GTK_CONTAINER(item), hbox); | 700 gtk_container_add(GTK_CONTAINER(item), hbox); |
686 gtk_widget_show(hbox); | 701 gtk_widget_show(hbox); |
687 | 702 |
688 /* Load the image. */ | 703 pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL); |
689 if (prpl_info != NULL) { | 704 |
690 proto_name = prpl_info->list_icon(account, NULL); | 705 if (pixbuf != NULL) { |
691 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | 706 if (purple_account_is_disconnected(account) && show_all && |
692 | 707 purple_connections_get_all()) |
693 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | 708 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
694 "16", buf, NULL); | 709 |
695 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | 710 image = gtk_image_new_from_pixbuf(pixbuf); |
696 g_free(filename); | 711 |
697 | 712 g_object_unref(G_OBJECT(pixbuf)); |
698 if (pixbuf != NULL) { | |
699 if (purple_account_is_disconnected(account) && show_all && | |
700 purple_connections_get_all()) | |
701 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); | |
702 | |
703 image = gtk_image_new_from_pixbuf(pixbuf); | |
704 | |
705 g_object_unref(G_OBJECT(pixbuf)); | |
706 } | |
707 else | |
708 image = gtk_image_new(); | |
709 } | 713 } |
710 else | 714 else |
711 image = gtk_image_new(); | 715 image = gtk_image_new(); |
712 | 716 |
713 gtk_size_group_add_widget(sg, image); | 717 gtk_size_group_add_widget(sg, image); |
1650 icon_size, "GtkWidget"); | 1654 icon_size, "GtkWidget"); |
1651 return pixbuf; | 1655 return pixbuf; |
1652 | 1656 |
1653 } | 1657 } |
1654 | 1658 |
1655 | |
1656 GdkPixbuf * | 1659 GdkPixbuf * |
1657 pidgin_create_prpl_icon(PurpleAccount *account, PidginPrplIconSize size) | 1660 pidgin_create_prpl_icon(PurpleAccount *account, PidginPrplIconSize size) |
1658 { | 1661 { |
1659 PurplePlugin *prpl; | 1662 PurplePlugin *prpl; |
1660 PurplePluginProtocolInfo *prpl_info; | |
1661 const char *protoname = NULL; | |
1662 char buf[256]; /* TODO: We should use a define for max file length */ | |
1663 char *filename = NULL; | |
1664 GdkPixbuf *pixbuf; | |
1665 | |
1666 g_return_val_if_fail(account != NULL, NULL); | 1663 g_return_val_if_fail(account != NULL, NULL); |
1667 | 1664 |
1668 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); | 1665 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1669 if (prpl == NULL) | 1666 if (prpl == NULL) |
1670 return NULL; | 1667 return NULL; |
1671 | 1668 |
1672 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | 1669 return pidgin_create_prpl_icon_from_prpl(prpl, size, account); |
1673 if (prpl_info->list_icon == NULL) | |
1674 return NULL; | |
1675 | |
1676 protoname = prpl_info->list_icon(account, NULL); | |
1677 if (protoname == NULL) | |
1678 return NULL; | |
1679 | |
1680 /* | |
1681 * Status icons will be themeable too, and then it will look up | |
1682 * protoname from the theme | |
1683 */ | |
1684 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
1685 | |
1686 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
1687 size == PIDGIN_PRPL_ICON_SMALL ? "16" : | |
1688 size == PIDGIN_PRPL_ICON_MEDIUM ? "22" : "48", | |
1689 buf, NULL); | |
1690 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
1691 g_free(filename); | |
1692 | |
1693 return pixbuf; | |
1694 } | 1670 } |
1695 | 1671 |
1696 static void | 1672 static void |
1697 menu_action_cb(GtkMenuItem *item, gpointer object) | 1673 menu_action_cb(GtkMenuItem *item, gpointer object) |
1698 { | 1674 { |