Use the XDG Base Directory Specification to store the data files
authorJavier Jardón <javier.jardon@codethink.co.uk>
Tue, 3 May 2011 05:55:41 +0000 (06:55 +0100)
committerJavier Jardón <javier.jardon@codethink.co.uk>
Tue, 3 May 2011 05:55:41 +0000 (06:55 +0100)
We store the data in the XDG_DATA_HOME directory

config.vapi
src/moonshot-identities-manager.vala

index 6e2f2ae..cbc5820 100644 (file)
@@ -5,6 +5,7 @@ namespace Config
         public const string PACKAGE_NAME;
         public const string PACKAGE_STRING;
         public const string PACKAGE_VERSION;
+        public const string PACKAGE_TARNAME;
 
         /* Gettext package */
         public const string GETTEXT_PACKAGE;
index a0654b3..44efcb5 100644 (file)
@@ -8,9 +8,12 @@ class IdentitiesManager : Object {
     {
         var key_file = new KeyFile ();
 
+        var path = get_data_dir ();
+        var filename = Path.build_filename (path, FILE_NAME);
+
         try
         {
-            key_file.load_from_file (FILE_NAME, KeyFileFlags.NONE);
+            key_file.load_from_file (filename, KeyFileFlags.NONE);
         }
         catch (Error e)
         {
@@ -54,7 +57,9 @@ class IdentitiesManager : Object {
 
         try
         {
-            FileUtils.set_contents (FILE_NAME, text, -1);
+            var path = get_data_dir ();
+            var filename = Path.build_filename (path, FILE_NAME);
+            FileUtils.set_contents (filename, text, -1);
         }
         catch (Error e)
         {
@@ -62,4 +67,17 @@ class IdentitiesManager : Object {
         }
     }
 
+    private string get_data_dir()
+    {
+        string path;
+
+        path = Path.build_filename (Environment.get_user_data_dir (),
+                                    Config.PACKAGE_TARNAME);
+        if (!FileUtils.test (path, FileTest.EXISTS))
+        {
+            DirUtils.create (path, 0700);
+        }
+
+        return path;
+    }
 }