From a875b79aed711ebb9941cf739534d2b042d767db Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sat, 27 Mar 2010 21:23:09 +0000 Subject: [PATCH] List log entries --- README | 2 +- src/log.vala | 42 +++++++++++++++++++++++++++++++++++++++--- src/zavai.vala | 6 ++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README b/README index 65bb847..9538fab 100644 --- a/README +++ b/README @@ -194,7 +194,7 @@ using vala-dbus-binding-tool: if GPS time is more than 1 hour different than the system time, show a "SYNC" button that will sync it if pressed - log - - load log entry for showing it + + load log entry for showing it - write data to disk as log happens (to have at least partial logs if power is cut) - more detailed GPX data (dop, elev..) diff --git a/src/log.vala b/src/log.vala index b8aac43..84b0d20 100644 --- a/src/log.vala +++ b/src/log.vala @@ -90,13 +90,15 @@ public class Log : Object { public string tag; public string title; + public bool acked; public List entries; public List 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 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 entries = new List(); + 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 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); diff --git a/src/zavai.vala b/src/zavai.vala index d682e82..29df675 100644 --- a/src/zavai.vala +++ b/src/zavai.vala @@ -279,6 +279,12 @@ static int main (string[] args) { if (args.length > 2 && args[1] == "showlog") { + string[] z = zavai.log.log.list_entries(false); + for (int i = 0; z[i] != null; ++i) + stderr.printf("FALSE %s\n", z[i]); + z = zavai.log.log.list_entries(true); + for (int i = 0; z[i] != null; ++i) + stderr.printf("TRUE %s\n", z[i]); zavai.log.Log l = zavai.log.log.load(args[2]); l.dump(); return 0; -- 2.39.5