4 // Copyright (C) 2005 Novell, Inc.
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
30 namespace Beagle
.Util
{
32 public class GalagoTools
{
34 private GalagoTools () {} // This class is static
35 private static Galago
.Service service
;
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);
51 return Status
.NoStatus
;
53 Galago
.Account account
= service
.GetAccount (username
, true);
56 return Status
.NoStatus
;
58 Galago
.Presence presence
= account
.Presence
;
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)
70 active_status
= presence
.ActiveStatus
.Primitive
;
71 switch (active_status
) {
72 case StatusType
.Away
:
73 user_status
= Status
.Away
;
75 case StatusType
.Offline
:
76 user_status
= Status
.Offline
;
78 case StatusType
.Available
:
79 user_status
= Status
.Available
;
83 Galago
.Global
.Uninit();
87 public static string GetIdleTime (string service_id
, string username
)
89 if (! Galago
.Global
.Init ("beagle-galago-presence"))
92 service
= Galago
.Global
.GetService (service_id
, Galago
.Origin
.Remote
, true);
96 Galago
.Account account
= service
.GetAccount (username
, true);
101 Galago
.Presence presence
= account
.Presence
;
103 if (presence
== null)
106 string str
= StringFu
.DurationToPrettyString ( DateTime
.Now
, presence
.IdleStartTime
);
108 Galago
.Global
.Uninit();