9 _moduleLogger = logging.getLogger("simple_presence")
12 class TheOneRingPresence(object):
17 ONLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE,
18 BUSY: telepathy.constants.CONNECTION_PRESENCE_TYPE_BUSY,
22 class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
25 telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
27 dbus_interface = 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'
29 self._implement_property_get(dbus_interface, {'Statuses' : self._get_statuses})
36 raise NotImplementedError()
43 raise NotImplementedError("Abstract property called")
45 @gtk_toolbox.log_exception(_moduleLogger)
46 def GetPresences(self, contacts):
48 @return {ContactHandle: (Status, Presence Type, Message)}
51 for handleId in contacts:
52 h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
53 if isinstance(h, handle.ConnectionHandle):
54 isDnd = self.session.backend.is_dnd()
55 presence = TheOneRingPresence.BUSY if isDnd else TheOneRingPresence.ONLINE
57 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
59 presence = TheOneRingPresence.ONLINE
61 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
63 presences[h] = (presenceType, presence, personalMessage)
66 @gtk_toolbox.log_exception(_moduleLogger)
67 def SetPresence(self, status, message):
69 raise telepathy.errors.InvalidArgument("Messages aren't supported")
72 if status == TheOneRingPresence.ONLINE:
73 self.gvoice_backend.set_dnd(False)
74 elif status == TheOneRingPresence.BUSY:
75 self.gvoice_backend.set_dnd(True)
77 raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status)
78 _moduleLogger.info("Setting Presence to '%s'" % status)
81 def _get_statuses(self):
83 Property mapping presence statuses available to the corresponding presence types
85 @returns {Name: (Telepathy Type, May Set On Self, Can Have Message)}
88 TheOneRingPresence.ONLINE: (
89 telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
92 TheOneRingPresence.BUSY: (
93 telepathy.CONNECTION_PRESENCE_TYPE_AWAY,