import gv_backend
import handle
import channel_manager
+import simple_presence
-class TheOneRingConnection(telepathy.server.Connection):
+_moduleLogger = logging.getLogger("connection")
- _mandatory_parameters = {
+
+class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePresenceMixin):
+
+ MANDATORY_PARAMETERS = {
'account' : 's',
'password' : 's'
}
+ OPTIONAL_PARAMETERS = {
+ }
+ PARAMETER_DEFAULTS = {
+ }
def __init__(self, manager, parameters):
try:
self.check_parameters(parameters)
account = unicode(parameters['account'])
- telepathy.server.Connection.__init__(self, 'gvoice', account, 'theonering')
+ telepathy.server.Connection.__init__(
+ self,
+ constants._telepathy_protocol_name_,
+ account,
+ constants._telepathy_implementation_name_
+ )
self._manager = weakref.proxy(manager)
self._credentials = (
cookieFilePath = "%s/cookies.txt" % constants._data_path_
self._backend = gv_backend.GVDialer(cookieFilePath)
- self.set_self_handle(handle.create_handle(self, 'self'))
-
- self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
- self._initial_presence = None
- self._initial_personal_message = None
+ self.set_self_handle(handle.create_handle(self, 'connection'))
- logging.info("Connection to the account %s created" % account)
+ _moduleLogger.info("Connection to the account %s created" % account)
except Exception, e:
- logging.exception("Failed to create Connection")
+ _moduleLogger.exception("Failed to create Connection")
raise
@property
def Connect(self):
"""
- org.freedesktop.telepathy.Connection
+ For org.freedesktop.telepathy.Connection
"""
- logging.info("Connecting")
- self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED
- self._backend.login(*self._credentials)
+ self.StatusChanged(
+ telepathy.CONNECTION_STATUS_CONNECTING,
+ telepathy.CONNECTION_STATUS_REASON_REQUESTED
+ )
+ try:
+ self._backend.login(*self._credentials)
+ except gv_backend.NetworkError:
+ self.StatusChanged(
+ telepathy.CONNECTION_STATUS_DISCONNECTED,
+ telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
+ )
+ except Exception:
+ self.StatusChanged(
+ telepathy.CONNECTION_STATUS_DISCONNECTED,
+ telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
+ )
+ else:
+ self.StatusChanged(
+ telepathy.CONNECTION_STATUS_CONNECTED,
+ telepathy.CONNECTION_STATUS_REASON_REQUESTED
+ )
def Disconnect(self):
"""
- org.freedesktop.telepathy.Connection
+ For org.freedesktop.telepathy.Connection
"""
- logging.info("Disconnecting")
- self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_REQUESTED
- self._backend.logout()
+ try:
+ self._backend.logout()
+ _moduleLogger.info("Disconnected")
+ except Exception:
+ _moduleLogger.exception("Disconnecting Failed")
+ self.StatusChanged(
+ telepathy.CONNECTION_STATUS_DISCONNECTED,
+ telepathy.CONNECTION_STATUS_REASON_REQUESTED
+ )
def RequestChannel(self, type, handleType, handleId, suppressHandler):
"""
- org.freedesktop.telepathy.Connection
+ For org.freedesktop.telepathy.Connection
+
@param type DBus interface name for base channel type
@param handleId represents a contact, list, etc according to handleType
def RequestHandles(self, handleType, names, sender):
"""
- org.freedesktop.telepathy.Connection
+ For org.freedesktop.telepathy.Connection
"""
self.check_connected()
self.check_handleType(handleType)