~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to GCalendar/GCalendarItemSource.cs

Merge non-b0rked GCal & Vinagre plugins

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
using Google.GData.Extensions;
 
32
 
 
33
namespace Do.GCalendar
 
34
{       
 
35
        public class GCalendarItemSource : IItemSource
 
36
        {
 
37
                List<IItem> items;
 
38
 
 
39
                public GCalendarItemSource ()
 
40
                {
 
41
                        items = new List<IItem> ();
 
42
                }
 
43
 
 
44
                public string Name { get { return "Google Calendars"; } }
 
45
                public string Description { get { return "Indexes your Google Calendars"; } }
 
46
                public string Icon { get { return "date"; } }
 
47
 
 
48
                public Type[] SupportedItemTypes
 
49
                {
 
50
                        get {
 
51
                                return new Type[] {
 
52
                                        typeof (GCalendarItem),
 
53
                                        typeof (GCalendarEventItem),
 
54
                                };
 
55
                        }
 
56
                }
 
57
 
 
58
                public ICollection<IItem> Items
 
59
                {
 
60
                        get { return items; }
 
61
                }
 
62
 
 
63
                public ICollection<IItem> ChildrenOfItem (IItem parent)
 
64
                {
 
65
                        GCalendarItem calItem = parent as GCalendarItem;
 
66
                        DoGCal cal = new DoGCal ();
 
67
                        List<IItem> children = new List<IItem> ();
 
68
                        string eventUrl, eventDesc, start;
 
69
                        EventFeed events = cal.GetEvents (calItem.URL);
 
70
                        /*for (int i = 0 ; i < events.Entries.Count; i++) {
 
71
                            Console.WriteLine(events.Entries[i].Times.StartTime);
 
72
                            eventUrl = events.Entries[i].AlternateUri.Content;
 
73
                            eventDesc = events.Entries[i].Content.Content;
 
74
                                children.Add (new GCalendarEventItem (events.Entries[i].Title.Text, eventUrl,
 
75
                                        eventDesc));
 
76
                        }*/
 
77
                        foreach (EventEntry entry in events.Entries) {
 
78
                            eventUrl = entry.AlternateUri.Content;
 
79
                            eventDesc = entry.Content.Content;
 
80
                            if (entry.Times.Count > 0) {
 
81
                                start = entry.Times[0].StartTime.ToString ();
 
82
                                start = start.Substring (0,start.IndexOf (' '));
 
83
                                eventDesc = start + " - " + eventDesc;
 
84
                }
 
85
                            children.Add (new GCalendarEventItem (entry.Title.Text, eventUrl,
 
86
                                    eventDesc));
 
87
            }
 
88
                        return children;
 
89
                }
 
90
 
 
91
                public void UpdateItems ()
 
92
                {       
 
93
                    items.Clear ();
 
94
                        DoGCal cal = new DoGCal ();
 
95
                        AtomFeed calList = cal.GetCalendars ();
 
96
                        for (int i = 0; i < calList.Entries.Count; i++) {
 
97
                                string calUrl = calList.Entries[i].Id.Uri.ToString ();
 
98
                                items.Add (new GCalendarItem (calList.Entries[i].Title.Text, 
 
99
                                        calUrl.Replace ("/default","") + "/private/full"));
 
100
                        }
 
101
                }
 
102
        }
 
103
}