From 389fe66922dc2d9e1066babf8c34a7e8656b265c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 3 Oct 2021 08:31:09 +0300 Subject: [PATCH 47/48] gtk4: Avoid using gtk_file_chooser_get_filename() See osdn #42978 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/luaconsole.c | 20 ++++++++++++-------- client/gui-gtk-4.0/pages.c | 16 ++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/client/gui-gtk-4.0/luaconsole.c b/client/gui-gtk-4.0/luaconsole.c index 5ccdd12b68..1249f0798b 100644 --- a/client/gui-gtk-4.0/luaconsole.c +++ b/client/gui-gtk-4.0/luaconsole.c @@ -335,14 +335,18 @@ static void luaconsole_load_file_callback(GtkWidget *widget, gint response, gpointer data) { if (response == GTK_RESPONSE_OK) { - gchar *filename = g_filename_to_utf8(gtk_file_chooser_get_filename - (GTK_FILE_CHOOSER(widget)), - -1, NULL, NULL, NULL); - - if (NULL != filename) { - luaconsole_printf(ftc_luaconsole_input, "(file)> %s", filename); - script_client_do_file(filename); - g_free(filename); + GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget)); + + if (file != NULL) { + gchar *filename = g_file_get_parse_name(file); + + if (NULL != filename) { + luaconsole_printf(ftc_luaconsole_input, "(file)> %s", filename); + script_client_do_file(filename); + g_free(filename); + } + + g_object_unref(file); } } gtk_widget_destroy(widget); diff --git a/client/gui-gtk-4.0/pages.c b/client/gui-gtk-4.0/pages.c index 6114de33a9..caf1ba7a0c 100644 --- a/client/gui-gtk-4.0/pages.c +++ b/client/gui-gtk-4.0/pages.c @@ -427,13 +427,17 @@ static void save_dialog_file_chooser_callback(GtkWidget *widget, { if (response == GTK_RESPONSE_OK) { save_dialog_action_fn_t action = data; - gchar *filename = g_filename_to_utf8(gtk_file_chooser_get_filename - (GTK_FILE_CHOOSER(widget)), - -1, NULL, NULL, NULL); + GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget)); - if (NULL != filename) { - action(filename); - g_free(filename); + if (file != NULL) { + gchar *filename = g_file_get_parse_name(file); + + if (NULL != filename) { + action(filename); + g_free(filename); + } + + g_object_unref(file); } } gtk_widget_destroy(widget); -- 2.33.0