Author: kumpera
Date: 2007-06-29 14:28:26 -0400 (Fri, 29 Jun 2007)
New Revision: 81057
Modified:
trunk/moon/desklet/glassycalendar/ChangeLog
trunk/moon/desklet/glassycalendar/calendar.cs
trunk/moon/desklet/glassycalendar/default.xaml
Log:
2007-06-29 Rodrigo Kumpera <[EMAIL PROTECTED]>
* default.xaml: Integrated google cal code.
* calendar.cs: Integrated google cal code.
Modified: trunk/moon/desklet/glassycalendar/ChangeLog
===================================================================
--- trunk/moon/desklet/glassycalendar/ChangeLog 2007-06-29 18:22:13 UTC (rev
81056)
+++ trunk/moon/desklet/glassycalendar/ChangeLog 2007-06-29 18:28:26 UTC (rev
81057)
@@ -1,3 +1,8 @@
+2007-06-29 Rodrigo Kumpera <[EMAIL PROTECTED]>
+
+ * default.xaml: Integrated google cal code.
+ * calendar.cs: Integrated google cal code.
+
2007-06-27 Everaldo Canuto <[EMAIL PROTECTED]>
* default.xaml: Improve calendar look.
Modified: trunk/moon/desklet/glassycalendar/calendar.cs
===================================================================
--- trunk/moon/desklet/glassycalendar/calendar.cs 2007-06-29 18:22:13 UTC
(rev 81056)
+++ trunk/moon/desklet/glassycalendar/calendar.cs 2007-06-29 18:28:26 UTC
(rev 81057)
@@ -13,6 +13,9 @@
using System;
using System.Globalization;
+using System.Xml;
+using System.Xml.XPath;
+using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
@@ -23,12 +26,62 @@
namespace Desklet
{
+ public class Entry : IComparable <Entry> {
+ private String title;
+ private String location;
+ private TimeSpan time;
+
+ public Entry (String title, String location, TimeSpan time)
+ {
+ this.title = title;
+ this.location = location;
+ this.time = time;
+ }
+
+ public string Title { get { return title; } }
+ public string Location { get { return location; } }
+ public TimeSpan Time { get { return time; } }
+
+ public int CompareTo (Entry other) {
+ return this.time.CompareTo (other.time);
+ }
+ }
+
+ public class DaySchedule
+ {
+ private List<Entry> entries = new List<Entry> ();
+ private DateTime date;
+
+ public DaySchedule (DateTime date)
+ {
+ this.date = date;
+ }
+
+ public List<Entry> Appointments { get { return entries; } }
+ public DateTime Date { get { return date; } }
+
+ public void Add (Entry entry)
+ {
+ this.entries.Add (entry);
+ }
+
+ public void Sort ()
+ {
+ this.entries.Sort ();
+ }
+ }
+
public class CalendarPanel : Canvas
{
TextBlock monthText;
+ TextBlock detailText;
TextBlock[,] days = new TextBlock[6,7];
DateTime current;
DateTime currentHour;
+ List<Rectangle> rectangles = new List<Rectangle> ();
+ Rectangle rect;
+ Storyboard detailsStoryboard;
+ DaySchedule selectedDay;
static readonly Brush CURRENT_DAY = new SolidColorBrush
(Colors.Yellow);
static readonly Brush CURRENT_MONTH = new SolidColorBrush
(Colors.White);
@@ -37,35 +90,137 @@
static readonly Brush BUTTON_UP_BRUSH = new SolidColorBrush
(Colors.White);
//Grey
- static readonly Brush BUTTON_DOWN_BRUSH = new SolidColorBrush
(Color.FromArgb (100, 150, 150, 150));
+ static readonly Brush BUTTON_DOWN_BRUSH = new SolidColorBrush
(Color.FromRgb (150, 150, 150));
+ static readonly Brush CALENDAR_BRUSH = new SolidColorBrush
(Colors.Red);
+ static readonly Brush CALENDAR_FILL_BRUSH = new SolidColorBrush
(Color.FromArgb (40, 255, 0, 0));
+
void drawDay (int l, int c, int day, bool mainMonth, bool
curDay) {
days[l, c].Text = day.ToString ();
days[l, c].Foreground = mainMonth ? (curDay ?
CURRENT_DAY : CURRENT_MONTH) : OTHERS;
}
+ public void DrawCalendarDetails ()
+ {
+ String text = "";
+ foreach (Entry entry in selectedDay.Appointments)
+ text += entry.Time.ToString () + "\n"
+entry.Title + "\n"+entry.Location+"\n";
+ detailText.Text = text;
+ Children.Add (detailText);
+ }
+
+ public static bool IsSameMonth (DateTime a, DateTime b)
+ {
+ return a.Month == b.Month && a.Year == b.Year;
+ }
+
void UpdateTime ()
{
- if (current.Month != currentHour.Month || current.Year
!= currentHour.Year)
+ if (!IsSameMonth (current, currentHour))
return;
DateTime now = DateTime.Now;
if (now.Day != currentHour.Day) {
current = currentHour = now;
- drawCalendar ();
+ DrawCalendar ();
} else
current = currentHour = now;
}
- void drawCalendar () {
- Calendar cal = new GregorianCalendar ();
- int currentMonthDays = cal.GetDaysInMonth (current.Year,
current.Month);
- int lastMonthDays = current.Month > 1 ? cal.GetDaysInMonth
(current.Year, current.Month - 1) : 31;
- int firstDayOfMonth = (int)current.AddDays (1 -
current.Day).DayOfWeek;
- bool activeMonth = DateTime.Now.Month == current.Month &&
DateTime.Now.Year == current.Year;
+ public Dictionary<DateTime, DaySchedule> parseXml (String xml)
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml (xml);
+ XmlNamespaceManager man = new XmlNamespaceManager
(doc.NameTable);
+ man.AddNamespace ("atom",
"http://www.w3.org/2005/Atom");
+ man.AddNamespace ("gd",
"http://schemas.google.com/g/2005");
- monthText.Text = current.ToString ("MMMM yyyy");
- int first = lastMonthDays - firstDayOfMonth + 1;
+ Dictionary<DateTime, DaySchedule> dic = new
Dictionary<DateTime, DaySchedule> ();
+
+ foreach (XmlNode et in doc.SelectNodes
("/atom:feed/atom:entry", man)) {
+ XmlNode n = et.SelectSingleNode ("atom:[EMAIL
PROTECTED]'text']", man);
+ String title = n != null ? n.InnerText : "";
+
+ String location = "";
+ foreach (XmlNode w in et.SelectNodes
("gd:where/@valueString", man))
+ location += (location.Length > 0 ? ", "
: "") + w.Value;
+
+ foreach (XmlNode w in et.SelectNodes
("gd:when/@startTime", man)) {
+ DateTime time = DateTime.Parse
(w.Value);
+ DaySchedule sched;
+ if (dic.ContainsKey (time.Date))
+ sched = dic [time.Date];
+ else
+ dic.Add (time.Date, sched = new
DaySchedule (time.Date));
+
+ sched.Appointments.Add ( new Entry
(title, location, time.TimeOfDay));
+ }
+ }
+
+ foreach (DaySchedule ds in dic.Values)
+ ds.Sort ();
+ return dic;
+ }
+
+ public void CalendarDownloadComplete (DateTime start, String
xml)
+ {
+ if (!IsSameMonth (start, current))
+ return;
+ Dictionary<DateTime, DaySchedule> dic = parseXml (xml);
+ int dayZero = (int)start.DayOfWeek;
+
+ foreach (DaySchedule ds in dic.Values) {
+ int day = ds.Date.Day;
+ int x = (day + dayZero - 1) % 7;
+ int y = (day + dayZero) / 7 - ((day + dayZero)
% 7 == 0 ? 1 : 0);
+ Rectangle dayRect = new Rectangle ();
+ dayRect.Stroke = CALENDAR_BRUSH;
+ dayRect.Fill = CALENDAR_FILL_BRUSH;
+ dayRect.StrokeThickness = 1;
+ dayRect.Width = 24;
+ dayRect.Height = 15;
+ dayRect.RadiusX = 4;
+ dayRect.RadiusY = 4;
+ dayRect.SetValue (Canvas.LeftProperty, 13 + x *
30);
+ dayRect.SetValue (Canvas.TopProperty, 65 + y *
17);
+ Children.Add (dayRect);
+ rectangles.Add (dayRect);
+ DaySchedule it = ds;
+ dayRect.MouseLeftButtonUp += delegate {
OpenCalendarDetailAnimation (x, y, it); };
+
+ }
+ }
+
+ public void UpdateCalendarData (DateTime start, DateTime end)
+ {
+ Console.WriteLine ("updating calendar "+start);
+ Downloader downloader = new Downloader ();
+ downloader.Completed += delegate {
+ CalendarDownloadComplete (start.Date,
downloader.GetResponseText ("What?"));
+ };
+
+ String uri =
"http://www.google.com/calendar/feeds/ca5i3j9j0gv2j0lln2htfb3tus%40group.calendar.google.com/public/full?start-min="
+ + start.ToString ("yyyy-MM-dd") + "&start-max="
+ end.ToString ("yyyy-MM-dd");
+
+ downloader.Open (
+ "GET",
+ new Uri (uri),
+ true);
+ downloader.Send ();
+ }
+
+
+ void DrawCalendar ()
+ {
+ Calendar cal = new GregorianCalendar ();
+ int currentMonthDays = cal.GetDaysInMonth
(current.Year, current.Month);
+ int lastMonthDays = current.Month > 1 ?
cal.GetDaysInMonth (current.Year, current.Month - 1) : 31;
+ DateTime dayOne = current.AddDays (1 - current.Day);
+ int firstDayOfMonth = (int)dayOne.DayOfWeek;
+ bool activeMonth = IsSameMonth (DateTime.Now, current);
+
+ monthText.Text = current.ToString ("MMMM yyyy");
+ int first = lastMonthDays - firstDayOfMonth + 1;
for (int i = 0; i < firstDayOfMonth; ++i)
drawDay (0, i, first + i, false, false);
@@ -88,6 +243,9 @@
}
}
}
+
+ foreach (Rectangle rec in rectangles)
+ Children.Remove (rec);
}
public void MouseDown (Object sender, MouseEventArgs e)
@@ -102,21 +260,61 @@
shape.Fill = shape.Stroke = BUTTON_UP_BRUSH;
}
+ public void OpenCalendarDetailAnimation (int l, int c,
DaySchedule ds) {
+ int x = (18 + l * 30) + 6;
+ int y = (65 + c * 17) + 7;
+ rect.Width = 2;
+ rect.Height = 2;
+ rect.SetValue (Canvas.LeftProperty, x);
+ rect.SetValue (Canvas.TopProperty, y);
+ Children.Add (rect);
+
+ DoubleAnimation animX = FindName ("anim_x") as
DoubleAnimation;
+ DoubleAnimation animY = FindName ("anim_y") as
DoubleAnimation;
+ DoubleAnimation animH = FindName ("anim_h") as
DoubleAnimation;
+ DoubleAnimation animW = FindName ("anim_w") as
DoubleAnimation;
+ animX.By = -x;
+ animY.By = -y;
+ animH.By = Height - rect.Height;
+ animW.By = Width - rect.Width;
+ selectedDay = ds;
+
+ detailsStoryboard.Begin ();
+ }
+
+
public void PageLoaded (object o, EventArgs e)
- {
+ {
monthText = FindName ("month") as TextBlock;
+ detailText = FindName ("detail") as TextBlock;
+ Children.Remove (detailText);
+
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 7; ++j)
days [i, j] = FindName ("c"+i+"_l"+j)
as TextBlock;
+ this.rect = FindName ("calendar_rect") as Rectangle;
+ rect.MouseLeftButtonUp += delegate {
+ Children.Remove (detailText);
+ Children.Remove (rect);
+ };
+ Children.Remove (rect);
+ Storyboard mouseChange = FindName ("mouse_click") as
Storyboard;
+ mouseChange.Completed += delegate {
+ DateTime dayOne = current.AddDays (1 -
current.Day);
+ UpdateCalendarData (dayOne, dayOne.AddMonths
(1));
+ };
+
Shape before = FindName ("priorButton") as Shape;
before.MouseLeftButtonDown += new
MouseEventHandler(this.MouseDown);
before.MouseLeave += new EventHandler(this.MouseLeft);
before.MouseLeftButtonUp += delegate {
before.Fill = before.Stroke = BUTTON_UP_BRUSH;
current = current.AddMonths (-1);
- drawCalendar ();
+ DrawCalendar ();
+ mouseChange.Stop ();
+ mouseChange.Begin ();
};
Shape after = FindName ("nextButton") as Shape;
@@ -125,22 +323,25 @@
after.MouseLeftButtonUp += delegate {
after.Fill = after.Stroke = BUTTON_UP_BRUSH;
current = current.AddMonths (1);
- drawCalendar ();
+ DrawCalendar ();
+ mouseChange.Stop ();
+ mouseChange.Begin ();
};
Storyboard sb = FindName ("run") as Storyboard;
- DoubleAnimation timer = new DoubleAnimation ();
- sb.Children.Add (timer);
- timer.Duration = new Duration (TimeSpan.FromSeconds
(3600));
-
sb.Completed += delegate {
UpdateTime ();
sb.Begin ();
};
- sb.Begin ();
+
+ detailsStoryboard = FindName ("detail_anim") as
Storyboard;
+ detailsStoryboard.Completed += delegate {
DrawCalendarDetails (); };
+
currentHour = current = DateTime.Now;
- drawCalendar ();
+ DrawCalendar ();
+ mouseChange.Begin ();
+ sb.Begin ();
}
}
Modified: trunk/moon/desklet/glassycalendar/default.xaml
===================================================================
--- trunk/moon/desklet/glassycalendar/default.xaml 2007-06-29 18:22:13 UTC
(rev 81056)
+++ trunk/moon/desklet/glassycalendar/default.xaml 2007-06-29 18:28:26 UTC
(rev 81057)
@@ -5,9 +5,50 @@
<Canvas.Resources>
<Storyboard x:Name="run">
+ <DoubleAnimation Duration="1:0:0"/>
</Storyboard>
+
+ <Storyboard x:Name="mouse_click">
+ <DoubleAnimation Duration="0:0:0.5"/>
+ </Storyboard>
+
+ <Storyboard x:Name="detail_anim">
+ <DoubleAnimation x:Name="anim_x"
+ Duration="0:0:0.5"
+ Storyboard.TargetName="calendar_rect"
+ Storyboard.TargetProperty="(Canvas.Left)"/>
+ <DoubleAnimation x:Name="anim_y"
+ Duration="0:0:0.5"
+ Storyboard.TargetName="calendar_rect"
+ Storyboard.TargetProperty="(Canvas.Top)"/>
+
+ <DoubleAnimation x:Name="anim_w"
+ Duration="0:0:0.5"
+ Storyboard.TargetName="calendar_rect"
+ Storyboard.TargetProperty="(Width)"/>
+
+ <DoubleAnimation x:Name="anim_h"
+ Duration="0:0:0.5"
+ Storyboard.TargetName="calendar_rect"
+ Storyboard.TargetProperty="(Height)"/>
+ </Storyboard>
</Canvas.Resources>
+ <Rectangle
+ Fill="#F0AFAFAF"
+ x:Name="calendar_rect"
+ RadiusX="10"
+ RadiusY="10"/>
+
+ <TextBlock
+ x:Name="detail"
+ FontSize="14"
+ FontWeight="ExtraBlack"
+ Foreground="Blue"
+ Canvas.Left="20"
+ Canvas.Top="25"/>
+
+
<!-- border -->
<Rectangle Fill="#33FFFFFF" Stroke="#66FFFFFF" StrokeThickness="1"
Canvas.Left="4" Canvas.Top="4" Width="220" Height="180"
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches