Updating branch refs/heads/master to 1b3156812d94e4dddfb7923d54f42456a9c6b772 (commit) from 2682481ef7a06e1c6a3d895a94b442b1e1cb406f (commit)
commit 1b3156812d94e4dddfb7923d54f42456a9c6b772 Author: Christian Dywan <christ...@twotoasts.de> Date: Thu Jun 2 21:13:00 2011 +0200 Implement Unity.LauncherEntry interface Expose Unread as a public property through DBus. postler/postler-service.vala | 53 ++++++++++++++++++++++++++++++++--------- 1 files changed, 41 insertions(+), 12 deletions(-) diff --git a/postler/postler-service.vala b/postler/postler-service.vala index 0155162..8a906f2 100644 --- a/postler/postler-service.vala +++ b/postler/postler-service.vala @@ -98,10 +98,35 @@ namespace Postler { internal signal void done (string error_message=""); } + [DBus (name = "com.canonical.Unity.LauncherEntry")] + class LauncherEntry : Object { + PostlerService service; + + public HashTable<string, Variant> query () { + var properties = new HashTable<string, Variant> (str_hash, str_equal); + properties.insert ("count", (int64)service.unread); + properties.insert ("count-visible", service.unread > 0); + properties.insert ("progress", 0.0); + properties.insert ("progress-visible", false); + properties.insert ("urgent", false); + return properties; + } + + public signal void update (string app_uri, HashTable<string, Variant> properties); + + public LauncherEntry (PostlerService service) { + this.service = service; + service.notify["unread"].connect ((object, pspec) => { + update ("application://postler.desktop", query ()); + }); + update ("application://postler.desktop", query ()); + } + } + [DBus (name = "org.elementary.Postler")] class PostlerService : Object { double total = 0; - int unread = 0; + public int64 unread { get; set; default = 0; } Dock.Item dockitem; Index? index = null; FileMonitor[] folder_monitors = {}; @@ -341,7 +366,6 @@ namespace Postler { string[] pieces = msg.split (" "); total = total - pieces[1].to_double (); if (helper.folder == "INBOX") { - unread += pieces[3].to_int (); helper.folder = _("Inbox"); } } @@ -401,7 +425,6 @@ namespace Postler { return; } - unread = 0; foreach (var info in infos) { try { progress (info.display_name, _("Checking for mail..."), 0.0); @@ -426,12 +449,17 @@ namespace Postler { received (helper.display_name, error_message); return; } - GLib.debug ("Done: %d new messages", unread); - if (unread > 0) { - Postler.App.send_notification ( - ngettext ("You have %d message", - "You have %d new messages", unread).printf (unread)); - Postler.App.play_sound ("message-new-email"); + try { + if ((unread = unread_messages ("%/INBOX/%")) > 0) { + GLib.debug ("Done: %d new messages", (int)unread); + Postler.App.send_notification ( + ngettext ("You have %d message", + "You have %d new messages", (int)unread).printf ((int)unread)); + Postler.App.play_sound ("message-new-email"); + } + } + catch (GLib.Error error) { + GLib.debug ("Done: ?? new messages"); } received (helper.display_name, ""); }); @@ -464,7 +492,6 @@ namespace Postler { if (infos.length () == 0) return false; - unread = 0; foreach (var info in infos) { try { string command = accounts.get_fetch_command (info); @@ -552,8 +579,10 @@ namespace Postler { void name_aquired (DBusConnection conn) { try { - conn.register_object ("/org/elementary/postler", - new PostlerService ()); + var service = new PostlerService (); + conn.register_object ("/org/elementary/postler", service); + conn.register_object ("/com/canonical/unity/launcherentry", + new LauncherEntry (service)); } catch (IOError e) { stderr.printf ("Could not register service\n"); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits