Thu, 26 Sep 2024 21:56:40 -0500
Remove old code from GTK request dialog
We only support fields now, so no need for the `union`, and the GObject data
can be replaced by the usual data struct.
There are also no signal connections using `pidgin_request_get_handle`, so
there's no need to clean them up.
Also remove unused `GtkSizeGroup`.
Testing Done:
Compiled and checked Request Fields from the Demo protocol.
Reviewed at https://reviews.imfreedom.org/r/3535/
| pidgin/gtkrequest.c | file | annotate | diff | comparison | revisions |
--- a/pidgin/gtkrequest.c Thu Sep 26 14:23:45 2024 -0500 +++ b/pidgin/gtkrequest.c Thu Sep 26 21:56:40 2024 -0500 @@ -31,50 +31,21 @@ #include <gdk/gdkkeysyms.h> -typedef struct -{ +typedef struct { PurpleRequestType type; + PurpleRequestPage *page; - void *user_data; - /* May be GtkWidget or GtkFileDialog. */ - gpointer dialog; + gpointer user_data; + GtkWidget *dialog; GCancellable *cancellable; GtkWidget *ok_button; + PurpleRequestHelpCb help_cb; + gpointer help_data; + size_t cb_count; GCallback *cbs; - - union - { - struct - { - GtkProgressBar *progress_bar; - } wait; - - struct - { - GtkWidget *entry; - - gboolean multiline; - gchar *hint; - - } input; - - struct - { - PurpleRequestPage *page; - - } multifield; - - struct - { - gboolean savedialog; - - } file; - - } u; - } PidginRequestData; static void @@ -96,16 +67,6 @@ } static void -generic_response_start(PidginRequestData *data) -{ - g_return_if_fail(data != NULL); - - g_object_set_data(G_OBJECT(data->dialog), - "pidgin-window-is-closing", GINT_TO_POINTER(TRUE)); - gtk_widget_set_visible(GTK_WIDGET(data->dialog), FALSE); -} - -static void field_choice_option_cb(GObject *obj, G_GNUC_UNUSED GParamSpec *pspec, gpointer data) { @@ -138,7 +99,7 @@ PidginRequestData *req_data = data; PurpleRequestFieldsCb cb = NULL; - generic_response_start(req_data); + gtk_widget_set_visible(GTK_WIDGET(req_data->dialog), FALSE); if(response == GTK_RESPONSE_OK) { cb = (PurpleRequestFieldsCb)req_data->cbs[0]; @@ -151,7 +112,7 @@ } if(cb != NULL) { - cb(req_data->user_data, req_data->u.multifield.page); + cb(req_data->user_data, req_data->page); } purple_request_close(PURPLE_REQUEST_FIELDS, data); @@ -257,36 +218,35 @@ } static void -pidgin_request_help_clicked(GtkButton *button, G_GNUC_UNUSED gpointer _unused) +pidgin_request_help_clicked(G_GNUC_UNUSED GtkButton *button, gpointer data) { - PurpleRequestHelpCb cb; - gpointer data; + PidginRequestData *req_data = data; - cb = g_object_get_data(G_OBJECT(button), "pidgin-help-cb"); - data = g_object_get_data(G_OBJECT(button), "pidgin-help-data"); - - g_return_if_fail(cb != NULL); - cb(data); + g_return_if_fail(req_data->help_cb != NULL); + req_data->help_cb(req_data->help_data); } static void -pidgin_request_add_help(GtkDialog *dialog, PurpleRequestCommonParameters *cpar) +pidgin_request_add_help(PidginRequestData *req_data, + PurpleRequestCommonParameters *cpar) { GtkWidget *button; PurpleRequestHelpCb help_cb; gpointer help_data; help_cb = purple_request_cpar_get_help_cb(cpar, &help_data); - if (help_cb == NULL) + if (help_cb == NULL) { return; + } - button = gtk_dialog_add_button(dialog, _("_Help"), GTK_RESPONSE_HELP); + button = gtk_dialog_add_button(GTK_DIALOG(req_data->dialog), + _("_Help"), GTK_RESPONSE_HELP); - g_object_set_data(G_OBJECT(button), "pidgin-help-cb", help_cb); - g_object_set_data(G_OBJECT(button), "pidgin-help-data", help_data); + req_data->help_cb = help_cb; + req_data->help_data = help_data; g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(pidgin_request_help_clicked), NULL); + G_CALLBACK(pidgin_request_help_clicked), req_data); } static GtkWidget * @@ -766,7 +726,6 @@ GtkWidget *vbox = NULL; GtkWidget *img; GtkWidget *content; - GtkSizeGroup *datasheet_buttons_sg; GSList *extra_actions; gint response; guint n_groups; @@ -774,7 +733,7 @@ data = g_new0(PidginRequestData, 1); data->type = PURPLE_REQUEST_FIELDS; data->user_data = user_data; - data->u.multifield.page = page; + data->page = page; data->dialog = win = gtk_dialog_new(); if(title != NULL) { @@ -807,7 +766,7 @@ pidgin_widget_decorate_account(vbox, purple_request_cpar_get_account(cpar)); - pidgin_request_add_help(GTK_DIALOG(win), cpar); + pidgin_request_add_help(data, cpar); /* Add responses and callbacks. */ g_signal_connect(data->dialog, "response", @@ -840,8 +799,6 @@ } gtk_dialog_set_default_response(GTK_DIALOG(win), response); - datasheet_buttons_sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - if(primary != NULL) { GtkWidget *label = gtk_label_new(primary); gtk_label_set_wrap(GTK_LABEL(label), TRUE); @@ -954,8 +911,6 @@ g_object_unref(group); } - g_object_unref(datasheet_buttons_sg); - g_object_bind_property(page, "valid", data->ok_button, "sensitive", 0); gtk_widget_set_visible(win, TRUE); @@ -1007,5 +962,4 @@ void pidgin_request_uninit(void) { - purple_signals_disconnect_by_handle(pidgin_request_get_handle()); }