7 import gvoice.state_machine as state_machine
10 _moduleLogger = logging.getLogger("simple_presence")
13 class TheOneRingPresence(object):
15 # Note: these strings are also in the theonering.profile file
22 ONLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE,
23 AWAY: telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY,
24 HIDDEN: telepathy.constants.CONNECTION_PRESENCE_TYPE_HIDDEN,
25 OFFLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_OFFLINE,
29 class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
32 telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
34 self._implement_property_get(
35 telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
36 {'Statuses' : self._get_statuses}
44 raise NotImplementedError()
51 raise NotImplementedError("Abstract property called")
57 raise NotImplementedError("Abstract function called")
59 @gtk_toolbox.log_exception(_moduleLogger)
60 def GetPresences(self, contacts):
62 @return {ContactHandle: (Status, Presence Type, Message)}
65 for handleId in contacts:
66 h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
67 if isinstance(h, handle.ConnectionHandle):
68 isDnd = self.session.backend.is_dnd()
70 presence = TheOneRingPresence.HIDDEN
72 state = self.session.stateMachine.get_state()
73 if state == state_machine.StateMachine.STATE_ACTIVE:
74 presence = TheOneRingPresence.ONLINE
75 elif state == state_machine.StateMachine.STATE_IDLE:
76 presence = TheOneRingPresence.AWAY
78 raise telepathy.errors.InvalidArgument("Unsupported state on the state machine: %s" % state)
80 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
82 presence = TheOneRingPresence.ONLINE
84 presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence]
86 presences[h] = (presenceType, presence, personalMessage)
89 @gtk_toolbox.log_exception(_moduleLogger)
90 def SetPresence(self, status, message):
92 raise telepathy.errors.InvalidArgument("Messages aren't supported")
94 if status == TheOneRingPresence.ONLINE:
95 self.session.backend.set_dnd(False)
96 self.session.stateMachine.set_state(state_machine.StateMachine.STATE_ACTIVE)
97 elif status == TheOneRingPresence.AWAY:
98 self.session.stateMachine.set_state(state_machine.StateMachine.STATE_IDLE)
99 elif status == TheOneRingPresence.HIDDEN:
100 self.session.backend.set_dnd(True)
101 elif status == TheOneRingPresence.OFFLINE:
104 raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status)
105 _moduleLogger.info("Setting Presence to '%s'" % status)
108 def _get_statuses(self):
110 Property mapping presence statuses available to the corresponding presence types
112 @returns {Name: (Telepathy Type, May Set On Self, Can Have Message)}
115 (localType, (telepathyType, True, False))
116 for (localType, telepathyType) in TheOneRingPresence.TO_PRESENCE_TYPE.iteritems()