[Xfce4-commits] <postler:master> Implement 'New Task' via GTG DBus interface

Christian Dywan noreply at xfce.org
Tue Aug 9 01:24:01 CEST 2011


Updating branch refs/heads/master
         to 197eed2b52d976b60c236ba422220d48bc35da61 (commit)
       from be2acb8aeedfa41838f4aab1a1d9310830981b16 (commit)

commit 197eed2b52d976b60c236ba422220d48bc35da61
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Aug 9 01:21:20 2011 +0200

    Implement 'New Task' via GTG DBus interface
    
    A button is shown next to Add Contact if GTG is installed.

 postler/gtg.vala             |   47 ++++++++++++++++++++++++++++++++++++++++++
 postler/postler-app.vala     |    2 +
 postler/postler-content.vala |   31 +++++++++++++++++++++------
 3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/postler/gtg.vala b/postler/gtg.vala
new file mode 100644
index 0000000..048f8fd
--- /dev/null
+++ b/postler/gtg.vala
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2011 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 GTG {
+
+    [DBus (name = "org.GTG")]
+    interface GTGService : GLib.DBusProxy {
+        [DBus (name = "open_new_task")]
+        public abstract void open_new_task (string subject, string text) throws IOError;
+    }
+
+    public class GTG : Object {
+        GTGService? service = null;
+        public GTG () {
+            if (service != null)
+                return;
+            try {
+                service = Bus.get_proxy_sync (BusType.SESSION, "org.GTG", "/org/GTG");
+            }
+            catch (GLib.Error error) { }
+        }
+        public static bool available { get {
+                return Environment.find_program_in_path ("gtg") != null;
+            }
+        }
+        public void open_new_task (string subject, string text) {
+            try {
+                if (service == null)
+                    service = Bus.get_proxy_sync (BusType.SESSION, "org.GTG", "/org/GTG");
+                service.open_new_task (subject, text);
+            }
+            catch (GLib.Error error) {
+                /* Fallback if GTG fails to launch automatically */
+                Postler.App.execute_command ("gtg_new_task " + subject);
+            }
+        }
+    }
+}
+
diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index 8496704..e37f44b 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -48,6 +48,7 @@ namespace Postler {
     const string STOCK_SENT_MAIL = "mail-sent";
     const string STOCK_USER_TRASH = "user-trash";
     const string STOCK_REPORT_BUG = "lpi-bug";
+    const string STOCK_TASK_DUE = "task-due";
 }
 
 #if HAVE_GTK3
@@ -123,6 +124,7 @@ public class Postler.App : Unique.App {
         { STOCK_OUTBOX, null, 0, 0, "stock_outbox" },
         { STOCK_REPORT_BUG, null, 0, 0, "bug-buddy" },
         { STOCK_SENT_MAIL, null, 0, 0, "stock_sent-mail" },
+        { STOCK_TASK_DUE },
         { STOCK_USER_TRASH }
     };
 
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index d4f1cf7..589ff9f 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -727,13 +727,25 @@ public class Postler.Content : WebKit.WebView {
                 }
 
                 var reply_chunk = new StringBuilder ();
-                message_parts.append (html_part ?? (text_part ?? child.parts.nth_data (0)));
-                if (html_part != null)
-                    reply_chunk.append (html_part.body.str);
-                else if (text_part != null)
-                    reply_chunk.append (render_plain_text (text_part.body.str, child));
+                var default_part = html_part ?? (text_part ?? child.parts.nth_data (0));
+                message_parts.append (default_part);
+                if (html_part == null && text_part != null)
+                    reply_chunk.append (render_plain_text (default_part.body.str, child));
                 else
-                    reply_chunk.append (child.parts.nth_data (0).body.str);
+                    reply_chunk.append (default_part.body.str);
+
+                if (GTG.GTG.available) {
+                    string task_desc = "%s \n\n @mail".printf (
+                        default_part.get_plain_text ());
+                    var info = account_info ?? child.get_account (new Accounts ());
+                    if (info != null)
+                        task_desc += " @" + info.display_name;
+                    reply_chunk.append_printf ("""
+                        <span class="contact">%s</span>
+                        """.printf (
+                        linkify_icon (STOCK_TASK_DUE, _("New Task"),
+                            "task:%s:%s".printf (child.subject, task_desc))));
+                }
 
                 string? sender_name = null;
                 if (child.can_reply_personally) {
@@ -1012,10 +1024,15 @@ public class Postler.Content : WebKit.WebView {
 
         decision.ignore ();
         if (uri.has_prefix ("contact:")) {
-            string[] parts = Soup.URI.decode (uri).split (":");
+            string[] parts = Soup.URI.decode (uri).split (":", 3);
             new Dexter.Dexter ().edit_contact (parts[1], parts[2]);
             return true;
         }
+        else if (uri.has_prefix ("task:")) {
+            string[] parts = Soup.URI.decode (uri).split (":", 3);
+            new GTG.GTG ().open_new_task (parts[1], parts[2]);
+            return true;
+        }
         else if (uri.has_prefix ("message-part:")) {
             int index;
             if (uri.has_prefix ("message-part:open:"))


More information about the Xfce4-commits mailing list