[Xfce4-commits] <postler:master> Optionally lookup contacts via libfolks

Christian Dywan noreply at xfce.org
Tue Jun 28 05:10:06 CEST 2011


Updating branch refs/heads/master
         to f3afb1d59b139782dae4bfb5411ce3ec24a70c83 (commit)
       from 0e2232616df30ce0cd644d14ecad6412283fec5c (commit)

commit f3afb1d59b139782dae4bfb5411ce3ec24a70c83
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Jun 28 01:18:19 2011 +0200

    Optionally lookup contacts via libfolks

 README                       |    2 +-
 postler/postler-index.vala   |   34 ++++++++++++++++++++++++++++++++++
 postler/postler-message.vala |    6 ++++--
 postler/postler.vapi         |   36 ++++++++++++++++++++++++++++++++++++
 postler/wscript_build        |    2 +-
 wscript                      |   13 +++++++++++++
 6 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/README b/README
index ffcc28d..96b34ee 100644
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ integration are provided by Dexter.
 Requirements: GIO 2.26, GTK+ 2.18, WebkitGTK+ 1.1.18, Unique 0.9, libnotify,
               libcanberra, (Berkeley) db, openssl
 
-Recommended: libindicate, Dexter, lynx
+Recommended: libfolks, Zeitgeist, libindicate, Dexter, lynx
 
 For installation instructions read INSTALL.
 
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 89d1e01..bb4d1e3 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -22,6 +22,26 @@ namespace Postler {
         static Sqlite.Statement? statement_unread = null;
         static Sqlite.Statement? statement_guess = null;
         static int64 startup_timestamp = new DateTime.now_utc ().to_unix ();
+        static GLib.HashTable<string,string> names;
+#if HAVE_FOLKS
+        static Folks.IndividualAggregator aggregator;
+
+        void populate_display_names () {
+            foreach (var individual in aggregator.get_individuals ().get_values ()) {
+                string? display_name = individual.full_name ?? individual.alias;
+                if (display_name != null) {
+                    foreach (string address in individual.email_addresses)
+                        names.insert (address, display_name);
+                    /* foreach (string address in individual.im_addresses.get_values ())
+                            names.insert (address, display_name); */
+                    foreach (var persona in individual.personas) {
+                        if (persona.display_id.chr (-1, '@') != null)
+                            names.insert (persona.display_id, display_name);
+                    }
+                }
+            }
+        }
+#endif
 
         bool row_or_done (int result) {
             return result == Sqlite.ROW || result == Sqlite.DONE;
@@ -35,6 +55,16 @@ namespace Postler {
             if (database != null)
                 return;
 
+            names = new GLib.HashTable<string,string> (str_hash, str_equal);
+#if HAVE_FOLKS
+            aggregator = new Folks.IndividualAggregator ();
+            /* FIXME: Connect to aggregator.individuals_changed */
+            aggregator.prepare ();
+            aggregator.notify["user"].connect ((object, pspec) => {
+                populate_display_names ();
+            });
+#endif
+
             unowned string data_dir = Environment.get_user_data_dir ();
             string data_path = data_dir + "/" + Config.PACKAGE_NAME + "/mail/";
             if (Sqlite.Database.open (data_path + "index.db", out database) != Sqlite.OK)
@@ -276,6 +306,10 @@ namespace Postler {
         }
 
         public string guess_name (string address) throws GLib.Error {
+            string? display_name = names.lookup (address);
+            if (display_name != null)
+                return "%s <%s>".printf (display_name, address);
+
             if (statement_guess == null) {
                 if (database.prepare_v2 ("""
                     SELECT sender FROM messages WHERE sender LIKE ?1
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index 88b4e82..eb1675a 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -283,12 +283,14 @@ namespace Postler {
                 }
                 else if (field == "from") {
                     string sender_charset = null;
+                    fields.insert (field, parse_encoded (parts[1], out sender_charset));
                     if (sender == null)
-                        sender = parse_encoded (parts[1], out sender_charset);
+                        sender = get_field (field);
                 }
                 else if (field == "x-bugzilla-who") {
                     string sender_charset = null;
-                    sender = parse_encoded (parts[1], out sender_charset);
+                    if (get_field ("from") == sender)
+                        sender = parse_encoded (parts[1], out sender_charset);
                 }
                 else if (field == "date") {
                     date = Postler.Content.date_from_string (parts[1]);}
diff --git a/postler/postler.vapi b/postler/postler.vapi
index edf6461..76ab784 100644
--- a/postler/postler.vapi
+++ b/postler/postler.vapi
@@ -38,3 +38,39 @@ namespace Gtk {
                                                     out float xalign, out int yalign);
 }
 
+[CCode (cprefix = "Folks", lower_case_cprefix = "folks_", cheader_filename = "folks/folks.h")]
+namespace Folks {
+    public class Individual : GLib.Object, AliasDetails, AvatarDetails, EmailDetails, ImDetails, NameDetails {
+        public bool is_user { get; }
+        public GLib.List<Folks.Persona> personas { get; set; }
+    }
+    public class Persona : GLib.Object {
+        public string display_id { get; construct; }
+    }
+    public interface AliasDetails : GLib.Object {
+        public abstract string? alias { get; set; }
+    }
+    public interface AvatarDetails : GLib.Object {
+        public abstract GLib.File? avatar { get; set; }
+    }
+    public interface EmailDetails : GLib.Object {
+        public abstract GLib.List<string?> email_addresses { get; set; }
+    }
+    public interface ImDetails : GLib.Object {
+        /* public abstract GLib.HashTable<string, string> im_addresses { get; set; } */
+    }
+    public interface NameDetails : GLib.Object {
+        public abstract string? full_name { get; set; }
+    }
+    public class IndividualAggregator : GLib.Object {
+        public IndividualAggregator ();
+        /* public signal void individuals_changed (Gee.Set<Individual> added,
+            Gee.Set<Individual> removed, string? message, Persona? actor,
+            GroupDetails.ChangeReason reason); */
+        public async void prepare () throws GLib.Error;
+        public bool is_prepared { get; }
+        public Folks.Individual? user { get; }
+        public unowned GLib.HashTable<string, Folks.Individual> get_individuals ();
+    }
+}
+
diff --git a/postler/wscript_build b/postler/wscript_build
index b1a6bf7..bc81c13 100644
--- a/postler/wscript_build
+++ b/postler/wscript_build
@@ -13,7 +13,7 @@ obj.name = 'postler'
 obj.target = 'postler'
 obj.includes = '. ..'
 obj.find_sources_in_dirs ('.')
-obj.uselib = 'GIO GTHREAD GTK LIBNOTIFY LIBCANBERRA INDICATE UNIQUE WEBKIT SQLITE3 ZEITGEIST'
+obj.uselib = 'GIO GTHREAD GTK LIBNOTIFY LIBCANBERRA INDICATE UNIQUE WEBKIT SQLITE3 FOLKS ZEITGEIST'
 obj.packages = 'config postler posix gio-2.0 gtk+-2.0 libnotify libcanberra ' \
                'unique-1.0 webkit-1.0 sqlite3'
 obj.vapi_dirs = '.'
diff --git a/wscript b/wscript
index 82e2513..033d188 100644
--- a/wscript
+++ b/wscript
@@ -118,6 +118,18 @@ def configure (conf):
     check_pkg ('libnotify', var='LIBNOTIFY')
     check_pkg ('libcanberra', var='LIBCANBERRA')
 
+    if option_enabled ('libfolks'):
+        check_pkg ('folks', '', mandatory=False)
+        if conf.env['HAVE_FOLKS']:
+            conf.env.append_value ('VALAFLAGS', '-D HAVE_FOLKS')
+        else:
+            Utils.pprint ('RED', 'libfolks enables contact lookup from ' \
+                'Telepathy and Evolution Data Server.\n' \
+                'If you want to build without it, pass --disable-libfolks.')
+            sys.exit (1)
+    else:
+        Utils.pprint ('YELLOW', 'Building without libfolks.')
+
     if option_enabled ('zeitgeist'):
         check_pkg ('zeitgeist-1.0', '0.3.10', mandatory=False)
         if conf.env['HAVE_ZEITGEIST']:
@@ -267,6 +279,7 @@ def set_options (opt):
         help='Update localization files', dest='update_po')
     add_enable_option ('docs', 'informational text files', group)
 
+    add_enable_option ('libfolks', 'libfolks support (Telepathy, EDS)')
     add_enable_option ('zeitgeist', 'Zeitgeist support (Synapse, Unity)')
     add_enable_option ('libindicate', 'Messaging Menu support (Ayatana)')
 



More information about the Xfce4-commits mailing list