Show
Ignore:
Timestamp:
01/13/07 23:35:41 (23 months ago)
Author:
asterix
Message:

merge diff from trunc to 0.11 branch

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/gajim_0.11/src/common/sleepy.py

    r7787 r7829  
    22## 
    33## Contributors for this file: 
    4 ##      - Yann Le Boulanger <asterix@lagaule.org> 
    5 ##      - Nikos Kouremenos <kourem@gmail.com> 
     4##        - Yann Le Boulanger <asterix@lagaule.org> 
     5##        - Nikos Kouremenos <kourem@gmail.com> 
    66## 
    77## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org> 
    8 ##                        Vincent Hanquez <tab@snarc.org> 
     8##                                              Vincent Hanquez <tab@snarc.org> 
    99## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org> 
    10 ##                    Nikos Kouremenos <kourem@gmail.com> 
     10##                                      Nikos Kouremenos <kourem@gmail.com> 
    1111## 
    1212## This program is free software; you can redistribute it and/or modify 
     
    2727STATE_XA   = 'extended away' 
    2828STATE_AWAY   = 'away' 
    29 STATE_AWAKE    = 'awake' 
     29STATE_AWAKE     = 'awake' 
    3030 
    3131SUPPORTED = True 
    3232try: 
    33         if os.name == 'nt': 
    34                 import ctypes 
     33                if os.name == 'nt': 
     34                        import ctypes 
    3535 
    36                 GetTickCount = ctypes.windll.kernel32.GetTickCount 
    37                 GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo 
     36                        GetTickCount = ctypes.windll.kernel32.GetTickCount 
     37                        GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo 
    3838 
    39                 class LASTINPUTINFO(ctypes.Structure): 
    40                         _fields_ = [('cbSize', ctypes.c_uint), 
    41                             ('dwTime', ctypes.c_uint)] 
     39                        class LASTINPUTINFO(ctypes.Structure): 
     40                                _fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)] 
    4241 
    43                 lastInputInfo = LASTINPUTINFO() 
    44                 lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo) 
     42                        lastInputInfo = LASTINPUTINFO() 
     43                        lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo) 
    4544 
    46         else: # unix 
    47                 import idle 
     45                else: # unix 
     46                        import idle 
    4847except: 
    4948        gajim.log.debug('Unable to load idle module') 
     
    5150 
    5251class SleepyWindows: 
    53         def __init__(self, away_interval = 60, xa_interval = 120): 
     52        def __init__(self, away_interval = 60, xa_interval = 120): 
    5453                self.away_interval = away_interval 
    5554                self.xa_interval = xa_interval 
    5655                self.state = STATE_AWAKE # assume we are awake 
    5756 
    58         def getIdleSec(self): 
    59                 GetLastInputInfo(ctypes.byref(lastInputInfo)) 
    60                 idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000 
    61                 return idleDelta 
     57        def getIdleSec(self): 
     58                GetLastInputInfo(ctypes.byref(lastInputInfo)) 
     59                idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000 
     60                return idleDelta 
    6261 
    6362        def poll(self): 
    6463                '''checks to see if we should change state''' 
     64                if not SUPPORTED: 
     65                        return False 
     66 
    6567                idleTime = self.getIdleSec() 
    66                  
     68 
    6769                # xa is stronger than away so check for xa first 
    6870                if idleTime > self.xa_interval: 
     
    8183 
    8284class SleepyUnix: 
    83  
    8485        def __init__(self, away_interval = 60, xa_interval = 120): 
    8586                self.away_interval = away_interval 
     
    9293                        self.state = STATE_UNKNOWN 
    9394 
    94         def getIdleSec(self): 
    95                 return idle.getIdleSec() 
     95        def getIdleSec(self): 
     96                return idle.getIdleSec() 
    9697 
    9798        def poll(self): 
     
    101102 
    102103                idleTime = self.getIdleSec() 
    103                  
     104 
    104105                # xa is stronger than away so check for xa first 
    105106                if idleTime > self.xa_interval: 
     
    118119 
    119120if os.name == 'nt': 
    120         Sleepy = SleepyWindows 
     121        Sleepy = SleepyWindows 
    121122else: 
    122         Sleepy = SleepyUnix 
     123        Sleepy = SleepyUnix