From e7345baf5444ffc1556b04465b0f42c70b0071cd Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sat, 10 Sep 2005 23:44:53 +0000 Subject: [PATCH] cleanup, coding style, and logic fixes in sleepy --- src/common/sleepy.py | 31 ++++++++++++++++--------------- src/gajim.py | 7 ++++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/common/sleepy.py b/src/common/sleepy.py index 11b713713..54582a941 100644 --- a/src/common/sleepy.py +++ b/src/common/sleepy.py @@ -1,8 +1,9 @@ -## common/sleepy.py +## common/sleepy.py ## ## Gajim Team: ## - Yann Le Boulanger ## - Vincent Hanquez +## - Nikos Kouremenos ## ## Copyright (C) 2003-2005 Gajim Team ## @@ -20,11 +21,11 @@ from common import gajim STATE_UNKNOWN = 'OS probably not supported' -STATE_XAWAY = 'extanted away' +STATE_XA = 'extanted away' STATE_AWAY = 'away' STATE_AWAKE = 'awake' -SUPPORTED = 1 +SUPPORTED = True try: import common.idle as idle # when we launch gajim from sources except: @@ -32,32 +33,32 @@ except: import idle # when Gajim is installed except: gajim.log.debug('Unable to load idle module') - SUPPORTED = 0 + SUPPORTED = False class Sleepy: - def __init__(self, interval1 = 60, interval2 = 120): - - self.interval1 = interval1 - self.interval2 = interval2 - self.state = STATE_AWAKE ## assume were awake to stake with + def __init__(self, away_interval = 60, xa_interval = 120): + self.away_interval = away_interval + self.xa_interval = xa_interval + self.state = STATE_AWAKE # assume we are awake try: idle.init() except: - SUPPORTED = 0 + SUPPORTED = False self.state = STATE_UNKNOWN def poll(self): - if not SUPPORTED: return 0 + if not SUPPORTED: + return False idleTime = idle.getIdleSec() - if idleTime > self.interval2: - self.state = STATE_XAWAY - elif idleTime > self.interval1: + if idleTime > self.xa_interval: + self.state = STATE_XA + elif idleTime > self.away_interval: self.state = STATE_AWAY else: self.state = STATE_AWAKE - return 1 + return True def getState(self): return self.state diff --git a/src/gajim.py b/src/gajim.py index f8abd18d3..5e8215d05 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -823,7 +823,8 @@ class Interface: def read_sleepy(self): '''Check idle status and change that status if needed''' if not self.sleeper.poll(): - return True # renew timeout (loop for ever) + # idle detection is not supported in that OS + return False # stop looping in vain state = self.sleeper.getState() for account in gajim.connections: if not gajim.sleeper_state.has_key(account) or \ @@ -845,7 +846,7 @@ class Interface: self.roster.send_status(account, 'away', gajim.config.get('autoaway_message'), True) gajim.sleeper_state[account] = 'autoaway' - elif state == common.sleepy.STATE_XAWAY and (\ + elif state == common.sleepy.STATE_XA and (\ gajim.sleeper_state[account] == 'autoaway' or \ gajim.sleeper_state[account] == 'online') and \ gajim.config.get('autoxa'): @@ -1165,7 +1166,7 @@ class Interface: gtk.window_set_default_icon(pix) # set the icon to all newly opened windows self.roster.window.set_icon_from_file(path_to_file) # and to roster window self.sleeper = common.sleepy.Sleepy( - gajim.config.get('autoawaytime') * 60, + gajim.config.get('autoawaytime') * 60, # make minutes to seconds gajim.config.get('autoxatime') * 60) self.systray_enabled = False