Facility for acking/unacking log entries
authorEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 23:51:41 +0000 (23:51 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 23:51:41 +0000 (23:51 +0000)
src/app_log.vala

index 884c007b4d6248c7e9ad14cdd47e48805bd527a0..fa247b4ea34e77dceab14e30a05eb7358f9fabbd 100644 (file)
@@ -32,6 +32,9 @@ public class Log : Applet
     protected Gtk.ScrolledWindow details_scroll;
     protected Gtk.TextBuffer details;
     protected Gtk.TextView details_view;
     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()
     {
 
     public Log()
     {
@@ -65,6 +68,12 @@ public class Log : Applet
         pack_start(details_frame, true, true, 0);
 
         list.cursor_changed += on_row_selected;
         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)
     }
 
     private void render_details(zavai.log.Log l)
@@ -88,23 +97,44 @@ public class Log : Applet
         Gtk.TreePath path;
         list.get_cursor(out path, null);
 
         Gtk.TreePath path;
         list.get_cursor(out path, null);
 
-        Gtk.TreeIter iter;
-        if (!model.get_iter(out iter, path)) return;
+        if (!model.get_iter(out cur_iter, path)) return;
 
         Value vdir, vname;
 
         Value vdir, vname;
-        model.get_value(iter, 0, out vdir);
-        model.get_value(iter, 1, out 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();
 
         string pathname = vdir.get_string() + "/" + vname.get_string();
-        zavai.log.Log l = zavai.log.log.load(pathname);
-        render_details(l);
+        cur_log = zavai.log.log.load(pathname);
+        render_details(cur_log);
 
 
-        // l.acked
+        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);
     }
 
 
         // 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);
+    }
+
+    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();
     public void refresh()
     {
         model.clear();