Yann Leboulanger pushed to branch master at gajim / gajim
Commits:
-
ce719a83
by Yann Leboulanger at 2017-08-22T21:55:18+02:00
4 changed files:
- gajim/common/app.py
- gajim/common/connection.py
- gajim/common/connection_handlers.py
- gajim/common/zeroconf/connection_handlers_zeroconf.py
Changes:
| ... | ... | @@ -244,6 +244,14 @@ try: |
| 244 | 244 |
except ImportError:
|
| 245 | 245 |
HAVE_PYCURL = False
|
| 246 | 246 |
|
| 247 |
+try:
|
|
| 248 |
+ from gajim.common import sleepy
|
|
| 249 |
+ if sleepy.SUPPORTED:
|
|
| 250 |
+ HAVE_IDLE = True
|
|
| 251 |
+except Exception:
|
|
| 252 |
+ log.debug(_('Unable to load idle module'))
|
|
| 253 |
+ HAVE_IDLE = False
|
|
| 254 |
+ |
|
| 247 | 255 |
|
| 248 | 256 |
gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'}
|
| 249 | 257 |
gajim_common_features = [nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE,
|
| ... | ... | @@ -630,9 +630,8 @@ class CommonConnection: |
| 630 | 630 |
self.connected = app.SHOW_LIST.index(show)
|
| 631 | 631 |
idle_time = None
|
| 632 | 632 |
if auto:
|
| 633 |
- global HAS_IDLE
|
|
| 634 |
- if HAS_IDLE and app.config.get('autoaway'):
|
|
| 635 |
- idle_sec = int(self.sleeper.getIdleSec())
|
|
| 633 |
+ if app.HAVE_IDLE and app.config.get('autoaway'):
|
|
| 634 |
+ idle_sec = int(app.interface.sleeper.getIdleSec())
|
|
| 636 | 635 |
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
|
| 637 | 636 |
time.gmtime(time.time() - idle_sec))
|
| 638 | 637 |
app.nec.push_incoming_event(BeforeChangeShowEvent(None,
|
| ... | ... | @@ -2705,9 +2704,8 @@ class Connection(CommonConnection, ConnectionHandlers): |
| 2705 | 2704 |
p = self.add_sha(p, ptype != 'unavailable')
|
| 2706 | 2705 |
self.add_lang(p)
|
| 2707 | 2706 |
if auto:
|
| 2708 |
- global HAS_IDLE
|
|
| 2709 |
- if HAS_IDLE and app.config.get('autoaway'):
|
|
| 2710 |
- idle_sec = int(self.sleeper.getIdleSec())
|
|
| 2707 |
+ if app.HAVE_IDLE and app.config.get('autoaway'):
|
|
| 2708 |
+ idle_sec = int(app.interface.sleeper.getIdleSec())
|
|
| 2711 | 2709 |
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
|
| 2712 | 2710 |
time.gmtime(time.time() - idle_sec))
|
| 2713 | 2711 |
idle = p.setTag('idle', namespace=nbxmpp.NS_IDLE)
|
| ... | ... | @@ -47,6 +47,7 @@ from gajim.common import app |
| 47 | 47 |
from gajim.common import exceptions
|
| 48 | 48 |
from gajim.common import dataforms
|
| 49 | 49 |
from gajim.common import jingle_xtls
|
| 50 |
+from gajim.common import sleepy
|
|
| 50 | 51 |
from gajim.common.commands import ConnectionCommands
|
| 51 | 52 |
from gajim.common.pubsub import ConnectionPubSub
|
| 52 | 53 |
from gajim.common.protocol.caps import ConnectionCaps
|
| ... | ... | @@ -74,13 +75,6 @@ DELIMITER_ARRIVED = 'delimiter_arrived' |
| 74 | 75 |
PRIVACY_ARRIVED = 'privacy_arrived'
|
| 75 | 76 |
BLOCKING_ARRIVED = 'blocking_arrived'
|
| 76 | 77 |
PEP_CONFIG = 'pep_config'
|
| 77 |
-HAS_IDLE = True
|
|
| 78 |
-try:
|
|
| 79 |
-# import idle
|
|
| 80 |
- from gajim.common import sleepy
|
|
| 81 |
-except Exception:
|
|
| 82 |
- log.debug(_('Unable to load idle module'))
|
|
| 83 |
- HAS_IDLE = False
|
|
| 84 | 78 |
|
| 85 | 79 |
|
| 86 | 80 |
class ConnectionDisco:
|
| ... | ... | @@ -1345,7 +1339,6 @@ ConnectionVcard, ConnectionSocks5Bytestream, ConnectionDisco, |
| 1345 | 1339 |
ConnectionCommands, ConnectionPubSub, ConnectionPEP, ConnectionCaps,
|
| 1346 | 1340 |
ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
|
| 1347 | 1341 |
def __init__(self):
|
| 1348 |
- global HAS_IDLE
|
|
| 1349 | 1342 |
ConnectionArchive313.__init__(self)
|
| 1350 | 1343 |
ConnectionVcard.__init__(self)
|
| 1351 | 1344 |
ConnectionSocks5Bytestream.__init__(self)
|
| ... | ... | @@ -1382,13 +1375,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): |
| 1382 | 1375 |
|
| 1383 | 1376 |
self.privacy_default_list = None
|
| 1384 | 1377 |
|
| 1385 |
- try:
|
|
| 1386 |
- self.sleeper = sleepy.Sleepy()
|
|
| 1387 |
- HAS_IDLE = True
|
|
| 1388 |
- except Exception:
|
|
| 1389 |
- log.warning('Error while calling Sleepy()', exc_info=True)
|
|
| 1390 |
- HAS_IDLE = False
|
|
| 1391 |
- |
|
| 1392 | 1378 |
self.gmail_last_tid = None
|
| 1393 | 1379 |
self.gmail_last_time = None
|
| 1394 | 1380 |
|
| ... | ... | @@ -1659,14 +1645,13 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): |
| 1659 | 1645 |
raise nbxmpp.NodeProcessed
|
| 1660 | 1646 |
|
| 1661 | 1647 |
def _nec_last_request_received(self, obj):
|
| 1662 |
- global HAS_IDLE
|
|
| 1663 | 1648 |
if obj.conn.name != self.name:
|
| 1664 | 1649 |
return
|
| 1665 |
- if HAS_IDLE and app.config.get_per('accounts', self.name,
|
|
| 1650 |
+ if app.HAVE_IDLE and app.config.get_per('accounts', self.name,
|
|
| 1666 | 1651 |
'send_idle_time'):
|
| 1667 | 1652 |
iq_obj = obj.stanza.buildReply('result')
|
| 1668 | 1653 |
qp = iq_obj.setQuery()
|
| 1669 |
- qp.attrs['seconds'] = int(self.sleeper.getIdleSec())
|
|
| 1654 |
+ qp.attrs['seconds'] = int(app.interface.sleeper.getIdleSec())
|
|
| 1670 | 1655 |
else:
|
| 1671 | 1656 |
iq_obj = obj.stanza.buildReply('error')
|
| 1672 | 1657 |
err = nbxmpp.ErrorNode(name=nbxmpp.NS_STANZAS + \
|
| ... | ... | @@ -39,12 +39,6 @@ STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', |
| 39 | 39 |
VCARD_PUBLISHED = 'vcard_published'
|
| 40 | 40 |
VCARD_ARRIVED = 'vcard_arrived'
|
| 41 | 41 |
AGENT_REMOVED = 'agent_removed'
|
| 42 |
-HAS_IDLE = True
|
|
| 43 |
-try:
|
|
| 44 |
- import idle
|
|
| 45 |
-except Exception:
|
|
| 46 |
- log.debug(_('Unable to load idle module'))
|
|
| 47 |
- HAS_IDLE = False
|
|
| 48 | 42 |
|
| 49 | 43 |
from gajim.common import connection_handlers
|
| 50 | 44 |
|
| ... | ... | @@ -73,12 +67,6 @@ connection_handlers.ConnectionJingle): |
| 73 | 67 |
connection_handlers.ConnectionJingle.__init__(self)
|
| 74 | 68 |
connection_handlers.ConnectionHandlersBase.__init__(self)
|
| 75 | 69 |
|
| 76 |
- try:
|
|
| 77 |
- idle.init()
|
|
| 78 |
- except Exception:
|
|
| 79 |
- global HAS_IDLE
|
|
| 80 |
- HAS_IDLE = False
|
|
| 81 |
- |
|
| 82 | 70 |
def _messageCB(self, ip, con, msg):
|
| 83 | 71 |
"""
|
| 84 | 72 |
Called when we receive a message
|