]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/log.vala
List log entries
[gregoa/zavai.git] / src / log.vala
index b8aac437363cb764d9cf6d0b448daa1ae3fc5590..84b0d2056922e5db9ae4bf0393367d29758409b8 100644 (file)
@@ -90,13 +90,15 @@ public class Log : Object
 {
     public string tag;
     public string title;
+    public bool acked;
     public List<LogEntry> entries;
     public List<TrackEntry> track;
 
-    public Log(string tag, string title)
+    public Log(string tag, string title, bool acked=false)
     {
         this.tag = tag;
         this.title = title;
+        this.acked = acked;
         entries = null;
         track = null;
     }
@@ -118,12 +120,16 @@ public class Log : Object
         if (entries == null) return;
 
         // Directory where we save the log
-        string dir = config.homedir + "/log-" + tag;
+        string dir;
+        if (acked)
+            dir = config.homedir + "/archive";
+        else
+            dir = config.homedir + "/log";
         DirUtils.create(dir, 0777);
 
         // First try with a plain name
         var t = Time.local(entries.data.ts);
-        string basename = dir + "/" + t.format("%Y%m%d-%H%M%S");
+        string basename = dir + "/" + t.format("%Y%m%d-%H%M%S") + "-" + tag;
 
         string pathname = basename + ".gpx";
 
@@ -361,6 +367,36 @@ public class Logger : Resource, Object
         return parser.result;
     }
 
+    protected size_t list_dir(string dir, ref List<string> res)
+    {
+        size_t count = 0;
+        var d = File.new_for_path(dir);
+        var enumerator = d.enumerate_children(FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
+        FileInfo file_info;
+        while ((file_info = enumerator.next_file(null)) != null)
+        {
+            if (!file_info.get_name().has_suffix(".gpx")) continue;
+            res.append(file_info.get_name());
+            ++count;
+        }
+        return count;
+    }
+
+    public string[] list_entries(bool only_unacked=true)
+    {
+        size_t count = 0;
+        List<string> entries = new List<string>();
+        if (!only_unacked)
+            count += list_dir(config.homedir + "/archive", ref entries);
+        count += list_dir(config.homedir + "/log", ref entries);
+        string[] res = new string[count+1];
+        size_t cur = 0;
+        for (weak List<string> i = entries; i != null; i = i.next)
+            res[cur++] = i.data;
+        res[cur] = null;
+        return res;
+    }
+
     public void instant(string tag, string msg)
     {
         var log = new Log(tag, msg);