# HG changeset patch
# Node ID 477bec0f3fbc
# Parent  bd6b5ad6017c
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -39,13 +39,11 @@ typedef struct {
 	GtkWidget *dialog;
 	GCancellable *cancellable;
 
-	GtkWidget *ok_button;
-
 	PurpleRequestHelpCb help_cb;
 	gpointer help_data;
 
-	size_t cb_count;
-	GCallback *cbs;
+	GPtrArray *action_widgets;
+	GPtrArray *action_cbs;
 } PidginRequestData;
 
 static void
@@ -93,22 +91,15 @@ field_account_cb(GObject *obj, G_GNUC_UN
 }
 
 static void
-multifield_response_cb(G_GNUC_UNUSED GtkDialog *dialog, gint response,
-                       gpointer data)
-{
+multifield_response_cb(GtkButton *button, gpointer data) {
 	PidginRequestData *req_data = data;
 	PurpleRequestFieldsCb cb = NULL;
+	guint index = 0;
 
 	gtk_widget_set_visible(GTK_WIDGET(req_data->dialog), FALSE);
 
-	if(response == GTK_RESPONSE_OK) {
-		cb = (PurpleRequestFieldsCb)req_data->cbs[0];
-	} else if(response == GTK_RESPONSE_CANCEL ||
-	          response == GTK_RESPONSE_DELETE_EVENT)
-	{
-		cb = (PurpleRequestFieldsCb)req_data->cbs[1];
-	} else if(2 <= response && (gsize)response < req_data->cb_count) {
-		cb = (PurpleRequestFieldsCb)req_data->cbs[response];
+	if (g_ptr_array_find(req_data->action_widgets, button, &index)) {
+		cb = g_ptr_array_index(req_data->action_cbs, index);
 	}
 
 	if(cb != NULL) {
@@ -227,7 +218,7 @@ pidgin_request_help_clicked(G_GNUC_UNUSE
 }
 
 static void
-pidgin_request_add_help(PidginRequestData *req_data,
+pidgin_request_add_help(PidginRequestData *req_data, GtkWidget *cbox,
                         PurpleRequestCommonParameters *cpar)
 {
 	GtkWidget *button;
@@ -239,8 +230,8 @@ pidgin_request_add_help(PidginRequestDat
 		return;
 	}
 
-	button = gtk_dialog_add_button(GTK_DIALOG(req_data->dialog),
-	                               _("_Help"), GTK_RESPONSE_HELP);
+	button = gtk_button_new_with_mnemonic(_("_Help"));
+	gtk_center_box_set_start_widget(GTK_CENTER_BOX(cbox), button);
 
 	req_data->help_cb = help_cb;
 	req_data->help_data = help_data;
@@ -721,13 +712,16 @@ pidgin_request_fields(const char *title,
 {
 	PidginRequestData *data;
 	GtkWidget *win;
+	GtkWidget *content = NULL;
+	GtkWidget *cbox = NULL;
+	GtkWidget *action_area = NULL;
+	GtkWidget *button = NULL;
+	GtkWidget *ok_button = NULL;
 	GtkWidget *page_widget = NULL;
 	AdwPreferencesGroup *group_widget = NULL;
 	GtkWidget *vbox = NULL;
 	GtkWidget *img;
-	GtkWidget *content;
 	GSList *extra_actions;
-	gint response;
 	guint n_groups;
 
 	data            = g_new0(PidginRequestData, 1);
@@ -735,7 +729,7 @@ pidgin_request_fields(const char *title,
 	data->user_data = user_data;
 	data->page = page;
 
-	data->dialog = win = gtk_dialog_new();
+	data->dialog = win = gtk_window_new();
 	if(title != NULL) {
 		gtk_window_set_title(GTK_WINDOW(win), title);
 	} else {
@@ -744,7 +738,9 @@ pidgin_request_fields(const char *title,
 	gtk_window_set_resizable(GTK_WINDOW(win), TRUE);
 	gtk_window_set_default_size(GTK_WINDOW(win), 480, -1);
 
-	content = gtk_dialog_get_content_area(GTK_DIALOG(win));
+	content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
+	gtk_window_set_child(GTK_WINDOW(win), content);
+
 	page_widget = adw_preferences_page_new();
 	gtk_widget_set_vexpand(page_widget, TRUE);
 	gtk_box_append(GTK_BOX(content), page_widget);
@@ -766,38 +762,55 @@ pidgin_request_fields(const char *title,
 	pidgin_widget_decorate_account(vbox,
 	                               purple_request_cpar_get_account(cpar));
 
-	pidgin_request_add_help(data, cpar);
+	cbox = gtk_center_box_new();
+	gtk_orientable_set_orientation(GTK_ORIENTABLE(cbox),
+	                               GTK_ORIENTATION_HORIZONTAL);
+	gtk_widget_set_margin_start(cbox, 6);
+	gtk_widget_set_margin_end(cbox, 6);
+	gtk_widget_set_margin_top(cbox, 6);
+	gtk_widget_set_margin_bottom(cbox, 6);
+	gtk_box_append(GTK_BOX(content), cbox);
+	action_area = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
+	gtk_widget_set_halign(action_area, GTK_ALIGN_END);
+	gtk_center_box_set_end_widget(GTK_CENTER_BOX(cbox), action_area);
+
+	pidgin_request_add_help(data, cbox, cpar);
 
 	/* Add responses and callbacks. */
-	g_signal_connect(data->dialog, "response",
-	                 G_CALLBACK(multifield_response_cb), data);
 	extra_actions = purple_request_cpar_get_extra_actions(cpar);
-	data->cb_count = 2 + g_slist_length(extra_actions);
-	data->cbs = g_new0(GCallback, data->cb_count);
+	data->action_widgets = g_ptr_array_sized_new(2 + g_slist_length(extra_actions));
+	data->action_cbs = g_ptr_array_sized_new(2 + g_slist_length(extra_actions));
 
-	data->cbs[0] = ok_cb;
-	data->cbs[1] = cancel_cb;
-
-	response = 2; /* So that response == data->cbs index. */
 	for(; extra_actions != NULL; extra_actions = extra_actions->next) {
 		PurpleKeyValuePair *extra_action = extra_actions->data;
 
-		gtk_dialog_add_button(GTK_DIALOG(win), extra_action->key, response);
-		data->cbs[response] = extra_action->value;
-		response++;
+		button = gtk_button_new_with_label(extra_action->key);
+		g_signal_connect(button, "clicked", G_CALLBACK(multifield_response_cb),
+		                 data);
+		gtk_box_append(GTK_BOX(action_area), button);
+		g_ptr_array_add(data->action_widgets, button);
+		g_ptr_array_add(data->action_cbs, extra_action->value);
 	}
 
 	/* Cancel button */
-	gtk_dialog_add_button(GTK_DIALOG(win), cancel_text, GTK_RESPONSE_CANCEL);
-	response = GTK_RESPONSE_CANCEL;
+	button = gtk_button_new_with_label(cancel_text);
+	g_signal_connect(button, "clicked", G_CALLBACK(multifield_response_cb),
+	                 data);
+	gtk_box_append(GTK_BOX(action_area), button);
+	gtk_window_set_default_widget(GTK_WINDOW(win), button);
+	g_ptr_array_add(data->action_widgets, button);
+	g_ptr_array_add(data->action_cbs, cancel_cb);
 
 	/* OK button */
 	if(ok_text != NULL) {
-		data->ok_button = gtk_dialog_add_button(GTK_DIALOG(win), ok_text,
-		                                        GTK_RESPONSE_OK);
-		response = GTK_RESPONSE_OK;
+		ok_button = gtk_button_new_with_label(ok_text);
+		g_signal_connect(ok_button, "clicked",
+		                 G_CALLBACK(multifield_response_cb), data);
+		gtk_box_append(GTK_BOX(action_area), ok_button);
+		gtk_window_set_default_widget(GTK_WINDOW(win), ok_button);
+		g_ptr_array_add(data->action_widgets, ok_button);
+		g_ptr_array_add(data->action_cbs, ok_cb);
 	}
-	gtk_dialog_set_default_response(GTK_DIALOG(win), response);
 
 	if(primary != NULL) {
 		GtkWidget *label = gtk_label_new(primary);
@@ -911,13 +924,30 @@ pidgin_request_fields(const char *title,
 		g_object_unref(group);
 	}
 
-	g_object_bind_property(page, "valid", data->ok_button, "sensitive", 0);
+	if(ok_button != NULL) {
+		g_object_bind_property(page, "valid", ok_button, "sensitive", 0);
+	}
 
 	gtk_widget_set_visible(win, TRUE);
 
 	return data;
 }
 
+static void
+pidgin_request_close_request(PurpleRequestType type, gpointer ui_handle) {
+	PidginRequestData *data = ui_handle;
+
+	if(type != PURPLE_REQUEST_FIELDS) {
+		/* This shouldn't happen as we don't support creating any others. */
+		return;
+	}
+
+	g_ptr_array_free(data->action_widgets, TRUE);
+	g_ptr_array_free(data->action_cbs, TRUE);
+	gtk_window_destroy(GTK_WINDOW(data->dialog));
+	g_free(data);
+}
+
 GtkWindow *
 pidgin_request_get_dialog_window(void *ui_handle)
 {
@@ -938,6 +968,7 @@ pidgin_request_get_dialog_window(void *u
 
 static PurpleRequestUiOps ops = {
 	.request_fields = pidgin_request_fields,
+	.close_request = pidgin_request_close_request,
 };
 
 PurpleRequestUiOps *
