/* * 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; protected BigButton read_unread; protected Gtk.TreeIter cur_iter; protected zavai.log.Log cur_log; 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; read_unread = new BigButton(); update_read_unread(false); read_unread.set_sensitive(false); read_unread.clicked += on_read_unread; button_box.pack_start(read_unread, true, true, 0); } 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); if (!model.get_iter(out cur_iter, path)) return; Value vdir, vname; model.get_value(cur_iter, 0, out vdir); model.get_value(cur_iter, 1, out vname); string pathname = vdir.get_string() + "/" + vname.get_string(); cur_log = zavai.log.log.load(pathname); render_details(cur_log); read_unread.set_sensitive(true); update_read_unread(cur_log.acked); // model.set(iter, 0, d); // set new dir //selected((int)year, (int)month, (int)day); } private void on_read_unread(Gtk.Button b) { if (cur_log.acked) { cur_log.acked = false; } else { cur_log.acked = true; } model.set(cur_iter, 2, cur_log.acked, -1); update_read_unread(cur_log.acked); Value vname; model.get_value(cur_iter, 1, out vname); zavai.log.log.set_acknowledged(vname.get_string(), cur_log.acked); } private void update_read_unread(bool acked) { if (acked) read_unread.set_label("Mark as unread"); else read_unread.set_label("Mark as read"); } 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); } } } }