[epiphany/wip/exalm/gtk4-cleanups-2: 22/27] popup-commands: Stop using gtk_native_dialog_run() for downloads




commit b445c8c9eaec2b06c75e689733fee24478935fba
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Nov 30 18:19:18 2021 +0500

    popup-commands: Stop using gtk_native_dialog_run() for downloads

 src/popup-commands.c | 59 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
---
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 4a3c5a9bb..dc3ccfbbc 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -146,54 +146,66 @@ cancel_download_idle_cb (EphyDownload *download)
 typedef struct {
   char *title;
   EphyWindow *window;
+  EphyDownload *download;
 } SavePropertyURLData;
 
 static void
-filename_suggested_cb (EphyDownload        *download,
-                       const char          *suggested_filename,
+filename_confirmed_cb (GtkFileChooser      *dialog,
+                       GtkResponseType      response,
                        SavePropertyURLData *data)
 {
-  GtkFileChooser *dialog;
-  char *sanitized_filename;
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (dialog));
 
-  dialog = ephy_create_file_chooser (data->title,
-                                     GTK_WIDGET (data->window),
-                                     GTK_FILE_CHOOSER_ACTION_SAVE,
-                                     EPHY_FILE_FILTER_NONE);
-  gtk_file_chooser_set_do_overwrite_confirmation (dialog, TRUE);
-  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_settings_get_string (EPHY_SETTINGS_WEB, 
EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY));
-
-  sanitized_filename = ephy_sanitize_filename (g_strdup (suggested_filename));
-  gtk_file_chooser_set_current_name (dialog, sanitized_filename);
-  g_free (sanitized_filename);
-
-  if (gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+  if (response == GTK_RESPONSE_ACCEPT) {
     char *uri;
     WebKitDownload *webkit_download;
 
     uri = gtk_file_chooser_get_uri (dialog);
-    ephy_download_set_destination_uri (download, uri);
+    ephy_download_set_destination_uri (data->download, uri);
     g_free (uri);
 
-    webkit_download = ephy_download_get_webkit_download (download);
+    webkit_download = ephy_download_get_webkit_download (data->download);
     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, 
gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)));
+                                         data->download);
+    g_settings_set_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY,
+                           gtk_file_chooser_get_current_folder (dialog));
   } else {
     g_idle_add_full (G_PRIORITY_DEFAULT,
                      (GSourceFunc)cancel_download_idle_cb,
-                     g_object_ref (download),
+                     g_object_ref (data->download),
                      g_object_unref);
   }
 
-  g_object_unref (dialog);
   g_free (data->title);
   g_object_unref (data->window);
+  g_object_unref (data->download);
   g_free (data);
+}
 
-  g_object_unref (download);
+static void
+filename_suggested_cb (EphyDownload        *download,
+                       const char          *suggested_filename,
+                       SavePropertyURLData *data)
+{
+  GtkFileChooser *dialog;
+  char *sanitized_filename;
+
+  dialog = ephy_create_file_chooser (data->title,
+                                     GTK_WIDGET (data->window),
+                                     GTK_FILE_CHOOSER_ACTION_SAVE,
+                                     EPHY_FILE_FILTER_NONE);
+  gtk_file_chooser_set_do_overwrite_confirmation (dialog, TRUE);
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_settings_get_string (EPHY_SETTINGS_WEB, 
EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY));
+
+  sanitized_filename = ephy_sanitize_filename (g_strdup (suggested_filename));
+  gtk_file_chooser_set_current_name (dialog, sanitized_filename);
+  g_free (sanitized_filename);
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (filename_confirmed_cb), data);
+  gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
 }
 
 static void
@@ -214,6 +226,7 @@ save_property_url (const char *title,
   data = g_new (SavePropertyURLData, 1);
   data->title = g_strdup (title);
   data->window = g_object_ref (window);
+  data->download = download;
   g_signal_connect (download, "filename-suggested",
                     G_CALLBACK (filename_suggested_cb),
                     data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]