~gotwig/gazette/global-service-states

« back to all changes in this revision

Viewing changes to src/Services/Calendar.vala

  • Committer: Santiago Ocamica
  • Date: 2013-04-26 23:06:22 UTC
  • Revision ID: santi6982@gmail.com-20130426230622-6zs94h7yyh1pqsdn
Started restructure of the project

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
public class Calendar : Service
2
 
{
3
 
        GData.CalendarService service;
4
 
        GData.CalendarEvent current_event = null;
5
 
 
6
 
        ShadowedLabel label;
7
 
 
8
 
// calendar names that are accepted as a list
9
 
        string [] accept = {""};
10
 
 
11
 
        string time;
12
 
        string place = "";
13
 
 
14
 
        public Calendar ()
15
 
        {
16
 
                base ("calendar");
17
 
 
18
 
                label = new ShadowedLabel ("");
19
 
                label.opacity = 0;
20
 
                add_child (label);
21
 
 
22
 
                try {
23
 
                        var auths = new List<GData.AuthorizationDomain> ();
24
 
                        auths.append (GData.CalendarService.get_primary_authorization_domain ());
25
 
                        var auth = new GData.ClientLoginAuthorizer.for_authorization_domains ("weather", auths);
26
 
                        auth.authenticate ("loginname", "password", null);
27
 
                        service = new GData.CalendarService (auth);
28
 
 
29
 
                        if (service == null)
30
 
                                return;
31
 
 
32
 
                        // let's see which calendar got the most recent event
33
 
                        var query = new GData.CalendarQuery (null);
34
 
                        query.start_min = new DateTime.now_local ().to_unix ();
35
 
                        query.is_strict = true;
36
 
                        query.future_events = true;
37
 
                        query.order_by = "starttime";
38
 
                        query.sort_order = "ascending";
39
 
                        query.max_results = 1;
40
 
 
41
 
                        var calendars = service.query_all_calendars (null, null, null);
42
 
                        foreach (var calendar in calendars.get_entries ()) {
43
 
                                if (!(calendar.title in accept))
44
 
                                        continue;
45
 
 
46
 
                                var res = service.query_events (calendar as GData.CalendarCalendar, query, null, null);
47
 
                                var new_event = res.get_entries ().nth_data (0) as GData.CalendarEvent;
48
 
                                print ("CALENDAR: %s\n", calendar.title);
49
 
                                foreach (var ev in res.get_entries ())
50
 
                                        print ("\tEVENT: %s\n", ev.title);
51
 
                                if (current_event == null || new_event.get_times ().nth_data (0).start_time < current_event.get_times ().nth_data (0).start_time)
52
 
                                        current_event = new_event;
53
 
                        }
54
 
 
55
 
                        if (current_event == null)
56
 
                                        return;
57
 
 
58
 
                        time = new DateTime.from_unix_local (current_event.get_times ().nth_data (0).start_time).format ("%H:%M");
59
 
                        if (current_event.get_places ().length () > 0 && current_event.get_places ().nth_data (0).label != null) {
60
 
                                        place = "@" + current_event.get_places ().nth_data (0).label;
61
 
                        }
62
 
                } catch (Error e) { warning (e.message); }
63
 
        }
64
 
 
65
 
        public override void create ()
66
 
        {
67
 
                var label = new ShadowedLabel ("<span face='wallstate' font='42'>i</span>"+
68
 
                                "<span face='Raleway' weight='100' font='72'> " + time + " </span>\n" +
69
 
                                "<span face='Open Sans Light' font='24'> " + current_event.title + place + " </span>");
70
 
                add_child (label);
71
 
        }
72
 
    public override bool update () {
73
 
        //TODO  
74
 
        return true;
75
 
    }
76
 
}