cleanup, coding style, and logic fixes in sleepy
This commit is contained in:
parent
7a8ff6d6f5
commit
e7345baf54
|
@ -1,8 +1,9 @@
|
|||
## common/sleepy.py
|
||||
## common/sleepy.py
|
||||
##
|
||||
## Gajim Team:
|
||||
## - Yann Le Boulanger <asterix@lagaule.org>
|
||||
## - Vincent Hanquez <tab@snarc.org>
|
||||
## - Nikos Kouremenos <kourem@gmail.com>
|
||||
##
|
||||
## 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue