diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 4415b40b..005a94ed 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 b0d6eef4..d73bcfd9 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 e96cf7a0..fcc20abd 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -194,6 +194,9 @@ midori_view_print (MidoriView* view); gboolean midori_view_can_view_source (MidoriView* view); +gboolean +midori_view_can_save (MidoriView* view); + gboolean midori_view_can_find (MidoriView* view);