[Xfce4-commits] <postler:master> Add .desktop file to message indicator folder

Christian Dywan noreply at xfce.org
Tue Jan 4 05:52:01 CET 2011


Updating branch refs/heads/master
         to af4a526da97814bc29faaaf5fe92640029bc01c7 (commit)
       from 8f4d29d485f49800c6e8b02346fa07c3abce5bbf (commit)

commit af4a526da97814bc29faaaf5fe92640029bc01c7
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jan 2 19:27:36 2011 +0100

    Add .desktop file to message indicator folder
    
    This makes Postler show up in the menu after adding an
    account, and remove itself if all accounts are deleted.
    
    This menu item is shown regardless of Postler running.

 postler/config.vapi           |   16 +++++++++-------
 postler/postler-accounts.vala |   27 +++++++++++++++++++++------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/postler/config.vapi b/postler/config.vapi
index fbd751e..da254f8 100644
--- a/postler/config.vapi
+++ b/postler/config.vapi
@@ -13,13 +13,15 @@
 namespace Config {
     [CCode (cname = "GETTEXT_PACKAGE")]
     public const string GETTEXT_PACKAGE;
+    [CCode (cname = "MDATADIR")]
+    public const string DATADIR;
     [CCode (cname = "LOCALEDIR")]
-	public const string LOCALEDIR;
-	[CCode (cname = "PACKAGE_NAME")]
-	public const string PACKAGE_NAME;
-	[CCode (cname = "PACKAGE_VERSION")]
-	public const string PACKAGE_VERSION;
-	[CCode (cname = "PACKAGE_BUGREPORT")]
-	public const string PACKAGE_BUGREPORT;
+    public const string LOCALEDIR;
+    [CCode (cname = "PACKAGE_NAME")]
+    public const string PACKAGE_NAME;
+    [CCode (cname = "PACKAGE_VERSION")]
+    public const string PACKAGE_VERSION;
+    [CCode (cname = "PACKAGE_BUGREPORT")]
+    public const string PACKAGE_BUGREPORT;
 }
 
diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 95c62a9..0e2cdaf 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -159,6 +159,25 @@ public class Postler.Accounts : GLib.Object {
         reload ();
     }
 
+    void write_keyfile () throws Error {
+        if (DirUtils.create_with_parents (config_path, 0700) != 0)
+            throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
+        FileUtils.set_contents (account_file, keyfile.to_data ());
+
+        unowned string config_dir = Environment.get_user_config_dir ();
+        unowned string indicator_dir = "/indicators/messages/applications";
+        string indicator_path = config_dir + indicator_dir;
+        string filename = indicator_path + "/postler.desktop";
+        bool exists = FileUtils.test (filename, FileTest.EXISTS);
+        if (infos.length () != 0 && !exists) {
+            DirUtils.create_with_parents (indicator_path, 0700);
+            FileUtils.set_contents (filename,
+                Config.DATADIR + "/applications/postler.desktop");
+        }
+        else if (infos.length () == 0)
+            FileUtils.unlink (filename);
+    }
+
     public void update () {
         try {
             foreach (AccountInfo account_info in infos) {
@@ -218,9 +237,7 @@ public class Postler.Accounts : GLib.Object {
                     assert_not_reached ();
             }
 
-            if (DirUtils.create_with_parents (config_path, 0700) != 0)
-                throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
-            FileUtils.set_contents (account_file, keyfile.to_data ());
+            write_keyfile ();
         }
         catch (GLib.Error error) {
             GLib.critical ("Failed to save \"%s\": %s", account_file, error.message);
@@ -231,9 +248,7 @@ public class Postler.Accounts : GLib.Object {
         requires (info.name != null) {
         try {
             keyfile.remove_group (info.name);
-            if (DirUtils.create_with_parents (config_path, 0700) != 0)
-                throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
-            FileUtils.set_contents (account_file, keyfile.to_data ());
+            write_keyfile ();
         }
         catch (GLib.Error error) {
             GLib.critical ("Failed to save \"%s\": %s", account_file, error.message);



More information about the Xfce4-commits mailing list