Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 17712:43a55528ff26
propagate from branch 'im.pidgin.pidgin' (head b5c55520ae8ff7186733fd82db23a6e4452976cc)
to branch 'im.pidgin.soc.2007.finchfeat' (head 93037197c5356731d62e75b4050ca7d01b1017d6)
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Mon, 04 Jun 2007 15:12:50 +0000 |
parents | ff04387682ce |
children | 3aafa9d3119c 70fb7663a918 2a6fb7c6d030 |
comparison
equal
deleted
inserted
replaced
17543:223a4fca43a1 | 17712:43a55528ff26 |
---|---|
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 { |
87 }; | 92 }; |
88 | 93 |
89 void | 94 void |
90 pidgin_setup_imhtml(GtkWidget *imhtml) | 95 pidgin_setup_imhtml(GtkWidget *imhtml) |
91 { | 96 { |
97 PangoFontDescription *desc = NULL; | |
92 g_return_if_fail(imhtml != NULL); | 98 g_return_if_fail(imhtml != NULL); |
93 g_return_if_fail(GTK_IS_IMHTML(imhtml)); | 99 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
94 | 100 |
95 g_signal_connect(G_OBJECT(imhtml), "url_clicked", | 101 g_signal_connect(G_OBJECT(imhtml), "url_clicked", |
96 G_CALLBACK(url_clicked_cb), NULL); | 102 G_CALLBACK(url_clicked_cb), NULL); |
97 | 103 |
98 pidgin_themes_smiley_themeize(imhtml); | 104 pidgin_themes_smiley_themeize(imhtml); |
99 | 105 |
100 gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), >kimhtml_cbs); | 106 gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), >kimhtml_cbs); |
101 | 107 |
102 /* Use the GNOME "document" font, if applicable */ | 108 if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/use_theme_font")) { |
103 if (purple_running_gnome()) { | 109 const char *font = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/custom_font"); |
110 desc = pango_font_description_from_string(font); | |
111 } else if (purple_running_gnome()) { | |
112 /* Use the GNOME "document" font, if applicable */ | |
104 char *path, *font; | 113 char *path, *font; |
105 PangoFontDescription *desc = NULL; | |
106 | 114 |
107 if ((path = g_find_program_in_path("gconftool-2"))) { | 115 if ((path = g_find_program_in_path("gconftool-2"))) { |
108 g_free(path); | 116 g_free(path); |
109 if (!g_spawn_command_line_sync( | 117 if (!g_spawn_command_line_sync( |
110 "gconftool-2 -g /desktop/gnome/interface/document_font_name", | 118 "gconftool-2 -g /desktop/gnome/interface/document_font_name", |
111 &font, NULL, NULL, NULL)) | 119 &font, NULL, NULL, NULL)) |
112 return; | 120 return; |
113 } | 121 } |
114 desc = pango_font_description_from_string(font); | 122 desc = pango_font_description_from_string(font); |
115 g_free(font); | 123 g_free(font); |
116 | 124 } |
117 if (desc) { | 125 |
118 gtk_widget_modify_font(imhtml, desc); | 126 if (desc) { |
119 pango_font_description_free(desc); | 127 gtk_widget_modify_font(imhtml, desc); |
120 } | 128 pango_font_description_free(desc); |
121 } | 129 } |
122 } | 130 } |
123 | 131 |
124 GtkWidget * | 132 GtkWidget * |
125 pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret) | 133 pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret) |
428 gtk_widget_show(vbox); | 436 gtk_widget_show(vbox); |
429 | 437 |
430 return vbox; | 438 return vbox; |
431 } | 439 } |
432 | 440 |
441 static gpointer | |
442 aop_option_menu_get_selected(GtkWidget *optmenu, GtkWidget **p_item) | |
443 { | |
444 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
445 GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu)); | |
446 if (p_item) | |
447 (*p_item) = item; | |
448 return g_object_get_data(G_OBJECT(item), "aop_per_item_data"); | |
449 } | |
450 | |
433 static void | 451 static void |
434 protocol_menu_cb(GtkWidget *optmenu, GCallback cb) | 452 aop_menu_cb(GtkWidget *optmenu, GCallback cb) |
435 { | 453 { |
436 GtkWidget *menu; | |
437 GtkWidget *item; | 454 GtkWidget *item; |
438 const char *protocol; | 455 gpointer per_item_data; |
439 gpointer user_data; | 456 |
440 | 457 per_item_data = aop_option_menu_get_selected(optmenu, &item); |
441 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 458 |
442 item = gtk_menu_get_active(GTK_MENU(menu)); | 459 if (cb != NULL) { |
443 | 460 ((void (*)(GtkWidget *, gpointer, gpointer))cb)(item, per_item_data, g_object_get_data(G_OBJECT(optmenu), "user_data")); |
444 protocol = g_object_get_data(G_OBJECT(item), "protocol"); | 461 } |
445 | |
446 if (!strcmp(protocol, "prpl-fake")) | |
447 protocol = g_object_get_data(G_OBJECT(item), "real_protocol"); | |
448 | |
449 if (!strcmp(protocol, g_object_get_data(G_OBJECT(optmenu), "last_protocol"))) | |
450 return; | |
451 | |
452 user_data = (g_object_get_data(G_OBJECT(optmenu), "user_data")); | |
453 g_object_set_data(G_OBJECT(optmenu), "last_protocol", (gpointer)protocol); | |
454 | |
455 if (cb != NULL) | |
456 ((void (*)(GtkWidget *, const char *, gpointer))cb)(item, protocol, | |
457 user_data); | |
458 } | 462 } |
459 | 463 |
460 static GtkWidget * | 464 static GtkWidget * |
461 pidgin_protocol_option_menu_item(GtkWidget *menu, GtkSizeGroup *sg, GtkWidget *image, | 465 aop_menu_item_new(GtkSizeGroup *sg, GdkPixbuf *pixbuf, const char *lbl, gpointer per_item_data) |
462 const char *name, const char *id) | |
463 { | 466 { |
464 GtkWidget *item; | 467 GtkWidget *item; |
465 GtkWidget *hbox; | 468 GtkWidget *hbox; |
469 GtkWidget *image; | |
466 GtkWidget *label; | 470 GtkWidget *label; |
467 | 471 |
468 /* Create the item. */ | |
469 item = gtk_menu_item_new(); | 472 item = gtk_menu_item_new(); |
470 | 473 gtk_widget_show(item); |
471 /* Create the hbox. */ | 474 |
472 hbox = gtk_hbox_new(FALSE, 4); | 475 hbox = gtk_hbox_new(FALSE, 4); |
476 gtk_widget_show(hbox); | |
477 | |
478 /* Create the image */ | |
479 if (pixbuf == NULL) | |
480 image = gtk_image_new(); | |
481 else | |
482 image = gtk_image_new_from_pixbuf(pixbuf); | |
483 gtk_widget_show(image); | |
484 | |
485 if (sg) | |
486 gtk_size_group_add_widget(sg, image); | |
487 | |
488 /* Create the label */ | |
489 label = gtk_label_new (lbl); | |
490 gtk_widget_show (label); | |
491 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
492 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
493 | |
473 gtk_container_add(GTK_CONTAINER(item), hbox); | 494 gtk_container_add(GTK_CONTAINER(item), hbox); |
474 gtk_widget_show(hbox); | |
475 | |
476 gtk_size_group_add_widget(sg, image); | |
477 | |
478 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | 495 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); |
479 gtk_widget_show(image); | |
480 | |
481 /* Create the label. */ | |
482 label = gtk_label_new(name); | |
483 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
484 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
485 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 496 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); |
486 gtk_widget_show(label); | 497 |
487 | 498 g_object_set_data(G_OBJECT (item), "aop_per_item_data", per_item_data); |
488 g_object_set_data(G_OBJECT(item), "protocol", (gpointer)id); | 499 |
489 | 500 pidgin_set_accessible_label(item, label); |
490 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
491 gtk_widget_show(item); | |
492 pidgin_set_accessible_label (item, label); | |
493 | 501 |
494 return item; | 502 return item; |
503 } | |
504 | |
505 static GtkWidget * | |
506 aop_option_menu_new(AopMenu *aop_menu, GCallback cb, gpointer user_data) | |
507 { | |
508 GtkWidget *optmenu; | |
509 | |
510 optmenu = gtk_option_menu_new(); | |
511 gtk_widget_show(optmenu); | |
512 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), aop_menu->menu); | |
513 | |
514 if (aop_menu->default_item != -1) | |
515 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), aop_menu->default_item); | |
516 | |
517 g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", aop_menu, (GDestroyNotify)g_free); | |
518 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | |
519 | |
520 g_signal_connect(G_OBJECT(optmenu), "changed", G_CALLBACK(aop_menu_cb), cb); | |
521 | |
522 return optmenu; | |
523 } | |
524 | |
525 static void | |
526 aop_option_menu_replace_menu(GtkWidget *optmenu, AopMenu *new_aop_menu) | |
527 { | |
528 if (gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))) | |
529 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
530 | |
531 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), new_aop_menu->menu); | |
532 | |
533 if (new_aop_menu->default_item != -1) | |
534 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), new_aop_menu->default_item); | |
535 | |
536 g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", new_aop_menu, (GDestroyNotify)g_free); | |
537 } | |
538 | |
539 static void | |
540 aop_option_menu_select_by_data(GtkWidget *optmenu, gpointer data) | |
541 { | |
542 guint idx; | |
543 GList *llItr = NULL; | |
544 | |
545 for (idx = 0, llItr = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children; | |
546 llItr != NULL; | |
547 llItr = llItr->next, idx++) { | |
548 if (data == g_object_get_data(G_OBJECT(llItr->data), "aop_per_item_data")) { | |
549 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), idx); | |
550 break; | |
551 } | |
552 } | |
553 } | |
554 | |
555 static GdkPixbuf * | |
556 get_prpl_pixbuf(PurplePluginProtocolInfo *prpl_info) | |
557 { | |
558 const char *proto_name; | |
559 GdkPixbuf *pixbuf = NULL; | |
560 char *filename; | |
561 char buf[256]; | |
562 | |
563 proto_name = prpl_info->list_icon(NULL, NULL); | |
564 g_return_val_if_fail(proto_name != NULL, NULL); | |
565 | |
566 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
567 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "16", buf, NULL); | |
568 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
569 g_free(filename); | |
570 | |
571 return pixbuf; | |
572 } | |
573 | |
574 static AopMenu * | |
575 create_protocols_menu(const char *default_proto_id) | |
576 { | |
577 AopMenu *aop_menu = NULL; | |
578 PurplePluginProtocolInfo *prpl_info; | |
579 PurplePlugin *plugin; | |
580 GdkPixbuf *pixbuf = NULL; | |
581 GtkSizeGroup *sg; | |
582 GList *p; | |
583 const char *gtalk_name = NULL; | |
584 int i; | |
585 | |
586 aop_menu = g_malloc0(sizeof(AopMenu)); | |
587 aop_menu->default_item = -1; | |
588 aop_menu->menu = gtk_menu_new(); | |
589 gtk_widget_show(aop_menu->menu); | |
590 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
591 | |
592 if (purple_find_prpl("prpl-jabber")) | |
593 gtalk_name = _("Google Talk"); | |
594 | |
595 for (p = purple_plugins_get_protocols(), i = 0; | |
596 p != NULL; | |
597 p = p->next, i++) { | |
598 | |
599 plugin = (PurplePlugin *)p->data; | |
600 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
601 | |
602 if (gtalk_name && strcmp(gtalk_name, plugin->info->name) < 0) { | |
603 char *filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
604 "16", "google-talk.png", NULL); | |
605 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
606 g_free(filename); | |
607 | |
608 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), | |
609 aop_menu_item_new(sg, pixbuf, gtalk_name, "prpl-jabber")); | |
610 | |
611 if (pixbuf) | |
612 g_object_unref(pixbuf); | |
613 | |
614 gtalk_name = NULL; | |
615 i++; | |
616 } | |
617 | |
618 pixbuf = get_prpl_pixbuf(prpl_info); | |
619 | |
620 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), | |
621 aop_menu_item_new(sg, pixbuf, plugin->info->name, plugin->info->id)); | |
622 | |
623 if (pixbuf) | |
624 g_object_unref(pixbuf); | |
625 | |
626 if (default_proto_id != NULL && !strcmp(plugin->info->id, default_proto_id)) | |
627 aop_menu->default_item = i; | |
628 } | |
629 | |
630 g_object_unref(sg); | |
631 | |
632 return aop_menu; | |
495 } | 633 } |
496 | 634 |
497 GtkWidget * | 635 GtkWidget * |
498 pidgin_protocol_option_menu_new(const char *id, GCallback cb, | 636 pidgin_protocol_option_menu_new(const char *id, GCallback cb, |
499 gpointer user_data) | 637 gpointer user_data) |
500 { | 638 { |
501 PurplePluginProtocolInfo *prpl_info; | 639 return aop_option_menu_new(create_protocols_menu(id), cb, user_data); |
502 PurplePlugin *plugin; | |
503 GtkWidget *optmenu; | |
504 GtkWidget *menu; | |
505 GdkPixbuf *pixbuf; | |
506 GtkWidget *image; | |
507 GList *p; | |
508 GtkSizeGroup *sg; | |
509 char *filename; | |
510 const char *proto_name; | |
511 char buf[256]; | |
512 int i, selected_index = -1; | |
513 const char *gtalk_name = NULL; | |
514 | |
515 if (purple_find_prpl("prpl-jabber")) | |
516 gtalk_name = _("Google Talk"); | |
517 | |
518 optmenu = gtk_option_menu_new(); | |
519 gtk_widget_show(optmenu); | |
520 | |
521 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | |
522 | |
523 menu = gtk_menu_new(); | |
524 gtk_widget_show(menu); | |
525 | |
526 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
527 | |
528 for (p = purple_plugins_get_protocols(), i = 0; | |
529 p != NULL; | |
530 p = p->next, i++) { | |
531 | |
532 plugin = (PurplePlugin *)p->data; | |
533 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
534 | |
535 if (gtalk_name && strcmp(gtalk_name, plugin->info->name) < 0) | |
536 { | |
537 GtkWidget *gtalk_item; | |
538 | |
539 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
540 "16", "google-talk.png", NULL); | |
541 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
542 g_free(filename); | |
543 | |
544 | |
545 if (pixbuf) | |
546 image = gtk_image_new_from_pixbuf(pixbuf); | |
547 else | |
548 image = gtk_image_new(); | |
549 | |
550 gtalk_item = pidgin_protocol_option_menu_item(menu, sg, image, gtalk_name, "prpl-fake"); | |
551 g_object_set_data(G_OBJECT(gtalk_item), "real_protocol", "prpl-jabber"); | |
552 i++; | |
553 | |
554 gtalk_name = NULL; | |
555 } | |
556 | |
557 /* Load the image. */ | |
558 proto_name = prpl_info->list_icon(NULL, NULL); | |
559 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | |
560 | |
561 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
562 "16", buf, NULL); | |
563 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
564 g_free(filename); | |
565 | |
566 if (pixbuf) | |
567 image = gtk_image_new_from_pixbuf(pixbuf); | |
568 else | |
569 image = gtk_image_new(); | |
570 | |
571 pidgin_protocol_option_menu_item(menu, sg, image, plugin->info->name, plugin->info->id); | |
572 | |
573 if (id != NULL && !strcmp(plugin->info->id, id)) | |
574 { | |
575 g_object_set_data(G_OBJECT(optmenu), "last_protocol", plugin->info->id); | |
576 selected_index = i; | |
577 } | |
578 else if (i == 0) | |
579 { | |
580 /* Ensure we set the protocol even if id is NULL or can't be found. */ | |
581 g_object_set_data(G_OBJECT(optmenu), "last_protocol", plugin->info->id); | |
582 } | |
583 | |
584 if (pixbuf) | |
585 g_object_unref(G_OBJECT(pixbuf)); | |
586 } | |
587 | |
588 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
589 | |
590 if (selected_index != -1) | |
591 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); | |
592 | |
593 g_signal_connect(G_OBJECT(optmenu), "changed", | |
594 G_CALLBACK(protocol_menu_cb), cb); | |
595 | |
596 g_object_unref(sg); | |
597 | |
598 return optmenu; | |
599 } | 640 } |
600 | 641 |
601 PurpleAccount * | 642 PurpleAccount * |
602 pidgin_account_option_menu_get_selected(GtkWidget *optmenu) | 643 pidgin_account_option_menu_get_selected(GtkWidget *optmenu) |
603 { | 644 { |
604 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 645 return (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL); |
605 GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu)); | 646 } |
606 return g_object_get_data(G_OBJECT(item), "account"); | 647 |
607 } | 648 static AopMenu * |
608 | 649 create_account_menu(PurpleAccount *default_account, |
609 static void | 650 PurpleFilterAccountFunc filter_func, gboolean show_all) |
610 account_menu_cb(GtkWidget *optmenu, GCallback cb) | 651 { |
611 { | 652 AopMenu *aop_menu = NULL; |
612 GtkWidget *menu; | |
613 GtkWidget *item; | |
614 PurpleAccount *account; | 653 PurpleAccount *account; |
615 gpointer user_data; | 654 GdkPixbuf *pixbuf = NULL; |
616 | |
617 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
618 item = gtk_menu_get_active(GTK_MENU(menu)); | |
619 | |
620 account = g_object_get_data(G_OBJECT(item), "account"); | |
621 user_data = g_object_get_data(G_OBJECT(optmenu), "user_data"); | |
622 | |
623 if (cb != NULL) | |
624 ((void (*)(GtkWidget *, PurpleAccount *, gpointer))cb)(item, account, | |
625 user_data); | |
626 } | |
627 | |
628 static void | |
629 create_account_menu(GtkWidget *optmenu, PurpleAccount *default_account, | |
630 PurpleFilterAccountFunc filter_func, gboolean show_all) | |
631 { | |
632 PurpleAccount *account; | |
633 GtkWidget *menu; | |
634 GtkWidget *item; | |
635 GtkWidget *image; | |
636 GtkWidget *hbox; | |
637 GtkWidget *label; | |
638 GdkPixbuf *pixbuf; | |
639 GList *list; | 655 GList *list; |
640 GList *p; | 656 GList *p; |
641 GtkSizeGroup *sg; | 657 GtkSizeGroup *sg; |
642 char *filename; | 658 int i; |
643 const char *proto_name; | |
644 char buf[256]; | 659 char buf[256]; |
645 int i, selected_index = -1; | |
646 | 660 |
647 if (show_all) | 661 if (show_all) |
648 list = purple_accounts_get_all(); | 662 list = purple_accounts_get_all(); |
649 else | 663 else |
650 list = purple_connections_get_all(); | 664 list = purple_connections_get_all(); |
651 | 665 |
652 menu = gtk_menu_new(); | 666 aop_menu = g_malloc0(sizeof(AopMenu)); |
653 gtk_widget_show(menu); | 667 aop_menu->default_item = -1; |
654 | 668 aop_menu->menu = gtk_menu_new(); |
669 gtk_widget_show(aop_menu->menu); | |
655 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | 670 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
656 | 671 |
657 for (p = list, i = 0; p != NULL; p = p->next, i++) { | 672 for (p = list, i = 0; p != NULL; p = p->next, i++) { |
658 PurplePluginProtocolInfo *prpl_info = NULL; | 673 PurplePluginProtocolInfo *prpl_info = NULL; |
659 PurplePlugin *plugin; | 674 PurplePlugin *plugin; |
671 continue; | 686 continue; |
672 } | 687 } |
673 | 688 |
674 plugin = purple_find_prpl(purple_account_get_protocol_id(account)); | 689 plugin = purple_find_prpl(purple_account_get_protocol_id(account)); |
675 | 690 |
676 if (plugin != NULL) | 691 if (plugin) |
677 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | 692 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
678 | 693 |
679 /* Create the item. */ | |
680 item = gtk_menu_item_new(); | |
681 | |
682 /* Create the hbox. */ | |
683 hbox = gtk_hbox_new(FALSE, 4); | |
684 gtk_container_add(GTK_CONTAINER(item), hbox); | |
685 gtk_widget_show(hbox); | |
686 | |
687 /* Load the image. */ | 694 /* Load the image. */ |
688 if (prpl_info != NULL) { | 695 if (prpl_info) { |
689 proto_name = prpl_info->list_icon(account, NULL); | 696 pixbuf = get_prpl_pixbuf(prpl_info); |
690 g_snprintf(buf, sizeof(buf), "%s.png", proto_name); | 697 |
691 | 698 if (pixbuf) { |
692 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", | |
693 "16", buf, NULL); | |
694 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
695 g_free(filename); | |
696 | |
697 if (pixbuf != NULL) { | |
698 if (purple_account_is_disconnected(account) && show_all && | 699 if (purple_account_is_disconnected(account) && show_all && |
699 purple_connections_get_all()) | 700 purple_connections_get_all()) |
700 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); | 701 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
701 | |
702 image = gtk_image_new_from_pixbuf(pixbuf); | |
703 | |
704 g_object_unref(G_OBJECT(pixbuf)); | |
705 } | 702 } |
706 else | 703 } |
707 image = gtk_image_new(); | |
708 } | |
709 else | |
710 image = gtk_image_new(); | |
711 | |
712 gtk_size_group_add_widget(sg, image); | |
713 | |
714 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
715 gtk_widget_show(image); | |
716 | 704 |
717 if (purple_account_get_alias(account)) { | 705 if (purple_account_get_alias(account)) { |
718 g_snprintf(buf, sizeof(buf), "%s (%s) (%s)", | 706 g_snprintf(buf, sizeof(buf), "%s (%s) (%s)", |
719 purple_account_get_username(account), | 707 purple_account_get_username(account), |
720 purple_account_get_alias(account), | 708 purple_account_get_alias(account), |
723 g_snprintf(buf, sizeof(buf), "%s (%s)", | 711 g_snprintf(buf, sizeof(buf), "%s (%s)", |
724 purple_account_get_username(account), | 712 purple_account_get_username(account), |
725 purple_account_get_protocol_name(account)); | 713 purple_account_get_protocol_name(account)); |
726 } | 714 } |
727 | 715 |
728 /* Create the label. */ | 716 gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu), |
729 label = gtk_label_new(buf); | 717 aop_menu_item_new(sg, pixbuf, buf, account)); |
730 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | 718 |
731 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 719 if (pixbuf) |
732 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 720 g_object_unref(pixbuf); |
733 gtk_widget_show(label); | 721 |
734 | 722 if (default_account && account == default_account) |
735 g_object_set_data(G_OBJECT(item), "account", account); | 723 aop_menu->default_item = i; |
736 | |
737 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
738 gtk_widget_show(item); | |
739 pidgin_set_accessible_label (item, label); | |
740 | |
741 if (default_account != NULL && account == default_account) | |
742 selected_index = i; | |
743 } | 724 } |
744 | 725 |
745 g_object_unref(sg); | 726 g_object_unref(sg); |
746 | 727 |
747 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | 728 return aop_menu; |
748 | |
749 /* Set the place we should be at. */ | |
750 if (selected_index != -1) | |
751 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index); | |
752 } | 729 } |
753 | 730 |
754 static void | 731 static void |
755 regenerate_account_menu(GtkWidget *optmenu) | 732 regenerate_account_menu(GtkWidget *optmenu) |
756 { | 733 { |
757 GtkWidget *menu; | |
758 GtkWidget *item; | |
759 gboolean show_all; | 734 gboolean show_all; |
760 PurpleAccount *account; | 735 PurpleAccount *account; |
761 PurpleFilterAccountFunc filter_func; | 736 PurpleFilterAccountFunc filter_func; |
762 | 737 |
763 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | 738 account = (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL); |
764 item = gtk_menu_get_active(GTK_MENU(menu)); | 739 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), "show_all")); |
765 account = g_object_get_data(G_OBJECT(item), "account"); | 740 filter_func = g_object_get_data(G_OBJECT(optmenu), "filter_func"); |
766 | 741 |
767 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), | 742 aop_option_menu_replace_menu(optmenu, create_account_menu(account, filter_func, show_all)); |
768 "show_all")); | |
769 | |
770 filter_func = g_object_get_data(G_OBJECT(optmenu), | |
771 "filter_func"); | |
772 | |
773 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
774 | |
775 create_account_menu(optmenu, account, filter_func, show_all); | |
776 } | 743 } |
777 | 744 |
778 static void | 745 static void |
779 account_menu_sign_on_off_cb(PurpleConnection *gc, GtkWidget *optmenu) | 746 account_menu_sign_on_off_cb(PurpleConnection *gc, GtkWidget *optmenu) |
780 { | 747 { |
797 } | 764 } |
798 | 765 |
799 void | 766 void |
800 pidgin_account_option_menu_set_selected(GtkWidget *optmenu, PurpleAccount *account) | 767 pidgin_account_option_menu_set_selected(GtkWidget *optmenu, PurpleAccount *account) |
801 { | 768 { |
802 GtkWidget *menu; | 769 aop_option_menu_select_by_data(optmenu, account); |
803 GtkWidget *item; | |
804 gboolean show_all; | |
805 PurpleAccount *curaccount; | |
806 PurpleFilterAccountFunc filter_func; | |
807 | |
808 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); | |
809 item = gtk_menu_get_active(GTK_MENU(menu)); | |
810 curaccount = g_object_get_data(G_OBJECT(item), "account"); | |
811 | |
812 if (account == curaccount) | |
813 return; | |
814 | |
815 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), | |
816 "show_all")); | |
817 | |
818 filter_func = g_object_get_data(G_OBJECT(optmenu), | |
819 "filter_func"); | |
820 | |
821 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
822 | |
823 create_account_menu(optmenu, account, filter_func, show_all); | |
824 } | 770 } |
825 | 771 |
826 GtkWidget * | 772 GtkWidget * |
827 pidgin_account_option_menu_new(PurpleAccount *default_account, | 773 pidgin_account_option_menu_new(PurpleAccount *default_account, |
828 gboolean show_all, GCallback cb, | 774 gboolean show_all, GCallback cb, |
830 gpointer user_data) | 776 gpointer user_data) |
831 { | 777 { |
832 GtkWidget *optmenu; | 778 GtkWidget *optmenu; |
833 | 779 |
834 /* Create the option menu */ | 780 /* Create the option menu */ |
835 optmenu = gtk_option_menu_new(); | 781 optmenu = aop_option_menu_new(create_account_menu(default_account, filter_func, show_all), cb, user_data); |
836 gtk_widget_show(optmenu); | |
837 | 782 |
838 g_signal_connect(G_OBJECT(optmenu), "destroy", | 783 g_signal_connect(G_OBJECT(optmenu), "destroy", |
839 G_CALLBACK(account_menu_destroyed_cb), NULL); | 784 G_CALLBACK(account_menu_destroyed_cb), NULL); |
840 | 785 |
841 /* Register the purple sign on/off event callbacks. */ | 786 /* Register the purple sign on/off event callbacks. */ |
853 optmenu); | 798 optmenu); |
854 | 799 |
855 /* Set some data. */ | 800 /* Set some data. */ |
856 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); | 801 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data); |
857 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all)); | 802 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all)); |
858 g_object_set_data(G_OBJECT(optmenu), "filter_func", | 803 g_object_set_data(G_OBJECT(optmenu), "filter_func", filter_func); |
859 filter_func); | |
860 | |
861 /* Create and set the actual menu. */ | |
862 create_account_menu(optmenu, default_account, filter_func, show_all); | |
863 | |
864 /* And now the last callback. */ | |
865 g_signal_connect(G_OBJECT(optmenu), "changed", | |
866 G_CALLBACK(account_menu_cb), cb); | |
867 | 804 |
868 return optmenu; | 805 return optmenu; |
869 } | 806 } |
870 | 807 |
871 gboolean | 808 gboolean |
1519 account, who, NULL, | 1456 account, who, NULL, |
1520 data, (GCallback)dnd_set_icon_ok_cb, (GCallback)dnd_set_icon_cancel_cb); | 1457 data, (GCallback)dnd_set_icon_ok_cb, (GCallback)dnd_set_icon_cancel_cb); |
1521 else | 1458 else |
1522 purple_request_choice(NULL, NULL, | 1459 purple_request_choice(NULL, NULL, |
1523 _("You have dragged an image"), | 1460 _("You have dragged an image"), |
1524 (ft ? _("You can send this image as a file transfer or " | 1461 (ft ? _("You can send this image as a file transfer, or use it as the buddy icon for this user.") : |
1525 "embed it into this message, or use it as the buddy icon for this user.") : | |
1526 _("You can insert this image into this message, or use it as the buddy icon for this user")), | 1462 _("You can insert this image into this message, or use it as the buddy icon for this user")), |
1527 (ft ? DND_FILE_TRANSFER : DND_IM_IMAGE), | 1463 (ft ? DND_FILE_TRANSFER : DND_IM_IMAGE), |
1528 "OK", (GCallback)dnd_image_ok_callback, | 1464 "OK", (GCallback)dnd_image_ok_callback, |
1529 "Cancel", (GCallback)dnd_image_cancel_callback, | 1465 "Cancel", (GCallback)dnd_image_cancel_callback, |
1530 account, who, NULL, | 1466 account, who, NULL, |
1901 g_value_unset(&val); | 1837 g_value_unset(&val); |
1902 | 1838 |
1903 if (account == NULL) | 1839 if (account == NULL) |
1904 return TRUE; | 1840 return TRUE; |
1905 | 1841 |
1906 if (optmenu != NULL) { | 1842 if (optmenu != NULL) |
1907 GList *items; | 1843 aop_option_menu_select_by_data(optmenu, account); |
1908 guint index = 0; | |
1909 pidgin_account_option_menu_set_selected(optmenu, account); | |
1910 items = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children; | |
1911 | |
1912 do { | |
1913 if (account == g_object_get_data(G_OBJECT(items->data), "account")) { | |
1914 /* Set the account in the GUI. */ | |
1915 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), index); | |
1916 return TRUE; | |
1917 } | |
1918 index++; | |
1919 } while ((items = items->next) != NULL); | |
1920 } | |
1921 | 1844 |
1922 return TRUE; | 1845 return TRUE; |
1923 } | 1846 } |
1924 | 1847 |
1925 static void | 1848 static void |
3015 size_t i; | 2938 size_t i; |
3016 size_t len; | 2939 size_t len; |
3017 PangoLogAttr *log_attrs; | 2940 PangoLogAttr *log_attrs; |
3018 gchar *word; | 2941 gchar *word; |
3019 | 2942 |
3020 if (strcasecmp(key, "Global Thermonuclear War") == 0) | 2943 if (g_ascii_strcasecmp(key, "Global Thermonuclear War") == 0) |
3021 { | 2944 { |
3022 purple_notify_info(NULL, "WOPR", | 2945 purple_notify_info(NULL, "WOPR", |
3023 "Wouldn't you prefer a nice game of chess?", NULL); | 2946 "Wouldn't you prefer a nice game of chess?", NULL); |
3024 return FALSE; | 2947 return FALSE; |
3025 } | 2948 } |