Autoswitch between next30 and day notes
authorEnrico Zini <enrico@enricozini.org>
Sat, 7 Nov 2009 14:18:26 +0000 (14:18 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sat, 7 Nov 2009 14:18:26 +0000 (14:18 +0000)
README
src/widgets/calendar.vala

diff --git a/README b/README
index ad603d9234e693d67d1a69c095a574aedba596c9..bf567275aea1f323dc675dc6c1c07de193fe1e7d 100644 (file)
--- a/README
+++ b/README
@@ -154,8 +154,10 @@ TODO list / wish list
  * Features to add:
  - calendar: show preview of next 30 days
    (not among the notes: it replaces the calendar view; unless we skip the empty dates, which is a good idea)
-   next30: when clicking on an item, show that day without updating next30
+   next30: when clicking on an item, show that day and switch to day notes (conflates next30 and day notes)
+      tab becomes day / month / all
    next30: don't update if not shown currently on the notebook
+   gtk_calendar_set_detail_func
  - contacts: show as a fancy focus+context list (see prefuse)
  - GSM power and network
     - link to open SHR-dialer
index 353f8a919d2743f62afaa6d013b4e607886b0536..b66acabc3d36b2cfa7cb9942c88c7f2575f89b13 100644 (file)
 namespace zavai {
 namespace widgets {
 
+private string month_path(int year, int month)
+{
+       return "%s/cal/%04d/%02d".printf(zavai.config.homedir, year, month);
+}
+
+private string day_path(int year, int month, int day)
+{
+       return "%s/%02d.txt".printf(month_path(year, month), day);
+}
+
+
 public class FileNotes : Gtk.ScrolledWindow
 {
        protected Gtk.TextBuffer text_buffer;
@@ -106,6 +117,7 @@ public class Next30 : Gtk.ScrolledWindow
 {
        protected Gtk.ListStore model;
        protected Gtk.TreeView list;
+       public signal void selected(int year, int month, int day);
 
        public Next30()
        {
@@ -115,14 +127,27 @@ public class Next30 : Gtk.ScrolledWindow
                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);
+
+               list.cursor_changed += on_row_selected;
        }
 
-       public void clear()
+       //private void on_row_selected(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
+       private void on_row_selected(Gtk.TreeView tv)
        {
-               model.clear();
+               Gtk.TreePath path;
+               list.get_cursor(out path, null);
+
+               Gtk.TreeIter iter;
+
+               if (!model.get_iter(out iter, path)) return;
+               Value year, month, day;
+               model.get_value(iter, 2, out year);
+               model.get_value(iter, 3, out month);
+               model.get_value(iter, 4, out day);
+               selected((int)year, (int)month, (int)day);
        }
 
-       public void add_day(Date date, string notes)
+       protected void add_day(Date date, string notes)
        {
                var buffer = new char[64];
                date.strftime(buffer, "%d %a");
@@ -130,9 +155,35 @@ public class Next30 : Gtk.ScrolledWindow
                model.append (out iter);
                model.set(iter, 0, (string)buffer);
                model.set(iter, 1, notes);
-               model.set(iter, 2, date.get_day());
+               model.set(iter, 2, date.get_year());
                model.set(iter, 3, date.get_month());
-               model.set(iter, 4, date.get_year());
+               model.set(iter, 4, date.get_day());
+       }
+
+       public void update(Date start)
+       {
+               Date date = start;
+               model.clear();
+               for (uint i = 0; i < 30; ++i)
+               {
+                       string 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 = "";
+                               }
+                       }
+                       if (i == 0 || text != "")
+                       {
+                               add_day(date, text);
+                       }
+                       date.add_days(1);
+               }
        }
 }
 
@@ -140,6 +191,7 @@ public class Calendar : Gtk.VBox
 {
        protected Gtk.Calendar calendar;
        protected Gtk.Notebook notebook;
+       protected Gtk.Notebook day_notebook;
        protected FileNotes month_notes;
        protected FileNotes day_notes;
        protected FileNotes general_notes;
@@ -158,10 +210,15 @@ public class Calendar : Gtk.VBox
 
                notebook = new Gtk.Notebook();
 
+               day_notebook = new Gtk.Notebook();
                next_30 = new Next30();
-               notebook.append_page(next_30, new Gtk.Label("Next 30"));
+               next_30.selected += on_next30_selected;
+               day_notebook.append_page(next_30, new Gtk.Label("Next 30"));
                day_notes = new FileNotes();
-               notebook.append_page(day_notes, new Gtk.Label("Day"));
+               day_notebook.append_page(day_notes, new Gtk.Label("Day"));
+               notebook.append_page(day_notebook, new Gtk.Label("Day"));
+               day_notebook.show_tabs = false; 
+
                month_notes = new FileNotes();
                notebook.append_page(month_notes, new Gtk.Label("Month"));
                general_notes = new FileNotes();
@@ -173,16 +230,20 @@ public class Calendar : Gtk.VBox
                re_dayfile = new Regex("[0-9][0-9]\\.txt");
 
                on_month_changed();
+               on_day_selected();
        }
 
-       private string month_path(int year, int month)
+       private void on_next30_selected(int year, int month, int day)
        {
-               return "%s/cal/%04d/%02d".printf(zavai.config.homedir, year, month);
-       }
+               // Select this day in the calendar
+               calendar.year = year;
+               calendar.month = month-1;
+               calendar.day = day;
 
-       private string day_path(int year, int month, int day)
-       {
-               return "%s/%02d.txt".printf(month_path(year, month), day);
+               // View the day notes
+               day_notebook.set_current_page(1);
+
+               // TODO: when clicking on calendar, show next30 again
        }
 
        private void on_month_changed()
@@ -221,29 +282,10 @@ 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);
-               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 = "";
-                               }
-                       }
-                       if (text != "")
-                       {
-                               next_30.add_day(date, text);
-                       }
-                       date.add_days(1);
-               }
+               next_30.update(date);
+               day_notebook.set_current_page(0);
        }
 
        public void flush()