pidgin/pidgin

Fix requesting files/folders

14 months ago, Elliott Sales de Andrade
9f746a79d7c4
Parents f29c4d466cf5
Children 4313c029db44
Fix requesting files/folders

`gtk_file_chooser_get_current_name` returns the value entered by the user, but
is _not_ the path selected. It also only works in a save dialog.

Testing Done:
Requested a file/folder and confirmed that the callback received the selected paths from the dialog.

Reviewed at https://reviews.imfreedom.org/r/2292/
--- a/pidgin/gtkrequest.c Sat Feb 25 23:09:23 2023 -0600
+++ b/pidgin/gtkrequest.c Sun Feb 26 00:15:53 2023 -0600
@@ -72,7 +72,6 @@
struct
{
gboolean savedialog;
- gchar *name;
} file;
@@ -2186,8 +2185,8 @@
}
static void
-file_ok_check_if_exists_cb(G_GNUC_UNUSED GtkWidget *widget, gint response,
- PidginRequestData *data)
+pidgin_request_file_folder_response_cb(G_GNUC_UNUSED GtkWidget *widget,
+ gint response, PidginRequestData *data)
{
GFile *current_path;
@@ -2198,7 +2197,6 @@
return;
}
- data->u.file.name = gtk_file_chooser_get_current_name(GTK_FILE_CHOOSER(data->dialog));
current_path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(data->dialog));
if (current_path != NULL) {
gchar *current_folder = g_file_get_path(current_path);
@@ -2210,7 +2208,11 @@
g_free(current_folder);
}
if (data->cbs[1] != NULL) {
- ((PurpleRequestFileCb)data->cbs[1])(data->user_data, data->u.file.name);
+ GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(data->dialog));
+ char *filename = g_file_get_path(file);
+ ((PurpleRequestFileCb)data->cbs[1])(data->user_data, filename);
+ g_free(filename);
+ g_object_unref(file);
}
purple_request_close(data->type, data);
@@ -2291,8 +2293,8 @@
g_clear_object(&file);
#endif
- g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel)), "response",
- G_CALLBACK(file_ok_check_if_exists_cb), data);
+ g_signal_connect(G_OBJECT(filesel), "response",
+ G_CALLBACK(pidgin_request_file_folder_response_cb), data);
#if 0
/* FIXME: Not implemented for native dialogs. */
@@ -2336,8 +2338,8 @@
g_object_unref(path);
}
- g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(dirsel)), "response",
- G_CALLBACK(file_ok_check_if_exists_cb), data);
+ g_signal_connect(G_OBJECT(dirsel), "response",
+ G_CALLBACK(pidgin_request_file_folder_response_cb), data);
data->dialog = dirsel;
#if 0
@@ -2396,8 +2398,6 @@
if (type == PURPLE_REQUEST_FIELDS)
purple_request_fields_destroy(data->u.multifield.fields);
- else if (type == PURPLE_REQUEST_FILE)
- g_free(data->u.file.name);
g_free(data);
}