6 class ButterflyPresenceMapping(object):
18 ONLINE: pymsn.Presence.ONLINE,
19 AWAY: pymsn.Presence.AWAY,
20 BUSY: pymsn.Presence.BUSY,
21 IDLE: pymsn.Presence.IDLE,
22 BRB: pymsn.Presence.BE_RIGHT_BACK,
23 PHONE: pymsn.Presence.ON_THE_PHONE,
24 LUNCH: pymsn.Presence.OUT_TO_LUNCH,
25 INVISIBLE: pymsn.Presence.INVISIBLE,
26 OFFLINE: pymsn.Presence.OFFLINE
30 pymsn.Presence.ONLINE: ONLINE,
31 pymsn.Presence.AWAY: AWAY,
32 pymsn.Presence.BUSY: BUSY,
33 pymsn.Presence.IDLE: IDLE,
34 pymsn.Presence.BE_RIGHT_BACK: BRB,
35 pymsn.Presence.ON_THE_PHONE: PHONE,
36 pymsn.Presence.OUT_TO_LUNCH: LUNCH,
37 pymsn.Presence.INVISIBLE: INVISIBLE,
38 pymsn.Presence.OFFLINE: OFFLINE
42 ONLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE,
43 AWAY: telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY,
44 BUSY: telepathy.constants.CONNECTION_PRESENCE_TYPE_BUSY,
45 IDLE: telepathy.constants.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
46 BRB: telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY,
47 PHONE: telepathy.constants.CONNECTION_PRESENCE_TYPE_BUSY,
48 LUNCH: telepathy.constants.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
49 INVISIBLE: telepathy.constants.CONNECTION_PRESENCE_TYPE_HIDDEN,
50 OFFLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_OFFLINE
54 class ButterflySimplePresence(telepathy.server.ConnectionInterfaceSimplePresence):
57 telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
59 dbus_interface = 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'
61 self._implement_property_get(dbus_interface, {'Statuses' : self.get_statuses})
63 def GetPresences(self, contacts):
64 return self.get_simple_presences(contacts)
66 def SetPresence(self, status, message):
67 if status == ButterflyPresenceMapping.OFFLINE:
71 presence = ButterflyPresenceMapping.to_pymsn[status]
73 raise telepathy.errors.InvalidArgument
74 message = message.encode("utf-8")
76 logging.info("Setting Presence to '%s'" % presence)
77 logging.info("Setting Personal message to '%s'" % message)
79 if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
80 self._initial_presence = presence
81 self._initial_personal_message = message
83 self.msn_client.profile.personal_message = message
84 self.msn_client.profile.presence = presence
86 def get_simple_presences(self, contacts):
88 for handle_id in contacts:
89 handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id)
91 contact = handle.contact
92 except AttributeError:
93 contact = handle.profile
95 if contact is not None:
96 presence = ButterflyPresenceMapping.to_telepathy[contact.presence]
97 personal_message = unicode(contact.personal_message, "utf-8")
99 presence = ButterflyPresenceMapping.OFFLINE
100 personal_message = u""
102 presence_type = ButterflyPresenceMapping.to_presence_type[presence]
104 presences[handle] = (presence_type, presence, personal_message)
107 def get_statuses(self):
108 # you get one of these for each status
109 # {name:(Type, May_Set_On_Self, Can_Have_Message}
111 ButterflyPresenceMapping.ONLINE:(
112 telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
114 ButterflyPresenceMapping.AWAY:(
115 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
117 ButterflyPresenceMapping.BUSY:(
118 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
120 ButterflyPresenceMapping.IDLE:(
121 telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
123 ButterflyPresenceMapping.BRB:(
124 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
126 ButterflyPresenceMapping.PHONE:(
127 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
129 ButterflyPresenceMapping.LUNCH:(
130 telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
132 ButterflyPresenceMapping.INVISIBLE:(
133 telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
135 ButterflyPresenceMapping.OFFLINE:(
136 telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,