Added log viewer
authorEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 23:42:01 +0000 (23:42 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 23:42:01 +0000 (23:42 +0000)
src/app_log.vala [new file with mode: 0644]
src/app_main.vala
src/zavai.vala

diff --git a/src/app_log.vala b/src/app_log.vala
new file mode 100644 (file)
index 0000000..884c007
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * app_log - zavai log applet
+ *
+ * Copyright (C) 2010  Enrico Zini <enrico@enricozini.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+namespace zavai {
+namespace ui {
+namespace logview {
+
+public class Log : Applet
+{
+    protected Gtk.ScrolledWindow scroll_list;
+    protected Gtk.ListStore model;
+    protected Gtk.TreeView list;
+    protected Gtk.CellRendererText rend_name;
+    protected Gtk.Frame details_frame;
+    protected Gtk.ScrolledWindow details_scroll;
+    protected Gtk.TextBuffer details;
+    protected Gtk.TextView details_view;
+
+    public Log()
+    {
+        _label = "Log";
+
+        model = new Gtk.ListStore(3, typeof(string), typeof(string), typeof(bool));
+        model.set_sort_column_id(1, Gtk.SortType.DESCENDING);
+
+        rend_name = new Gtk.CellRendererText();
+
+        list = new Gtk.TreeView.with_model(model);
+        list.insert_column_with_attributes (-1, "Name", rend_name, "text", 1, "strikethrough", 2, null);
+        //list.insert_column_with_attributes (-1, "Notes", new Gtk.CellRendererText(), "text", 1);
+
+        scroll_list = new Gtk.ScrolledWindow(null, null);
+        scroll_list.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+        scroll_list.add(list);
+
+        details_frame = new Gtk.Frame("Entry details");
+        details = new Gtk.TextBuffer(null);
+        details_view = new Gtk.TextView.with_buffer(details);
+        details_view.wrap_mode = Gtk.WrapMode.WORD;
+        details_view.cursor_visible = false;
+        details_view.editable = false;
+        details_scroll = new Gtk.ScrolledWindow(null, null);
+        details_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+        details_scroll.add(details_view);
+        details_frame.add(details_scroll);
+
+        pack_start(scroll_list, true, true, 0);
+        pack_start(details_frame, true, true, 0);
+
+        list.cursor_changed += on_row_selected;
+    }
+
+    private void render_details(zavai.log.Log l)
+    {
+        details.text = "";
+        details.insert_at_cursor("%s: %s\n".printf(l.tag, l.title), -1);
+
+        for (weak List<zavai.log.LogEntry> i = l.entries; i != null; i = i.next)
+        {
+            // We are displaying it to the user, so use local timezone
+            var t = Time.local(i.data.ts);
+            string formatted = t.format("%Y-%m-%d %H:%M:%S");
+            details.insert_at_cursor("%s: %s\n".printf(formatted, i.data.msg), -1);
+            // public double lat;
+            // public double lon;
+        }
+    }
+
+    private void on_row_selected(Gtk.TreeView tv)
+    {
+        Gtk.TreePath path;
+        list.get_cursor(out path, null);
+
+        Gtk.TreeIter iter;
+        if (!model.get_iter(out iter, path)) return;
+
+        Value vdir, vname;
+        model.get_value(iter, 0, out vdir);
+        model.get_value(iter, 1, out vname);
+
+        string pathname = vdir.get_string() + "/" + vname.get_string();
+        zavai.log.Log l = zavai.log.log.load(pathname);
+        render_details(l);
+
+        // l.acked
+
+        // model.set(iter, 0, d); // set new dir
+        //selected((int)year, (int)month, (int)day);
+    }
+
+    public void refresh()
+    {
+        model.clear();
+
+        zavai.log.log.list_entries((d, f) => {
+            Gtk.TreeIter iter;
+            model.insert_with_values(out iter, -1, 0, d, 1, f, 2, false, -1);
+            return true;
+        });
+    }
+
+    public override void start()
+    {
+        refresh();
+    }
+    public override void stop()
+    {
+    }
+}
+
+public Log log;
+
+public void init()
+{
+    log = new Log();
+    zavai.menu_misc.add_applet(log);
+}
+
+}
+}
+}
index 94b7df2362014ab78621892fa877ebfab5797fd7..0faa7274ba4bb6c9080dc64caea93693db686940 100644 (file)
@@ -426,7 +426,7 @@ public class Log : Gtk.VBox
         l_info_button.set_image(l_info);
         l_info_button.relief = Gtk.ReliefStyle.NONE;
         l_info_button.clicked += (b) => {
-            //zavai.app.push_applet(zavai.ui.log.log);
+            zavai.app.push_applet(zavai.ui.logview.log);
         };
         pack_start(l_info_button, false, false, 0);
 
index caa6f3f166a2dcf9b0d3658313620a25f93940c7..f9838c5af31a51de2aa3ef3b077bdb5753715889 100644 (file)
@@ -229,6 +229,7 @@ static int main (string[] args) {
        zavai.ui.alarm.init();
        zavai.ui.wifi.init();
        zavai.ui.bluetooth.init();
+       zavai.ui.logview.init();
        zavai.ui.debug.init();
 
        //zavai.app.show_applet("menu.main");