| Trees | Indices | Help |
|
|---|
|
|
1 # -*- coding:utf-8 -*- 2 ## src/common/sleepy.py 3 ## 4 ## Copyright (C) 2003-2010 Yann Leboulanger <asterix AT lagaule.org> 5 ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com> 6 ## Copyright (C) 2007 Jean-Marie Traissard <jim AT lapin.org> 7 ## Copyright (C) 2008 Mateusz Biliński <mateusz AT bilinski.it> 8 ## 9 ## This file is part of Gajim. 10 ## 11 ## Gajim is free software; you can redistribute it and/or modify 12 ## it under the terms of the GNU General Public License as published 13 ## by the Free Software Foundation; version 3 only. 14 ## 15 ## Gajim is distributed in the hope that it will be useful, 16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ## GNU General Public License for more details. 19 ## 20 ## You should have received a copy of the GNU General Public License 21 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. 22 ## 23 24 from common import gajim 25 import os, sys 26 27 28 STATE_UNKNOWN = 'OS probably not supported' 29 STATE_XA = 'extended away' 30 STATE_AWAY = 'away' 31 STATE_AWAKE = 'awake' 32 33 SUPPORTED = True 34 try: 35 if os.name == 'nt': 36 import ctypes 37 38 GetTickCount = ctypes.windll.kernel32.GetTickCount 39 GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo 4042 _fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)]43 44 lastInputInfo = LASTINPUTINFO() 45 lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo) 46 47 # one or more of these may not be supported before XP. 48 OpenInputDesktop = ctypes.windll.user32.OpenInputDesktop 49 CloseDesktop = ctypes.windll.user32.CloseDesktop 50 SystemParametersInfo = ctypes.windll.user32.SystemParametersInfoW 51 else: # unix 52 from common import idle 53 except Exception: 54 gajim.log.debug('Unable to load idle module') 55 SUPPORTED = False 5610659 self.away_interval = away_interval 60 self.xa_interval = xa_interval 61 self.state = STATE_AWAKE # assume we are awake6264 GetLastInputInfo(ctypes.byref(lastInputInfo)) 65 idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000 66 return idleDelta6769 """ 70 Check to see if we should change state 71 """ 72 if not SUPPORTED: 73 return False 74 75 # screen saver, in windows >= XP 76 saver_runing = ctypes.c_int(0) 77 # 0x72 is SPI_GETSCREENSAVERRUNNING 78 if SystemParametersInfo(0x72, 0, ctypes.byref(saver_runing), 0) and \ 79 saver_runing.value: 80 self.state = STATE_XA 81 return True 82 83 desk = OpenInputDesktop(0, False, 0) 84 if not desk: 85 # Screen locked 86 self.state = STATE_XA 87 return True 88 CloseDesktop(desk) 89 90 idleTime = self.getIdleSec() 91 92 # xa is stronger than away so check for xa first 93 if idleTime > self.xa_interval: 94 self.state = STATE_XA 95 elif idleTime > self.away_interval: 96 self.state = STATE_AWAY 97 else: 98 self.state = STATE_AWAKE 99 return True100102 return self.state103105 self.state = val140 141 if os.name == 'nt': 142 Sleepy = SleepyWindows 143 else: 144 Sleepy = SleepyUnix 145109 global SUPPORTED 110 self.away_interval = away_interval 111 self.xa_interval = xa_interval 112 self.state = STATE_AWAKE # assume we are awake113 116118 """ 119 Check to see if we should change state 120 """ 121 if not SUPPORTED: 122 return False 123 124 idleTime = self.getIdleSec() 125 126 # xa is stronger than away so check for xa first 127 if idleTime > self.xa_interval: 128 self.state = STATE_XA 129 elif idleTime > self.away_interval: 130 self.state = STATE_AWAY 131 else: 132 self.state = STATE_AWAKE 133 return True134136 return self.state137139 self.state = val
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 12 02:08:07 2010 | http://epydoc.sourceforge.net |