home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / Sentinel / Source / LockMgr.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  3.1 KB  |  174 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <libc.h>
  5.  
  6. #import "LockMgr.h"
  7. #import "ScreenLock.h"
  8. #import <appkit/appkit.h>
  9.  
  10.  
  11. void idleTimerProc ( DPSTimedEntry teNumber, double now, char *userData )
  12. {
  13.     [ (id) userData idle ] ;
  14.     return ;
  15. }
  16.  
  17.  
  18. @implementation LockMgr
  19.  
  20. - init
  21. {
  22.     static NXDefaultsVector    SentinelDefaults =
  23.                             {
  24.                                 { "DimTime", "5" },
  25.                                 { "AutoLock", "NO" },
  26.                                 { "RequirePassword", "YES" },
  27.                                 { NULL }
  28.                             } ;
  29.  
  30.     NXRegisterDefaults ( "Sentinel", SentinelDefaults ) ;
  31.     maxIdleTime = atoi ( NXGetDefaultValue ( "Sentinel", "DimTime" ) ) ;
  32.     autoLock = ! strcmp (
  33.             NXGetDefaultValue ( "Sentinel", "AutoLock" ), "YES" ) ;
  34.     requirePassword = ! strcmp (
  35.             NXGetDefaultValue ( "Sentinel", "RequirePassword" ), "YES" ) ;
  36.     lastDimDestiny = 0 ;
  37.  
  38.     evsDriver = NXOpenEventStatus() ;
  39.  
  40.     timedEntry = DPSAddTimedEntry ( 60.0, (DPSTimedEntryProc) idleTimerProc,
  41.             (void *) self, NX_MODALRESPTHRESHOLD ) ;
  42.  
  43.     return [ super init ] ;
  44. }
  45.  
  46.  
  47. - free
  48. {
  49.     NXCloseEventStatus(evsDriver) ;
  50.     DPSRemoveTimedEntry ( timedEntry ) ;
  51.     return [ super free ] ;
  52. }
  53.  
  54.  
  55. - ok: sender
  56. {
  57.     char                idleString [ 4 ] ;
  58.     char                autoString [ 4 ] ;
  59.     char                pwordString [ 4 ] ;
  60.     NXDefaultsVector    SentinelDefaults =
  61.                         {
  62.                             { "DimTime", idleString },
  63.                             { "AutoLock", autoString },
  64.                             { "RequirePassword", pwordString },
  65.                             { NULL }
  66.                         } ;
  67.  
  68.     autoLock = [ autoLockSwitch intValue ] ;
  69.     requirePassword = [ requirePasswordSwitch intValue ] ;
  70.     maxIdleTime = [ idleSlider intValue ] ;
  71.  
  72.     sprintf ( idleString, "%d", maxIdleTime ) ;
  73.     strcpy ( autoString, autoLock ? "YES" : "NO" ) ;
  74.     strcpy ( pwordString, requirePassword ? "YES" : "NO" ) ;
  75.     NXWriteDefaults ( "Sentinel", SentinelDefaults ) ;
  76.  
  77.     [ revertButton setEnabled: NO ] ;
  78.     [ okButton setEnabled: NO ] ;
  79.     [ prefsPanel orderOut: self ] ;
  80.  
  81.     lastDimDestiny = 0 ;
  82.  
  83.     return self ;
  84. }
  85.  
  86.  
  87. - revert: sender
  88. {
  89.     [ autoLockSwitch setIntValue: autoLock ] ;
  90.     [ requirePasswordSwitch setIntValue: requirePassword ] ;
  91.     [ idleSlider setIntValue: maxIdleTime ] ;
  92.     [ idleField setIntValue: maxIdleTime ] ;
  93.     [ revertButton setEnabled: NO ] ;
  94.     [ okButton setEnabled: NO ] ;
  95.     [ prefsPanel makeKeyAndOrderFront: self ] ;
  96.  
  97.     lastDimDestiny = 0 ;
  98.  
  99.     return self ;
  100. }
  101.  
  102. - changeSetting: sender
  103. {
  104.     switch ( [ sender tag ] )
  105.     {
  106.         case 1:
  107.         {
  108.             [ idleField setIntValue:[ idleSlider intValue ] ] ;
  109.             break ;
  110.         }
  111.         
  112.         case 2:
  113.         {
  114.             [ idleSlider setIntValue:[ idleField intValue ] ] ;
  115.             break ;
  116.         }
  117.     }
  118.     [ revertButton setEnabled: YES ] ;
  119.     [ okButton setEnabled: YES ] ;
  120.     return self ;
  121. }
  122.  
  123.  
  124. - idle
  125. {
  126.     double    currentDimDestiny ;
  127.  
  128.     if ( [ screenLock isLocked ] )
  129.     {
  130.         idleTime = 0 ;
  131.         return self ;
  132.     }
  133.     
  134.     currentDimDestiny = NXAutoDimTime ( evsDriver ) ;
  135.     if ( currentDimDestiny < lastDimDestiny )
  136.     {
  137.         idleTime++ ;
  138.     }
  139.     else
  140.     {
  141.         idleTime = 0 ;
  142.     }
  143.     if ( ( autoLock ) && ( idleTime >= maxIdleTime ) )
  144.     {
  145.         [ screenLock lock: self ] ;
  146.     }
  147.     lastDimDestiny = currentDimDestiny ;
  148.     return self ;
  149. }
  150.  
  151.  
  152. - (BOOL) requirePassword
  153. {
  154.     return requirePassword ;
  155. }
  156.  
  157.  
  158. - (double) brightness
  159. {
  160.     double        theBrightness ;
  161.     
  162.     theBrightness = NXScreenBrightness(evsDriver) ;
  163.     return theBrightness ;
  164. }
  165.  
  166.  
  167. - setBrightness: (double) newBrightness
  168. {
  169.     NXSetScreenBrightness(evsDriver, newBrightness) ;
  170.     return self ;
  171. }
  172.  
  173. @end
  174.