use NEC to handle our-status event
This commit is contained in:
parent
f68d270f8f
commit
69578659a2
|
@ -43,6 +43,7 @@ import re
|
|||
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 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
"""
|
||||
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 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
# 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 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
# 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):
|
||||
"""
|
||||
|
|
|
@ -231,7 +231,8 @@ class CommonConnection:
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
# 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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
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):
|
||||
|
|
|
@ -708,7 +708,8 @@ class ConnectionVcard:
|
|||
# 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 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
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)
|
||||
|
|
|
@ -758,7 +758,8 @@ class PresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
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 @@ class UnsubscribedPresenceReceivedEvent(nec.NetworkIncomingEvent):
|
|||
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']
|
||||
|
|
|
@ -168,14 +168,16 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
# 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 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
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 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
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 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
|
||||
# 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 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
|
||||
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'))
|
||||
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,
|
||||
|
@ -303,10 +311,12 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
|
||||
def _update_status(self, show, msg):
|
||||
if self.connection.set_show_msg(show, msg):
|
||||
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,
|
||||
|
|
|
@ -202,10 +202,10 @@ class Interface:
|
|||
def unblock_signed_in_notifications(self, account):
|
||||
gajim.block_signed_in_notifications[account] = False
|
||||
|
||||
def handle_event_status(self, account, show): # OUR status
|
||||
def handle_event_status(self, obj): # OUR status
|
||||
#('STATUS', account, show)
|
||||
model = self.roster.status_combobox.get_model()
|
||||
if show in ('offline', 'error'):
|
||||
account = obj.conn.name
|
||||
if obj.show in ('offline', 'error'):
|
||||
for name in self.instances[account]['online_dialog'].keys():
|
||||
# .keys() is needed to not have a dictionary length changed
|
||||
# during iteration error
|
||||
|
@ -218,10 +218,7 @@ class Interface:
|
|||
request.interrupt(account=account)
|
||||
if account in self.pass_dialog:
|
||||
self.pass_dialog[account].window.destroy()
|
||||
if show == 'offline':
|
||||
# sensitivity for this menuitem
|
||||
if gajim.get_number_of_connected_accounts() == 0:
|
||||
model[self.roster.status_message_menuitem_iter][3] = False
|
||||
if obj.show == 'offline':
|
||||
gajim.block_signed_in_notifications[account] = True
|
||||
else:
|
||||
# 30 seconds after we change our status to sth else than offline
|
||||
|
@ -230,32 +227,10 @@ class Interface:
|
|||
# contacts. 30 seconds should be enough time
|
||||
gobject.timeout_add_seconds(30,
|
||||
self.unblock_signed_in_notifications, account)
|
||||
# sensitivity for this menuitem
|
||||
model[self.roster.status_message_menuitem_iter][3] = True
|
||||
|
||||
# Inform all controls for this account of the connection state change
|
||||
ctrls = self.msg_win_mgr.get_controls()
|
||||
if account in self.minimized_controls:
|
||||
# Can not be the case when we remove account
|
||||
ctrls += self.minimized_controls[account].values()
|
||||
for ctrl in ctrls:
|
||||
if ctrl.account == account:
|
||||
if show == 'offline' or (show == 'invisible' and \
|
||||
gajim.connections[account].is_zeroconf):
|
||||
ctrl.got_disconnected()
|
||||
else:
|
||||
# Other code rejoins all GCs, so we don't do it here
|
||||
if not ctrl.type_id == message_control.TYPE_GC:
|
||||
ctrl.got_connected()
|
||||
if ctrl.parent_win:
|
||||
ctrl.parent_win.redraw_tab(ctrl)
|
||||
|
||||
self.roster.on_status_changed(account, show)
|
||||
if account in self.show_vcard_when_connect and show not in ('offline',
|
||||
'error'):
|
||||
if account in self.show_vcard_when_connect and obj.show not in (
|
||||
'offline', 'error'):
|
||||
self.edit_own_details(account)
|
||||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('AccountPresence', (show, account))
|
||||
|
||||
def edit_own_details(self, account):
|
||||
jid = gajim.get_jid_from_account(account)
|
||||
|
@ -1833,7 +1808,6 @@ class Interface:
|
|||
'ERROR': [self.handle_event_error],
|
||||
'DB_ERROR': [self.handle_event_db_error],
|
||||
'INFORMATION': [self.handle_event_information],
|
||||
'STATUS': [self.handle_event_status],
|
||||
'MSGERROR': [self.handle_event_msgerror],
|
||||
'MSGSENT': [self.handle_event_msgsent],
|
||||
'MSGNOTSENT': [self.handle_event_msgnotsent],
|
||||
|
@ -1901,6 +1875,7 @@ class Interface:
|
|||
'last-result-received': [self.handle_event_last_status_time],
|
||||
'muc-admin-received': [self.handle_event_gc_affiliation],
|
||||
'muc-owner-received': [self.handle_event_gc_config],
|
||||
'our-show': [self.handle_event_status],
|
||||
'presence-received': [self.handle_event_presence],
|
||||
'roster-info': [self.handle_event_roster_info],
|
||||
'roster-item-exchange-received': \
|
||||
|
|
|
@ -125,6 +125,8 @@ class Remote:
|
|||
ged.POSTGUI, self.on_unsubscribed_presence_received)
|
||||
gajim.ged.register_event_handler('gc-message-received',
|
||||
ged.POSTGUI, self.on_gc_message_received)
|
||||
gajim.ged.register_event_handler('our-show',
|
||||
ged.POSTGUI, self.on_our_status)
|
||||
|
||||
def on_last_status_time(self, obj):
|
||||
self.raise_signal('LastStatusTime', (obj.conn.name, [
|
||||
|
@ -178,6 +180,9 @@ class Remote:
|
|||
obj.timestamp, obj.has_timestamp, obj.xhtml_msgtxt, obj.status_code,
|
||||
obj.displaymarking, obj.captcha_form, obj.needs_highlight]))
|
||||
|
||||
def on_our_status(self, obj):
|
||||
self.raise_signal('AccountPresence', (obj.show, obj.conn.name))
|
||||
|
||||
def raise_signal(self, signal, arg):
|
||||
if self.signal_object:
|
||||
try:
|
||||
|
|
|
@ -2484,6 +2484,17 @@ class RosterWindow:
|
|||
"""
|
||||
self.rename_self_contact(obj.old_jid, obj.new_jid, obj.conn.name)
|
||||
|
||||
def _nec_our_show(self, obj):
|
||||
model = self.status_combobox.get_model()
|
||||
if obj.show == 'offline':
|
||||
# sensitivity for this menuitem
|
||||
if gajim.get_number_of_connected_accounts() == 0:
|
||||
model[self.status_message_menuitem_iter][3] = False
|
||||
else:
|
||||
# sensitivity for this menuitem
|
||||
model[self.status_message_menuitem_iter][3] = True
|
||||
self.on_status_changed(obj.conn.name, obj.show)
|
||||
|
||||
################################################################################
|
||||
### Menu and GUI callbacks
|
||||
### FIXME: order callbacks in itself...
|
||||
|
@ -6215,4 +6226,6 @@ class RosterWindow:
|
|||
gajim.ged.register_event_handler('roster-received', ged.GUI1,
|
||||
self._nec_roster_received)
|
||||
gajim.ged.register_event_handler('anonymous-auth', ged.GUI1,
|
||||
self._nec_anonymous_auth)
|
||||
self._nec_anonymous_auth)
|
||||
gajim.ged.register_event_handler('our-show', ged.GUI1,
|
||||
self._nec_our_show)
|
Loading…
Reference in New Issue