[epiphany] Restore download on shift-click functionality



commit b6102135d673197eecdc6497d6153d00f6b75301
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Fri Dec 18 13:17:25 2009 +0100

    Restore download on shift-click functionality

 embed/ephy-embed.c    |   20 ++++++++++++++++++--
 embed/ephy-embed.h    |    1 +
 embed/ephy-web-view.c |    4 ++++
 src/ephy-window.c     |   45 ++++++++++++++++++++-------------------------
 4 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 95b630c..3b1e7c0 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -563,7 +563,7 @@ define_destination_uri (WebKitDownload *download,
   return TRUE;
 }
 
-static void
+static gboolean
 perform_auto_download (WebKitDownload *download)
 {
   DownloaderView *dview;
@@ -571,13 +571,29 @@ perform_auto_download (WebKitDownload *download)
   if (!define_destination_uri (download, FALSE)) {
     webkit_download_cancel (download);
     ephy_file_delete_uri (webkit_download_get_destination_uri (download));
-    return;
+    return FALSE;
   }
 
   dview = EPHY_DOWNLOADER_VIEW (ephy_embed_shell_get_downloader_view (embed_shell));
 
   g_object_set_data (G_OBJECT(download), "download-action", GINT_TO_POINTER(DOWNLOAD_ACTION_OPEN));
   downloader_view_add_download (dview, download);
+
+  return TRUE;
+}
+
+void
+ephy_embed_auto_download_url (EphyEmbed *embed, const char *url)
+{
+  WebKitNetworkRequest *request;
+  WebKitDownload *download;
+
+  request = webkit_network_request_new (url);
+  download = webkit_download_new (request);
+  g_object_unref (request);
+
+  if (perform_auto_download (download))
+    webkit_download_start (download);
 }
 
 static void
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 939cfa7..e6b4e77 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -55,6 +55,7 @@ GType        ephy_embed_get_type          (void);
 EphyWebView* ephy_embed_get_web_view      (EphyEmbed *embed);
 void         ephy_embed_add_top_widget    (EphyEmbed *embed, GtkWidget *widget, gboolean destroy_on_transition);
 void         ephy_embed_remove_top_widget (EphyEmbed *embed, GtkWidget *widget);
+void         ephy_embed_auto_download_url (EphyEmbed *embed, const char *url);
 
 G_END_DECLS
 
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 4871fc9..2935ed2 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -520,6 +520,10 @@ ephy_web_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
     if (event->button == 3 && event->state & GDK_CONTROL_MASK)
       return FALSE;
 
+    /* We use this for downloading */
+    if (event->button == 1 && event->state & GDK_SHIFT_MASK)
+      return FALSE;
+
     return GTK_WIDGET_CLASS (ephy_web_view_parent_class)->button_press_event (widget, event);
 }
 
diff --git a/src/ephy-window.c b/src/ephy-window.c
index d614f47..91b163e 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -35,6 +35,7 @@
 #include "eel-gconf-extensions.h"
 #include "ephy-prefs.h"
 #include "ephy-embed-prefs.h"
+#include "ephy-embed-utils.h"
 #include "ephy-zoom.h"
 #include "ephy-debug.h"
 #include "ephy-file-helpers.h"
@@ -2271,37 +2272,32 @@ show_embed_popup (EphyWindow *window,
 	}
 }
 
-#if 0
 static gboolean
 save_property_url (EphyEmbed *embed,
-		   EphyEmbedEvent *event,
-		   const char *property,
-		   const char *key)
+		   GdkEventButton *gdk_event,
+		   WebKitHitTestResult *hit_test_result,
+		   const char *property)
 {
 	const char *location;
-	const GValue *value;
-	EphyEmbedPersist *persist;
-
-	value = ephy_embed_event_get_property (event, property);
-	location = g_value_get_string (value);
+	GValue value = { 0, };
+	EphyEmbedEvent *event = ephy_embed_event_new (gdk_event, hit_test_result);
+	gboolean retval;
 
-	if (!ephy_embed_utils_address_has_web_scheme (location)) return FALSE;
+	ephy_embed_event_get_property (event, property, &value);
+	location = g_value_get_string (&value);
 
-	persist = EPHY_EMBED_PERSIST
-		(g_object_new (EPHY_TYPE_EMBED_PERSIST, NULL));
+	LOG ("Location: %s", location);
 
-	ephy_embed_persist_set_embed (persist, embed);
-	ephy_embed_persist_set_flags (persist, 0);
-	ephy_embed_persist_set_persist_key (persist, key);
-	ephy_embed_persist_set_source (persist, location);
+	retval = ephy_embed_utils_address_has_web_scheme (location);
 
-	ephy_embed_persist_save (persist);
+	if (retval)
+		ephy_embed_auto_download_url (embed, location);
 
-	g_object_unref (G_OBJECT(persist));
+	g_value_unset (&value);
+	g_object_unref (event);
 
-	return TRUE;
+	return retval;
 }
-#endif
 
 typedef struct
 {
@@ -2354,7 +2350,6 @@ ephy_window_dom_mouse_click_cb (WebKitWebView *view,
 
 	modifier = event->state;
 	g_object_get (hit_test_result, "context", &context, NULL);
-	g_object_unref (hit_test_result);
 
 	LOG ("ephy_window_dom_mouse_click_cb: button %d, context %d, modifier %d (%d:%d)",
 	     button, context, modifier, (int)event->x, (int)event->y);
@@ -2376,20 +2371,19 @@ ephy_window_dom_mouse_click_cb (WebKitWebView *view,
 				|| (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE));
 	is_input = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) != 0;
 
-#if 0
 	/* shift+click saves the link target */
 	if (is_link && is_left_click && with_shift)
 	{
-		handled = save_property_url (embed, event, "link", CONF_STATE_SAVE_DIR);
+		handled = save_property_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), event, hit_test_result, "link-uri");
 	}
 	/* shift+click saves the non-link image
 	 * Note: pressing enter to submit a form synthesizes a mouse click event
 	 */
 	else if (is_image && is_left_click && with_shift && !is_input)
 	{
-		handled = save_property_url (embed, event, "image", CONF_STATE_SAVE_IMAGE_DIR);
+		handled = save_property_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), event, hit_test_result, "image-uri");
 	}
-#endif
+
 	/* middle click opens the selection url */
 	if (is_middle_clickable && is_middle_click && middle_click_opens)
 	{
@@ -2423,6 +2417,7 @@ ephy_window_dom_mouse_click_cb (WebKitWebView *view,
 		handled = FALSE;
 	}
 
+	g_object_unref (hit_test_result);
 	return handled;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]