From a4b53a970c40c798fefd7e115ba07bb2ae70df80 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sat, 27 Mar 2010 23:42:01 +0000 Subject: [PATCH] Added log viewer --- src/app_log.vala | 138 ++++++++++++++++++++++++++++++++++++++++++++++ src/app_main.vala | 2 +- src/zavai.vala | 1 + 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/app_log.vala diff --git a/src/app_log.vala b/src/app_log.vala new file mode 100644 index 0000000..884c007 --- /dev/null +++ b/src/app_log.vala @@ -0,0 +1,138 @@ +/* + * app_log - zavai log applet + * + * Copyright (C) 2010 Enrico Zini + * + * 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 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); +} + +} +} +} diff --git a/src/app_main.vala b/src/app_main.vala index 94b7df2..0faa727 100644 --- a/src/app_main.vala +++ b/src/app_main.vala @@ -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); diff --git a/src/zavai.vala b/src/zavai.vala index caa6f3f..f9838c5 100644 --- a/src/zavai.vala +++ b/src/zavai.vala @@ -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"); -- 2.39.5