[Xfce4-commits] <postler:master> Click name in message to add or edit contact

Christian Dywan noreply at xfce.org
Wed Jan 19 02:58:02 CET 2011


Updating branch refs/heads/master
         to ce1ef37ffdaf008833751b29216e767af8fe3963 (commit)
       from 448534cf541be3fee22d7b8918ad7eb11cc4a880 (commit)

commit ce1ef37ffdaf008833751b29216e767af8fe3963
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Jan 18 22:39:18 2011 +0100

    Click name in message to add or edit contact

 postler/dexter.vala          |    8 ++++++++
 postler/postler-content.vala |   39 +++++++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/postler/dexter.vala b/postler/dexter.vala
index 28bad16..d7b0927 100644
--- a/postler/dexter.vala
+++ b/postler/dexter.vala
@@ -13,6 +13,7 @@ namespace Dexter {
 
     [DBus (name = "org.elementary.dexterserver")]
     interface DexterService : Object {
+        public abstract void edit_contact (string name, string email_address) throws IOError;
         public abstract string get_name (string email_address) throws IOError;
         public abstract string[] autocomplete_contact (string keywords) throws IOError;
         public abstract void show_window () throws IOError;
@@ -33,6 +34,13 @@ namespace Dexter {
                     null, null);
             } catch (GLib.Error error) {  }
         }
+        public void edit_contact (string name, string email_address) {
+            try {
+                service.edit_contact (name, email_address);
+            } catch (GLib.Error error) {
+                Postler.App.execute_command ("dexter");
+            }
+        }
         public string? get_name (string email_address) {
             try {
                 string name = service.get_name (email_address);
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index a8da4a2..733af5f 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -189,6 +189,7 @@ public class Postler.Content : WebKit.WebView {
     internal static string linkify_address (string addresses, string? arguments)
         requires (arguments == null || !arguments.contains ("<")) {
         var linkified = new StringBuilder ();
+        string data_uri = icon_name_to_data_uri ("bookmark-new");
         foreach (string address in addresses.split (",")) {
             if (address == "")
                 continue;
@@ -201,6 +202,8 @@ public class Postler.Content : WebKit.WebView {
                linkified.append (", ");
             linkified.append ("<a href=\"" + quoted + (arguments != null ? arguments : "") +
                 "\" title=\"" + original + "\">" + name + "</a>");
+            linkified.append (" <a href=\"contact:%s:%s\"><img src=\"%s\"><b>←</b></a>".printf (
+                name, quoted, data_uri));
         }
         return linkified.str;
     }
@@ -312,34 +315,41 @@ public class Postler.Content : WebKit.WebView {
         { "^_~", "face-wink" }
     };
 
-    static bool evaluate_emoticon (GLib.MatchInfo     match_info,
-                                   GLib.StringBuilder result,
-                                   EmoticonMapping    emoticon) {
-        Gdk.Pixbuf pixbuf = null;
+    static string? icon_name_to_data_uri (string icon_name) {
+        Gdk.Pixbuf? pixbuf = null;
         try {
             pixbuf = Gtk.IconTheme.get_for_screen (
-                Gdk.Screen.get_default ()).load_icon (emoticon.icon_name, 1, 0);
+                Gdk.Screen.get_default ()).load_icon (icon_name,
+                    Gtk.IconSize.MENU, Gtk.IconLookupFlags.FORCE_SIZE);
         } catch (GLib.Error error) { }
         if (pixbuf == null) {
-            result.append (" " + emoticon.token);
-            return true;
+            return null;
         }
         string buffer;
         size_t buffer_size;
         try {
             if (!Gdk.pixbuf_save_to_buffer (pixbuf, out buffer,
                 out buffer_size, "png", null, null)) {
-                result.append (" " + emoticon.token);
-                return true;
+                return null;
             }
         }
         catch (GLib.Error error) {
+            return null;
+        }
+
+        string encoded = GLib.base64_encode (buffer, buffer_size);
+        return "data:image/png;base64," + encoded;
+    }
+
+    static bool evaluate_emoticon (GLib.MatchInfo     match_info,
+                                   GLib.StringBuilder result,
+                                   EmoticonMapping    emoticon) {
+        string? data_uri = icon_name_to_data_uri (emoticon.icon_name);
+        if (data_uri == null) {
             result.append (" " + emoticon.token);
             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;
@@ -1040,7 +1050,12 @@ public class Postler.Content : WebKit.WebView {
             return false;
 
         decision.ignore ();
-        if (uri.has_prefix ("message-part:")) {
+        if (uri.has_prefix ("contact:")) {
+            string[] parts = uri.split (":");
+            new Dexter.Dexter ().edit_contact (parts[1], parts[2]);
+            return true;
+        }
+        else if (uri.has_prefix ("message-part:")) {
             int index;
             if (uri.has_prefix ("message-part:open:"))
                 index = uri.substring (18, -1).to_int ();



More information about the Xfce4-commits mailing list