Added config options for call and sms ringtones
[gregoa/zavai.git] / src / app_calendar.vala
index 66a0ae5ea8c183aab67d555aa4014292e2fb4ef4..e35c2cd687da2d8915d00b4fa7fc358ba04fd848 100644 (file)
@@ -24,153 +24,31 @@ namespace calendar {
 
 public class Calendar : Applet
 {
-       protected Gtk.Calendar calendar;
-       protected Gtk.ScrolledWindow scroll;
-       protected Gtk.TextBuffer text_buffer;
-       protected Gtk.TextView text;
-       protected int cur_year;
-       protected int cur_month;
-       protected int cur_day;
-       protected bool text_dirty;
-       protected Regex re_dayfile;
-
-       public Calendar()
-       {
-               _label = "Calendar";
-               calendar = new Gtk.Calendar();
-               calendar.day_selected += on_day_selected;
-               calendar.month_changed += on_month_changed;
-               pack_start(calendar, false, false, 0);
-
-               text_buffer = new Gtk.TextBuffer(null);
-               text_buffer.changed += on_textbuffer_changed;
-               text = new Gtk.TextView.with_buffer(text_buffer);
-               text.wrap_mode = Gtk.WrapMode.WORD;
-               text.cursor_visible = true;
-               text.editable = true;
-               scroll = new Gtk.ScrolledWindow (null, null);
-               scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
-               scroll.add(text);
-               pack_start(scroll, true, true, 0);
-
-               re_dayfile = new Regex("[0-9][0-9]\\.txt");
-
-               text_dirty = false;
-       }
-       
-       private void on_textbuffer_changed()
-       {
-               text_dirty = true;
-       }
-
-       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);
-       }
-
-       private void flush()
-       {
-               if (text_dirty)
-                       save(cur_year, cur_month, cur_day);
-       }
-
-       private void on_month_changed()
-       {
-               flush();
-               calendar.clear_marks();
-               string mpath = month_path(calendar.year, calendar.month);
-               Dir dir;
-               try {
-                       dir = Dir.open(mpath);
-               } catch (FileError e) {
-                       zavai.log.error(e.message);
-                       return;
-               }
-               while (true)
-               {
-                       var d = dir.read_name();
-                       if (d == null) break;
-                       if (re_dayfile.match(d))
-                       {
-                               calendar.mark_day((int)d.to_ulong(null, 10));
-                       }
-               }
-       }
-
-       private void on_day_selected()
-       {
-               flush();
-               load(calendar.year, calendar.month, calendar.day);
-               // Scroll to beginning
-               Gtk.TextIter iter;
-               text_buffer.get_iter_at_offset(out iter, 0);
-               Gtk.TextMark mark = text_buffer.create_mark(null, iter, true);
-               text.scroll_mark_onscreen(mark);
-       }
-
-       private void load(int year, int month, int day)
-       {
-               string path = day_path(year, month, day);
-               if (!FileUtils.test (path, FileTest.IS_REGULAR))
-                       text_buffer.text = "";
-               else
-               {
-                       try {
-                               string text;
-                               FileUtils.get_contents(path, out text);
-                               text_buffer.text = text;
-                       } catch (FileError e) {
-                               zavai.log.error(e.message);
-                               text_buffer.text = "";
-                       }
-               }
-               text_dirty = false;
-               cur_year = year; cur_month = month; cur_day = day;
-       }
-
-       private void save(int year, int month, int day)
-       {
-               string mpath = month_path(year, month);
-               if (DirUtils.create_with_parents(mpath, 0777) < 0)
-               {
-                       zavai.log.error("Cannot create directory " + mpath);
-                       return;
-               }
-               string path = day_path(year, month, day);
-               try {
-                       FileUtils.set_contents(path, text_buffer.text);
-               } catch (FileError e) {
-                       zavai.log.error(e.message);
-               }
-               text_dirty = false;
-       }
-
-       public override void start()
-       {
-               // Go to current date
-               var now = Time.local(time_t());
-               calendar.year = now.year + 1900;
-               calendar.month = now.month;
-               calendar.day = now.day;
-       }
-       public override void stop()
-       {
-               flush();
-       }
+    protected widgets.Calendar calendar;
+
+    public Calendar()
+    {
+        _label = "Calendar";
+        calendar = new widgets.Calendar();
+        pack_start(calendar, true, true, 0);
+    }
+
+    public override void start()
+    {
+        calendar.show_today();
+    }
+    public override void stop()
+    {
+        calendar.flush();
+    }
 }
 
-Calendar calendar;
+public Calendar calendar;
 
 public void init()
 {
-       calendar = new Calendar();
-        zavai.registry.register_applet("ui.calendar", calendar);
-        zavai.registry.getmenu("menu.misc").add_applet("ui.calendar");
+    calendar = new Calendar();
+    zavai.menu_misc.add_applet(calendar);
 }
 
 }