]> spindle.queued.net Git - midori/commitdiff
Implement a Save As button in the download dialogue
authorChristian Dywan <christian@twotoasts.de>
Mon, 1 Jun 2009 17:33:44 +0000 (19:33 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 1 Jun 2009 17:33:44 +0000 (19:33 +0200)
midori/midori-browser.c
midori/midori-view.c

index 0cbd1ed153fc2dc34c4cac571e01bf223b8376e7..81b650a6ca17a29be586ec5a476727d7685984f5 100644 (file)
@@ -1215,6 +1215,21 @@ midori_browser_add_download_item (MidoriBrowser*  browser,
         G_CALLBACK (midori_browser_download_button_clicked_cb), download);
 }
 
+static void
+midori_view_download_save_as_response_cb (GtkWidget*      dialog,
+                                          gint            response,
+                                          WebKitDownload* download)
+{
+    if (response == GTK_RESPONSE_ACCEPT)
+    {
+        gchar* uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+        webkit_download_set_destination_uri (download, uri);
+        g_free (uri);
+        webkit_download_start (download);
+    }
+    gtk_widget_destroy (dialog);
+}
+
 static gboolean
 midori_view_download_requested_cb (GtkWidget*      view,
                                    WebKitDownload* download,
@@ -1223,21 +1238,40 @@ 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;
         gchar* filename;
         gchar* uri;
 
-        if (g_object_get_data (G_OBJECT (download), "open-download"))
-            folder = g_strdup (g_get_tmp_dir ());
+        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); */
+            gtk_widget_show (dialog);
+            g_signal_connect (dialog, "response",
+                G_CALLBACK (midori_view_download_save_as_response_cb), download);
+        }
         else
-            folder = katze_object_get_string (browser->settings, "download-folder");
-        filename = g_build_filename (folder,
-            webkit_download_get_suggested_filename (download), NULL);
-        g_free (folder);
-        uri = g_filename_to_uri (filename, NULL, NULL);
-        g_free (filename);
-        webkit_download_set_destination_uri (download, uri);
-        g_free (uri);
+        {
+            gchar* folder;
+            if (g_object_get_data (G_OBJECT (download), "open-download"))
+                folder = g_strdup (g_get_tmp_dir ());
+            else
+                folder = katze_object_get_string (browser->settings, "download-folder");
+            filename = g_build_filename (folder,
+                webkit_download_get_suggested_filename (download), NULL);
+            g_free (folder);
+            uri = g_filename_to_uri (filename, NULL, NULL);
+            g_free (filename);
+            webkit_download_set_destination_uri (download, uri);
+            g_free (uri);
+        }
     }
     midori_browser_add_download_item (browser, download);
     return TRUE;
index f1625e0e238b6d806fa133527c1281e3707d8932..705da7e7780ac9f67e5af764006674a32699cdee 100644 (file)
@@ -1489,6 +1489,7 @@ webkit_web_view_mime_type_decision_cb (GtkWidget*               web_view,
     }
     gtk_dialog_add_buttons (GTK_DIALOG (dialog),
         GTK_STOCK_SAVE, 1,
+        GTK_STOCK_SAVE_AS, 4,
         GTK_STOCK_CANCEL, 2,
         GTK_STOCK_OPEN, 3,
         NULL);
@@ -1497,6 +1498,11 @@ webkit_web_view_mime_type_decision_cb (GtkWidget*               web_view,
     g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
     switch (response)
     {
+       case 4:
+            g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)1);
+            webkit_web_policy_decision_download (decision);
+            webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
+            return TRUE;
         case 3:
             g_object_set_data (G_OBJECT (view), "open-download", (gpointer)1);
         case 1:
@@ -1535,7 +1541,10 @@ webkit_web_view_download_requested_cb (GtkWidget*      web_view,
     gboolean handled;
     g_object_set_data (G_OBJECT (download), "open-download",
         g_object_get_data (G_OBJECT (view), "open-download"));
+    g_object_set_data (G_OBJECT (download), "save-as-download",
+        g_object_get_data (G_OBJECT (view), "save-as-download"));
     g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
+    g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)0);
     g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
     return handled;
 }