[epiphany/gnome-42] Revert "popup-commands: Stop using gtk_native_dialog_run() for downloads"



commit 54a3d57910dee0104775fd27aa2f28378d890e55
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Wed Apr 20 15:49:38 2022 -0500

    Revert "popup-commands: Stop using gtk_native_dialog_run() for downloads"
    
    This reverts commit a748d58c10f465165579b852f03187ea13974d26.
    
    This fixes #1760. This bug is specific to the gnome-42 branch. A similar
    problem has been fixed in master via !1103.

 src/popup-commands.c | 59 ++++++++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 36 deletions(-)
---
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 2f321a190..b48612df2 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -146,66 +146,54 @@ cancel_download_idle_cb (EphyDownload *download)
 typedef struct {
   char *title;
   EphyWindow *window;
-  EphyDownload *download;
 } SavePropertyURLData;
 
 static void
-filename_confirmed_cb (GtkFileChooser      *dialog,
-                       GtkResponseType      response,
+filename_suggested_cb (EphyDownload        *download,
+                       const char          *suggested_filename,
                        SavePropertyURLData *data)
 {
-  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (dialog));
+  GtkFileChooser *dialog;
+  char *sanitized_filename;
 
-  if (response == GTK_RESPONSE_ACCEPT) {
+  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) {
     char *uri;
     WebKitDownload *webkit_download;
 
     uri = gtk_file_chooser_get_uri (dialog);
-    ephy_download_set_destination_uri (data->download, uri);
+    ephy_download_set_destination_uri (download, uri);
     g_free (uri);
 
-    webkit_download = ephy_download_get_webkit_download (data->download);
+    webkit_download = ephy_download_get_webkit_download (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 ()),
-                                         data->download);
-    g_settings_set_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY,
-                           gtk_file_chooser_get_current_folder (dialog));
+                                         download);
+    g_settings_set_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_LAST_DOWNLOAD_DIRECTORY, 
gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)));
   } else {
     g_idle_add_full (G_PRIORITY_DEFAULT,
                      (GSourceFunc)cancel_download_idle_cb,
-                     g_object_ref (data->download),
+                     g_object_ref (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);
-}
 
-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));
+  g_object_unref (download);
 }
 
 static void
@@ -226,7 +214,6 @@ 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]