comparison src/dialogs.c @ 6327:493eed80869c

[gaim-migrate @ 6826] I like what KingAnt did earlier. I didn't think about using the core request API for our normal, tiny little input dialogs and such. Now the Alias Buddy dialog uses our multi-field request API. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 29 Jul 2003 05:56:15 +0000
parents dd2be7cd66df
children cbe2f320c214
comparison
equal deleted inserted replaced
6326:f6480d79cb89 6327:493eed80869c
46 static GtkWidget *imdialog = NULL; /*I only want ONE of these :) */ 46 static GtkWidget *imdialog = NULL; /*I only want ONE of these :) */
47 static GList *dialogwindows = NULL; 47 static GList *dialogwindows = NULL;
48 static GtkWidget *importdialog; 48 static GtkWidget *importdialog;
49 static GaimConnection *importgc; 49 static GaimConnection *importgc;
50 static GtkWidget *icondlg; 50 static GtkWidget *icondlg;
51 static GtkWidget *alias_dialog = NULL;
52 static GtkWidget *rename_dialog = NULL; 51 static GtkWidget *rename_dialog = NULL;
53 static GtkWidget *fontseld = NULL; 52 static GtkWidget *fontseld = NULL;
54 53
55 54
56 struct confirm_del { 55 struct confirm_del {
120 struct getuserinfo { 119 struct getuserinfo {
121 GtkWidget *window; 120 GtkWidget *window;
122 GtkWidget *entry; 121 GtkWidget *entry;
123 GtkWidget *account; 122 GtkWidget *account;
124 GaimConnection *gc; 123 GaimConnection *gc;
125 };
126
127 struct alias_dialog_info
128 {
129 GtkWidget *window;
130 GtkWidget *name_entry;
131 GtkWidget *alias_entry;
132 struct buddy *buddy;
133 }; 124 };
134 125
135 static GSList *info_dlgs = NULL; 126 static GSList *info_dlgs = NULL;
136 127
137 static struct info_dlg *find_info_dlg(GaimConnection *gc, const char *who) 128 static struct info_dlg *find_info_dlg(GaimConnection *gc, const char *who)
3606 gaim_blist_save(); 3597 gaim_blist_save();
3607 } 3598 }
3608 gtk_widget_destroy(w); 3599 gtk_widget_destroy(w);
3609 } 3600 }
3610 3601
3611 static void
3612 do_alias_buddy(GtkWidget *w, int resp, struct alias_dialog_info *info)
3613 {
3614 if (resp == GTK_RESPONSE_OK) {
3615 const char *alias;
3616
3617 alias = gtk_entry_get_text(GTK_ENTRY(info->alias_entry));
3618
3619 gaim_blist_alias_buddy(info->buddy, (alias && *alias) ? alias : NULL);
3620 serv_alias_buddy(info->buddy);
3621 gaim_blist_save();
3622 }
3623
3624 destroy_dialog(NULL, alias_dialog);
3625 alias_dialog = NULL;
3626
3627 g_free(info);
3628 }
3629
3630 void alias_dialog_chat(struct chat *chat) { 3602 void alias_dialog_chat(struct chat *chat) {
3631 GtkWidget *dialog; 3603 GtkWidget *dialog;
3632 GtkWidget *hbox; 3604 GtkWidget *hbox;
3633 GtkWidget *img; 3605 GtkWidget *img;
3634 GtkWidget *vbox; 3606 GtkWidget *vbox;
3694 G_CALLBACK(do_alias_chat), chat); 3666 G_CALLBACK(do_alias_chat), chat);
3695 3667
3696 gtk_widget_show_all(dialog); 3668 gtk_widget_show_all(dialog);
3697 } 3669 }
3698 3670
3671 static void
3672 alias_buddy_cb(struct buddy *buddy, GaimRequestFields *fields)
3673 {
3674 const char *alias;
3675
3676 alias = gaim_request_fields_get_string(fields, "alias");
3677
3678 gaim_blist_alias_buddy(buddy,
3679 (alias != NULL && *alias != '\0') ? alias : NULL);
3680 serv_alias_buddy(buddy);
3681 gaim_blist_save();
3682 }
3683
3699 void 3684 void
3700 alias_dialog_bud(struct buddy *b) 3685 alias_dialog_bud(struct buddy *b)
3701 { 3686 {
3702 struct alias_dialog_info *info = NULL; 3687 GaimRequestFields *fields;
3703 struct gaim_gtk_buddy_list *gtkblist; 3688 GaimRequestFieldGroup *group;
3704 GtkWidget *hbox; 3689 GaimRequestField *field;
3705 GtkWidget *vbox; 3690
3706 GtkWidget *label; 3691 fields = gaim_request_fields_new();
3707 GtkWidget *table; 3692
3708 GtkWidget *img; 3693 group = gaim_request_field_group_new(NULL);
3709 3694 gaim_request_fields_add_group(fields, group);
3710 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); 3695
3711 3696 field = gaim_request_field_string_new("screenname", _("_Screenname"),
3712 if (!alias_dialog) { 3697 b->name, FALSE);
3713 info = g_new0(struct alias_dialog_info, 1); 3698 gaim_request_field_group_add_field(group, field);
3714 info->buddy = b; 3699
3715 3700 field = gaim_request_field_string_new("alias", _("_Alias"),
3716 alias_dialog = gtk_dialog_new_with_buttons(_("Alias Buddy"), 3701 b->alias, FALSE);
3717 (gtkblist ? GTK_WINDOW(gtkblist->window) : NULL), 3702 gaim_request_field_group_add_field(group, field);
3718 GTK_DIALOG_NO_SEPARATOR, 3703
3719 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 3704 gaim_request_fields(NULL, _("Alias Buddy"),
3720 GTK_STOCK_OK, GTK_RESPONSE_OK, 3705 _("Alias buddy"),
3721 NULL); 3706 _("Please enter an aliased name for the person "
3722 3707 "below, or rename this contact in your buddy list."),
3723 gtk_dialog_set_default_response(GTK_DIALOG(alias_dialog), 3708 fields,
3724 GTK_RESPONSE_OK); 3709 _("OK"), G_CALLBACK(alias_buddy_cb),
3725 gtk_container_set_border_width(GTK_CONTAINER(alias_dialog), 6); 3710 _("Cancel"), NULL,
3726 gtk_window_set_resizable(GTK_WINDOW(alias_dialog), FALSE); 3711 b);
3727 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(alias_dialog)->vbox), 12); 3712 }
3728 gtk_container_set_border_width(
3729 GTK_CONTAINER(GTK_DIALOG(alias_dialog)->vbox), 6);
3730
3731 /* The main hbox container. */
3732 hbox = gtk_hbox_new(FALSE, 12);
3733 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(alias_dialog)->vbox), hbox);
3734
3735 /* The dialog image. */
3736 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
3737 GTK_ICON_SIZE_DIALOG);
3738 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
3739 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
3740
3741 /* The main vbox container. */
3742 vbox = gtk_vbox_new(FALSE, 0);
3743 gtk_container_add(GTK_CONTAINER(hbox), vbox);
3744
3745 /* Setup the label containing the description. */
3746 label = gtk_label_new(_("Please enter an aliased name for the "
3747 "person below, or rename this contact "
3748 "in your buddy list.\n"));
3749 gtk_widget_set_size_request(GTK_WIDGET(label), 350, -1);
3750
3751 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
3752 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
3753 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
3754
3755 hbox = gtk_hbox_new(FALSE, 6);
3756 gtk_container_add(GTK_CONTAINER(vbox), hbox);
3757
3758 /* The table containing the entry widgets and labels. */
3759 table = gtk_table_new(2, 2, FALSE);
3760 gtk_table_set_row_spacings(GTK_TABLE(table), 6);
3761 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
3762 gtk_container_set_border_width(GTK_CONTAINER(table), 12);
3763 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3764
3765 /* The "Screenname:" label. */
3766 label = gtk_label_new(NULL);
3767 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Screenname:"));
3768 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
3769 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
3770
3771 /* The Screen name entry field. */
3772 info->name_entry = gtk_entry_new();
3773 gtk_table_attach_defaults(GTK_TABLE(table), info->name_entry,
3774 1, 2, 0, 1);
3775 gtk_entry_set_activates_default(GTK_ENTRY(info->name_entry), TRUE);
3776 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->name_entry);
3777 gtk_entry_set_text(GTK_ENTRY(info->name_entry), info->buddy->name);
3778 gtk_editable_set_editable(GTK_EDITABLE(info->name_entry), FALSE);
3779
3780 /* The "Alias:" label. */
3781 label = gtk_label_new(NULL);
3782 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Alias:"));
3783 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
3784 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
3785
3786 /* The alias entry field. */
3787 info->alias_entry = gtk_entry_new();
3788 gtk_table_attach_defaults(GTK_TABLE(table), info->alias_entry,
3789 1, 2, 1, 2);
3790 gtk_entry_set_activates_default(GTK_ENTRY(info->alias_entry), TRUE);
3791 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->alias_entry);
3792
3793 if (info->buddy->alias != NULL)
3794 gtk_entry_set_text(GTK_ENTRY(info->alias_entry),
3795 info->buddy->alias);
3796
3797 g_signal_connect(G_OBJECT(alias_dialog), "response",
3798 G_CALLBACK(do_alias_buddy), info);
3799 }
3800
3801 gtk_widget_show_all(alias_dialog);
3802
3803 if (info)
3804 gtk_widget_grab_focus(info->alias_entry);
3805 }
3806
3807 3713
3808 static gboolean dont_destroy(gpointer a, gpointer b, gpointer c) 3714 static gboolean dont_destroy(gpointer a, gpointer b, gpointer c)
3809 { 3715 {
3810 return TRUE; 3716 return TRUE;
3811 } 3717 }