changeset c717413e7ffa in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=c717413e7ffa
description: use NEC to handle new account connected events

diffstat:

 src/common/connection.py                 |  30 +++++-------------
 src/common/connection_handlers_events.py |  27 +++++++++++++++++
 src/config.py                            |  49 ++++++++++++++++---------------
 3 files changed, 61 insertions(+), 45 deletions(-)

diffs (201 lines):

diff -r 353529a960cb -r c717413e7ffa src/common/connection.py
--- a/src/common/connection.py  Sun Nov 07 18:26:31 2010 +0100
+++ b/src/common/connection.py  Sun Nov 07 18:50:24 2010 +0100
@@ -872,30 +872,17 @@
                                     self._hostname, self.new_account_form,
                                     _on_register_result)
                         return
-                    try:
-                        errnum = self.connection.Connection.ssl_errnum
-                    except AttributeError:
-                        errnum = -1 # we don't have an errnum
-                    ssl_msg = ''
-                    if errnum > 0:
-                        ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: 
%d') % errnum)
-                    ssl_cert = ''
-                    if hasattr(self.connection.Connection, 'ssl_cert_pem'):
-                        ssl_cert = self.connection.Connection.ssl_cert_pem
-                    ssl_fingerprint = ''
-                    if hasattr(self.connection.Connection, 
'ssl_fingerprint_sha1'):
-                        ssl_fingerprint = \
-                                self.connection.Connection.ssl_fingerprint_sha1
-                    self.dispatch('NEW_ACC_CONNECTED', (conf, is_form, ssl_msg,
-                            errnum, ssl_cert, ssl_fingerprint))
+                    
gajim.nec.push_incoming_event(NewAccountConnectedEvent(None,
+                        conn=self, config=conf, is_form=is_form))
                     self.connection.UnregisterDisconnectHandler(
-                            self._on_new_account)
+                        self._on_new_account)
                     self.disconnect(on_purpose=True)
                     return
                 if not data[1]: # wrong answer
                     self.dispatch('ERROR', (_('Invalid answer'),
-                            _('Transport %(name)s answered wrongly to register 
request: '
-                            '%(error)s') % {'name': data[0], 'error': 
data[3]}))
+                        _('Transport %(name)s answered wrongly to register '
+                        'request: %(error)s') % {'name': data[0],
+                        'error': data[3]}))
                     return
                 is_form = data[2]
                 conf = data[1]
@@ -1810,8 +1797,9 @@
             if len(self._connection_types) or len(self._hosts):
                 # There are still other way to try to connect
                 return
-            self.dispatch('NEW_ACC_NOT_CONNECTED',
-                    (_('Could not connect to "%s"') % self._hostname))
+            reason = _('Could not connect to "%s"') % self._hostname
+            gajim.nec.push_incoming_event(NewAccountNotConnectedEvent(None,
+                conn=self, reason=reason))
             return
         self.on_connect_failure = None
         self.connection = con
diff -r 353529a960cb -r c717413e7ffa src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Sun Nov 07 18:26:31 2010 +0100
+++ b/src/common/connection_handlers_events.py  Sun Nov 07 18:50:24 2010 +0100
@@ -1240,4 +1240,31 @@
 
 class AccountNotCreatedEvent(nec.NetworkIncomingEvent):
     name = 'account-not-created'
+    base_network_events = []
+
+class NewAccountConnectedEvent(nec.NetworkIncomingEvent):
+    name = 'new-account-connected'
+    base_network_events = []
+
+    def generate(self):
+        try:
+            self.errnum = self.conn.connection.Connection.ssl_errnum
+        except AttributeError:
+            self.errnum = -1 # we don't have an errnum
+        self.ssl_msg = ''
+        if self.errnum > 0:
+            from common.connection import ssl_error
+            self.ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % \
+                errnum)
+        self.ssl_cert = ''
+        if hasattr(self.conn.connection.Connection, 'ssl_cert_pem'):
+            self.ssl_cert = self.conn.connection.Connection.ssl_cert_pem
+        self.ssl_fingerprint = ''
+        if hasattr(self.conn.connection.Connection, 'ssl_fingerprint_sha1'):
+            self.ssl_fingerprint = \
+                self.conn.connection.Connection.ssl_fingerprint_sha1
+        return True
+
+class NewAccountNotConnectedEvent(nec.NetworkIncomingEvent):
+    name = 'new-account-not-connected'
     base_network_events = []
\ No newline at end of file
diff -r 353529a960cb -r c717413e7ffa src/config.py
--- a/src/config.py     Sun Nov 07 18:26:31 2010 +0100
+++ b/src/config.py     Sun Nov 07 18:50:24 2010 +0100
@@ -3443,10 +3443,10 @@
         self.notebook.set_current_page(0)
         self.xml.connect_signals(self)
         self.window.show_all()
-        gajim.ged.register_event_handler('NEW_ACC_CONNECTED', ged.CORE,
-            self.new_acc_connected)
-        gajim.ged.register_event_handler('NEW_ACC_NOT_CONNECTED', ged.CORE,
-            self.new_acc_not_connected)
+        gajim.ged.register_event_handler('new-account-connected', ged.GUI1,
+            self._nec_new_acc_connected)
+        gajim.ged.register_event_handler('new-account-not-connected', ged.GUI1,
+            self._nec_new_acc_not_connected)
         gajim.ged.register_event_handler('account-created', ged.GUI1,
             self._nec_acc_is_ok)
         gajim.ged.register_event_handler('account-not-created', ged.GUI1,
@@ -3460,10 +3460,10 @@
             del gajim.connections[self.account]
             if self.account in gajim.config.get_per('accounts'):
                 gajim.config.del_per('accounts', self.account)
-        gajim.ged.remove_event_handler('NEW_ACC_CONNECTED', ged.CORE,
-            self.new_acc_connected)
-        gajim.ged.remove_event_handler('NEW_ACC_NOT_CONNECTED', ged.CORE,
-            self.new_acc_not_connected)
+        gajim.ged.remove_event_handler('new-account-connected', ged.GUI1,
+            self._nec_new_acc_connected)
+        gajim.ged.remove_event_handler('new-account-not-connected', ged.GUI1,
+            self._nec_new_acc_not_connected)
         gajim.ged.remove_event_handler('account-created', ged.GUI1,
             self._nec_acc_is_ok)
         gajim.ged.remove_event_handler('account-not-created', ged.GUI1,
@@ -3706,41 +3706,42 @@
         self.progressbar.pulse()
         return True # loop forever
 
-    def new_acc_connected(self, account, array):
+    def _nec_new_acc_connected(self, obj):
         """
         Connection to server succeded, present the form to the user
         """
         # We receive events from all accounts from GED
-        if account != self.account:
+        if obj.conn.name != self.account:
             return
         form, is_form, ssl_msg, ssl_err, ssl_cert, ssl_fingerprint = array
         if self.update_progressbar_timeout_id is not None:
             gobject.source_remove(self.update_progressbar_timeout_id)
         self.back_button.show()
         self.forward_button.show()
-        self.is_form = is_form
-        if is_form:
-            dataform = dataforms.ExtendForm(node = form)
+        self.is_form = obj.is_form
+        if obj.is_form:
+            dataform = dataforms.ExtendForm(node=obj.config)
             self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
         else:
-            self.data_form_widget = FakeDataForm(form)
+            self.data_form_widget = FakeDataForm(obj.config)
         self.data_form_widget.show_all()
         self.xml.get_object('form_vbox').pack_start(self.data_form_widget)
-        self.ssl_fingerprint = ssl_fingerprint
-        self.ssl_cert = ssl_cert
-        if ssl_msg:
+        self.ssl_fingerprint = obj.ssl_fingerprint
+        self.ssl_cert = obj.ssl_cert
+        if obj.ssl_msg:
             # An SSL warning occured, show it
-            hostname = 
gajim.connections[self.account].new_account_info['hostname']
+            hostname = gajim.connections[self.account].new_account_info[
+                'hostname']
             self.xml.get_object('ssl_label').set_markup(_(
                 '<b>Security Warning</b>'
                 '\n\nThe authenticity of the %(hostname)s SSL certificate 
could'
                 ' be invalid.\nSSL Error: %(error)s\n'
                 'Do you still want to connect to this server?') % {
-                'hostname': hostname, 'error': ssl_msg})
-            if ssl_err in (18, 27):
+                'hostname': hostname, 'error': obj.ssl_msg})
+            if obj.ssl_err in (18, 27):
                 text = _('Add this certificate to the list of trusted '
                     'certificates.\nSHA1 fingerprint of the certificate:\n%s') 
\
-                    % ssl_fingerprint
+                    % obj.ssl_fingerprint
                 self.xml.get_object('ssl_checkbutton').set_label(text)
             else:
                 self.xml.get_object('ssl_checkbutton').set_no_show_all(True)
@@ -3749,12 +3750,12 @@
         else:
             self.notebook.set_current_page(4) # show form page
 
-    def new_acc_not_connected(self, account, reason):
+    def _nec_new_acc_not_connected(self, obj):
         """
         Account creation failed: connection to server failed
         """
         # We receive events from all accounts from GED
-        if account != self.account:
+        if obj.conn.name != self.account:
             return
         if self.account not in gajim.connections:
             return
@@ -3770,7 +3771,7 @@
         img = self.xml.get_object('finish_image')
         img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
         finish_text = '<big><b>%s</b></big>\n\n%s' % (
-            _('An error occurred during account creation'), reason)
+            _('An error occurred during account creation'), obj.reason)
         self.finish_label.set_markup(finish_text)
         self.notebook.set_current_page(6) # show finish page
 
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to