# HG changeset patch # User Christian Hammond # Date 1053650900 0 # Node ID b7c0be69c749370af6253f5a035641a96c4ef14e # Parent 5b678994929b5b4bacf6324918ddb9e22a8d79c1 [gaim-migrate @ 5892] do_ask_dialog() will soon go the way of the something that goes away a lot. committer: Tailor Script diff -r 5b678994929b -r b7c0be69c749 src/gtkrequest.c --- a/src/gtkrequest.c Thu May 22 23:59:01 2003 +0000 +++ b/src/gtkrequest.c Fri May 23 00:48:20 2003 +0000 @@ -77,6 +77,15 @@ gaim_request_close(GAIM_REQUEST_INPUT, data); } +static void +__action_response_cb(GtkDialog *dialog, gint id, GaimRequestData *data) +{ + if (id < data->cb_count && data->cbs[id] != NULL) + ((GaimRequestActionCb)data->cbs[id])(id, data->user_data); + + gaim_request_close(GAIM_REQUEST_INPUT, data); +} + #define STOCK_ITEMIZE(r, l) \ if (!strcmp((r), text)) \ return (l); @@ -124,13 +133,6 @@ data->cbs[0] = ok_cb; data->cbs[1] = cancel_cb; -#if 0 - data->dialog = dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); - gtk_window_set_role(GTK_WINDOW(dialog), "input"); - gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); -#endif - /* Create the dialog. */ dialog = gtk_dialog_new_with_buttons("", NULL, 0, __text_to_stock(cancel_text), 1, @@ -227,7 +229,7 @@ const char *secondary, unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, va_list args) + void *user_data, size_t choice_count, va_list args) { return NULL; } @@ -235,9 +237,91 @@ void * gaim_gtk_request_action(const char *title, const char *primary, const char *secondary, unsigned int default_action, - void *user_data, va_list actions) + void *user_data, size_t action_count, va_list actions) { - return NULL; + GaimRequestData *data; + GtkWidget *dialog; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *img; + void **buttons; + char *label_text; + int i; + + data = g_new0(GaimRequestData, 1); + data->type = GAIM_REQUEST_ACTION; + data->user_data = user_data; + + data->cb_count = action_count; + data->cbs = g_new0(GCallback, action_count); + + /* Reverse the buttons */ + buttons = g_new0(void *, action_count * 2); + + for (i = 0; i < action_count * 2; i += 2) { + buttons[(action_count * 2) - i - 2] = va_arg(actions, char *); + buttons[(action_count * 2) - i - 1] = va_arg(actions, GCallback); + } + + /* Create the dialog. */ + data->dialog = dialog = gtk_dialog_new(); + + for (i = 0; i < action_count; i++) { + gaim_debug(GAIM_DEBUG_MISC, "gtkrequest", + "buttons[2 * %d] = '%s'\n", + i, buttons[2 * i]); + gtk_dialog_add_button(GTK_DIALOG(dialog), + __text_to_stock(buttons[2 * i]), i); + + data->cbs[i] = buttons[2 * i + 1]; + } + + g_free(buttons); + + g_signal_connect(G_OBJECT(dialog), "response", + G_CALLBACK(__action_response_cb), data); + + /* Setup the dialog */ + gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); + gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); + + /* Setup the main horizontal box */ + hbox = gtk_hbox_new(FALSE, 12); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); + + /* Dialog icon. */ + img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, + GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(img), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); + + /* Vertical box */ + vbox = gtk_vbox_new(FALSE, 12); + + gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); + + /* Descriptive label */ + label_text = g_strdup_printf("" + "%s\n\n%s", + primary, (secondary ? secondary : "")); + + label = gtk_label_new(NULL); + + gtk_label_set_markup(GTK_LABEL(label), label_text); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); + + g_free(label_text); + + /* Show everything. */ + gtk_widget_show_all(dialog); + + return data; } void diff -r 5b678994929b -r b7c0be69c749 src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Thu May 22 23:59:01 2003 +0000 +++ b/src/protocols/msn/msn.c Fri May 23 00:48:20 2003 +0000 @@ -112,13 +112,13 @@ } static void -__enable_msn_pages_cb(struct gaim_connection *gc, const char *entry) +__enable_msn_pages_cb(int id, struct gaim_connection *gc) { msn_set_prp(gc, "MOB", "Y"); } static void -__disable_msn_pages_cb(struct gaim_connection *gc, const char *entry) +__disable_msn_pages_cb(int id, struct gaim_connection *gc) { msn_set_prp(gc, "MOB", "N"); } @@ -224,15 +224,13 @@ static void msn_show_set_mobile_pages(struct gaim_connection *gc) { - MsnSession *session = gc->proto_data; - - do_ask_dialog(_("MSN Mobile Pages"), - _("Do you want to allow or disallow people on your buddy " - "list to send you mobile pages?"), - gc, - _("Allow"), __enable_msn_pages_cb, - _("Disallow"), __disable_msn_pages_cb, - session->prpl->handle, FALSE); + gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"), + _("Do you want to allow or disallow people on " + "your buddy list to send you MSN Mobile pages " + "to your cell phone or other mobile device?"), + -1, gc, 2, + _("Allow"), G_CALLBACK(__enable_msn_pages_cb), + _("Disallow"), G_CALLBACK(__disable_msn_pages_cb)); } static void diff -r 5b678994929b -r b7c0be69c749 src/prpl.c --- a/src/prpl.c Thu May 22 23:59:01 2003 +0000 +++ b/src/prpl.c Fri May 23 00:48:20 2003 +0000 @@ -66,11 +66,6 @@ return NULL; } -static void des_win(GtkWidget *a, GtkWidget *b) -{ - gtk_widget_destroy(b); -} - static GSList *do_ask_dialogs = NULL; struct doaskstruct { diff -r 5b678994929b -r b7c0be69c749 src/request.c --- a/src/request.c Thu May 22 23:59:01 2003 +0000 +++ b/src/request.c Fri May 23 00:48:20 2003 +0000 @@ -75,21 +75,21 @@ const char *secondary, unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, const char *choice, ...) + void *user_data, size_t choice_count, ...) { void *ui_handle; va_list args; - g_return_val_if_fail(primary != NULL, NULL); - g_return_val_if_fail(ok_text != NULL, NULL); - g_return_val_if_fail(ok_cb != NULL, NULL); - g_return_val_if_fail(choice != NULL, NULL); + g_return_val_if_fail(primary != NULL, NULL); + g_return_val_if_fail(ok_text != NULL, NULL); + g_return_val_if_fail(ok_cb != NULL, NULL); + g_return_val_if_fail(choice_count > 0, NULL); - va_start(args, choice); + va_start(args, choice_count); ui_handle = gaim_request_choice_varg(handle, title, primary, secondary, default_value, ok_text, ok_cb, cancel_text, cancel_cb, user_data, - args); + choice_count, args); va_end(args); return ui_handle; @@ -101,17 +101,19 @@ unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, va_list choices) + void *user_data, size_t choice_count, + va_list choices) { GaimRequestUiOps *ops; - g_return_val_if_fail(primary != NULL, NULL); - g_return_val_if_fail(ok_text != NULL, NULL); - g_return_val_if_fail(ok_cb != NULL, NULL); + g_return_val_if_fail(primary != NULL, NULL); + g_return_val_if_fail(ok_text != NULL, NULL); + g_return_val_if_fail(ok_cb != NULL, NULL); + g_return_val_if_fail(choice_count > 0, NULL); ops = gaim_get_request_ui_ops(); - if (ops != NULL && ops->request_input != NULL) { + if (ops != NULL && ops->request_choice != NULL) { GaimRequestInfo *info; info = g_new0(GaimRequestInfo, 1); @@ -121,7 +123,8 @@ default_value, ok_text, ok_cb, cancel_text, cancel_cb, - user_data, choices); + user_data, choice_count, + choices); handles = g_list_append(handles, info); @@ -134,17 +137,18 @@ void * gaim_request_action(void *handle, const char *title, const char *primary, const char *secondary, unsigned int default_action, - void *user_data, const char *action, ...) + void *user_data, size_t action_count, ...) { void *ui_handle; va_list args; - g_return_val_if_fail(primary != NULL, NULL); - g_return_val_if_fail(action != NULL, NULL); + g_return_val_if_fail(primary != NULL, NULL); + g_return_val_if_fail(action_count > 0, NULL); - va_start(args, action); + va_start(args, action_count); ui_handle = gaim_request_action_varg(handle, title, primary, secondary, - default_action, user_data, args); + default_action, user_data, + action_count, args); va_end(args); return ui_handle; @@ -154,15 +158,16 @@ gaim_request_action_varg(void *handle, const char *title, const char *primary, const char *secondary, unsigned int default_action, void *user_data, - va_list actions) + size_t action_count, va_list actions) { GaimRequestUiOps *ops; - g_return_val_if_fail(primary != NULL, NULL); + g_return_val_if_fail(primary != NULL, NULL); + g_return_val_if_fail(action_count > 0, NULL); ops = gaim_get_request_ui_ops(); - if (ops != NULL && ops->request_input != NULL) { + if (ops != NULL && ops->request_action != NULL) { GaimRequestInfo *info; info = g_new0(GaimRequestInfo, 1); @@ -170,7 +175,7 @@ info->handle = handle; info->ui_handle = ops->request_action(title, primary, secondary, default_action, user_data, - actions); + action_count, actions); handles = g_list_append(handles, info); diff -r 5b678994929b -r b7c0be69c749 src/request.h --- a/src/request.h Thu May 22 23:59:01 2003 +0000 +++ b/src/request.h Fri May 23 00:48:20 2003 +0000 @@ -53,16 +53,19 @@ const char *secondary, unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, va_list args); + void *user_data, size_t choice_count, + va_list choices); void *(*request_action)(const char *title, const char *primary, const char *secondary, unsigned int default_action, - void *user_data, va_list actions); + void *user_data, size_t action_count, + va_list actions); void (*close_request)(GaimRequestType type, void *ui_handle); } GaimRequestUiOps; typedef void (*GaimRequestInputCb)(const char *, void *); +typedef void (*GaimRequestActionCb)(int, void *); /**************************************************************************/ /** @name Request API */ @@ -106,6 +109,7 @@ * @param cancel_text The text for the cancel button. * @param cancel_cb The callback for the cancel button. * @param user_data The data to pass to the callback. + * @param choice_count The number of choices. * @param choice The choices. * * @return A UI-specific handle. @@ -115,8 +119,7 @@ unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, - const char *choice, ...); + void *user_data, size_t choice_count, ...); /** * Prompts the user for multiple-choice input. @@ -131,6 +134,7 @@ * @param cancel_text The text for the cancel button. * @param cancel_cb The callback for the cancel button. * @param user_data The data to pass to the callback. + * @param choice_count The number of choices. * @param choices The choices. * * @return A UI-specific handle. @@ -140,7 +144,8 @@ unsigned int default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, - void *user_data, va_list choices); + void *user_data, size_t choice_count, + va_list choices); /** * Prompts the user for an action. @@ -153,6 +158,7 @@ * @param secondary The secondary information. * @param default_action The default value. * @param user_data The data to pass to the callback. + * @param action_count The number of actions. * @param action The first action. * * @return A UI-specific handle. @@ -160,7 +166,7 @@ void *gaim_request_action(void *handle, const char *title, const char *primary, const char *secondary, unsigned int default_action, - void *user_data, const char *action, ...); + void *user_data, size_t action_count, ...); /** * Prompts the user for an action. @@ -173,6 +179,7 @@ * @param secondary The secondary information. * @param default_action The default value. * @param user_data The data to pass to the callback. + * @param action_count The number of actions. * @param actions A list of actions and callbacks. * * @return A UI-specific handle. @@ -180,7 +187,8 @@ void *gaim_request_action_varg(void *handle, const char *title, const char *primary, const char *secondary, unsigned int default_action, - void *user_data, va_list actions); + void *user_data, size_t action_count, + va_list actions); /** * Closes a request.