9 _moduleLogger = logging.getLogger("simple_presence")
12 class TheOneRingPresence(object):
18 ONLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE,
19 IDLE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY,
20 BUSY: telepathy.constants.CONNECTION_PRESENCE_TYPE_HIDDEN,
24 class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
27 telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
29 dbus_interface = 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'
31 self._implement_property_get(dbus_interface, {'Statuses' : self._get_statuses})
38 raise NotImplementedError()
45 raise NotImplementedError("Abstract property called")
47 @gtk_toolbox.log_exception(_moduleLogger)
48 def GetPresences(self, contacts):
50 @return {ContactHandle: (Status, Presence Type, Message)}
53 for handleId in contacts:
54 h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
55 if isinstance(h, handle.ConnectionHandle):
56 isDnd = self.session.backend.is_dnd()
58 presence = TheOneRingPresence.BUSY
60 # @todo switch this over to also supporting idle
61 presence = TheOneRingPresence.ONLINE
63 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
65 presence = TheOneRingPresence.ONLINE
67 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
69 presences[h] = (presenceType, presence, personalMessage)
72 @gtk_toolbox.log_exception(_moduleLogger)
73 def SetPresence(self, status, message):
75 raise telepathy.errors.InvalidArgument("Messages aren't supported")
77 if status == TheOneRingPresence.ONLINE:
78 self.session.backend.set_dnd(False)
79 elif status == TheOneRingPresence.IDLE:
80 # @todo Add idle support
81 raise telepathy.errors.InvalidArgument("Not Supported Yet")
82 elif status == TheOneRingPresence.BUSY:
83 self.session.backend.set_dnd(True)
85 raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status)
86 _moduleLogger.info("Setting Presence to '%s'" % status)
89 def _get_statuses(self):
91 Property mapping presence statuses available to the corresponding presence types
93 @returns {Name: (Telepathy Type, May Set On Self, Can Have Message)}
96 (localType, (telepathyType, True, False))
97 for (localType, telepathyType) in TheOneRingPresence.TO_PRESENCE_TYPE.iteritems()