From 0d24549112b2c2656812a8dacb07e10bec208c5e Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 12 Jan 2009 00:26:45 +0100 Subject: [PATCH] Display a message if a document cannot be displayed --- midori/midori-view.c | 46 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/midori/midori-view.c b/midori/midori-view.c index 5d035569..847d7b9e 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -26,6 +26,10 @@ #include #include +#ifndef WEBKIT_CHECK_VERSION + #define WEBKIT_CHECK_VERSION(a,b,c) 0 +#endif + /* This is unstable API, so we need to declare it */ gchar* webkit_web_view_get_selected_text (WebKitWebView* web_view); @@ -1037,6 +1041,10 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view, gpointer decision, MidoriView* view) { + #if WEBKIT_CHECK_VERSION (1, 0, 0) + gchar* uri; + #endif + if (web_frame != webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view))) return FALSE; @@ -1045,7 +1053,25 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view, g_object_notify (G_OBJECT (view), "mime-type"); /* TODO: Display contents with a Viewable if WebKit can't do it */ - /* TODO: Offer to download file if it cannot be displayed at all */ + /* TODO: Offer downloading file if it cannot be displayed at all */ + + #if WEBKIT_CHECK_VERSION (1, 1, 0) + if (webkit_web_view_can_show_mime_type (WEBKIT_WEB_VIEW (web_view), mime_type)) + #else + if (g_str_has_prefix (mime_type, "image/") || + g_strrstr (mime_type, "script") || + g_str_has_prefix (mime_type, "text/") || g_strrstr (mime_type, "xml")) + #endif + return TRUE; + + #if WEBKIT_CHECK_VERSION (1, 0, 0) + uri = g_strdup_printf ("error:nodisplay %s", + webkit_network_request_get_uri (request)); + midori_view_set_uri (view, uri); + g_free (uri); + #else + midori_view_set_uri (view, "error:nodisplay "); + #endif return TRUE; } @@ -1525,7 +1551,23 @@ midori_view_set_uri (MidoriView* view, if (g_str_has_prefix (uri, "error:")) { data = NULL; - if (!strncmp (uri, "error:nodocs ", 13)) + if (!strncmp (uri, "error:nodisplay ", 16)) + { + gchar* title; + + katze_assign (view->uri, g_strdup (&uri[16])); + title = g_strdup_printf (_("Document cannot be displayed")); + data = g_strdup_printf ( + "%s" + "

%s

" + "" + "

The document %s cannot be displayed." + "", + title, title, view->uri); + g_free (title); + } + else if (!strncmp (uri, "error:nodocs ", 13)) { gchar* title;