8 class ButterflyPresence(telepathy.server.ConnectionInterfacePresence):
11 telepathy.server.ConnectionInterfacePresence.__init__(self)
13 def GetStatuses(self):
14 # the arguments are in common to all on-line presences
15 arguments = {'message' : 's'}
17 # you get one of these for each status
18 # {name:(type, self, exclusive, {argument:types}}
20 simple_presence.ButterflyPresenceMapping.ONLINE:(
21 telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
22 True, True, arguments),
23 simple_presence.ButterflyPresenceMapping.AWAY:(
24 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
25 True, True, arguments),
26 simple_presence.ButterflyPresenceMapping.BUSY:(
27 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
28 True, True, arguments),
29 simple_presence.ButterflyPresenceMapping.IDLE:(
30 telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
31 True, True, arguments),
32 simple_presence.ButterflyPresenceMapping.BRB:(
33 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
34 True, True, arguments),
35 simple_presence.ButterflyPresenceMapping.PHONE:(
36 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
37 True, True, arguments),
38 simple_presence.ButterflyPresenceMapping.LUNCH:(
39 telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
40 True, True, arguments),
41 simple_presence.ButterflyPresenceMapping.INVISIBLE:(
42 telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
44 simple_presence.ButterflyPresenceMapping.OFFLINE:(
45 telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
49 def RequestPresence(self, contacts):
50 presences = self.get_presences(contacts)
51 self.PresenceUpdate(presences)
53 def GetPresence(self, contacts):
54 return self.get_presences(contacts)
56 def SetStatus(self, statuses):
57 status, arguments = statuses.items()[0]
58 if status == simple_presence.ButterflyPresenceMapping.OFFLINE:
61 presence = simple_presence.ButterflyPresenceMapping.to_pymsn[status]
62 message = arguments.get('message', u'').encode("utf-8")
64 logging.info("Setting Presence to '%s'" % presence)
65 logging.info("Setting Personal message to '%s'" % message)
67 if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
68 self._initial_presence = presence
69 self._initial_personal_message = message
71 self.msn_client.profile.personal_message = message
72 self.msn_client.profile.presence = presence
74 def get_presences(self, contacts):
76 for handleId in contacts:
77 h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
80 except AttributeError:
83 if contact is not None:
84 presence = simple_presence.ButterflyPresenceMapping.to_telepathy[contact.presence]
85 personal_message = unicode(contact.personal_message, "utf-8")
87 presence = simple_presence.ButterflyPresenceMapping.OFFLINE
88 personal_message = u""
92 arguments = {'message' : personal_message}
94 presences[h] = (0, {presence : arguments}) # TODO: Timestamp