
    Eg                        d dl Z  e j                  dd       d dlmZmZmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZmZ d dlZd dlmZ d dlZ ej                  ej,                  ej.                          e
j0                  dd	        G d
 de      Z G d d      Zedk(  r5ej8                  j;                  dd      Z ee      ZejA                          yy)    NCScreensaverz1.0)GLibr   Gio)IntEnum)PopenDEVNULL)settingszcinnamon-screensaverz/usr/share/localec                   (    e Zd ZdZdZdZdZdZdZdZ	y)	Action                     N)
__name__
__module____qualname__EXITQUERYTIMELOCKACTIVATE
DEACTIVATEVERSION     ?/usr/share/cinnamon-screensaver/cinnamon-screensaver-command.pyr   r      s%    DEDDHJGr   r   c                   *    e Zd ZdZd Zd ZddZd Zy)ScreensaverCommandz
    This is a standalone executable that provides a simple way
    of controlling the screensaver via its dbus interface.
    c           
         || _         d | _        t        j                  d      }|j	                  ddddt
        j                  t        d             |j	                  d	d
ddt
        j                  t        d             |j	                  ddddt
        j                  t        d             |j	                  ddddt
        j                  t        d             |j	                  ddddt
        j                  t        d             |j	                  ddddt
        j                  t        d             |j	                  ddddt
        j                  t        d             |j	                  dddddt        d       !       |j                         }|j                  s|j!                          t#                |j                  t
        j                  k(  r&t%        d"t&        j                  z         t#                |j                  | _        |j(                  | _        t+        j,                         }|dk7  r| j/                  |       t#                t0        j2                  j5                  t6        j8                  j:                  t6        j<                  j>                  t@        jB                  t@        jD                  d | jF                         y )#NzCinnamon Screensaver Command)descriptionz--exitz-e	action_idstore_constz)Causes the screensaver to exit gracefully)destactionconsthelpz--queryz-qz"Query the state of the screensaverz--timez-tz8Query the length of time the screensaver has been activez--lockz-lzDTells the running screensaver process to lock the screen immediatelyz
--activatez-az*Turn the screensaver on (blank the screen)z--deactivatez-dzEIf the screensaver is active then deactivate it (un-blank the screen)z	--versionz-VzVersion of this applicationz--away-messagez-mmessagestore z&Message to be displayed in lock screen)r&   r'   defaultr)   zcinnamon-screensaver %s)$mainloopproxyargparseArgumentParseradd_argumentr   r   _r   r   r   r   r   r   
parse_argsr$   
print_helpquitprintconfigr*   r	   get_custom_screensaverhandle_custom_saverr   ScreenSaverProxynew_for_busr   BusTypeSESSIONDBusProxyFlagsNONEc
SS_SERVICESS_PATH_on_proxy_ready)selfr.   parserargscustom_savers        r   __init__zScreensaverCommand.__init__%   sb    
((5STHd]Z`ZeZe!"#N!O 	 	QIt+m[a[g[g!"#G!H 	 	JHd]Z`ZeZe!"#]!^ 	 	`Hd]Z`ZeZe!"#i!j 	 	lL$[^d^m^m!"#O!P 	 	RND{=`f`q`q!"#j!k 	 	mKK]c]k]k!"#@!A 	 	C,d7\^!"#K!L 	 	N  "~~F>>V^^++fnn<=F||6682$$\2F%%11#++2E2E252D2D2I2I23,,23))26262F2F	Hr   c                 4   | j                   t        j                  t        j                  fv r&	 t	        t        j                  |      t               y t        d       y # t        $ r/}t        d|j                  ||j                  fz         Y d }~y d }~ww xY w)N)stdinzError %d running %s: %sz-Action not supported with custom screensaver.)r$   r   r   r   r   shlexsplitr   OSErrorr7   errnostrerror)rE   rH   es      r   r:   z&ScreensaverCommand.handle_custom_saverS   s~    >>fkk6??;;@ekk,/w?
 AB	  @/177L34::3? ? @ @@s   $A 	B(%BBNc                 *   	 t         j                  j                  |      | _        | j	                          y # t
        j                  $ rH}t        d|j                  |j                  fz         | j                  j                          Y d }~y d }~ww xY w)Nz%Can't connect to screensaver: %d - %s)r   r;   new_for_bus_finishr/   perform_actionr   Errorr7   coder*   r.   r6   )rE   objectresultdatarQ   s        r   rD   z"ScreensaverCommand._on_proxy_ready]   sm    	!%66II&QDJ!zz 	!9QVVQYY<OOPMM  	!s   47 B
>BBc                    | j                   t        j                  k(  r| j                  j	                          n| j                   t        j
                  k(  rF| j                  j                         rt        t        d             n?t        t        d             n)| j                   t        j                  k(  rX| j                  j                         }|dk(  rt        t        d             nt        t        j                  dd|      |z         n| j                   t        j                  k(  r&| j                  j                  | j                         nq| j                   t        j                   k(  r| j                  j#                  d       n8| j                   t        j$                  k(  r| j                  j#                  d       | j&                  j)                          y )	NzThe screensaver is active
zThe screensaver is inactive
r   z)The screensaver is not currently active.
z/The screensaver has been active for %d second.
z0The screensaver has been active for %d seconds.
TF)r$   r   r   r/   call_quit_syncr   call_get_active_syncr7   r3   r   call_get_active_time_syncgettextngettextr   call_lock_syncr*   r   call_set_active_syncr   r.   r6   )rE   times     r   rT   z!ScreensaverCommand.perform_actione   sF   >>V[[(JJ%%'^^v||+zz..0a567a789^^v{{*::779DqyaDEFg&&(Z  ]P  RV  W  Z^  ^  _^^v{{*JJ%%dll3^^v.JJ++D1^^v000JJ++E2r   )N)r   r   r   __doc__rI   r:   rD   rT   r   r   r   r!   r!       s    ,H\C!r   r!   __main__T)!girequire_versiongi.repositoryr   r   r   ossyssignalr0   r^   rL   enumr   
subprocessr   r   r8   utilr	   	constantsrA   SIGINTSIG_DFLinstallr   r!   r   MainLoopnewmlmainrunr   r   r   <module>rw      s    
   >5 ) 1 1 	 
      %    fmmV^^ , &(; <W Z Zx z			4	&Bb!DFFH	 r   