Remember last folder of the Save As dialog when downloading files

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.
This commit is contained in:
Enrico Tröger 2009-06-03 01:15:36 +02:00 committed by Christian Dywan
parent 144eb69e5c
commit ad0b2ac077

View 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,9 +1262,14 @@ 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 (
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,
@ -1272,17 +1277,20 @@ midori_view_download_requested_cb (GtkWidget* view,
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); */
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;