Skip to content
Snippets Groups Projects
Commit 176bd508 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Add SimpleClientState

parent b054c3e4
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment