[Xfce4-commits] <postler:master> Initial Postler DBus service with ReceiveMail()

Christian Dywan noreply at xfce.org
Fri Dec 10 20:50:01 CET 2010


Updating branch refs/heads/master
         to b887d990ee86bc33df1d83acaed1d38952e0149f (commit)
       from e2c4a15ebda3979752282ae41bc4d8c4de1c1757 (commit)

commit b887d990ee86bc33df1d83acaed1d38952e0149f
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Dec 10 00:05:11 2010 +0100

    Initial Postler DBus service with ReceiveMail()
    
    The service is started as a module 'service', it will silently
    quit if already running.
    
    The service will be run from the client side automatically just
    like Dexter is.
    
    The service runs without any graphical interface.

 postler/postler-client.vala  |   44 ++++++++++++++++++++++++++++++++++++
 postler/postler-reader.vala  |   13 +++++++++-
 postler/postler-service.vala |   51 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/postler/postler-client.vala b/postler/postler-client.vala
new file mode 100644
index 0000000..fc14bd5
--- /dev/null
+++ b/postler/postler-client.vala
@@ -0,0 +1,44 @@
+/*
+ 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 Postler {
+
+    [DBus (name = "org.elementary.Postler")]
+    interface PostlerClient : Object {
+        public abstract void receive_mail () throws IOError;
+    }
+
+    public class Client : Object {
+        PostlerClient client;
+
+        public Client () {
+            try {
+                client = Bus.get_proxy_sync (BusType.SESSION,
+                                             "org.elementary.Postler",
+                                             "/org/elementary/postler");
+                /* Ensure Postler is running, ignore errors */
+                Process.spawn_async (null,
+                    { Postler.App.argv0, "-m", "service" }, null,
+                    SpawnFlags.SEARCH_PATH
+                  | SpawnFlags.STDOUT_TO_DEV_NULL
+                  | SpawnFlags.STDERR_TO_DEV_NULL,
+                    null, null);
+            } catch (GLib.Error error) { }
+        }
+
+        public void receive_mail () {
+            try {
+                client.receive_mail ();
+            } catch (GLib.Error error) { }
+        }
+    }
+}
+
diff --git a/postler/postler-reader.vala b/postler/postler-reader.vala
index 4eb228b..e4955a5 100644
--- a/postler/postler-reader.vala
+++ b/postler/postler-reader.vala
@@ -31,6 +31,7 @@ public class Postler.Reader {
         context.set_help_enabled (true);
         context.add_main_entries (options, null);
         context.add_group (Gtk.get_option_group (true));
+        Environment.set_application_name (_("Postler"));
         try {
 	    context.parse (ref args);
 	} catch (GLib.Error error) {
@@ -42,7 +43,15 @@ public class Postler.Reader {
             Log.set_handler (null, LogLevelFlags.LEVEL_DEBUG, handler);
         }
 
-        Environment.set_application_name (_("Postler"));
+        if (module == "service") {
+            var service = new Postler.Service ();
+            service.done.connect ((status) => {
+                Process.exit (status);
+            });
+            service.run ();
+            assert_not_reached ();
+        }
+
         Gtk.init (ref args);
         /* FIXME: only for new webkit */
         WebKit.set_cache_model (WebKit.CacheModel.DOCUMENT_VIEWER);
@@ -119,7 +128,7 @@ public class Postler.Reader {
             }
             else
                 GLib.error ("Unknown module \"%s\". Valid modules are: %s",
-                    module, "content source compose");
+                    module, "content source compose service");
 
             /* FIXME: Escape to close window */
             var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
new file mode 100644
index 0000000..1fe6733
--- /dev/null
+++ b/postler/postler-service.vala
@@ -0,0 +1,51 @@
+/*
+ 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 Postler {
+
+    [DBus (name = "org.elementary.Postler")]
+    class PostlerService : Object {
+        public void receive_mail () {
+            var accounts = new Accounts ();
+            accounts.receive (null);
+        } 
+    }
+
+    public class Service {
+        void bus_aquired (DBusConnection conn) {
+            try {
+                conn.register_object ("/org/elementary/postler",
+                                      new PostlerService ());
+            } catch (IOError e) {
+                stderr.printf ("Could not register service\n");
+                done (1);
+            }
+        }
+
+        void name_aquired () {
+        }
+
+        void name_lost () {
+            done (0);
+        }
+
+        public void run () {
+            Bus.own_name (BusType.SESSION, "org.elementary.Postler",
+                          BusNameOwnerFlags.NONE,
+                          bus_aquired, name_aquired, name_lost);
+            new MainLoop ().run ();
+            done (0);
+        }
+
+        public signal void done (int status);
+    }
+}
+



More information about the Xfce4-commits mailing list