]> spindle.queued.net Git - midori/commitdiff
Remember last folder of the Save As dialog when downloading files
authorEnrico Tröger <enrico.troeger@uvena.de>
Tue, 2 Jun 2009 23:15:36 +0000 (01:15 +0200)
committerChristian Dywan <christian@twotoasts.de>
Tue, 2 Jun 2009 23:15:36 +0000 (01:15 +0200)
This is done by creating the dialog only once and holding a
reference to it in memory. When the dialog is closed, it is only
hidden instead of destroyed. So, the next time we just re-show
the dialog with the previously used directory. It is destroyed
when the parent MidoriBrowser instance is destroyed.

midori/midori-browser.c

index 6d1ae8474c04296aac9628270d609a7b028f9e19..4f27c22393543951198dad857a4d9772c6426394 100644 (file)
@@ -1238,12 +1238,12 @@ midori_browser_add_download_item (MidoriBrowser*  browser,
 static void
 midori_view_download_save_as_response_cb (GtkWidget*      dialog,
                                           gint            response,
-                                          WebKitDownload* download)
+                                          MidoriBrowser*  browser)
 {
+    WebKitDownload* download = g_object_get_data (G_OBJECT (dialog), "download");
     if (response == GTK_RESPONSE_ACCEPT)
     {
         gchar* uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-        MidoriBrowser* browser = midori_browser_get_for_widget (dialog);
         webkit_download_set_destination_uri (download, uri);
         midori_browser_add_download_item (browser, download);
         g_free (uri);
@@ -1251,7 +1251,7 @@ midori_view_download_save_as_response_cb (GtkWidget*      dialog,
     }
     else
         g_object_unref (download);
-    gtk_widget_destroy (dialog);
+    gtk_widget_hide (dialog);
 }
 
 static gboolean
@@ -1262,27 +1262,35 @@ midori_view_download_requested_cb (GtkWidget*      view,
     g_signal_emit (browser, signals[ADD_DOWNLOAD], 0, download);
     if (!webkit_download_get_destination_uri (download))
     {
+        gchar* folder;
         if (g_object_get_data (G_OBJECT (download), "save-as-download"))
         {
-            GtkWidget* dialog = gtk_file_chooser_dialog_new (
-                _("Save file"), GTK_WINDOW (browser),
-                GTK_FILE_CHOOSER_ACTION_SAVE,
-                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                NULL);
-            gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE);
-            gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser));
-            /* FIXME: Remember the last folder
-               gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir); */
+            static GtkWidget* dialog = NULL;
+
+            if (!dialog)
+            {
+                dialog = gtk_file_chooser_dialog_new (
+                    _("Save file"), GTK_WINDOW (browser),
+                    GTK_FILE_CHOOSER_ACTION_SAVE,
+                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                    GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+                    NULL);
+                gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE);
+                gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser));
+                gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+                folder = katze_object_get_string (browser->settings, "download-folder");
+                gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder);
+                g_free (folder);
+                g_signal_connect (dialog, "response",
+                    G_CALLBACK (midori_view_download_save_as_response_cb), browser);
+            }
+            g_object_set_data (G_OBJECT (dialog), "download", download);
             gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
                 webkit_download_get_suggested_filename (download));
             gtk_widget_show (dialog);
-            g_signal_connect (dialog, "response",
-                G_CALLBACK (midori_view_download_save_as_response_cb), download);
         }
         else
         {
-            gchar* folder;
             gchar* filename;
             gchar* uri;