Consolidate download types as MidoriDownloadType

This commit is contained in:
Christian Dywan 2012-07-08 23:55:39 +02:00
parent 3bdf2e7b73
commit 6a4a506f24
5 changed files with 46 additions and 63 deletions

View file

@ -35,10 +35,7 @@ namespace EDM {
private GLib.PtrArray download_managers = new GLib.PtrArray ();
public bool download_requested (Midori.View view, WebKit.Download download) {
if (download.get_data<void*> ("save-as-download") == null
&& download.get_data<void*> ("open-download") == null
&& download.get_data<void*> ("open-in-viewer") == null
&& download.get_data<void*> ("cancel-download") == null) {
if (download.get_data<void*> ("midori-download-type") == null) {
var dlReq = new DownloadRequest ();
dlReq.uri = download.get_uri ();

View file

@ -1423,6 +1423,8 @@ midori_view_download_requested_cb (GtkWidget* view,
WebKitDownload* download,
MidoriBrowser* browser)
{
MidoriDownloadType type = GPOINTER_TO_INT (
g_object_get_data (G_OBJECT (download), "midori-download-type"));
GtkWidget* web_view;
WebKitWebFrame* web_frame;
WebKitWebDataSource* datasource;
@ -1430,11 +1432,11 @@ midori_view_download_requested_cb (GtkWidget* view,
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
handled = TRUE;
if (g_object_get_data (G_OBJECT (download), "cancel-download"))
if (type == MIDORI_DOWNLOAD_CANCEL)
{
handled = FALSE;
}
else if (g_object_get_data (G_OBJECT (download), "open-in-viewer"))
else if (type == MIDORI_DOWNLOAD_OPEN_IN_VIEWER)
{
gchar* destination_uri =
midori_browser_download_prepare_destination_uri (download, NULL);
@ -1446,7 +1448,7 @@ midori_view_download_requested_cb (GtkWidget* view,
}
else if (!webkit_download_get_destination_uri (download))
{
if (g_object_get_data (G_OBJECT (download), "save-as-download"))
if (type == MIDORI_DOWNLOAD_SAVE_AS)
{
static GtkWidget* dialog = NULL;
gchar* filename;
@ -1489,8 +1491,8 @@ midori_view_download_requested_cb (GtkWidget* view,
}
else
{
gchar* folder = g_object_get_data (G_OBJECT (download), "open-download")
? NULL : katze_object_get_string (browser->settings, "download-folder");
gchar* folder = type == MIDORI_DOWNLOAD_OPEN ? NULL
: katze_object_get_string (browser->settings, "download-folder");
gchar* destination_uri =
midori_browser_download_prepare_destination_uri (download, folder);
midori_browser_prepare_download (browser, download, destination_uri);

View file

@ -205,13 +205,6 @@ enum {
LAST_SIGNAL
};
enum {
DOWNLOAD_SAVE = 1,
DOWNLOAD_SAVE_AS,
DOWNLOAD_CANCEL,
DOWNLOAD_OPEN,
};
static guint signals[LAST_SIGNAL];
static gchar* speeddial_markup = NULL;
@ -2182,17 +2175,26 @@ midori_web_view_menu_link_copy_activate_cb (GtkWidget* widget,
}
static void
midori_web_view_menu_save_activate_cb (GtkWidget* widget,
MidoriView* view)
midori_view_download_uri (MidoriView* view,
MidoriDownloadType type,
const gchar* uri)
{
WebKitNetworkRequest* request = webkit_network_request_new (view->link_uri);
WebKitNetworkRequest* request = webkit_network_request_new (uri);
WebKitDownload* download = webkit_download_new (request);
gboolean handled;
g_object_unref (request);
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
g_object_set_data (G_OBJECT (download), "midori-download-type",
GINT_TO_POINTER (type));
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
}
static void
midori_web_view_menu_save_activate_cb (GtkWidget* widget,
MidoriView* view)
{
midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, view->link_uri);
}
static void
midori_web_view_menu_image_new_tab_activate_cb (GtkWidget* widget,
MidoriView* view)
@ -2217,26 +2219,16 @@ midori_web_view_menu_image_save_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
WebKitNetworkRequest* request = webkit_network_request_new (uri);
WebKitDownload* download = webkit_download_new (request);
gboolean handled;
g_object_unref (request);
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, uri);
g_free (uri);
}
static void
midori_web_view_open_picture_cb (GtkWidget* widget,
midori_web_view_open_in_viewer_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
WebKitNetworkRequest* request = webkit_network_request_new (uri);
WebKitDownload* download = webkit_download_new (request);
gboolean handled;
g_object_unref (request);
g_object_set_data (G_OBJECT (download), "open-in-viewer", (void*)0xdeadbeef);
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
midori_view_download_uri (view, MIDORI_DOWNLOAD_OPEN_IN_VIEWER, uri);
g_free (uri);
}
@ -2254,12 +2246,7 @@ midori_web_view_menu_video_save_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "media-uri");
WebKitNetworkRequest* request = webkit_network_request_new (uri);
WebKitDownload* download = webkit_download_new (request);
gboolean handled;
g_object_unref (request);
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, uri);
g_free (uri);
}
@ -2593,7 +2580,7 @@ midori_view_populate_popup (MidoriView* view,
G_CALLBACK (midori_web_view_menu_image_save_activate_cb), widget);
midori_view_insert_menu_item (menu_shell, -1,
_("Open in Image _Viewer"), GTK_STOCK_OPEN,
G_CALLBACK (midori_web_view_open_picture_cb), widget);
G_CALLBACK (midori_web_view_open_in_viewer_cb), widget);
}
if (is_media)
@ -3075,31 +3062,17 @@ webkit_web_view_download_requested_cb (GtkWidget* web_view,
gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN);
}
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
GTK_STOCK_SAVE, DOWNLOAD_SAVE,
GTK_STOCK_SAVE_AS, DOWNLOAD_SAVE_AS,
GTK_STOCK_CANCEL, DOWNLOAD_CANCEL,
GTK_STOCK_OPEN, DOWNLOAD_OPEN,
GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE,
GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS,
GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL,
GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN,
NULL);
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
switch (response)
{
case DOWNLOAD_SAVE_AS:
g_object_set_data (G_OBJECT (download), "save-as-download", (gpointer)1);
break;
case DOWNLOAD_OPEN:
g_object_set_data (G_OBJECT (download), "open-download", (gpointer)1);
case DOWNLOAD_SAVE:
break;
case DOWNLOAD_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
g_object_set_data (G_OBJECT (download), "cancel-download", (gpointer)1);
break;
default:
g_warn_if_reached ();
}
if (response == GTK_RESPONSE_DELETE_EVENT)
response = MIDORI_DOWNLOAD_CANCEL;
g_object_set_data (G_OBJECT (download), "midori-download-type", GINT_TO_POINTER (response));
/* Propagate original URI to make it available when the download finishes */
g_object_set_data_full (G_OBJECT (request), "midori-original-uri",

View file

@ -57,6 +57,15 @@ midori_security_get_type (void) G_GNUC_CONST;
#define MIDORI_TYPE_SECURITY \
(midori_security_get_type ())
typedef enum
{
MIDORI_DOWNLOAD_CANCEL,
MIDORI_DOWNLOAD_OPEN,
MIDORI_DOWNLOAD_SAVE,
MIDORI_DOWNLOAD_SAVE_AS,
MIDORI_DOWNLOAD_OPEN_IN_VIEWER,
} MidoriDownloadType;
#define MIDORI_VIEW(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_VIEW, MidoriView))
#define MIDORI_VIEW_CLASS(klass) \

View file

@ -102,6 +102,8 @@ midori_transferbar_download_notify_status_cb (WebKitDownload* download,
case WEBKIT_DOWNLOAD_STATUS_FINISHED:
{
MidoriBrowser* browser = midori_browser_get_for_widget (button);
MidoriDownloadType type = GPOINTER_TO_INT (
g_object_get_data (G_OBJECT (download), "midori-download-type"));
WebKitNetworkRequest* request;
const gchar* original_uri;
GChecksumType checksum_type;
@ -110,7 +112,7 @@ midori_transferbar_download_notify_status_cb (WebKitDownload* download,
icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (button), icon);
if (g_object_get_data (G_OBJECT (download), "open-download"))
if (type == MIDORI_DOWNLOAD_OPEN)
gtk_button_clicked (GTK_BUTTON (button));
if (1)