Commit 3f6edc15 authored by Philipp Hörist's avatar Philipp Hörist

Refactor our-show event handlers

parent fbe8c156
......@@ -42,6 +42,7 @@ from gajim.common import i18n
from gajim.common.i18n import _
from gajim.common.nec import EventHelper
from gajim.common.helpers import AdditionalDataDict
from gajim.common.helpers import event_filter
from gajim.common.contacts import GC_Contact
from gajim.common.const import Chatstate
from gajim.common.structs import OutgoingMessage
......@@ -434,14 +435,12 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
self.session.control = None
self.session = None
def _nec_our_status(self, obj):
if self.account != obj.conn.name:
@event_filter(['account'])
def _nec_our_status(self, event):
if event.show == 'connecting':
return
if obj.show == 'connecting':
return
if obj.show == 'offline':
if event.show == 'offline':
self.got_disconnected()
else:
self.got_connected()
......
......@@ -216,7 +216,7 @@ class Client(ConnectionHandlers):
def _on_resume_failed(self, _client, _signal_name):
log.info('Resume failed')
app.nec.push_incoming_event(NetworkEvent(
'our-show', conn=self, show='offline'))
'our-show', account=self._account, show='offline'))
self.get_module('Chatstate').enabled = False
def _on_resume_successful(self, _client, _signal_name):
......@@ -260,7 +260,7 @@ class Client(ConnectionHandlers):
self._reconnect = False
self._after_disconnect()
app.nec.push_incoming_event(NetworkEvent(
'our-show', conn=self, show='offline'))
'our-show', account=self._account, show='offline'))
self.process_ssl_errors()
elif domain in (StreamError.STREAM, StreamError.BIND):
......@@ -292,12 +292,12 @@ class Client(ConnectionHandlers):
self._after_disconnect()
self._schedule_reconnect()
app.nec.push_incoming_event(
NetworkEvent('our-show', conn=self, show='error'))
NetworkEvent('our-show', account=self._account, show='error'))
else:
self.get_module('Chatstate').enabled = False
app.nec.push_incoming_event(NetworkEvent(
'our-show', conn=self, show='offline'))
'our-show', account=self._account, show='offline'))
self._after_disconnect()
def _after_disconnect(self):
......@@ -535,7 +535,7 @@ class Client(ConnectionHandlers):
self._set_state(ClientState.DISCONNECTED)
self._disable_reconnect_timer()
app.nec.push_incoming_event(
NetworkEvent('our-show', conn=self, show='offline'))
NetworkEvent('our-show', account=self._account, show='offline'))
if self._destroy_client:
self._client.destroy()
......
......@@ -90,7 +90,7 @@ class Presence(BaseModule):
if properties.is_self_presence:
app.nec.push_incoming_event(
NetworkEvent('our-show',
conn=self._con,
account=self._account,
show=properties.show.value))
return
......
......@@ -1128,12 +1128,11 @@ class GroupchatControl(ChatControlBase):
msg_log_id=event.msg_log_id,
displaymarking=event.displaymarking)
@event_filter(['account'])
def _nec_our_status(self, event):
if self.account != event.conn.name:
return
client = app.get_client(event.account)
if (event.show == 'offline' and
not event.conn.state.is_reconnect_scheduled):
not client.state.is_reconnect_scheduled):
self.got_disconnected()
if self.parent_win:
......
......@@ -132,9 +132,9 @@ class Notification(EventHelper):
'printed_gc_msg'):
self._withdraw('new-message', event.account, event.jid)
def _nec_our_status(self, obj):
if app.account_is_connected(obj.conn.name):
self._withdraw('connection-failed', obj.conn.name)
def _nec_our_status(self, event):
if app.account_is_connected(event.account):
self._withdraw('connection-failed', event.account)
@staticmethod
def _get_icon_name(obj):
......
......@@ -201,28 +201,27 @@ class Interface:
def unblock_signed_in_notifications(account):
app.block_signed_in_notifications[account] = False
def handle_event_status(self, obj): # OUR status
#('STATUS', account, show)
account = obj.conn.name
if obj.show in ('offline', 'error'):
def handle_event_status(self, event):
if event.show in ('offline', 'error'):
# TODO: Close all account windows
pass
if obj.show == 'offline':
app.block_signed_in_notifications[account] = True
if event.show == 'offline':
app.block_signed_in_notifications[event.account] = True
else:
# 30 seconds after we change our status to sth else than offline
# we stop blocking notifications of any kind
# this prevents from getting the roster items as 'just signed in'
# contacts. 30 seconds should be enough time
GLib.timeout_add_seconds(30, self.unblock_signed_in_notifications,
account)
if account in self.show_vcard_when_connect and obj.show not in (
'offline', 'error'):
action = '%s-profile' % account
app.app.activate_action(action, GLib.Variant('s', account))
self.show_vcard_when_connect.remove(account)
GLib.timeout_add_seconds(30,
self.unblock_signed_in_notifications,
event.account)
if (event.account in self.show_vcard_when_connect and
event.show not in ('offline', 'error')):
action = '%s-profile' % event.account
app.app.activate_action(action, GLib.Variant('s', event.account))
self.show_vcard_when_connect.remove(event.account)
@staticmethod
def handle_gc_error(gc_control, pritext, sectext):
......
......@@ -382,8 +382,8 @@ class GajimRemote(Server):
event_type, obj.properties.subject,
obj.msg_log_id, obj.properties.nickname]))
def on_our_status(self, obj):
self.raise_signal('AccountPresence', (obj.show, obj.conn.name))
def on_our_status(self, event):
self.raise_signal('AccountPresence', (event.show, event.account))
def on_account_created(self, obj):
self.raise_signal('NewAccount', (obj.conn.name, obj.account_info))
......
......@@ -2568,19 +2568,19 @@ class RosterWindow:
"""
self.rename_self_contact(obj.old_jid, obj.new_jid, obj.conn.name)
def _nec_our_show(self, obj):
def _nec_our_show(self, event):
model = self.status_combobox.get_model()
iter_ = model.get_iter_from_string('6')
if obj.show == 'offline':
if event.show == 'offline':
# sensitivity for this menuitem
if app.get_number_of_connected_accounts() == 0:
model[iter_][3] = False
self.application.set_account_actions_state(obj.conn.name)
self.application.set_account_actions_state(event.account)
self.application.update_app_actions_state()
else:
# sensitivity for this menuitem
model[iter_][3] = True
self.on_status_changed(obj.conn.name, obj.show)
self.on_status_changed(event.account, event.show)
def _nec_connection_type(self, obj):
self.draw_account(obj.conn.name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment