Mercurial > pidgin.yaz
comparison src/dialogs.c @ 8286:89d9d004e3f3
[gaim-migrate @ 9010]
Improved the field request API, adding required fields and account fields,
as well as some new utility API functions and bug fixes. These changes
allowed me to migrate the New IM dialog over to the field request API,
removing a lot of code and improving consistency.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 18 Feb 2004 07:22:53 +0000 |
parents | 82aeed3c90f0 |
children | 84ec38c3efcc |
comparison
equal
deleted
inserted
replaced
8285:d335cc7bca54 | 8286:89d9d004e3f3 |
---|---|
466 | 466 |
467 gtk_widget_show_all(window); | 467 gtk_widget_show_all(window); |
468 return TRUE; | 468 return TRUE; |
469 } | 469 } |
470 | 470 |
471 static void do_im(GtkWidget *dialog, int id, struct getuserinfo *info) | |
472 { | |
473 const char *who; | |
474 GaimConversation *conv; | |
475 GaimAccount *account; | |
476 | |
477 switch(id) { | |
478 case GTK_RESPONSE_OK: | |
479 who = gtk_entry_get_text(GTK_ENTRY(info->entry)); | |
480 | |
481 if (who && *who) { | |
482 account = (info->gc ? info->gc->account : NULL); | |
483 | |
484 conv = gaim_find_conversation_with_account(who, account); | |
485 | |
486 if (conv == NULL) | |
487 conv = gaim_conversation_new(GAIM_CONV_IM, account, who); | |
488 else | |
489 gaim_conv_window_raise(gaim_conversation_get_window(conv)); | |
490 } | |
491 | |
492 break; | |
493 } | |
494 | |
495 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
496 g_free(info); | |
497 } | |
498 | |
499 static void do_info(GtkWidget *dialog, int id, struct getuserinfo *info) | 471 static void do_info(GtkWidget *dialog, int id, struct getuserinfo *info) |
500 { | 472 { |
501 char *who; | 473 char *who; |
502 gboolean found = FALSE; | 474 gboolean found = FALSE; |
503 | 475 |
525 struct getuserinfo *info) | 497 struct getuserinfo *info) |
526 { | 498 { |
527 info->gc = gaim_account_get_connection(account); | 499 info->gc = gaim_account_get_connection(account); |
528 } | 500 } |
529 | 501 |
530 void show_im_dialog() | 502 static void |
531 { | 503 new_im_cb(gpointer data, GaimRequestFields *fields) |
532 GtkWidget *window, *hbox, *vbox; | 504 { |
533 GtkWidget *label; | 505 const char *username; |
534 GtkWidget *table; | 506 GaimAccount *account; |
535 GaimGtkBuddyList *gtkblist; | 507 GaimConversation *conv; |
536 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); | 508 |
537 struct getuserinfo *info = g_new0(struct getuserinfo, 1); | 509 username = gaim_request_fields_get_string(fields, "screenname"); |
538 | 510 account = gaim_request_fields_get_account(fields, "account"); |
539 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | 511 |
540 | 512 conv = gaim_find_conversation_with_account(username, account); |
541 info->gc = gaim_connections_get_all()->data; | 513 |
542 | 514 if (conv == NULL) |
543 window = gtk_dialog_new_with_buttons(_("New Instant Message"), gtkblist ? GTK_WINDOW(gtkblist->window) : NULL, 0, | 515 conv = gaim_conversation_new(GAIM_CONV_IM, account, username); |
544 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); | 516 else |
545 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK); | 517 gaim_conv_window_raise(gaim_conversation_get_window(conv)); |
546 gtk_container_set_border_width (GTK_CONTAINER(window), 6); | 518 } |
547 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | 519 |
548 gtk_dialog_set_has_separator(GTK_DIALOG(window), FALSE); | 520 void |
549 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(window)->vbox), 12); | 521 show_im_dialog(void) |
550 gtk_container_set_border_width (GTK_CONTAINER(GTK_DIALOG(window)->vbox), 6); | 522 { |
551 gtk_dialog_set_response_sensitive(GTK_DIALOG(window), GTK_RESPONSE_OK, FALSE); | 523 GaimRequestFields *fields; |
552 | 524 GaimRequestFieldGroup *group; |
553 hbox = gtk_hbox_new(FALSE, 12); | 525 GaimRequestField *field; |
554 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window)->vbox), hbox); | 526 |
555 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | 527 fields = gaim_request_fields_new(); |
556 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | 528 |
557 | 529 group = gaim_request_field_group_new(NULL); |
558 vbox = gtk_vbox_new(FALSE, 0); | 530 gaim_request_fields_add_group(fields, group); |
559 gtk_container_add(GTK_CONTAINER(hbox), vbox); | 531 |
560 | 532 field = gaim_request_field_string_new("screenname", _("_Screen name"), |
561 label = gtk_label_new(_("Please enter the screen name of the person you would like to IM.\n")); | 533 NULL, FALSE); |
562 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 534 gaim_request_field_set_required(field, TRUE); |
563 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 535 gaim_request_field_group_add_field(group, field); |
564 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 536 |
565 | 537 field = gaim_request_field_account_new("account", _("_Account"), NULL); |
566 table = gtk_table_new(2, 2, FALSE); | 538 gaim_request_field_set_visible(field, |
567 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | 539 (gaim_connections_get_all() != NULL && |
568 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | 540 gaim_connections_get_all()->next != NULL)); |
569 gtk_container_set_border_width(GTK_CONTAINER(table), 12); | 541 gaim_request_field_set_required(field, TRUE); |
570 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | 542 gaim_request_field_group_add_field(group, field); |
571 | 543 |
572 label = gtk_label_new(NULL); | 544 gaim_request_fields(gaim_get_blist(), _("New Instant Message"), |
573 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Screen Name:")); | 545 NULL, |
574 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 546 _("Please enter the screen name of the person you " |
575 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | 547 "would like to IM."), |
576 | 548 fields, |
577 info->entry = gtk_entry_new(); | 549 _("OK"), G_CALLBACK(new_im_cb), |
578 gtk_table_attach_defaults(GTK_TABLE(table), info->entry, 1, 2, 0, 1); | 550 _("Cancel"), NULL, |
579 gtk_entry_set_activates_default (GTK_ENTRY(info->entry), TRUE); | 551 NULL); |
580 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(info->entry)); | |
581 gaim_set_accessible_label (info->entry, label); | |
582 | |
583 g_signal_connect(G_OBJECT(info->entry), "changed", | |
584 G_CALLBACK(gaim_gtk_set_sensitive_if_input), window); | |
585 | |
586 if (gaim_connections_get_all()->next) { | |
587 | |
588 label = gtk_label_new(NULL); | |
589 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
590 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); | |
591 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
592 | |
593 info->account = gaim_gtk_account_option_menu_new(NULL, FALSE, | |
594 G_CALLBACK(show_info_select_account), NULL, info); | |
595 | |
596 gtk_table_attach_defaults(GTK_TABLE(table), info->account, 1, 2, 1, 2); | |
597 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(info->account)); | |
598 gaim_set_accessible_label (info->account, label); | |
599 } | |
600 | |
601 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_im), info); | |
602 | |
603 gtk_widget_show_all(window); | |
604 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); | |
605 } | 552 } |
606 | 553 |
607 void show_info_dialog() | 554 void show_info_dialog() |
608 { | 555 { |
609 GtkWidget *window, *hbox, *vbox; | 556 GtkWidget *window, *hbox, *vbox; |