[Xfce4-commits] <postler:master> Refactor error display into a function
Christian Dywan
noreply at xfce.org
Thu Jul 29 12:26:07 CEST 2010
Updating branch refs/heads/master
to 27cc1579fb96559cb26f6888ea857cabb9f2ed6e (commit)
from ba06b69b85e6574f038940aa75f85df9613bbb32 (commit)
commit 27cc1579fb96559cb26f6888ea857cabb9f2ed6e
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jul 23 21:05:46 2010 +0200
Refactor error display into a function
postler/postler-content.vala | 62 +++++++++++++----------------------------
1 files changed, 20 insertions(+), 42 deletions(-)
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index e82cdc9..cad9d46 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -316,18 +316,8 @@ public class Postler.Content : WebKit.WebView {
}
body.append_c ('\n');
} catch (GLib.Error error) {
- load_string ("""
- <title>%s</title>
- <body>
- <h1>%s</h1>
- <p>%s</p>
- </body>
- """.
- printf (_("Error"), _("Error"),
- error.message),
- "text/html", "UTF-8", "about:blank");
- GLib.critical (_("Failed to quote message \"%s\": %s"),
- contents.get_path (), error.message);
+ display_error (_("Failed to quote message \"%s\": %s").printf (
+ contents.get_path (), error.message));
}
}
@@ -545,11 +535,8 @@ public class Postler.Content : WebKit.WebView {
else
multipart = 0;
if (!(mime_type.has_prefix ("text/") || multipart > 0)) {
- load_string ("<h1>%s</h1><p>%s".printf (
- _("Error"),
- _("This message of type \"%s\" can't be displayed.").
- printf (mime_type)),
- "text/html", "UTF-8", "about:blank");
+ display_error (_("This message of type \"%s\" can't be displayed.").
+ printf (mime_type));
last_location = location;
return false;
}
@@ -670,19 +657,7 @@ public class Postler.Content : WebKit.WebView {
throw new GLib.FileError.FAILED (
_("No text in the message that can be displayed"));
} catch (GLib.Error contents_error) {
- load_string ("""
- <title>%s</title>
- <body>
- <h1>%s</h1>
- <p>%s</p>
- <p>%s</p>
- </body>
- """.
- printf (_("Error"), _("Error"),
- contents.get_path (), contents_error.message),
- "text/html", "UTF-8", "about:blank");
- GLib.critical (_("Failed to read message \"%s\": %s"),
- contents.get_path (), contents_error.message);
+ display_error (_("Failed to read message: %s").printf (contents_error.message));
}
notify_property ("n-parts");
return false;
@@ -752,21 +727,24 @@ public class Postler.Content : WebKit.WebView {
body_chunk),
mime_type, "UTF-8", "about:blank");
} catch (GLib.Error contents_error) {
- load_string ("""
- <title>%s</title>
- <body>
- <h1>%s</h1>
- <p>%s</p>
- </body>
- """.
- printf (_("Error"), _("Error"),
- contents_error.message),
- "text/html", "UTF-8", "about:blank");
- GLib.critical (_("Failed to display message part \"%s\": %s"),
- mime_type, contents_error.message);
+ display_error (_("Failed to display message part \"%s\": %s").printf (
+ mime_type, contents_error.message));
}
}
+ void display_error (string message) {
+ load_string ("""
+ <title>%s</title>
+ <body>
+ <h1>%s</h1>
+ <p>%s</p>
+ </body>
+ """.
+ printf (_("Error"), _("Error"), message),
+ "text/html", "UTF-8", "about:blank");
+ GLib.critical (message);
+ }
+
bool navigation_decision (WebKit.WebFrame web_frame,
WebKit.NetworkRequest request, WebKit.WebNavigationAction action,
WebKit.WebPolicyDecision decision) {
More information about the Xfce4-commits
mailing list