Implement a Save As button in the download dialogue
This commit is contained in:
parent
1bd94a4d28
commit
842a83d481
2 changed files with 54 additions and 11 deletions
|
@ -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,10 +1238,28 @@ 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), "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
|
||||
{
|
||||
gchar* folder;
|
||||
if (g_object_get_data (G_OBJECT (download), "open-download"))
|
||||
folder = g_strdup (g_get_tmp_dir ());
|
||||
else
|
||||
|
@ -1239,6 +1272,7 @@ midori_view_download_requested_cb (GtkWidget* view,
|
|||
webkit_download_set_destination_uri (download, uri);
|
||||
g_free (uri);
|
||||
}
|
||||
}
|
||||
midori_browser_add_download_item (browser, download);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue