No need to have one sleepy instance per connection object
This commit is contained in:
parent
7de4aa1a06
commit
ce719a8317
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 + \
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue