[Xfce4-commits] <postler:master> Implement initial Dexter class for DBus access

Christian Dywan noreply at xfce.org
Mon Dec 6 19:10:01 CET 2010


Updating branch refs/heads/master
         to 84a39a0b59c63127e1af1a1a387fa7f7377fd602 (commit)
       from bfea0ee2ef89aac9647082a17cab2b7513d9ba2f (commit)

commit 84a39a0b59c63127e1af1a1a387fa7f7377fd602
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Dec 6 19:07:23 2010 +0100

    Implement initial Dexter class for DBus access
    
    The Dexter class provides access to the addressbook, if available,
    and gracefully handles errors.
    
    The address book button in the composer now opens Dexter.
    
    Senders in the message list are looked up in the address book.
    
    Fixes: https://bugs.launchpad.net/dexter-rolodex/+bug/678040

 postler/dexter.vala           |   46 +++++++++++++++++++++++++++++++++++++++++
 postler/postler-composer.vala |    7 +++++-
 postler/postler-messages.vala |    3 ++
 3 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/postler/dexter.vala b/postler/dexter.vala
new file mode 100644
index 0000000..7f9ec4a
--- /dev/null
+++ b/postler/dexter.vala
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+namespace Dexter {
+
+    [DBus (name = "org.elementary.dexterservice")]
+    interface DexterService : Object {
+        public abstract string get_name (string email_address) throws IOError;
+        public abstract void show_window () throws IOError;
+    }
+
+    public class Dexter : Object {
+        DexterService service;
+        public Dexter () {
+            try {
+                service = Bus.get_proxy_sync (BusType.SESSION,
+                                              "org.elementary.dexterservice",
+                                              "/org/elementary/dexterservice");
+            } catch (GLib.Error error) {  }
+        }
+        public string? get_name (string email_address) {
+            try {
+                string name = service.get_name (email_address);
+                return name != "" ? name : null;
+            } catch (GLib.Error error) {
+                return null;
+            }
+        }
+        public void show_window () {
+            try {
+                service.show_window ();
+            } catch (GLib.Error error) {
+                Postler.App.execute_command ("dexter");
+            }
+        }
+    }
+}
+
diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index 3c9504e..73d7d43 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -11,6 +11,7 @@
 
 public class Postler.Composer : Gtk.Window {
     Accounts accounts = new Accounts ();
+    Dexter.Dexter dexter = new Dexter.Dexter ();
 
     Gtk.UIManager ui;
     Gtk.ActionGroup actions;
@@ -303,6 +304,10 @@ public class Postler.Composer : Gtk.Window {
         insert_text (emoticon);
     }
 
+    void action_address_book () {
+        dexter.show_window ();
+    }
+
     const Gtk.ActionEntry[] action_entries = {
         { "Mail", null, N_("_Mail") },
         { "MessageSend", STOCK_MAIL_SEND, null, "<Ctrl>Return",
@@ -315,7 +320,7 @@ public class Postler.Composer : Gtk.Window {
           N_("Close the window"), action_close },
         { "Edit", null, N_("_Edit") },
         { "AddressBook", STOCK_ADDRESSBOOK, null, "<Ctrl><Shift>a",
-          N_("Open the addressbook"), null },
+          N_("Open the addressbook"), action_address_book },
         { "Preferences", Gtk.STOCK_PREFERENCES, null, "<Ctrl><Alt>p",
           N_("Configure the application preferences"), action_preferences },
         { "Quote", Gtk.STOCK_INDENT, N_("_Quote the selected text"), "",
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index eea23c1..e250371 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -13,6 +13,7 @@ public class Postler.Messages : Gtk.TreeView {
     Accounts accounts;
     Gtk.TreeStore store;
     Gtk.TreeModelSort sort;
+    Dexter.Dexter dexter = new Dexter.Dexter ();
 
     public Postler.Content content { get; set; }
     public bool hide_read { get; set; }
@@ -137,6 +138,8 @@ public class Postler.Messages : Gtk.TreeView {
         now.set_time_val (GLib.TimeVal ());
         string date = Postler.Messages.format_timestamp (timestamp, now);
         from = escape_text (parse_address (parse_encoded (from, out charset))[0]);
+        from = dexter.get_name (from) ?? from;
+
         renderer.ellipsize = Pango.EllipsizeMode.END;
         renderer.markup = ("<span weight=\"%d\">%s</span>\n" +
                            "<small><tt>%s      </tt></small> %s").printf (



More information about the Xfce4-commits mailing list