Preliminary next30 implementation
authorEnrico Zini <enrico@enricozini.org>
Sat, 7 Nov 2009 00:02:44 +0000 (00:02 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sat, 7 Nov 2009 00:02:44 +0000 (00:02 +0000)
src/widgets/calendar.vala

index bfa1f3dbf11a91ef56ddc4acff1a08b7177d1f1d..cf8a7fc3b6ad5cd6d5b113d81a39245dff6d552c 100644 (file)
@@ -102,6 +102,35 @@ public class FileNotes : Gtk.ScrolledWindow
        }
 }
 
+public class Next30 : Gtk.ScrolledWindow
+{
+       protected Gtk.ListStore model;
+       protected Gtk.TreeView list;
+
+       public Next30()
+       {
+               set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+               model = new Gtk.ListStore(2, typeof(string), typeof(string));
+               list = new Gtk.TreeView.with_model(model);
+               list.insert_column_with_attributes (-1, "Day", new Gtk.CellRendererText(), "text", 0);
+               list.insert_column_with_attributes (-1, "Notes", new Gtk.CellRendererText(), "text", 1);
+               add(list);
+       }
+
+       public void clear()
+       {
+               model.clear();
+       }
+
+       public void add_day(string day, string notes)
+       {
+               Gtk.TreeIter iter;
+               model.append (out iter);
+               model.set(iter, 0, day);
+               model.set(iter, 1, notes);
+       }
+}
+
 public class Calendar : Gtk.VBox
 {
        protected Gtk.Calendar calendar;
@@ -109,6 +138,7 @@ public class Calendar : Gtk.VBox
        protected FileNotes month_notes;
        protected FileNotes day_notes;
        protected FileNotes general_notes;
+       protected Next30 next_30;
        protected int cur_year;
        protected int cur_month;
        protected int cur_day;
@@ -130,7 +160,8 @@ public class Calendar : Gtk.VBox
                general_notes = new FileNotes();
                general_notes.load(zavai.config.homedir + "/cal/notes.txt");
                notebook.append_page(general_notes, new Gtk.Label("General"));
-               notebook.append_page(new Gtk.Label("TODO"), new Gtk.Label("Next 30"));
+               next_30 = new Next30();
+               notebook.append_page(next_30, new Gtk.Label("Next 30"));
 
                pack_start(notebook, true, true, 0);
 
@@ -184,6 +215,29 @@ public class Calendar : Gtk.VBox
 
                string mpath = month_path(cur_year, cur_month);
                month_notes.load(mpath + "/00.txt");
+
+               next_30.clear();
+               Date date = Date();
+               date.set_dmy((DateDay)cur_day, cur_month, (DateYear)cur_year);
+               var buffer = new char[64];
+               for (uint i = 0; i < 30; ++i)
+               {
+                       path = day_path(date.get_year(), date.get_month(), date.get_day());
+                       string text;
+                       if (!FileUtils.test (path, FileTest.IS_REGULAR))
+                               text = "";
+                       else
+                       {
+                               try {
+                                       FileUtils.get_contents(path, out text);
+                               } catch (FileError e) {
+                                       text = "";
+                               }
+                       }
+                       date.strftime(buffer, "%d %a");
+                       next_30.add_day((string)buffer, text);
+                       date.add_days(1);
+               }
        }
 
        public void flush()