[Xfce4-commits] <postler:master> Render emoticons lazily only when needed
Christian Dywan
noreply at xfce.org
Mon May 31 21:10:01 CEST 2010
Updating branch refs/heads/master
to e49eff41725bc101542cacfed0bf2678363fe5f7 (commit)
from 0b9e9c2802362545d08c7711797d0ac5b3f74504 (commit)
commit e49eff41725bc101542cacfed0bf2678363fe5f7
Author: Christian Dywan <christian at twotoasts.de>
Date: Mon May 31 20:48:28 2010 +0200
Render emoticons lazily only when needed
postler/postler-content.vala | 51 ++++++++++++++++++++++++++++++-----------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index b45ed93..e145da5 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -114,6 +114,36 @@ public class Postler.Content : WebKit.WebView {
{ "~_^", "face-wink" },
{ "^_~", "face-wink" }
};
+
+ static bool evaluate_emoticon (GLib.MatchInfo match_info,
+ GLib.StringBuilder result,
+ void* user_data) {
+ EmoticonMapping emoticon = *(EmoticonMapping*)user_data;
+ Gdk.Pixbuf pixbuf = null;
+ try {
+ pixbuf = Gtk.IconTheme.get_for_screen (
+ Gdk.Screen.get_default ()).load_icon (emoticon.icon_name, 1, 0);
+ } catch (GLib.Error error) { }
+ if (pixbuf == null)
+ true;
+ string buffer;
+ size_t buffer_size;
+ try {
+ if (!Gdk.pixbuf_save_to_buffer (pixbuf, out buffer,
+ out buffer_size, "png", null, null))
+ return true;
+ }
+ catch (GLib.Error error) {
+ return true;
+ }
+
+ string encoded = GLib.base64_encode (buffer, buffer_size);
+ string data_uri = "data:image/png;base64," + encoded;
+ result.append (" <img src=\"" + data_uri + "\" " +
+ "title=\"" + emoticon.token + "\"/>");
+ return false;
+ }
+
const string[] link_formats = {
"(https?:\\/\\/\\S+)",
"([a-zA-Z0-9.\\-]+@[a-zA-Z0-9.\\-]+[a-zA-Z0-9.]+)"
@@ -345,20 +375,13 @@ public class Postler.Content : WebKit.WebView {
/* Emoticons */
foreach (var emoticon in emoticons) {
- var pixbuf = Gtk.IconTheme.get_for_screen (
- get_screen ()).load_icon (emoticon.icon_name, 1, 0);
- if (pixbuf == null)
- continue;
- string buffer;
- size_t buffer_size;
- if (!Gdk.pixbuf_save_to_buffer (pixbuf, out buffer,
- out buffer_size, "png", null, null))
- continue;
- string encoded = GLib.base64_encode (buffer, buffer_size);
- string data_uri = "data:image/png;base64," + encoded;
- body_chunk = body_chunk.replace (" " + emoticon.token,
- "<img src=\"" + data_uri + "\" " +
- "title=\"" + emoticon.token + "\"/>");
+ try {
+ var escaped = GLib.Regex.escape_string (" " + emoticon.token);
+ var regex = new GLib.Regex (escaped);
+ body_chunk = regex.replace_eval (body_chunk, -1, 0, 0,
+ evaluate_emoticon, &emoticon);
+ }
+ catch (GLib.RegexError error) { }
}
load_string ("""
More information about the Xfce4-commits
mailing list