2 * app_log - zavai log applet
4 * Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public class Log : Applet
27 protected Gtk.ScrolledWindow scroll_list;
28 protected Gtk.ListStore model;
29 protected Gtk.TreeView list;
30 protected Gtk.CellRendererText rend_name;
31 protected Gtk.Frame details_frame;
32 protected Gtk.ScrolledWindow details_scroll;
33 protected Gtk.TextBuffer details;
34 protected Gtk.TextView details_view;
35 protected BigButton read_unread;
36 protected Gtk.TreeIter cur_iter;
37 protected zavai.log.Log cur_log;
43 model = new Gtk.ListStore(3, typeof(string), typeof(string), typeof(bool));
44 model.set_sort_column_id(1, Gtk.SortType.DESCENDING);
46 rend_name = new Gtk.CellRendererText();
48 list = new Gtk.TreeView.with_model(model);
49 list.insert_column_with_attributes (-1, "Name", rend_name, "text", 1, "strikethrough", 2, null);
50 //list.insert_column_with_attributes (-1, "Notes", new Gtk.CellRendererText(), "text", 1);
52 scroll_list = new Gtk.ScrolledWindow(null, null);
53 scroll_list.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
54 scroll_list.add(list);
56 details_frame = new Gtk.Frame("Entry details");
57 details = new Gtk.TextBuffer(null);
58 details_view = new Gtk.TextView.with_buffer(details);
59 details_view.wrap_mode = Gtk.WrapMode.WORD;
60 details_view.cursor_visible = false;
61 details_view.editable = false;
62 details_scroll = new Gtk.ScrolledWindow(null, null);
63 details_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
64 details_scroll.add(details_view);
65 details_frame.add(details_scroll);
67 pack_start(scroll_list, true, true, 0);
68 pack_start(details_frame, true, true, 0);
70 list.cursor_changed += on_row_selected;
72 read_unread = new BigButton();
73 update_read_unread(false);
74 read_unread.set_sensitive(false);
75 read_unread.clicked += on_read_unread;
76 button_box.pack_start(read_unread, true, true, 0);
79 private void render_details(zavai.log.Log l)
82 details.insert_at_cursor("%s: %s\n".printf(l.tag, l.title), -1);
84 for (weak List<zavai.log.LogEntry> i = l.entries; i != null; i = i.next)
86 // We are displaying it to the user, so use local timezone
87 var t = Time.local(i.data.ts);
88 string formatted = t.format("%Y-%m-%d %H:%M:%S");
89 details.insert_at_cursor("%s: %s\n".printf(formatted, i.data.msg), -1);
95 private void on_row_selected(Gtk.TreeView tv)
98 list.get_cursor(out path, null);
100 if (!model.get_iter(out cur_iter, path)) return;
103 model.get_value(cur_iter, 0, out vdir);
104 model.get_value(cur_iter, 1, out vname);
106 string pathname = vdir.get_string() + "/" + vname.get_string();
107 cur_log = zavai.log.log.load(pathname);
108 render_details(cur_log);
110 read_unread.set_sensitive(true);
111 update_read_unread(cur_log.acked);
113 // model.set(iter, 0, d); // set new dir
114 //selected((int)year, (int)month, (int)day);
117 private void on_read_unread(Gtk.Button b)
121 cur_log.acked = false;
123 cur_log.acked = true;
125 model.set(cur_iter, 2, cur_log.acked, -1);
127 update_read_unread(cur_log.acked);
130 private void update_read_unread(bool acked)
133 read_unread.set_label("Mark as unread");
135 read_unread.set_label("Mark as read");
138 public void refresh()
142 zavai.log.log.list_entries((d, f) => {
144 model.insert_with_values(out iter, -1, 0, d, 1, f, 2, false, -1);
149 public override void start()
153 public override void stop()
163 zavai.menu_misc.add_applet(log);