
    Eg4                         d dl Z d dlmZmZmZmZmZ d dlZd dlm	Z	m
Z
 d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ  G d	 d
e      Zy)    N)GtkGdkGObjectCScreensaverGio)utilstrackers)
BaseWindow)FramedImage)PasswordEntry)
AuthClient)TransparentButtonc                       e Zd ZdZej
                  j                  ddfej
                  j                  ddfej
                  j                  ddfej
                  j                  ddfej
                  j                  ddfdZ fdZd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd ZddZ xZ S )UnlockDialoga  
    The main widget for the unlock dialog - this is a direct child of
    the Stage's GtkOverlay.

    It has a number of parts, namely:
        - The user face image.
        - The user's real name (or username if the real name is unavailable)
        - The password entry widget
        - Unlock and Switch User buttons
        - A caps lock warning label
        - An invalid password error label
    N )inhibit-timeoutuninhibit-timeoutauthenticate-successauthenticate-failureauthenticate-cancelc                 L   t         t        |           t        j                  j                  d      }| j                  t        j                  j                         | j                  t        j                  j                         d | _        d | _        d | _        d | _        d| _        t        j                   t        j"                  j$                  d      | _        | j&                  j)                         j+                  d       | j-                  | j&                         t/        t0        j2                  j5                               | _        | j6                  j                  t        j                  j                         | j6                  j)                         j+                  d       | j6                  j9                  d       | j&                  j;                  | j6                  ddd       t        j<                  d       | _        | j>                  jA                  dd	       | j>                  j                  t        j                  j                         | j&                  j;                  | j>                  ddd       t        j                   t        j"                  jB                  t        j                  j                  
      | _"        | j&                  j;                  | jD                  ddd       tG               | _$        tK        jL                         jO                  | jH                  d| jP                         tK        jL                         jO                  | jH                  d| jR                         tK        jL                         jO                  | jH                  d| jT                         | jD                  j;                  | jH                  ddd       t        j                   t        j"                  jB                        }| jD                  jW                  |ddd       tY        dt        jZ                  j\                        | _/        | j^                  ja                  tc        d             tK        jL                         jO                  | j^                  d| jd                         |j;                  | j^                  ddd       | jH                  | j^                  gt0        _3        |ji                  d      stY        dt        jZ                  j\                        | _5        | jj                  ja                  tc        d             tK        jL                         jO                  | jj                  d| jl                         |j;                  | jj                  ddd       t0        jf                  jo                  | jj                         t        j                   t        j"                  j$                  d      }t        j<                  d      | _8        | jp                  j)                         j+                  d       | jp                  jA                  d	d	       |j;                  | jp                  ddd       t        j<                  d      | _9        | jr                  j)                         j+                  d       | jr                  jA                  d	d	       |j;                  | jr                  ddd       t        j<                  d       | _:        | jt                  jA                  dd	       | jt                  j                  t        j                  j                         |j;                  | jt                  ddd       | j&                  j;                  |ddd       tw        jx                         | _        tw        jz                         | _        | j}                          t~        j                  | _A        | j                          tK        jL                         jO                  | j                  d| j                         t        j                  j                         | _G        tK        jL                         jO                  | j                  d| j                         | j                  | j                         t               | _J        tK        jL                         jO                  | j                  d| j                         tK        jL                         jO                  | j                  d| j                         tK        jL                         jO                  | j                  d| j                         tK        jL                         jO                  | j                  d | j                         tK        jL                         jO                  | j                  d!| j                         tK        jL                         jO                  | j                  d"| j                         | j&                  j                          y )#Nzorg.cinnamon.desktop.lockdownr   
   )orientationspacing	unlockbox	faceimageTFg      ?)r   halign   changedzbutton-press-eventactivate   )r   zscreensaver-unlock-symbolicUnlockclicked   zdisable-user-switchingz!screensaver-switch-users-symboliczSwitch User zcaps-messagezauth-messageaccounts-readyzstate-changedzauth-successzauth-failurezauth-cancelz	auth-busyzauth-promptz	auth-info)Rsuperr   __init__r   Settingsnew
set_halignr   AlignCENTER
set_valign	real_name	user_name	auth_infobounce_rectbounce_countBoxOrientationVERTICALboxget_style_context	add_classaddr   statusscreenget_low_res_mode
face_imageset_no_show_all
pack_startLabelrealname_labelset_alignment
HORIZONTAL	entry_boxr   password_entryr	   con_tracker_getconnecton_password_entry_text_changedon_password_entry_button_presson_auth_enter_keypack_endr   IconSizeLARGE_TOOLBARauth_unlock_buttonset_tooltip_text_on_unlock_clickedfocusWidgetsget_booleanauth_switch_buttonon_switch_user_clickedappendcapslock_labelauth_message_labelauthinfo_labelr   get_user_display_nameget_user_nameupdate_realname_label
singletonsAccountsServiceClientaccount_clientset_user_detailson_accounts_readyr   Keymapget_defaultkeymapkeymap_handlerr   auth_clienton_authentication_successon_authentication_failureon_authentication_cancelledon_authentication_busy_changed on_authentication_prompt_changedon_authentication_info_changedshow_all)selfsettings
button_boxvbox_messages	__class__s       )/usr/share/cinnamon-screensaver/unlock.pyr(   zUnlockDialog.__init__(   s9   lD*,<<##$CD		(()		(()77s'?'?L""$..{;%fmm&D&D&FG""399#3#34))+55kB''-DOOUE2>!iio))!S1&&syy'7'78D//rBS__-G-GPSPYPYP`P`aDNND$:+o  "**4+>+>+4+/+N+N	P 	  "**4+>+>+?+/+N+N	P 	  "**4+>+>+5+/+A+A	C 	!!$"5"5ueRHWW)C)CD

E5!<"34QSVS_S_SmSm"n008=  "**4+B+B+4+/+A+A	C 	d55ueQG#22D4K4KL##$<=&78[]`]i]i]w]w&xD###44Q}5EF$$&..t/F/F	SWSnSno!!$"9"95%K&&t'>'>?COO,D,DaP!iim--/99.I))#s3  !4!4eUAF"%))B-113==nM--c37  !8!8%J!iio))!S1&&syy'7'78  !4!4eUAFM5%;446,,.""$(>>  "**4+>+>+;+/+A+A	C jj,,.  "**4;;+:+/+>+>	@ 	DKK(%<  "**4+;+;+9+/+I+I	K 	  "**4+;+;+9+/+I+I	K 	  "**4+;+;+8+/+K+K	M 	  "**4+;+;+6+/+N+N	P 	  "**4+;+;+8+/+P+P	R 	  "**4+;+;+6+/+N+N	P
 	    c                 6    | j                   j                         S N)rg   
initializero   s    rt   initialize_auth_clientz#UnlockDialog.initialize_auth_client   s    **,,ru   c                 H    | j                  d       | j                  d       y )NFr   )set_busyemitro   rg   s     rt   rh   z&UnlockDialog.on_authentication_success   s    e		()ru   c                     | j                  d       | j                  j                  t        d             | j	                  d       | j	                  d       y)z
        Called upon authentication failure, clears the password, sets an error message,
        and refocuses the password entry.
        FzIncorrect passwordr   r   N)r|   rY   set_textrQ   r}   r~   s     rt   ri   z&UnlockDialog.on_authentication_failure   sD    
 	e((+?)@A		()		%&ru   c                 &    | j                  d       y )Nr   )r}   r~   s     rt   rj   z(UnlockDialog.on_authentication_cancelled   s    		'(ru   c                 &    | j                  |       y rw   )r|   )ro   rg   busys      rt   rk   z+UnlockDialog.on_authentication_busy_changed   s    dru   c                    |r| j                   j                  d       | j                          | j                  j	                  d       | j
                  j                          | j
                  j                  t        d             y | j                  j	                  d       | j
                  j                          | j
                  j                  | j
                  j                         d| _        | j                          y )Nr%   FzChecking...T)rY   r   clear_entryrE   set_sensitiverF   start_progressset_placeholder_textrQ   stop_progressplaceholder_textr1   update_authinfo_label)ro   r   s     rt   r|   zUnlockDialog.set_busy   s    ##,,R0NN((/..044a6FGNN((.--/44d6I6I6Z6Z[DN&&(ru   c                     d|j                         v rt        d      }n|j                  dd      }|| j                  _        | j                  j                  | j                  j                         y )Nz	password:zPlease enter your password...:r%   )lowerrQ   replacerF   r   r   )ro   rg   prompts      rt   rl   z-UnlockDialog.on_authentication_prompt_changed   sY    &,,.(67F^^C,F/5,001D1D1U1UVru   c                 2    || _         | j                          y rw   )r1   r   )ro   rg   infos      rt   rm   z+UnlockDialog.on_authentication_info_changed   s    ""$ru   c                 X    | j                   j                          | j                          y)z>
        Clears the auth message text if we have any.
        N)rg   cancelr   ry   s    rt   r   zUnlockDialog.cancel   s"     	!ru   c                     | j                   j                         s4| j                   j                          | j                   j                          | j                   j	                  |       y)z
        Takes a propagated key event from the stage and passes it to the entry widget,
        possibly queueing up the first character of the password.
        N)rF   get_realizedrealize
grab_focusevent)ro   r   s     rt   queue_key_eventzUnlockDialog.queue_key_event   sN    
 ""//1'')**,!!%(ru   c                     |j                         r%| j                  j                  t        d             y| j                  j                  d       y)z\
        Handler for the GdkKeymap changing - updates our capslock indicator label.
        zYou have the Caps Lock key on.r%   N)get_caps_lock_staterX   r   rQ   )ro   re   s     rt   rf   zUnlockDialog.keymap_handler   s>     %%'((+K)LM((,ru   c                     t        j                         j                  | j                  d| j                         | j                          y)z`
        Handler for the AccountsService - requests the user real name and .face image.
        r&   N)r	   rG   
disconnectr`   rb   ra   )ro   clients     rt   rb   zUnlockDialog.on_accounts_ready   s>     	  "--d.A.A.>.2.D.D	F 	ru   c                 f   | j                   j                         /| j                   j                         | _        | j                          | j                   j	                         N| j
                  j                  | j                   j	                                | j
                  j                          y y rw   )r`   get_real_namer/   r]   get_face_pathr>   set_from_pathshowry   s    rt   ra   zUnlockDialog.set_user_details  s    ,,.:!00>>@DN&&(,,.:OO))$*=*=*K*K*MNOO  " ;ru   c                 n    | j                   j                         s| j                   j                          yy)z
        Handler for the password entry text changing - this controls the sensitivity
        of the unlock button, as well as returning visual focus to the entry any time
        a key event is received.
        N)rF   	has_focusr   )ro   editables     rt   rI   z+UnlockDialog.on_password_entry_text_changed  s-     "",,.**, /ru   c                     |j                   dk(  r7|j                  t        j                  j                  k(  rt        j
                  S t        j                  S )z\
        Prevents the usual copy/paste popup when right-clicking the PasswordEntry.
           )buttontyper   	EventTypeBUTTON_PRESS
EVENT_STOPEVENT_PROPAGATE)ro   widgetr   s      rt   rJ   z+UnlockDialog.on_password_entry_button_press  s;     <<1s}}/I/I!I>>!"""ru   c                     | j                  d       | j                  j                         }|dd dk7  r|dz  }| j                  j	                  |       y)a3  
        Callback for the unlock button.  Activates the 'progress' animation
        in the GtkEntry, and attempts to authenticate the password.  During this
        time, we also inhibit the unlock timeout, so we don't fade out while waiting
        for an authentication result (highly unlikely.)
        r   N
)r}   rF   get_textrg   message_to_child)ro   r   texts      rt   rR   zUnlockDialog.on_unlock_clicked#  sR     			#$""++- 9DLD))$/ru   c                 $    | j                          y)z^
        Implicitly activates the unlock button when the Enter/Return key is pressed.
        N)rR   ro   r   s     rt   rK   zUnlockDialog.on_auth_enter_key4  s    
 	 ru   c                 ,    t        j                          y)z6
        Callback for the switch-user button.
        N)r   do_user_switchr   s     rt   rV   z#UnlockDialog.on_switch_user_clicked;  s     	ru   c                 h    | j                   j                  d       d| _        | j                          y)z2
        Clear the password entry widget.
        r%   N)rF   r   r1   r   ry   s    rt   r   zUnlockDialog.clear_entryA  s+     	$$R(""$ru   c                 N    | j                   j                  | j                         y)zB
        Updates the name label to the current real_name.
        N)rB   r   r/   ry   s    rt   r]   z"UnlockDialog.update_realname_labelI       	$$T^^4ru   c                 N    | j                   j                  | j                         y)zO
        Updates the auth info label to the current auth_info message.
        N)rZ   r   r1   ry   s    rt   r   z"UnlockDialog.update_authinfo_labelO  r   ru   c                 D    t        j                  d| j                         y )NK   )r   timeout_addon_blink_tickry   s    rt   blinkzUnlockDialog.blinkU  s    B 2 23ru   c                 B   | j                         }|y|j                         \  }}| j                  dk  rc| j                  dz  dk(  r|dz  }n|dz  }| j                         j                  ||       | j	                          | xj                  dz  c_        yd| _        y)NF   r   r      T)
get_windowget_positionr3   move
queue_draw)ro   datawindowxys        rt   r   zUnlockDialog.on_blink_tickX  s    ">""$1q   1$)QQOO""1a(OO"ru   rw   )!__name__
__module____qualname____doc__r   SignalFlagsRUN_LAST__gsignals__r(   rz   rh   ri   rj   rk   r|   rl   rm   r   r   rf   rb   ra   rI   rJ   rR   rK   rV   r   r]   r   r   r   __classcell__)rs   s   @rt   r   r      s     $//88$C%11::D"E!(!4!4!=!=tR H!(!4!4!=!=tR H ' 3 3 < <dBGLEN-*	'))W%	)- #-#0"!%554ru   r   )gigi.repositoryr   r   r   r   r   	tracebackutilr   r	   r;   r^   
baseWindowr
   widgets.framedImager   passwordEntryr   pamhelper.authClientr   widgets.transparentButtonr   r   r   ru   rt   <module>r      s;    
 > >  !   ! + ' + 7Z: Zru   