Mercurial > pidgin.yaz
comparison src/dialogs.c @ 8290:84ec38c3efcc
[gaim-migrate @ 9014]
Moved the Get User Info and Insert Link dialogs to the request API.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 19 Feb 2004 08:06:23 +0000 |
parents | 89d9d004e3f3 |
children | a1b7c7f3d9a7 |
comparison
equal
deleted
inserted
replaced
8289:e39ea2b4f6cd | 8290:84ec38c3efcc |
---|---|
72 struct getuserinfo { | 72 struct getuserinfo { |
73 GtkWidget *window; | 73 GtkWidget *window; |
74 GtkWidget *entry; | 74 GtkWidget *entry; |
75 GtkWidget *account; | 75 GtkWidget *account; |
76 GaimConnection *gc; | 76 GaimConnection *gc; |
77 }; | |
78 | |
79 struct linkdlg { | |
80 GtkWidget *ok; | |
81 GtkWidget *cancel; | |
82 GtkWidget *window; | |
83 GtkWidget *url; | |
84 GtkWidget *text; | |
85 GtkWidget *entry; | |
86 GaimConversation *c; | |
87 }; | 77 }; |
88 | 78 |
89 struct view_log { | 79 struct view_log { |
90 long offset; | 80 long offset; |
91 int options; | 81 int options; |
466 | 456 |
467 gtk_widget_show_all(window); | 457 gtk_widget_show_all(window); |
468 return TRUE; | 458 return TRUE; |
469 } | 459 } |
470 | 460 |
471 static void do_info(GtkWidget *dialog, int id, struct getuserinfo *info) | |
472 { | |
473 char *who; | |
474 gboolean found = FALSE; | |
475 | |
476 switch(id) { | |
477 case GTK_RESPONSE_OK: | |
478 who = g_strdup(gaim_normalize(info->gc->account, gtk_entry_get_text(GTK_ENTRY(info->entry)))); | |
479 | |
480 if (who && gaim_str_has_suffix(who, "rocksmyworld")) { | |
481 found = show_ee_dialog(who); | |
482 } | |
483 | |
484 if (!found && who && *who && info->gc) | |
485 serv_get_info(info->gc, who); | |
486 | |
487 g_free(who); | |
488 break; | |
489 } | |
490 | |
491 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
492 g_free(info); | |
493 } | |
494 | |
495 static void | |
496 show_info_select_account(GObject *w, GaimAccount *account, | |
497 struct getuserinfo *info) | |
498 { | |
499 info->gc = gaim_account_get_connection(account); | |
500 } | |
501 | |
502 static void | 461 static void |
503 new_im_cb(gpointer data, GaimRequestFields *fields) | 462 new_im_cb(gpointer data, GaimRequestFields *fields) |
504 { | 463 { |
505 const char *username; | 464 const char *username; |
506 GaimAccount *account; | 465 GaimAccount *account; |
549 _("OK"), G_CALLBACK(new_im_cb), | 508 _("OK"), G_CALLBACK(new_im_cb), |
550 _("Cancel"), NULL, | 509 _("Cancel"), NULL, |
551 NULL); | 510 NULL); |
552 } | 511 } |
553 | 512 |
554 void show_info_dialog() | 513 static void |
555 { | 514 get_info_cb(gpointer data, GaimRequestFields *fields) |
556 GtkWidget *window, *hbox, *vbox; | 515 { |
557 GtkWidget *label; | 516 char *username; |
558 GtkWidget *table; | 517 gboolean found = FALSE; |
559 GaimGtkBuddyList *gtkblist; | 518 GaimAccount *account; |
560 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); | 519 |
561 struct getuserinfo *info = g_new0(struct getuserinfo, 1); | 520 account = gaim_request_fields_get_account(fields, "account"); |
562 | 521 |
563 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | 522 username = g_strdup(gaim_normalize(account, |
564 | 523 gaim_request_fields_get_string(fields, "screenname"))); |
565 info->gc = gaim_connections_get_all()->data; | 524 |
566 | 525 if (username != NULL && gaim_str_has_suffix(username, "rocksmyworld")) |
567 window = gtk_dialog_new_with_buttons(_("Get User Info"), gtkblist->window ? GTK_WINDOW(gtkblist->window) : NULL, 0, | 526 found = show_ee_dialog(username); |
568 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); | 527 |
569 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK); | 528 if (!found && username != NULL && *username != '\0' && account != NULL) |
570 gtk_container_set_border_width (GTK_CONTAINER(window), 6); | 529 serv_get_info(gaim_account_get_connection(account), username); |
571 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | 530 |
572 gtk_dialog_set_has_separator(GTK_DIALOG(window), FALSE); | 531 g_free(username); |
573 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(window)->vbox), 12); | 532 } |
574 gtk_container_set_border_width (GTK_CONTAINER(GTK_DIALOG(window)->vbox), 6); | 533 |
575 gtk_dialog_set_response_sensitive(GTK_DIALOG(window), GTK_RESPONSE_OK, FALSE); | 534 void |
576 | 535 show_info_dialog(void) |
577 hbox = gtk_hbox_new(FALSE, 12); | 536 { |
578 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window)->vbox), hbox); | 537 GaimRequestFields *fields; |
579 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | 538 GaimRequestFieldGroup *group; |
580 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | 539 GaimRequestField *field; |
581 | 540 |
582 vbox = gtk_vbox_new(FALSE, 0); | 541 fields = gaim_request_fields_new(); |
583 gtk_container_add(GTK_CONTAINER(hbox), vbox); | 542 |
584 | 543 group = gaim_request_field_group_new(NULL); |
585 label = gtk_label_new(_("Please enter the screen name of the person whose info you would like to view.\n")); | 544 gaim_request_fields_add_group(fields, group); |
586 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 545 |
587 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 546 field = gaim_request_field_string_new("screenname", _("_Screen name"), |
588 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 547 NULL, FALSE); |
589 | 548 gaim_request_field_set_required(field, TRUE); |
590 table = gtk_table_new(2, 2, FALSE); | 549 gaim_request_field_group_add_field(group, field); |
591 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | 550 |
592 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | 551 field = gaim_request_field_account_new("account", _("_Account"), NULL); |
593 gtk_container_set_border_width(GTK_CONTAINER(table), 12); | 552 gaim_request_field_set_visible(field, |
594 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | 553 (gaim_connections_get_all() != NULL && |
595 | 554 gaim_connections_get_all()->next != NULL)); |
596 label = gtk_label_new(NULL); | 555 gaim_request_field_set_required(field, TRUE); |
597 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Screen Name:")); | 556 gaim_request_field_group_add_field(group, field); |
598 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | 557 |
599 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | 558 gaim_request_fields(gaim_get_blist(), _("Get User Info"), |
600 | 559 NULL, |
601 info->entry = gtk_entry_new(); | 560 _("Please enter the screen name of the person whose " |
602 gtk_table_attach_defaults(GTK_TABLE(table), info->entry, 1, 2, 0, 1); | 561 "info you would like to view."), |
603 gtk_entry_set_activates_default (GTK_ENTRY(info->entry), TRUE); | 562 fields, |
604 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(info->entry)); | 563 _("OK"), G_CALLBACK(get_info_cb), |
605 gaim_set_accessible_label (info->entry, label); | 564 _("Cancel"), NULL, |
606 | 565 NULL); |
607 g_signal_connect(G_OBJECT(info->entry), "changed", | |
608 G_CALLBACK(gaim_gtk_set_sensitive_if_input), window); | |
609 | |
610 if (gaim_connections_get_all()->next) { | |
611 | |
612 label = gtk_label_new(NULL); | |
613 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
614 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); | |
615 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
616 | |
617 info->account = gaim_gtk_account_option_menu_new(NULL, FALSE, | |
618 G_CALLBACK(show_info_select_account), NULL, info); | |
619 | |
620 gtk_table_attach_defaults(GTK_TABLE(table), info->account, 1, 2, 1, 2); | |
621 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(info->account)); | |
622 gaim_set_accessible_label (info->account, label); | |
623 } | |
624 | |
625 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_info), info); | |
626 | |
627 gtk_widget_show_all(window); | |
628 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); | |
629 } | |
630 | |
631 | |
632 /*------------------------------------------------------*/ | |
633 /* Link Dialog */ | |
634 /*------------------------------------------------------*/ | |
635 | |
636 void dialog_link_destroy(GaimConversation *c) | |
637 { | |
638 GaimGtkConversation *gtkconv; | |
639 | |
640 gtkconv = GAIM_GTK_CONVERSATION(c); | |
641 | |
642 gtk_widget_destroy(gtkconv->dialogs.link); | |
643 gtkconv->dialogs.link = NULL; | |
644 } | |
645 | |
646 static void do_insert_link(GtkWidget *w, int resp, struct linkdlg *a) | |
647 { | |
648 GaimGtkConversation *gtkconv; | |
649 const char *urltext, *showtext; | |
650 | |
651 gtkconv = GAIM_GTK_CONVERSATION(a->c); | |
652 | |
653 if (resp == GTK_RESPONSE_OK) { | |
654 urltext = gtk_entry_get_text(GTK_ENTRY(a->url)); | |
655 showtext = gtk_entry_get_text(GTK_ENTRY(a->text)); | |
656 | |
657 if (!strlen(showtext)) | |
658 showtext = urltext; | |
659 | |
660 gtk_imhtml_insert_link(GTK_IMHTML(gtkconv->entry), urltext, showtext); | |
661 gaim_gtk_advance_past(gtkconv, "<A HREF>", "</A>"); | |
662 } | |
663 | |
664 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link), FALSE); | |
665 } | |
666 | |
667 static void dialog_link_freedata(GtkWidget *w, gpointer user_data) | |
668 { | |
669 struct linkdlg *a = user_data; | |
670 | |
671 g_free(a); | |
672 } | |
673 | |
674 void dialog_link_show(GaimConversation *c) | |
675 { | |
676 GaimGtkConversation *gtkconv; | |
677 GaimGtkWindow *gtkwin; | |
678 GtkWidget *table; | |
679 GtkWidget *label; | |
680 GtkWidget *hbox; | |
681 GtkWidget *vbox; | |
682 struct linkdlg *a; | |
683 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); | |
684 | |
685 gtkconv = GAIM_GTK_CONVERSATION(c); | |
686 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
687 | |
688 a = g_new0(struct linkdlg, 1); | |
689 | |
690 a->c = c; | |
691 a->window = gtk_dialog_new_with_buttons(_("Insert Link"), | |
692 GTK_WINDOW(gtkwin->window), 0, GTK_STOCK_CANCEL, | |
693 GTK_RESPONSE_CANCEL, _("_Insert"), GTK_RESPONSE_OK, NULL); | |
694 gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK); | |
695 g_signal_connect(G_OBJECT(a->window), "response", | |
696 G_CALLBACK(do_insert_link), a); | |
697 g_signal_connect(G_OBJECT(a->window), "destroy", | |
698 G_CALLBACK(dialog_link_freedata), a); | |
699 | |
700 gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK); | |
701 gtk_container_set_border_width(GTK_CONTAINER(a->window), 6); | |
702 gtk_window_set_resizable(GTK_WINDOW(a->window), FALSE); | |
703 gtk_dialog_set_has_separator(GTK_DIALOG(a->window), FALSE); | |
704 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(a->window)->vbox), 12); | |
705 gtk_container_set_border_width( | |
706 GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), 6); | |
707 gtk_window_set_role(GTK_WINDOW(a->window), "insert_link"); | |
708 gtk_dialog_set_response_sensitive(GTK_DIALOG(a->window), GTK_RESPONSE_OK, FALSE); | |
709 | |
710 hbox = gtk_hbox_new(FALSE, 12); | |
711 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), hbox); | |
712 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
713 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
714 | |
715 vbox = gtk_vbox_new(FALSE, 0); | |
716 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
717 | |
718 label = gtk_label_new(_("Please enter the URL and description of " | |
719 "the link that you want to insert. The " | |
720 "description is optional.\n")); | |
721 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
722 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
723 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
724 | |
725 table = gtk_table_new(2, 2, FALSE); | |
726 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | |
727 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | |
728 gtk_container_set_border_width(GTK_CONTAINER(table), 0); | |
729 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
730 | |
731 label = gtk_label_new_with_mnemonic(_("_URL:")); | |
732 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
733 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
734 | |
735 a->url = gtk_entry_new(); | |
736 gtk_table_attach_defaults(GTK_TABLE(table), a->url, 1, 2, 0, 1); | |
737 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->url)); | |
738 gaim_set_accessible_label (a->url, label); | |
739 gtk_widget_grab_focus(a->url); | |
740 | |
741 gtk_entry_set_activates_default (GTK_ENTRY(a->url), TRUE); | |
742 g_signal_connect(G_OBJECT(a->url), "changed", | |
743 G_CALLBACK(gaim_gtk_set_sensitive_if_input), a->window); | |
744 | |
745 label = gtk_label_new_with_mnemonic(_("_Description:")); | |
746 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
747 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
748 | |
749 a->text = gtk_entry_new(); | |
750 gtk_table_attach_defaults(GTK_TABLE(table), a->text, 1, 2, 1, 2); | |
751 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(a->text)); | |
752 gaim_set_accessible_label (a->text, label); | |
753 gtk_entry_set_activates_default (GTK_ENTRY(a->text), TRUE); | |
754 | |
755 gtkconv->dialogs.link = a->window; | |
756 | |
757 gtk_widget_show_all(gtkconv->dialogs.link); | |
758 gdk_window_raise(gtkconv->dialogs.link->window); | |
759 } | 566 } |
760 | 567 |
761 /*------------------------------------------------------*/ | 568 /*------------------------------------------------------*/ |
762 /* Color Selection Dialog */ | 569 /* Color Selection Dialog */ |
763 /*------------------------------------------------------*/ | 570 /*------------------------------------------------------*/ |