Yann Leboulanger pushed to branch master at gajim / gajim
Commits: ce719a83 by Yann Leboulanger at 2017-08-22T21:55:18+02:00 No need to have one sleepy instance per connection object
- - - - -
4 changed files:
- gajim/common/app.py - gajim/common/connection.py - gajim/common/connection_handlers.py - gajim/common/zeroconf/connection_handlers_zeroconf.py
Changes:
===================================== gajim/common/app.py ===================================== --- a/gajim/common/app.py +++ b/gajim/common/app.py @@ -244,6 +244,14 @@ try: except ImportError: HAVE_PYCURL = False
+try: + from gajim.common import sleepy + if sleepy.SUPPORTED: + HAVE_IDLE = True +except Exception: + log.debug(_('Unable to load idle module')) + HAVE_IDLE = False +
gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'} gajim_common_features = [nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE,
===================================== gajim/common/connection.py ===================================== --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -630,9 +630,8 @@ class CommonConnection: self.connected = app.SHOW_LIST.index(show) idle_time = None if auto: - global HAS_IDLE - if HAS_IDLE and app.config.get('autoaway'): - idle_sec = int(self.sleeper.getIdleSec()) + if app.HAVE_IDLE and app.config.get('autoaway'): + idle_sec = int(app.interface.sleeper.getIdleSec()) idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time() - idle_sec)) app.nec.push_incoming_event(BeforeChangeShowEvent(None, @@ -2705,9 +2704,8 @@ class Connection(CommonConnection, ConnectionHandlers): p = self.add_sha(p, ptype != 'unavailable') self.add_lang(p) if auto: - global HAS_IDLE - if HAS_IDLE and app.config.get('autoaway'): - idle_sec = int(self.sleeper.getIdleSec()) + if app.HAVE_IDLE and app.config.get('autoaway'): + idle_sec = int(app.interface.sleeper.getIdleSec()) idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time() - idle_sec)) idle = p.setTag('idle', namespace=nbxmpp.NS_IDLE)
===================================== gajim/common/connection_handlers.py ===================================== --- a/gajim/common/connection_handlers.py +++ b/gajim/common/connection_handlers.py @@ -47,6 +47,7 @@ from gajim.common import app from gajim.common import exceptions from gajim.common import dataforms from gajim.common import jingle_xtls +from gajim.common import sleepy from gajim.common.commands import ConnectionCommands from gajim.common.pubsub import ConnectionPubSub from gajim.common.protocol.caps import ConnectionCaps @@ -74,13 +75,6 @@ DELIMITER_ARRIVED = 'delimiter_arrived' PRIVACY_ARRIVED = 'privacy_arrived' BLOCKING_ARRIVED = 'blocking_arrived' PEP_CONFIG = 'pep_config' -HAS_IDLE = True -try: -# import idle - from gajim.common import sleepy -except Exception: - log.debug(_('Unable to load idle module')) - HAS_IDLE = False
class ConnectionDisco: @@ -1345,7 +1339,6 @@ ConnectionVcard, ConnectionSocks5Bytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionPEP, ConnectionCaps, ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): def __init__(self): - global HAS_IDLE ConnectionArchive313.__init__(self) ConnectionVcard.__init__(self) ConnectionSocks5Bytestream.__init__(self) @@ -1382,13 +1375,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
self.privacy_default_list = None
- try: - self.sleeper = sleepy.Sleepy() - HAS_IDLE = True - except Exception: - log.warning('Error while calling Sleepy()', exc_info=True) - HAS_IDLE = False - self.gmail_last_tid = None self.gmail_last_time = None
@@ -1659,14 +1645,13 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): raise nbxmpp.NodeProcessed
def _nec_last_request_received(self, obj): - global HAS_IDLE if obj.conn.name != self.name: return - if HAS_IDLE and app.config.get_per('accounts', self.name, + if app.HAVE_IDLE and app.config.get_per('accounts', self.name, 'send_idle_time'): iq_obj = obj.stanza.buildReply('result') qp = iq_obj.setQuery() - qp.attrs['seconds'] = int(self.sleeper.getIdleSec()) + qp.attrs['seconds'] = int(app.interface.sleeper.getIdleSec()) else: iq_obj = obj.stanza.buildReply('error') err = nbxmpp.ErrorNode(name=nbxmpp.NS_STANZAS + \
===================================== gajim/common/zeroconf/connection_handlers_zeroconf.py ===================================== --- a/gajim/common/zeroconf/connection_handlers_zeroconf.py +++ b/gajim/common/zeroconf/connection_handlers_zeroconf.py @@ -39,12 +39,6 @@ STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', VCARD_PUBLISHED = 'vcard_published' VCARD_ARRIVED = 'vcard_arrived' AGENT_REMOVED = 'agent_removed' -HAS_IDLE = True -try: - import idle -except Exception: - log.debug(_('Unable to load idle module')) - HAS_IDLE = False
from gajim.common import connection_handlers
@@ -73,12 +67,6 @@ connection_handlers.ConnectionJingle): connection_handlers.ConnectionJingle.__init__(self) connection_handlers.ConnectionHandlersBase.__init__(self)
- try: - idle.init() - except Exception: - global HAS_IDLE - HAS_IDLE = False - def _messageCB(self, ip, con, msg): """ Called when we receive a message
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/ce719a8317fb67d9b78589c3abd68329a28...
--- View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/ce719a8317fb67d9b78589c3abd68329a28... You're receiving this email because of your account on dev.gajim.org.