]> spindle.queued.net Git - midori/commitdiff
Support error pages with the load-error signal in WebKitGTK+ 1.1.6
authorChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:44:20 +0000 (21:44 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:44:20 +0000 (21:44 +0200)
data/error.html [new file with mode: 0644]
midori/midori-view.c
wscript

diff --git a/data/error.html b/data/error.html
new file mode 100644 (file)
index 0000000..4f6d43a
--- /dev/null
@@ -0,0 +1,65 @@
+<!--
+ Error page template for Midori.
+ This file is licensed under the terms of the expat license, see the file EXPAT.
+-->
+
+<html>
+<head>
+<title>{title}</title>
+<style type="text/css">
+body {
+   background-color: #eee;
+   margin: 0;
+   padding: 0;
+}
+
+#container {
+   background: #f6fff3;
+   min-width: 70%;
+   max-width: 70%;
+   margin: 2em auto 1em;
+   padding: 1em;
+   border: 0.2em solid #9acb7f;
+   -webkit-border-radius: 1em;
+}
+
+h1 {
+   font-size: 1.4em;
+   font-weight: bold;
+}
+
+#logo {
+  position: absolute; right: 15px; bottom: 15px;
+  z-index: -1;
+}
+
+message {
+   font-size: 1.1em;
+}
+
+description {
+   font-size: 1em;
+}
+
+</style>
+</head>
+<body>
+
+<div id="container">
+
+<img id="logo" src="{res}/logo-shade.png" />
+
+<h1>{title}</h1>
+<div class="message">
+ <p>{message}</p>
+ <p>{description}</p>
+</div>
+
+<form onsubmit="location.reload()">
+<input type="submit" value="{tryagain}" />
+</form>
+
+</div>
+
+</body>
+</html>
index 060c7fb4fafaee77da1ee27341fa284f4ce9cf35..5146d39b9f129e267e3b52049b7d87b849dc7ee4 100644 (file)
@@ -615,6 +615,50 @@ webkit_web_view_progress_changed_cb (WebKitWebView* web_view,
     g_object_notify (G_OBJECT (view), "progress");
 }
 
+#if WEBKIT_CHECK_VERSION (1, 1, 6)
+static gboolean
+webkit_web_view_load_error_cb (WebKitWebView*  web_view,
+                               WebKitWebFrame* web_frame,
+                               const gchar*    uri,
+                               GError*         error,
+                               MidoriView*     view)
+{
+    const gchar* template_file = DATADIR "/midori/res/error.html";
+    gchar* template;
+
+    if (g_file_get_contents (template_file, &template, NULL, NULL))
+    {
+        SoupServer* res_server;
+        guint port;
+        gchar* res_root;
+        gchar* message;
+        gchar* result;
+
+        res_server = sokoke_get_res_server ();
+        port = soup_server_get_port (res_server);
+        res_root = g_strdup_printf ("http://localhost:%d/res", port);
+
+        message = g_strdup_printf (_("The page %s couldn't be loaded."), uri);
+        result = sokoke_replace_variables (template,
+            "{title}", _("Error"),
+            "{message}", message,
+            "{description}", error->message,
+            "{tryagain}", _("Try again"),
+            "{res}", res_root, NULL);
+        g_free (template);
+        g_free (message);
+
+        webkit_web_frame_load_alternate_string (web_frame,
+            result, res_root, uri);
+        g_free (res_root);
+        g_free (result);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+#else
 static void
 webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame,
                                gboolean        success,
@@ -645,6 +689,7 @@ webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame,
 
     midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
 }
+#endif
 
 static void
 webkit_web_view_load_finished_cb (WebKitWebView*  web_view,
@@ -1755,12 +1800,18 @@ midori_view_construct_web_view (MidoriView* view)
                       "signal::download-requested",
                       webkit_web_view_download_requested_cb, view,
                       #endif
+                      #if WEBKIT_CHECK_VERSION (1, 1, 6)
+                      "signal::load-error",
+                      webkit_web_view_load_error_cb, view,
+                      #endif
                       NULL);
 
+    #if !WEBKIT_CHECK_VERSION (1, 1, 6)
     g_object_connect (web_frame,
                       "signal::load-done",
                       webkit_web_frame_load_done_cb, view,
                       NULL);
+    #endif
 
     if (view->settings)
     {
@@ -1802,6 +1853,7 @@ midori_view_set_uri (MidoriView*  view,
         if (g_str_has_prefix (uri, "error:"))
         {
             data = NULL;
+            #if !WEBKIT_CHECK_VERSION (1, 1, 3)
             if (!strncmp (uri, "error:nodisplay ", 16))
             {
                 gchar* title;
@@ -1818,7 +1870,8 @@ midori_view_set_uri (MidoriView*  view,
                     title, title, view->uri, view->mime_type);
                 g_free (title);
             }
-            else if (!strncmp (uri, "error:nodocs ", 13))
+            #endif
+            if (!strncmp (uri, "error:nodocs ", 13))
             {
                 gchar* title;
 
diff --git a/wscript b/wscript
index f9579b24fb223da098ed9590aa02985d2ce14f19..d8502e7d9c45e265b5f9aaf2aaa7d1264fd25a61 100644 (file)
--- a/wscript
+++ b/wscript
@@ -336,9 +336,10 @@ def build (bld):
             ' -o ' + blddir + '/data/logo-shade.png ' + \
             srcdir + '/data/logo-shade.svg'
         if not Utils.exec_command (command):
-            bld.install_files ('${DATADIR}/' + APPNAME, blddir + '/data/logo-shade.png')
+            bld.install_files ('${DATADIR}/' + APPNAME + '/res', blddir + '/data/logo-shade.png')
         else:
             Utils.pprint ('BLUE', "logo-shade could not be rasterized.")
+    bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/error.html')
 
     if Options.commands['check']:
         bld.add_subdirs ('tests')