comparison src/prpl.c @ 3730:a20bf3d247ff

[gaim-migrate @ 3868] Pretty do_ask_dialog. I also "fixed" the "hitting yes calls the 'no' function anyway" behavior. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 17 Oct 2002 21:29:53 +0000
parents e941bfbacf7c
children 6767b4b1ce31
comparison
equal deleted inserted replaced
3729:a8f0c169e529 3730:a20bf3d247ff
135 if (d) 135 if (d)
136 gtk_signal_disconnect_by_data(GTK_OBJECT(b), d); 136 gtk_signal_disconnect_by_data(GTK_OBJECT(b), d);
137 gtk_widget_destroy(b); 137 gtk_widget_destroy(b);
138 } 138 }
139 139
140 void do_ask_dialog(const char *text, void *data, void *doit, void *dont) 140 struct doaskstruct {
141 void (*yesfunc)(gpointer);
142 void (*nofunc)(gpointer);
143 gpointer data;
144 };
145
146 static void do_ask_callback(GtkDialog *d, gint resp, struct doaskstruct *doask)
147 {
148 switch (resp)
149 {
150 case GTK_RESPONSE_YES:
151 if (doask->yesfunc)
152 doask->yesfunc(doask->data);
153 break;
154 case GTK_RESPONSE_NO:
155 case GTK_RESPONSE_DELETE_EVENT:
156 if (doask->nofunc)
157 doask->nofunc(doask->data);
158 break;
159 }
160 g_free(doask);
161 }
162
163
164 void do_ask_dialog(const char *prim, const char *sec, void *data, char *yestext, void *doit, char *notext, void *dont)
141 { 165 {
142 GtkWidget *window; 166 GtkWidget *window;
143 GtkWidget *vbox; 167 GtkWidget *hbox;
144 GtkWidget *label; 168 GtkWidget *label;
145 GtkWidget *hbox; 169 char labeltext[1024 * 2];
146 GtkWidget *button; 170 char filename = g_build_filename(DATADIR, "pixmaps", "gaim", "dialogs", "gaim_question.png", NULL);
147 171 GtkWidget *img = gtk_image_new_from_file(filename);
148 GAIM_DIALOG(window); 172 struct doaskstruct *doask = g_new0(struct doaskstruct, 1);
149 gtk_window_set_wmclass(GTK_WINDOW(window), "accept", "Gaim"); 173
150 gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); 174 doask->yesfunc = doit;
151 gtk_window_set_title(GTK_WINDOW(window), _("Accept?")); 175 doask->nofunc = dont;
152 gtk_widget_realize(window); 176 doask->data = data;
153 if (dont) 177
154 gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(dont), data); 178 g_free(filename);
155 179 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
156 vbox = gtk_vbox_new(FALSE, 5); 180
157 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); 181 window = gtk_dialog_new_with_buttons("", NULL, GTK_DIALOG_MODAL, yestext, GTK_RESPONSE_YES, notext, GTK_RESPONSE_NO, NULL);
158 gtk_container_add(GTK_CONTAINER(window), vbox); 182 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_YES);
159 183 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_ask_callback), doask);
160 label = gtk_label_new(text); 184
161 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); 185 gtk_container_set_border_width (GTK_CONTAINER(window), 6);
186 gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
187 gtk_dialog_set_has_separator(GTK_DIALOG(window), FALSE);
188 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(window)->vbox), 12);
189 gtk_container_set_border_width (GTK_CONTAINER(GTK_DIALOG(window)->vbox), 6);
190
191 hbox = gtk_hbox_new(FALSE, 12);
192 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window)->vbox), hbox);
193 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
194
195 g_snprintf(labeltext, sizeof(labeltext), "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", prim, sec ? sec : "");
196 label = gtk_label_new(NULL);
197 gtk_label_set_markup(GTK_LABEL(label), labeltext);
162 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 198 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
163 199 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
164 hbox = gtk_hbox_new(FALSE, 5); 200 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
165 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 201
166
167 button = picture_button(window, _("Cancel"), cancel_xpm);
168 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
169 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(des_win), window);
170
171 button = picture_button(window, _("Accept"), ok_xpm);
172 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
173 if (dont)
174 gtk_object_set_user_data(GTK_OBJECT(button), data);
175 if (doit)
176 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(doit), data);
177 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(rem_win), window);
178
179 gtk_widget_show_all(window); 202 gtk_widget_show_all(window);
180 } 203 }
181 204
182 static void des_prompt(GtkWidget *w, struct _prompt *p) 205 static void des_prompt(GtkWidget *w, struct _prompt *p)
183 { 206 {
560 struct gaim_connection *gc; 583 struct gaim_connection *gc;
561 char *who; 584 char *who;
562 char *alias; 585 char *alias;
563 }; 586 };
564 587
565 static void dont_add(gpointer x, struct got_add *ga) 588 static void dont_add(struct got_add *ga)
566 { 589 {
567 g_free(ga->who); 590 g_free(ga->who);
568 if (ga->alias) 591 if (ga->alias)
569 g_free(ga->alias); 592 g_free(ga->alias);
570 g_free(ga); 593 g_free(ga);
571 } 594 }
572 595
573 static void do_add(gpointer x, struct got_add *ga) 596 static void do_add(struct got_add *ga)
574 { 597 {
575 if (g_slist_find(connections, ga->gc)) 598 if (g_slist_find(connections, ga->gc))
576 show_add_buddy(ga->gc, ga->who, NULL, ga->alias); 599 show_add_buddy(ga->gc, ga->who, NULL, ga->alias);
600 dont_add(ga);
577 } 601 }
578 602
579 void show_got_added(struct gaim_connection *gc, const char *id, 603 void show_got_added(struct gaim_connection *gc, const char *id,
580 const char *who, const char *alias, const char *msg) 604 const char *who, const char *alias, const char *msg)
581 { 605 {
596 msg ? msg : "", 620 msg ? msg : "",
597 find_buddy(gc, ga->who) ? "" : _("\n\nDo you wish to add him or her to your buddy list?")); 621 find_buddy(gc, ga->who) ? "" : _("\n\nDo you wish to add him or her to your buddy list?"));
598 if (find_buddy(gc, ga->who)) 622 if (find_buddy(gc, ga->who))
599 do_error_dialog(buf, NULL, GAIM_INFO); 623 do_error_dialog(buf, NULL, GAIM_INFO);
600 else 624 else
601 do_ask_dialog(buf, ga, do_add, dont_add); 625 do_ask_dialog(buf, NULL, ga, _("Add"), do_add, _("Cancel"), dont_add);
602 } 626 }
603 627
604 static GtkWidget *regdlg = NULL; 628 static GtkWidget *regdlg = NULL;
605 static GtkWidget *reg_list = NULL; 629 static GtkWidget *reg_list = NULL;
606 static GtkWidget *reg_area = NULL; 630 static GtkWidget *reg_area = NULL;