[Xfce4-commits] <midori:master> Distinguish a view that can be saved, view source

Christian Dywan noreply at xfce.org
Wed Dec 14 01:42:01 CET 2011


Updating branch refs/heads/master
         to 9a45f8976ea817cf35c2cd0bdb72ef2a53fdbe44 (commit)
       from 7e50bb18f847d121d46dc3da7349f5f8aa7f5a8a (commit)

commit 9a45f8976ea817cf35c2cd0bdb72ef2a53fdbe44
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Dec 14 01:37:14 2011 +0100

    Distinguish a view that can be saved, view source
    
    Looking at the data source determines if there's a
    way to save the data. The prime use case is having
    images in tabs.
    
    Fixes: https://bugs.launchpad.net/midori/+bug/903499

 midori/midori-browser.c |    4 +---
 midori/midori-view.c    |   41 +++++++++++++++++++++++++++++++++++++----
 midori/midori-view.h    |    3 +++
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 4415b40..005a94e 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -305,9 +305,7 @@ _midori_browser_update_interface (MidoriBrowser* browser)
 
     gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"),
         !midori_view_is_blank (view));
-    /* Currently views that don't support source, don't support
-       saving either. If that changes, we need to think of something. */
-    _action_set_sensitive (browser, "SaveAs", midori_view_can_view_source (view));
+    _action_set_sensitive (browser, "SaveAs", midori_view_can_save (view));
     _action_set_sensitive (browser, "Print", midori_view_can_print (view));
     _action_set_sensitive (browser, "ZoomIn", midori_view_can_zoom_in (view));
     _action_set_sensitive (browser, "ZoomOut", midori_view_can_zoom_out (view));
diff --git a/midori/midori-view.c b/midori/midori-view.c
index b0d6eef..d73bcfd 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -2587,10 +2587,6 @@ midori_view_populate_popup (MidoriView* view,
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SaveAs"));
         gtk_menu_shell_append (menu_shell, menuitem);
-        /* Currently views that don't support source, don't support
-           saving either. If that changes, we need to think of something. */
-        if (!midori_view_can_view_source (view))
-            gtk_widget_set_sensitive (menuitem, FALSE);
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SourceView"));
         gtk_menu_shell_append (menu_shell, menuitem);
@@ -4835,6 +4831,43 @@ midori_view_can_view_source (MidoriView* view)
     return is_text;
 }
 
+/**
+ * midori_view_can_save:
+ * @view: a #MidoriView
+ *
+ * Determines if the view can be saved to disk.
+ *
+ * Return value: %TRUE if the website or image can be saved
+ *
+ * Since: 0.4.3
+ **/
+gboolean
+midori_view_can_save (MidoriView* view)
+{
+    GtkWidget* web_view;
+    WebKitWebDataSource *data_source;
+    WebKitWebFrame *frame;
+    const GString *data;
+
+    g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
+
+    if (midori_view_is_blank (view) || view->mime_type == NULL)
+        return FALSE;
+
+    web_view = midori_view_get_web_view (view);
+    if (webkit_web_view_get_view_source_mode (WEBKIT_WEB_VIEW (web_view)))
+        return FALSE;
+
+    frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+    data_source = webkit_web_frame_get_data_source (frame);
+    data = webkit_web_data_source_get_data (data_source);
+
+    if (data != NULL)
+        return TRUE;
+
+    return FALSE;
+}
+
 #define can_do(what) \
 gboolean \
 midori_view_can_##what (MidoriView* view) \
diff --git a/midori/midori-view.h b/midori/midori-view.h
index e96cf7a..fcc20ab 100644
--- a/midori/midori-view.h
+++ b/midori/midori-view.h
@@ -195,6 +195,9 @@ gboolean
 midori_view_can_view_source            (MidoriView*        view);
 
 gboolean
+midori_view_can_save                   (MidoriView*        view);
+
+gboolean
 midori_view_can_find                   (MidoriView*        view);
 
 void


More information about the Xfce4-commits mailing list