changeset 2142:be96beb7ca14

core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
author Goffi <goffi@goffi.org>
date Mon, 06 Feb 2017 22:54:43 +0100
parents 35762e9ce8b9
children c3cac21157d4
files frontends/src/bridge/dbus_bridge.py frontends/src/jp/base.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py src/bridge/bridge_constructor/bridge_template.ini src/bridge/dbus_bridge.py src/core/sat_main.py src/plugins/plugin_misc_account.py src/stdui/ui_profile_manager.py
diffstat 9 files changed, 34 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/dbus_bridge.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/frontends/src/bridge/dbus_bridge.py	Mon Feb 06 22:54:43 2017 +0100
@@ -164,15 +164,6 @@
             kwargs['error_handler'] = error_handler
         return self.db_core_iface.addContact(entity_jid, profile_key, **kwargs)
 
-    def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None):
-        if callback is None:
-            error_handler = None
-        else:
-            if errback is None:
-                errback = log.error
-            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
-        return self.db_core_iface.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
-
     def asyncCreateProfile(self, profile, password='', callback=None, errback=None):
         if callback is None:
             error_handler = None
@@ -209,6 +200,15 @@
             error_handler = lambda err:errback(dbus_to_bridge_exception(err))
         return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
+    def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
+        if callback is None:
+            error_handler = None
+        else:
+            if errback is None:
+                errback = log.error
+            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.connect(profile_key, password, options, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
+
     def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
         if callback is None:
             error_handler = None
--- a/frontends/src/jp/base.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/frontends/src/jp/base.py	Mon Feb 06 22:54:43 2017 +0100
@@ -482,7 +482,7 @@
             # a profile can be present without connect option (e.g. on profile creation/deletion)
             return
         elif self.args.connect is True:  # if connection is asked, we connect the profile
-            self.bridge.asyncConnect(self.profile, self.args.pwd, lambda dummy: callback(), cant_connect)
+            self.bridge.connect(self.profile, self.args.pwd, {}, lambda dummy: callback(), cant_connect)
             self._auto_loop = True
             return
         else:
--- a/frontends/src/primitivus/primitivus	Mon Feb 06 20:51:56 2017 +0100
+++ b/frontends/src/primitivus/primitivus	Mon Feb 06 22:54:43 2017 +0100
@@ -787,7 +787,7 @@
 
     #MENU EVENTS#
     def onConnectRequest(self, menu):
-        QuickApp.asyncConnect(self, self.current_profile)
+        QuickApp.connect(self, self.current_profile)
 
     def onDisconnectRequest(self, menu):
         self.disconnect(self.current_profile)
--- a/frontends/src/quick_frontend/quick_app.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Mon Feb 06 22:54:43 2017 +0100
@@ -90,7 +90,7 @@
     def _plug_profile_autoconnect(self, value_str):
         autoconnect = C.bool(value_str)
         if autoconnect and not self.connected:
-            self.host.asyncConnect(self.profile, callback=lambda dummy: self._plug_profile_afterconnect())
+            self.host.connect(self.profile, callback=lambda dummy: self._plug_profile_afterconnect())
         else:
             self._plug_profile_afterconnect()
 
@@ -440,7 +440,7 @@
         if not self._plugs_in_progress:
             self.contact_lists.lockUpdate(False)
 
-    def asyncConnect(self, profile, callback=None, errback=None):
+    def connect(self, profile, callback=None, errback=None):
         if not callback:
             callback = lambda dummy: None
         if not errback:
@@ -462,7 +462,7 @@
                     self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile=profile)
                 else:
                     self.showDialog(message, fullname, 'error')
-        self.bridge.asyncConnect(profile, callback=callback, errback=errback)
+        self.bridge.connect(profile, callback=callback, errback=errback)
 
     def plug_profiles(self, profiles):
         """Tell application which profiles must be used
--- a/src/bridge/bridge_constructor/bridge_template.ini	Mon Feb 06 20:51:56 2017 +0100
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Mon Feb 06 22:54:43 2017 +0100
@@ -264,17 +264,19 @@
  - ProfileUnknownError: the profile name is unknown
  - ConnectedProfileError: a connected profile would not be deleted
 
-[asyncConnect]
+[connect]
 async=
 type=method
 category=core
-sig_in=ss
+sig_in=ssa{ss}
 sig_out=b
 param_0_default="@DEFAULT@"
 param_1_default=''
+param_2_default={}
 doc=Connect a profile
 doc_param_0=%(doc_profile_key)s
 doc_param_1=password: the SàT profile password
+doc_param_2=options: connection options
 doc_return=a deferred boolean or failure:
     - boolean if the profile authentication succeed:
         - True if the XMPP connection was already established
--- a/src/bridge/dbus_bridge.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/src/bridge/dbus_bridge.py	Mon Feb 06 22:54:43 2017 +0100
@@ -204,12 +204,6 @@
         return self._callback("addContact", unicode(entity_jid), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
-                         in_signature='ss', out_signature='b',
-                         async_callbacks=('callback', 'errback'))
-    def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None):
-        return self._callback("asyncConnect", unicode(profile_key), unicode(password), callback=callback, errback=errback)
-
-    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ss', out_signature='',
                          async_callbacks=('callback', 'errback'))
     def asyncCreateProfile(self, profile, password='', callback=None, errback=None):
@@ -234,6 +228,12 @@
         return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback)
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='ssa{ss}', out_signature='b',
+                         async_callbacks=('callback', 'errback'))
+    def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
+        return self._callback("connect", unicode(profile_key), unicode(password), options, callback=callback, errback=errback)
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ss', out_signature='',
                          async_callbacks=('callback', 'errback'))
     def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
--- a/src/core/sat_main.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/src/core/sat_main.py	Mon Feb 06 22:54:43 2017 +0100
@@ -86,7 +86,7 @@
         self.bridge.register_method("profileStartSession", self.memory.startSession)
         self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted)
         self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault)
-        self.bridge.register_method("asyncConnect", self._asyncConnect)
+        self.bridge.register_method("connect", self._connect)
         self.bridge.register_method("disconnect", self.disconnect)
         self.bridge.register_method("getContacts", self.getContacts)
         self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup)
@@ -263,22 +263,25 @@
                 defers_list.append(defer.maybeDeferred(unload))
         return defers_list
 
-    def _asyncConnect(self, profile_key, password=''):
+    def _connect(self, profile_key, password='', options=None):
         profile = self.memory.getProfileName(profile_key)
-        return self.asyncConnect(profile, password)
+        return self.connect(profile, password, options)
 
-    def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES):
+    def connect(self, profile, password='', options=None, max_retries=C.XMPP_MAX_RETRIES):
         """Retrieve the individual parameters, authenticate the profile
         and initiate the connection to the associated XMPP server.
 
         @param profile: %(doc_profile)s
         @param password (string): the SàT profile password
+        @param options (dict): connection options
         @param max_retries (int): max number of connection retries
         @return (D(bool)):
             - True if the XMPP connection was already established
             - False if the XMPP connection has been initiated (it may still fail)
         @raise exceptions.PasswordError: Profile password is wrong
         """
+        if options is None:
+            options={}
         def connectXMPPClient(dummy=None):
             if self.isConnected(profile):
                 log.info(_("already connected !"))
@@ -292,7 +295,7 @@
 
     @defer.inlineCallbacks
     def _connectXMPPClient(self, profile, max_retries):
-        """This part is called from asyncConnect when we have loaded individual parameters from memory"""
+        """This part is called from connect when we have loaded individual parameters from memory"""
         try:
             port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
         except ValueError:
--- a/src/plugins/plugin_misc_account.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/src/plugins/plugin_misc_account.py	Mon Feb 06 22:54:43 2017 +0100
@@ -617,7 +617,7 @@
 
         d = self.createProfile(password, jid_s, jid_s)
         d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s))  # checks if the profile has been successfuly created
-        d.addCallback(self.host.asyncConnect, password, 0)
+        d.addCallback(self.host.connect, password, {}, 0)
 
 
         def connected(result):
--- a/src/stdui/ui_profile_manager.py	Mon Feb 06 20:51:56 2017 +0100
+++ b/src/stdui/ui_profile_manager.py	Mon Feb 06 22:54:43 2017 +0100
@@ -109,7 +109,7 @@
     def _changeXMPPPasswordCb(self, data, profile):
         xmpp_password = data[xml_tools.formEscape('xmpp_password')]
         d = self.host.memory.setParam("Password", xmpp_password, "Connection", profile_key=profile)
-        d.addCallback(lambda dummy: self.host.asyncConnect(profile))
+        d.addCallback(lambda dummy: self.host.connect(profile))
         d.addCallback(lambda dummy: {})
         d.addErrback(lambda dummy: self._changeXMPPPassword({}, profile))
         return d