diff --git a/gajim/common/client.py b/gajim/common/client.py index 81f859f02678fd6b4f4d48b13b0ea89f793837a5..87eeb76409838440f5495e60416b76694672a456 100644 --- a/gajim/common/client.py +++ b/gajim/common/client.py @@ -28,12 +28,14 @@ from gajim.common import helpers from gajim.common import modules from gajim.common.const import ClientState +from gajim.common.const import SimpleClientState from gajim.common.structs import UNKNOWN_PRESENCE from gajim.common.helpers import get_custom_host from gajim.common.helpers import get_user_proxy from gajim.common.helpers import warn_about_plain_connection from gajim.common.helpers import get_resource from gajim.common.helpers import get_idle_status_message +from gajim.common.helpers import Observable from gajim.common.idle import Monitor from gajim.common.i18n import _ @@ -45,8 +47,9 @@ log = logging.getLogger('gajim.client') -class Client: +class Client(Observable): def __init__(self, account): + Observable.__init__(self, log) self._client = None self._account = account self.name = account @@ -199,6 +202,8 @@ def _on_resume_successful(self, _client, _signal_name): account=self._account, show=self._status)) + self.notify('state-changed', SimpleClientState.CONNECTED) + def _set_client_available(self): self._set_state(ClientState.AVAILABLE) app.nec.push_incoming_event(NetworkEvent('account-connected', @@ -270,18 +275,18 @@ def _on_password(password): self._schedule_reconnect() app.nec.push_incoming_event( NetworkEvent('our-show', account=self._account, show='error')) + self.notify('state-changed', SimpleClientState.RESUME_IN_PREGRESS) else: self.get_module('Chatstate').enabled = False app.nec.push_incoming_event(NetworkEvent( 'our-show', account=self._account, show='offline')) self._after_disconnect() + self.notify('state-changed', SimpleClientState.DISCONNECTED) def _after_disconnect(self): self._disable_reconnect_timer() - self.get_module('VCardAvatars').avatar_advertised = False - app.proxy65_manager.disconnect(self._client) self.get_module('Bytestream').remove_all_transfers() @@ -440,6 +445,8 @@ def _finish_connect(self): self.get_module('Annotations').request_annotations() self.get_module('Blocking').get_blocking_list() + self.notify('state-changed', SimpleClientState.CONNECTED) + # Inform GUI we just signed in app.nec.push_incoming_event(NetworkEvent( 'signed-in', account=self._account, conn=self)) @@ -624,6 +631,7 @@ def _screensaver_state_changed(application, _param): Monitor.set_extended_away(active) def cleanup(self): + self.disconnect_signals() self._destroyed = True if Monitor.is_available(): Monitor.disconnect(self._idle_handler_id) diff --git a/gajim/common/const.py b/gajim/common/const.py index aeb6302b19b2077bfa0a2dd44a2600d0033b9bd6..60904bd87a9406f7beea957611b9a0dd64cbe80b 100644 --- a/gajim/common/const.py +++ b/gajim/common/const.py @@ -274,6 +274,24 @@ def is_available(self): return self == ClientState.AVAILABLE +class SimpleClientState(IntEnum): + DISCONNECTED = 'disconnected' + CONNECTED = 'connected' + RESUME_IN_PREGRESS = 'resume-in-progress' + + @property + def is_disconnected(self): + return self == SimpleClientState.DISCONNECTED + + @property + def is_connected(self): + return self == SimpleClientState.CONNECTED + + @property + def is_resume_in_progress(self): + return self == SimpleClientState.RESUME_IN_PREGRESS + + class JingleState(Enum): NULL = 'stop' CONNECTING = 'connecting'