[epiphany/wip/exalm/gtk4-cleanups-2: 24/27] download: Stop using gtk_dialog_run()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/gtk4-cleanups-2: 24/27] download: Stop using gtk_dialog_run()
- Date: Tue, 30 Nov 2021 19:43:50 +0000 (UTC)
commit d92b3d4cc2ed5cb1d041fd11706b7f9907c52788
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Nov 30 19:05:19 2021 +0500
download: Stop using gtk_dialog_run()
embed/ephy-download.c | 61 +++++++++++++++++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 17 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index b0bafb082..eb95b6e9b 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -786,6 +786,41 @@ download_failed_cb (WebKitDownload *wk_download,
g_signal_emit (download, signals[ERROR], 0, download->error);
}
+typedef struct {
+ EphyDownload *download;
+ WebKitDownload *webkit_download;
+ char *suggested_filename;
+ GtkFileChooser *file_chooser;
+} SuggestedFilenameData;
+
+static void
+filename_suggested_dialog_cb (GtkDialog *dialog,
+ GtkResponseType response,
+ SuggestedFilenameData *data)
+{
+ if (response == GTK_RESPONSE_OK) {
+ g_autofree gchar *uri = gtk_file_chooser_get_uri (data->file_chooser);
+ g_autofree gchar *folder = g_filename_from_uri (uri, NULL, NULL);
+ g_autofree gchar *path = g_build_filename (uri, data->suggested_filename, NULL);
+
+ ephy_download_set_destination_uri (data->download, path);
+
+ webkit_download_set_allow_overwrite (data->webkit_download, TRUE);
+
+ ephy_downloads_manager_add_download (ephy_embed_shell_get_downloads_manager
(ephy_embed_shell_get_default ()),
+ data->download);
+
+ g_settings_set_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY, folder);
+ } else {
+ ephy_download_cancel (data->download);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ g_free (data->suggested_filename);
+ g_free (data);
+}
+
static void
filename_suggested_cb (EphyDownload *download,
const char *suggested_filename,
@@ -806,6 +841,7 @@ filename_suggested_cb (EphyDownload *download,
g_autofree gchar *from_text = NULL;
g_autofree gchar *content_length = NULL;
const gchar *content_type;
+ SuggestedFilenameData *data;
application = G_APPLICATION (ephy_embed_shell_get_default ());
toplevel = gtk_application_get_active_window (GTK_APPLICATION (application));
@@ -851,24 +887,15 @@ filename_suggested_cb (EphyDownload *download,
gtk_widget_show_all (box);
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
- g_autofree gchar *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (filechooser));
- g_autofree gchar *folder = g_filename_from_uri (uri, NULL, NULL);
- g_autofree gchar *path = g_build_filename (uri, suggested_filename, NULL);
-
- ephy_download_set_destination_uri (download, path);
-
- webkit_download_set_allow_overwrite (webkit_download, TRUE);
-
- ephy_downloads_manager_add_download (ephy_embed_shell_get_downloads_manager
(ephy_embed_shell_get_default ()),
- download);
-
- g_settings_set_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY, folder);
- } else {
- ephy_download_cancel (download);
- }
+ data = g_new0 (SuggestedFilenameData, 1);
+ data->download = download;
+ data->webkit_download = webkit_download;
+ data->suggested_filename = g_strdup (suggested_filename);
+ data->file_chooser = GTK_FILE_CHOOSER (filechooser);
- gtk_widget_destroy (dialog);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (filename_suggested_dialog_cb), data);
+ gtk_window_present (GTK_WINDOW (dialog));
}
EphyDownload *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]