Mercurial > pidgin
comparison src/gtkrequest.c @ 10229:9aa0b6d11bbf
[gaim-migrate @ 11364]
This is a heavily warmenhoved patch from Alceste Scalas. Here's what it
changes:
If the user drags an image file into the buddy list or conversation, it
presents three options (when applicable):
Set as buddy icon - sets this image to be the buddy icon for this buddy
Send image file - Initiates a file transfer to send this image.
Insert in message - Inserts in the gtkimhtml for use as an IM image.
If the user drags a .desktop web link, it will insert a hyperlink in the
conversation. All other types of .desktop files fail with an error dialog.
If anyone can think of better ways to handle any of them, let me know.
This also happens to implement gaim_request_choice, which had previously
been unimplemented.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 22 Nov 2004 02:57:34 +0000 |
parents | ecf3ce2e2ab1 |
children | e8d62dc363c5 |
comparison
equal
deleted
inserted
replaced
10228:37c411c8cde3 | 10229:9aa0b6d11bbf |
---|---|
42 typedef struct | 42 typedef struct |
43 { | 43 { |
44 GaimRequestType type; | 44 GaimRequestType type; |
45 | 45 |
46 void *user_data; | 46 void *user_data; |
47 GtkWidget *dialog; | 47 GtkWidget *dialog; |
48 | 48 |
49 GtkWidget *ok_button; | 49 GtkWidget *ok_button; |
50 | 50 |
51 size_t cb_count; | 51 size_t cb_count; |
52 GCallback *cbs; | 52 GCallback *cbs; |
129 action_response_cb(GtkDialog *dialog, gint id, GaimGtkRequestData *data) | 129 action_response_cb(GtkDialog *dialog, gint id, GaimGtkRequestData *data) |
130 { | 130 { |
131 if (id < data->cb_count && data->cbs[id] != NULL) | 131 if (id < data->cb_count && data->cbs[id] != NULL) |
132 ((GaimRequestActionCb)data->cbs[id])(data->user_data, id); | 132 ((GaimRequestActionCb)data->cbs[id])(data->user_data, id); |
133 | 133 |
134 gaim_request_close(GAIM_REQUEST_INPUT, data); | |
135 } | |
136 | |
137 | |
138 static void | |
139 choice_response_cb(GtkDialog *dialog, gint id, GaimGtkRequestData *data) | |
140 { | |
141 GtkWidget *radio = g_object_get_data(G_OBJECT(dialog), "radio"); | |
142 GSList *group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)); | |
143 if (id < data->cb_count) | |
144 while (group) { | |
145 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(group->data))) { | |
146 ((GaimRequestChoiceCb)data->cbs[id])(data->user_data, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(group->data), "choice_id"))); | |
147 break; | |
148 } | |
149 group = group->next; | |
150 } | |
134 gaim_request_close(GAIM_REQUEST_INPUT, data); | 151 gaim_request_close(GAIM_REQUEST_INPUT, data); |
135 } | 152 } |
136 | 153 |
137 static gboolean | 154 static gboolean |
138 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, | 155 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, |
402 return data; | 419 return data; |
403 } | 420 } |
404 | 421 |
405 static void * | 422 static void * |
406 gaim_gtk_request_choice(const char *title, const char *primary, | 423 gaim_gtk_request_choice(const char *title, const char *primary, |
407 const char *secondary, unsigned int default_value, | 424 const char *secondary, unsigned int default_value, |
408 const char *ok_text, GCallback ok_cb, | 425 const char *ok_text, GCallback ok_cb, |
409 const char *cancel_text, GCallback cancel_cb, | 426 const char *cancel_text, GCallback cancel_cb, |
410 void *user_data, size_t choice_count, va_list args) | 427 void *user_data, va_list args) |
411 { | 428 { |
412 return NULL; | 429 GaimGtkRequestData *data; |
430 GtkWidget *dialog; | |
431 GtkWidget *vbox, *vbox2; | |
432 GtkWidget *hbox; | |
433 GtkWidget *label; | |
434 GtkWidget *img; | |
435 GtkWidget *radio = NULL; | |
436 char *label_text; | |
437 char *radio_text; | |
438 | |
439 data = g_new0(GaimGtkRequestData, 1); | |
440 data->type = GAIM_REQUEST_ACTION; | |
441 data->user_data = user_data; | |
442 | |
443 data->cb_count = 2; | |
444 data->cbs = g_new0(GCallback, 2); | |
445 data->cbs[0] = cancel_cb; | |
446 data->cbs[1] = ok_cb; | |
447 | |
448 /* Create the dialog. */ | |
449 data->dialog = dialog = gtk_dialog_new(); | |
450 | |
451 if (title != NULL) | |
452 gtk_window_set_title(GTK_WINDOW(dialog), title); | |
453 | |
454 | |
455 gtk_dialog_add_button(GTK_DIALOG(dialog), | |
456 text_to_stock(cancel_text), 0); | |
457 | |
458 gtk_dialog_add_button(GTK_DIALOG(dialog), | |
459 text_to_stock(ok_text), 1); | |
460 | |
461 g_signal_connect(G_OBJECT(dialog), "response", | |
462 G_CALLBACK(choice_response_cb), data); | |
463 | |
464 /* Setup the dialog */ | |
465 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); | |
466 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
467 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
468 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); | |
469 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); | |
470 | |
471 /* Setup the main horizontal box */ | |
472 hbox = gtk_hbox_new(FALSE, 12); | |
473 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); | |
474 | |
475 /* Dialog icon. */ | |
476 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
477 GTK_ICON_SIZE_DIALOG); | |
478 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
479 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
480 | |
481 /* Vertical box */ | |
482 vbox = gtk_vbox_new(FALSE, 12); | |
483 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
484 | |
485 /* Descriptive label */ | |
486 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" | |
487 "%s</span>%s%s" : "%s%s%s"), | |
488 (primary ? primary : ""), | |
489 ((primary && secondary) ? "\n\n" : ""), | |
490 (secondary ? secondary : "")); | |
491 | |
492 label = gtk_label_new(NULL); | |
493 | |
494 gtk_label_set_markup(GTK_LABEL(label), label_text); | |
495 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
496 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
497 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | |
498 | |
499 g_free(label_text); | |
500 | |
501 vbox2 = gtk_vbox_new(FALSE, 6); | |
502 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0); | |
503 while ((radio_text = va_arg(args, char*))) { | |
504 int resp = va_arg(args, int); | |
505 radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), radio_text); | |
506 gtk_box_pack_start(GTK_BOX(vbox2), radio, FALSE, FALSE, 0); | |
507 g_object_set_data(G_OBJECT(radio), "choice_id", GINT_TO_POINTER(resp)); | |
508 if (resp == default_value) | |
509 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); | |
510 } | |
511 | |
512 g_object_set_data(G_OBJECT(dialog), "radio", radio); | |
513 | |
514 /* Show everything. */ | |
515 gtk_widget_show_all(dialog); | |
516 | |
517 return data; | |
413 } | 518 } |
414 | 519 |
415 static void * | 520 static void * |
416 gaim_gtk_request_action(const char *title, const char *primary, | 521 gaim_gtk_request_action(const char *title, const char *primary, |
417 const char *secondary, unsigned int default_action, | 522 const char *secondary, unsigned int default_action, |