changeset 255873d093cf in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=255873d093cf
description: use NEC to handle our-status event

diffstat:

 src/chat_control.py                        |  19 +++++++++++++
 src/common/connection.py                   |  42 ++++++++++++++++++++----------
 src/common/connection_handlers.py          |   6 ++-
 src/common/connection_handlers_events.py   |   7 ++++-
 src/common/zeroconf/connection_zeroconf.py |  30 ++++++++++++++-------
 src/gui_interface.py                       |  41 +++++-----------------------
 src/remote_control.py                      |   5 +++
 src/roster_window.py                       |  15 ++++++++++-
 8 files changed, 104 insertions(+), 61 deletions(-)

diffs (truncated from 457 to 300 lines):

diff -r c262ae0da86d -r 255873d093cf src/chat_control.py
--- a/src/chat_control.py       Sat Nov 06 09:19:20 2010 +0100
+++ b/src/chat_control.py       Sat Nov 06 10:04:41 2010 +0100
@@ -43,6 +43,7 @@
 from common import gajim
 from common import helpers
 from common import exceptions
+from common import ged
 from message_control import MessageControl
 from conversation_textview import ConversationTextview
 from message_textview import MessageTextView
@@ -198,6 +199,19 @@
         """
         pass
 
+    def _nec_our_status(self, obj):
+        if self.account != obj.conn.name:
+            return
+        if obj.show == 'offline' or (obj.show == 'invisible' and \
+        obj.conn.is_zeroconf):
+            self.got_disconnected()
+        else:
+            # Other code rejoins all GCs, so we don't do it here
+            if not self.type_id == message_control.TYPE_GC:
+                self.got_connected()
+        if self.parent_win:
+            self.parent_win.redraw_tab(self)
+
     def handle_message_textview_mykey_press(self, widget, event_keyval,
     event_keymod):
         """
@@ -430,6 +444,9 @@
         # instance object (also subclasses, eg. ChatControl or 
GroupchatControl)
         gajim.plugin_manager.gui_extension_point('chat_control_base', self)
 
+        gajim.ged.register_event_handler('our-show', ged.GUI1,
+            self._nec_our_status)
+
         # This is bascially a very nasty hack to surpass the inability
         # to properly use the super, because of the old code.
         CommandTools.__init__(self)
@@ -474,6 +491,8 @@
         # instance object
         gajim.plugin_manager.remove_gui_extension_point('chat_control_base', 
self)
         
gajim.plugin_manager.remove_gui_extension_point('chat_control_base_draw_banner',
 self)
+        gajim.ged.remove_event_handler('our-show', ged.GUI1,
+            self._nec_our_status)
 
     def on_msg_textview_populate_popup(self, textview, menu):
         """
diff -r c262ae0da86d -r 255873d093cf src/common/connection.py
--- a/src/common/connection.py  Sat Nov 06 09:19:20 2010 +0100
+++ b/src/common/connection.py  Sat Nov 06 10:04:41 2010 +0100
@@ -231,7 +231,8 @@
         Called when a disconnect request has completed successfully
         """
         self.disconnect(on_purpose=True)
-        self.dispatch('STATUS', 'offline')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='offline'))
 
     def get_status(self):
         return gajim.SHOW_LIST[self.connected]
@@ -731,7 +732,8 @@
         if self.connected < 2: # connection failed
             log.debug('reconnect')
             self.connected = 1
-            self.dispatch('STATUS', 'connecting')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='connecting'))
             self.retrycount += 1
             self.on_connect_auth = self._discover_server_at_connection
             self.connect_and_init(self.old_show, self.status, self.USE_GPG)
@@ -768,11 +770,13 @@
             self.old_show = gajim.SHOW_LIST[self.connected]
         self.connected = 0
         if not self.on_purpose:
-            self.dispatch('STATUS', 'offline')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
             self.disconnect()
             if gajim.config.get_per('accounts', self.name, 'autoreconnect'):
                 self.connected = -1
-                self.dispatch('STATUS', 'error')
+                gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                    show='error'))
                 if gajim.status_before_autoaway[self.name]:
                     # We were auto away. So go back online
                     self.status = gajim.status_before_autoaway[self.name]
@@ -804,7 +808,8 @@
     def _connection_lost(self):
         log.debug('_connection_lost')
         self.disconnect(on_purpose = False)
-        self.dispatch('STATUS', 'offline')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='offline'))
         self.dispatch('CONNECTION_LOST',
                 (_('Connection with account "%s" has been lost') % self.name,
                 _('Reconnect manually.')))
@@ -1164,7 +1169,8 @@
             # we are not retrying, and not conecting
             if not self.retrycount and self.connected != 0:
                 self.disconnect(on_purpose = True)
-                self.dispatch('STATUS', 'offline')
+                gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                    show='offline'))
                 pritxt = _('Could not connect to "%s"') % self._hostname
                 sectxt = _('Check your connection or try again later.')
                 if self.streamError:
@@ -1182,7 +1188,8 @@
         self.time_to_reconnect = None
         self.on_connect_failure = None
         self.disconnect(on_purpose = True)
-        self.dispatch('STATUS', 'offline')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='offline'))
         self.dispatch('CONNECTION_LOST',
                 (_('Connection to proxy failed'), reason))
 
@@ -1213,7 +1220,8 @@
     def connection_accepted(self, con, con_type):
         if not con or not con.Connection:
             self.disconnect(on_purpose=True)
-            self.dispatch('STATUS', 'offline')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
             self.dispatch('CONNECTION_LOST',
                     (_('Could not connect to account %s') % self.name,
                     _('Connection with account %s has been lost. Retry 
connecting.') % \
@@ -1272,7 +1280,8 @@
     def ssl_certificate_accepted(self):
         if not self.connection:
             self.disconnect(on_purpose=True)
-            self.dispatch('STATUS', 'offline')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
             self.dispatch('CONNECTION_LOST',
                     (_('Could not connect to account %s') % self.name,
                     _('Connection with account %s has been lost. Retry 
connecting.') % \
@@ -1292,7 +1301,8 @@
     def __on_auth(self, con, auth):
         if not con:
             self.disconnect(on_purpose=True)
-            self.dispatch('STATUS', 'offline')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
             self.dispatch('CONNECTION_LOST',
                     (_('Could not connect to "%s"') % self._hostname,
                     _('Check your connection or try again later')))
@@ -1327,7 +1337,8 @@
                 self.password = None
             gajim.log.debug("Couldn't authenticate to %s" % self._hostname)
             self.disconnect(on_purpose = True)
-            self.dispatch('STATUS', 'offline')
+            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.')))
@@ -1475,7 +1486,8 @@
         if not gajim.account_is_connected(self.name):
             return
         if not self.privacy_rules_supported:
-            self.dispatch('STATUS', gajim.SHOW_LIST[self.connected])
+            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))
             return
@@ -1512,7 +1524,8 @@
             p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed)
         self.connection.send(p)
         self.priority = priority
-        self.dispatch('STATUS', 'invisible')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='invisible'))
         if initial:
             # ask our VCard
             self.request_vcard(None)
@@ -1617,7 +1630,8 @@
         if self.connection:
             self.connection.send(p)
             self.priority = priority
-        self.dispatch('STATUS', show)
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show=show))
 
     def send_motd(self, jid, subject = '', msg = '', xhtml = None):
         if not gajim.account_is_connected(self.name):
diff -r c262ae0da86d -r 255873d093cf src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Sat Nov 06 09:19:20 2010 +0100
+++ b/src/common/connection_handlers.py Sat Nov 06 10:04:41 2010 +0100
@@ -708,7 +708,8 @@
                     # Trying to login as invisible but privacy list not
                     # supported
                     self.disconnect(on_purpose=True)
-                    self.dispatch('STATUS', 'offline')
+                    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))
@@ -2035,7 +2036,8 @@
         if self.connection:
             self.connection.send(p)
             self.priority = priority
-        self.dispatch('STATUS', show)
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show=show))
         if self.vcard_supported:
             # ask our VCard
             self.request_vcard(None)
diff -r c262ae0da86d -r 255873d093cf src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Sat Nov 06 09:19:20 2010 +0100
+++ b/src/common/connection_handlers_events.py  Sat Nov 06 10:04:41 2010 +0100
@@ -758,7 +758,8 @@
             if self.jid == our_jid and self.resource == \
             self.conn.server_resource:
                 # We got our own presence
-                self.conn.dispatch('STATUS', self.show)
+                gajim.nec.push_incoming_event(OurShowEvent(None, 
conn=self.conn,
+                    show=self.show))
             elif self.jid in jid_list or self.jid == our_jid:
                 return True
 
@@ -874,6 +875,10 @@
         self.jid = self.presence_obj.jid
         return True
 
+class OurShowEvent(nec.NetworkIncomingEvent):
+    name = 'our-show'
+    base_network_events = []
+
 class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
     name = 'message-received'
     base_network_events = ['raw-message-received']
diff -r c262ae0da86d -r 255873d093cf src/common/zeroconf/connection_zeroconf.py
--- a/src/common/zeroconf/connection_zeroconf.py        Sat Nov 06 09:19:20 
2010 +0100
+++ b/src/common/zeroconf/connection_zeroconf.py        Sat Nov 06 10:04:41 
2010 +0100
@@ -168,14 +168,16 @@
             # after we auth to server
             self.old_show = STATUS_LIST[self.connected]
         self.connected = 0
-        self.dispatch('STATUS', 'offline')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='offline'))
         # random number to show we wait network manager to send us a reconenct
         self.time_to_reconnect = 5
         self.on_purpose = False
 
     def _on_name_conflictCB(self, alt_name):
         self.disconnect()
-        self.dispatch('STATUS', 'offline')
+        gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+            show='offline'))
         self.dispatch('ZC_NAME_CONFLICT', alt_name)
 
     def _on_error(self, message):
@@ -187,7 +189,8 @@
         if not self.connection:
             self.connection = client_zeroconf.ClientZeroconf(self)
             if not zeroconf.test_zeroconf():
-                self.dispatch('STATUS', 'offline')
+                gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                    show='offline'))
                 self.status = 'offline'
                 self.dispatch('CONNECTION_LOST',
                         (_('Could not connect to "%s"') % self.name,
@@ -196,7 +199,8 @@
                 return
             result = self.connection.connect(show, msg)
             if not result:
-                self.dispatch('STATUS', 'offline')
+                gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                    show='offline'))
                 self.status = 'offline'
                 if result is False:
                     self.dispatch('CONNECTION_LOST',
@@ -278,10 +282,12 @@
 
         # stay offline when zeroconf does something wrong
         if check:
-            self.dispatch('STATUS', show)
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show=show))
         else:
             # show notification that avahi or system bus is down
-            self.dispatch('STATUS', 'offline')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
             self.status = 'offline'
             self.dispatch('CONNECTION_LOST',
                     (_('Could not change status of account "%s"') % self.name,
@@ -289,10 +295,12 @@
 
     def _change_to_invisible(self, msg):
         if self.connection.remove_announce():
-            self.dispatch('STATUS', 'invisible')
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='invisible'))
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to