~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to GCalendar/GCalendarItemSource.cs

  • Committer: Alex Launi
  • Date: 2008-04-03 16:42:36 UTC
  • mfrom: (85 do-plugins)
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: alex.launi@gmail.com-20080403164236-6ut2l710phmv92o5
clean up

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GCalendarItemSource.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.Text;
 
23
using System.IO;
 
24
using System.Collections.Generic;
 
25
 
 
26
using Do.Addins;
 
27
using Do.Universe;
 
28
 
 
29
using Google.GData.Client;
 
30
using Google.GData.Calendar;
 
31
 
 
32
namespace Do.GCalendar
 
33
{       
 
34
        public class GCalendarItemSource : IItemSource
 
35
        {
 
36
                List<IItem> items;
 
37
 
 
38
                public GCalendarItemSource ()
 
39
                {
 
40
                        items = new List<IItem> ();
 
41
                }
 
42
 
 
43
                public string Name { get { return "Google Calendars"; } }
 
44
                public string Description { get { return "Indexes your Google Calendars"; } }
 
45
                public string Icon { get { return "date"; } }
 
46
 
 
47
                public Type[] SupportedItemTypes
 
48
                {
 
49
                        get {
 
50
                                return new Type[] {
 
51
                                        typeof (GCalendarItem),
 
52
                                        typeof (GCalendarEventItem),
 
53
                                };
 
54
                        }
 
55
                }
 
56
 
 
57
                public ICollection<IItem> Items
 
58
                {
 
59
                        get { return items; }
 
60
                }
 
61
 
 
62
                public ICollection<IItem> ChildrenOfItem (IItem parent)
 
63
                {
 
64
                        GCalendarItem calItem = parent as GCalendarItem;
 
65
                        DoGCal cal = new DoGCal ();
 
66
                        List<IItem> children = new List<IItem> ();
 
67
                        string eventUrl, eventDesc;
 
68
                        EventFeed events = cal.GetEvents (calItem.URL);
 
69
                        for (int i = 0 ; i < events.Entries.Count; i++) {
 
70
                            //Console.WriteLine(events.Entries[i].gdwhen);
 
71
                            eventUrl = events.Entries[i].AlternateUri.Content;
 
72
                            eventDesc = events.Entries[i].Content.Content;
 
73
                                children.Add (new GCalendarEventItem (events.Entries[i].Title.Text, eventUrl,
 
74
                                        eventDesc));
 
75
                        }
 
76
                        return children;
 
77
                }
 
78
 
 
79
                public void UpdateItems ()
 
80
                {       
 
81
                    items.Clear ();
 
82
                        DoGCal cal = new DoGCal ();
 
83
                        AtomFeed calList = cal.GetCalendars ();
 
84
                        for (int i = 0; i < calList.Entries.Count; i++) {
 
85
                                string calUrl = calList.Entries[i].Id.Uri.ToString ();
 
86
                                items.Add (new GCalendarItem (calList.Entries[i].Title.Text, 
 
87
                                        calUrl.Replace ("/default","") + "/private/full"));
 
88
                        }
 
89
                }
 
90
        }
 
91
}