~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to GCalendar/DoGCal.cs

Merge non-b0rked GCal & Vinagre plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* DoGCal.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.IO;
 
23
using System.Net;
 
24
 
 
25
using Google.GData.Client;
 
26
using Google.GData.Calendar;
 
27
 
 
28
using GConf;
 
29
 
 
30
namespace Do.GCalendar
 
31
{
 
32
        public class DoGCal
 
33
        {
 
34
                string username, password;
 
35
                CalendarService service;
 
36
                
 
37
                public DoGCal ()
 
38
                {
 
39
                        GConf.Client gconf = new GConf.Client ();
 
40
                        try {
 
41
                                username = gconf.Get ("/apps/gnome-do/plugins/gcal/username") as string;
 
42
                                password = gconf.Get ("/apps/gnome-do/plugins/gcal/password") as string;
 
43
                        } catch (GConf.NoSuchKeyException) {
 
44
                                gconf.Set ("/apps/gnome-do/plugins/gcal/username","");
 
45
                                gconf.Set ("/apps/gnome-do/plugins/gcal/password","");
 
46
                        }
 
47
                        Connect ();
 
48
                }
 
49
 
 
50
                public void Connect () 
 
51
                {
 
52
                        service = new CalendarService("alexLauni-gnomeDoGCalPlugin-1");
 
53
            service.setUserCredentials(username, password);     
 
54
                }
 
55
                
 
56
                public AtomFeed GetCalendars ()
 
57
                {
 
58
                        FeedQuery query = new FeedQuery ();
 
59
            query.Uri = new Uri ("http://www.google.com/calendar/feeds/default");
 
60
            
 
61
            return service.Query (query);
 
62
                }
 
63
                
 
64
                public EventFeed GetEvents (string calUrl)
 
65
                {
 
66
                        return GetEvents (calUrl, DateTime.Now, DateTime.Now.AddYears(1));
 
67
                }
 
68
                
 
69
                public EventFeed GetEvents (string calUrl, DateTime startTime,
 
70
                                            DateTime endTime)
 
71
        {
 
72
            EventQuery query = new EventQuery (calUrl);
 
73
            query.StartTime = startTime;
 
74
            query.EndTime = endTime;
 
75
                    
 
76
            return service.Query (query) as EventFeed;
 
77
        }
 
78
        
 
79
        public EventFeed SearchEvents (string calUrl, string needle) 
 
80
        {
 
81
            EventQuery query = new EventQuery(calUrl);
 
82
            query.Query = needle;
 
83
 
 
84
            return service.Query(query) as EventFeed;
 
85
        }
 
86
        
 
87
        public EventEntry NewEvent (string calUrl, string data) 
 
88
        {
 
89
            EventEntry entry = new EventEntry ();
 
90
            entry.QuickAdd = true;
 
91
            entry.Content.Content = data;
 
92
            Uri post_uri = new Uri(calUrl);
 
93
            
 
94
            return (EventEntry) service.Insert(post_uri, entry);
 
95
        }
 
96
        }
 
97
}