Remove debug statements from KCal backends.
[beagle.git] / Util / Galago.cs
blob52f5ea8257473fd5b0311a2ee4ad3be76859b394
1 //
2 // Galago.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
27 using System;
28 using Galago;
30 namespace Beagle.Util {
32 public class GalagoTools {
34 private GalagoTools () {} // This class is static
35 private static Galago.Service service;
37 public enum Status {
38 Available = 0,
39 Offline = 1,
40 Away = 2,
41 Idle = 3,
42 NoStatus = -1,
45 public static Status GetPresence (string service_id, string username)
47 if (! Galago.Global.Init ("beagle-galago-presence"))
48 return Status.NoStatus;
49 service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
50 if (service == null)
51 return Status.NoStatus;
53 Galago.Account account = service.GetAccount (username, true);
55 if (account == null)
56 return Status.NoStatus;
58 Galago.Presence presence = account.Presence;
60 if (presence == null)
61 return Status.NoStatus;
63 Status user_status = Status.NoStatus;
64 StatusType active_status;
65 if (presence.IsIdle) {
66 user_status = Status.Idle;
67 // FIXME: We should try to find a way to display the actual away message (if relivent)
69 else {
70 active_status = presence.ActiveStatus.Primitive;
71 switch (active_status) {
72 case StatusType.Away :
73 user_status = Status.Away;
74 break;
75 case StatusType.Offline :
76 user_status = Status.Offline;
77 break;
78 case StatusType.Available:
79 user_status = Status.Available;
80 break;
83 Galago.Global.Uninit();
85 return user_status;
87 public static string GetIdleTime (string service_id, string username)
89 if (! Galago.Global.Init ("beagle-galago-presence"))
90 return null;
92 service = Galago.Global.GetService (service_id, Galago.Origin.Remote, true);
93 if (service == null)
94 return null;
96 Galago.Account account = service.GetAccount (username, true);
98 if (account == null)
99 return null;
101 Galago.Presence presence = account.Presence;
103 if (presence == null)
104 return null;
106 string str = StringFu.DurationToPrettyString ( DateTime.Now, presence.IdleStartTime);
108 Galago.Global.Uninit();
109 return str;