changeset 512329de821c in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=512329de821c
description: handle ERROR and INFORMATION events through NEC

diffstat:

 src/common/connection.py                   |  48 ++++++++++++++++++-----------
 src/common/connection_handlers.py          |  22 ++++++++-----
 src/common/connection_handlers_events.py   |  28 ++++++++++++-----
 src/common/jingle_rtp.py                   |  20 ++++++-----
 src/common/protocol/bytestream.py          |   5 +-
 src/common/zeroconf/connection_zeroconf.py |   5 +-
 src/config.py                              |   9 +++--
 src/gui_interface.py                       |  22 ++++++++-----
 src/session.py                             |   8 +++-
 9 files changed, 103 insertions(+), 64 deletions(-)

diffs (truncated from 373 to 300 lines):

diff -r eca7a7b23b66 -r 512329de821c src/common/connection.py
--- a/src/common/connection.py  Mon Nov 21 23:51:14 2011 +0100
+++ b/src/common/connection.py  Tue Nov 22 19:25:15 2011 +0100
@@ -256,9 +256,10 @@
         try:
             jid = self.check_jid(jid)
         except helpers.InvalidFormat:
-            self.dispatch('ERROR', (_('Invalid Jabber ID'),
-                    _('It is not possible to send a message to %s, this JID is 
not '
-                    'valid.') % jid))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Invalid Jabber ID'), sec_txt=_(
+                'It is not possible to send a message to %s, this JID is not '
+                'valid.') % jid))
             return
 
         if msg and not xhtml and gajim.config.get(
@@ -924,9 +925,10 @@
                     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],
+                    gajim.nec.push_incoming_event(InformationEvent(None,
+                        conn=self, level='error', pri_txt=_('Invalid answer'),
+                        sec_txt=_('Transport %(name)s answered wrongly to '
+                        'register request: %(error)s') % {'name': data[0],
                         'error': data[3]}))
                     return
                 is_form = data[2]
@@ -1207,7 +1209,9 @@
                     key = common.xmpp.NS_XMPP_STREAMS + ' ' + self.streamError
                     if key in common.xmpp.ERRORS:
                         sectxt2 = _('Server replied: %s') % 
common.xmpp.ERRORS[key][2]
-                        self.dispatch('ERROR', (pritxt, '%s\n%s' % (sectxt2, 
sectxt)))
+                        gajim.nec.push_incoming_event(InformationEvent(None,
+                            conn=self, level='error', pri_txt=pritxt,
+                            sec_txt='%s\n%s' % (sectxt2, sectxt)))
                         return
                 # show popup
                 gajim.nec.push_incoming_event(ConnectionLostEvent(None,
@@ -1375,9 +1379,10 @@
             self.disconnect(on_purpose = True)
             gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
                 show='offline'))
-            self.dispatch('ERROR', (_('Authentication failed with "%s"') % \
-                    self._hostname,
-                    _('Please check your login and password for 
correctness.')))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Authentication failed with "%s"') % \
+                self._hostname, sec_txt=_('Please check your login and 
password'
+                'for correctness.')))
             if self.on_connect_auth:
                 self.on_connect_auth(None)
                 self.on_connect_auth = None
@@ -1450,10 +1455,11 @@
                 gajim.nec.push_incoming_event(PrivacyListRemovedEvent(None,
                     conn=self, list_name=privacy_list))
             else:
-                self.dispatch('ERROR', (_('Error while removing privacy list'),
-                        _('Privacy list %s has not been removed. It is maybe 
active in '
-                        'one of your connected resources. Deactivate it and 
try '
-                        'again.') % privacy_list))
+                gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                    level='error', pri_txt=_('Error while removing privacy '
+                    'list'), sec_txt=_('Privacy list %s has not been removed. '
+                    'It is maybe active in one of your connected resources. '
+                    'Deactivate it and tryagain.') % privacy_list))
         common.xmpp.features_nb.delPrivacyList(self.connection, privacy_list,
                 _on_del_privacy_list_result)
 
@@ -1528,8 +1534,10 @@
         if not self.privacy_rules_supported:
             gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
                 show=gajim.SHOW_LIST[self.connected]))
-            self.dispatch('ERROR', (_('Invisibility not supported'),
-                    _('Account %s doesn\'t support invisibility.') % 
self.name))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Invisibility not supported',
+                sec_txt=_('Account %s doesn\'t support invisibility.') % \
+                self.name)))
             return
         # If we are already connected, and privacy rules are supported, send
         # offline presence first as it's required by XEP-0126
@@ -2535,9 +2543,11 @@
                     if result.getID() == id_:
                         on_remove_success(True)
                         return
-                    self.dispatch('ERROR', (_('Unregister failed'),
-                        _('Unregistration with server %(server)s failed: '
-                        '%(error)s') % {'server': hostname,
+                    gajim.nec.push_incoming_event(InformationEvent(None,
+                        conn=self, level='error',
+                        pri_txt=_('Unregister failed'),
+                        sec_txt=_('Unregistration with server %(server)s '
+                        'failed: %(error)s') % {'server': hostname,
                         'error': result.getErrorMsg()}))
                     on_remove_success(False)
                 con.RegisterHandler('iq', _on_answer, 'result', system=True)
diff -r eca7a7b23b66 -r 512329de821c src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Mon Nov 21 23:51:14 2011 +0100
+++ b/src/common/connection_handlers.py Tue Nov 22 19:25:15 2011 +0100
@@ -125,8 +125,9 @@
 
     def _agent_registered_cb(self, con, resp, agent):
         if resp.getType() == 'result':
-            self.dispatch('INFORMATION', (_('Registration succeeded'),
-                _('Registration with agent %s succeeded') % agent))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='info', pri_txt=_('Registration succeeded'), sec_txt=_(
+                'Registration with agent %s succeeded') % agent))
             self.request_subscription(agent, auto_auth=True)
             self.agent_registrations[agent]['roster_push'] = True
             if self.agent_registrations[agent]['sub_received']:
@@ -134,9 +135,10 @@
                 p = self.add_sha(p)
                 self.connection.send(p)
         if resp.getType() == 'error':
-            self.dispatch('ERROR', (_('Registration failed'), _('Registration '
-                'with agent %(agent)s failed with error %(error)s: '
-                '%(error_msg)s') % {'agent': agent, 'error': resp.getError(),
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Registration failed'), sec_txt=_(
+                'Registration with agent %(agent)s failed with error 
%(error)s:'
+                ' %(error_msg)s') % {'agent': agent, 'error': resp.getError(),
                 'error_msg': resp.getErrorMsg()}))
 
     def register_agent(self, agent, info, is_form=False):
@@ -328,7 +330,8 @@
             fil.write(str(card))
             fil.close()
         except IOError, e:
-            self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Disk Write Error'), sec_txt=str(e)))
 
     def get_cached_vcard(self, fjid, is_fake_jid=False):
         """
@@ -564,9 +567,10 @@
                     self.disconnect(on_purpose=True)
                     gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
                         show='offline'))
-                    self.dispatch('ERROR', (_('Invisibility not supported'),
-                        _('Account %s doesn\'t support invisibility.') % \
-                        self.name))
+                    gajim.nec.push_incoming_event(InformationEvent(None,
+                        conn=self, level='error', pri_txt=_('Invisibility not '
+                        'supported'), sec_txt=_('Account %s doesn\'t support '
+                        'invisibility.') % self.name))
                     return
             # Ask metacontacts before roster
             self.get_metacontacts()
diff -r eca7a7b23b66 -r 512329de821c src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Mon Nov 21 23:51:14 2011 +0100
+++ b/src/common/connection_handlers_events.py  Tue Nov 22 19:25:15 2011 +0100
@@ -1008,8 +1008,9 @@
         try:
             self.get_jid_resource()
         except helpers.InvalidFormat:
-            self.conn.dispatch('ERROR', (_('Invalid Jabber ID'),
-                _('A message from a non-valid JID arrived, it has been '
+            gajim.nec.push_incoming_event(InformationEvent(None, 
conn=self.conn,
+                level='error', pri_txt=_('Invalid Jabber ID'),
+                sec_txt=_('A message from a non-valid JID arrived, it has been 
'
                 'ignored.')))
             return
 
@@ -1038,9 +1039,11 @@
                 try:
                     self.get_jid_resource()
                 except helpers.InvalidFormat:
-                    self.conn.dispatch('ERROR', (_('Invalid Jabber ID'),
-                        _('A message from a non-valid JID arrived, it has been 
'
-                        'ignored.')))
+                    gajim.nec.push_incoming_event(InformationEvent(None,
+                        conn=self.conn, level='error',
+                        pri_txt=_('Invalid Jabber ID'),
+                        sec_txt=_('A message from a non-valid JID arrived, it '
+                        'has been ignored.')))
                     return
                 self.forwarded = True
             elif sent_tag:
@@ -1052,9 +1055,11 @@
                 try:
                     self.get_jid_resource()
                 except helpers.InvalidFormat:
-                    self.conn.dispatch('ERROR', (_('Invalid Jabber ID'),
-                        _('A message from a non-valid JID arrived, it has been 
'
-                        'ignored.')))
+                    gajim.nec.push_incoming_event(InformationEvent(None,
+                        conn=self.conn, level='error',
+                        pri_txt=_('Invalid Jabber ID'),
+                        sec_txt=_('A message from a non-valid JID arrived, it '
+                        'has been ignored.')))
                     return
                 self.forwarded = True
                 self.sent = True
@@ -2281,3 +2286,10 @@
 class ClientCertPassphraseEvent(nec.NetworkIncomingEvent):
     name = 'client-cert-passphrase'
     base_network_events = []
+
+class InformationEvent(nec.NetworkIncomingEvent):
+    name = 'information'
+    base_network_events = []
+
+    def init(self):
+        self.popup = True
diff -r eca7a7b23b66 -r 512329de821c src/common/jingle_rtp.py
--- a/src/common/jingle_rtp.py  Mon Nov 21 23:51:14 2011 +0100
+++ b/src/common/jingle_rtp.py  Tue Nov 22 19:25:15 2011 +0100
@@ -103,11 +103,12 @@
             bin = gst.parse_bin_from_description(pipeline, True)
             return bin
         except GError, error_str:
-            self.session.connection.dispatch('ERROR',
-                    (_("%s configuration error") % text.capitalize(),
-                            _("Couldn't setup %s. Check your 
configuration.\n\n"
-                                    "Pipeline was:\n%s\n\n"
-                                    "Error was:\n%s") % (text, pipeline, 
error_str)))
+            gajim.nec.push_incoming_event(InformationEvent(None,
+                conn=self.session.connection, level='error',
+                pri_txt=_('%s configuration error') % text.capitalize(),
+                sec_txt=_("Couldn't setup %s. Check your configuration.\n\n"
+                "Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline,
+                error_str)))
             raise JingleContentSetupException
 
     def add_remote_candidates(self, candidates):
@@ -201,10 +202,11 @@
             # or raise an error, Jingle way
             # or maybe one-sided stream?
             if not self.stream_failed_once:
-                self.session.connection.dispatch('ERROR',
-                        (_("GStreamer error"),
-                         _("Error: %s\nDebug: %s" % 
(message.structure['gerror'],
-                                message.structure['debug']))))
+                gajim.nec.push_incoming_event(InformationEvent(None,
+                    conn=self.session.connection, level='error',
+                    pri_txt=_('GStreamer error'), sec_txt=_('Error: %s\nDebug: 
'
+                    '%s' % (message.structure['gerror'],
+                    message.structure['debug']))))
 
             sink_pad = self.p2psession.get_property('sink-pad')
 
diff -r eca7a7b23b66 -r 512329de821c src/common/protocol/bytestream.py
--- a/src/common/protocol/bytestream.py Mon Nov 21 23:51:14 2011 +0100
+++ b/src/common/protocol/bytestream.py Tue Nov 22 19:25:15 2011 +0100
@@ -374,8 +374,9 @@
             port = gajim.config.get('file_transfers_port')
             self._add_streamhosts_to_query(query, sender, port, my_ips)
         except socket.gaierror:
-            self.dispatch('ERROR', (_('Wrong host'),
-                    _('Invalid local address? :-O')))
+            gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+                level='error', pri_txt=_('Wrong host'),
+                sec_txt=_('Invalid local address? :-O')))
 
     def _add_addiditional_streamhosts_to_query(self, query, file_props):
         sender = file_props['sender']
diff -r eca7a7b23b66 -r 512329de821c src/common/zeroconf/connection_zeroconf.py
--- a/src/common/zeroconf/connection_zeroconf.py        Mon Nov 21 23:51:14 
2011 +0100
+++ b/src/common/zeroconf/connection_zeroconf.py        Tue Nov 22 19:25:15 
2011 +0100
@@ -189,8 +189,9 @@
             alt_name=alt_name))
 
     def _on_error(self, message):
-        self.dispatch('ERROR', (_('Avahi error'),
-                _('%s\nLink-local messaging might not work properly.') % 
message))
+        gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
+            level='error', pri_txt=_('Avahi error'), sec_txt=_('%s\nLink-local 
'
+            'messaging might not work properly.') % message))
 
     def connect(self, show='online', msg=''):
         self.get_config_values_or_default()
diff -r eca7a7b23b66 -r 512329de821c src/config.py
--- a/src/config.py     Mon Nov 21 23:51:14 2011 +0100
+++ b/src/config.py     Tue Nov 22 19:25:15 2011 +0100
@@ -2575,10 +2575,11 @@
             return
         if gajim.ZEROCONF_ACC_NAME in gajim.connections and not \
         gajim.connections[gajim.ZEROCONF_ACC_NAME].is_zeroconf:
-            gajim.connections[gajim.ZEROCONF_ACC_NAME].dispatch('ERROR',
-                    (_('Account Local already exists.'),
-                    _('Please rename or remove it before enabling link-local 
messaging'
-                    '.')))
+            gajim.nec.push_incoming_event(InformationEvent(None,
+                conn=gajim.connections[gajim.ZEROCONF_ACC_NAME],
+                level='error', pri_txt=_('Account Local already exists.'),
+                sec_txt=_('Please rename or remove it before enabling '
+                'link-local messaging.')))
             return
 
         if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'active') 
\
diff -r eca7a7b23b66 -r 512329de821c src/gui_interface.py
--- a/src/gui_interface.py      Mon Nov 21 23:51:14 2011 +0100
+++ b/src/gui_interface.py      Tue Nov 22 19:25:15 2011 +0100
@@ -105,10 +105,6 @@
 ### Methods handling events from connection
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to