--- /dev/null
+/*
+ * 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);
+}
+
+}
+}
+}