
    FgwB                        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Zd dlmZ d dl	Z	d dl
Z
 e
j                  dd        e
j                  dd       d dlmZmZmZmZmZ  e j                   e j$                  e j&                          ej(                  e	j*                  e	j,                          ej(                  e	j*                  e	j,                          ej.                  e	j*                         ej                  Z ej                  d        G d	 d
e      Z G d de      Z G d de      Z G d d      Zedk(  r+ e       Z ej>                           ej@                  d        yy)    N)IntEnumGtkz3.0XAppz1.0)GLibGior   Gdkr   cinnamon-session-quitc                       e Zd ZdZdZdZy)Action         N)__name__
__module____qualname__LOGOUTSHUTDOWNRESTART     4/usr/share/cinnamon-session/cinnamon-session-quit.pyr   r      s    FHGr   r   c                   0    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)ResponseCode      r         r   r      	   N)r   r   r   SUSPEND	HIBERNATEr   SWITCH_USERCANCELr   r   CONTINUENONEr   r   r   r   r   $   s/    GIGKFFHHDr   r   c                       e Zd ZdZdZdZy)LogoutParamsr   )r   r   N)r   r   r   NORMAL	NO_PROMPTFORCEr   r   r   r'   r'   /   s    FIEr   r'   c                   p    e 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dZy)
QuitDialogc           	         t        j                  d      }|j                  d      }|j                  dddt        j
                  t        d      	       |j                  d
ddt        j                  t        d      	       |j                  dddt        j                  d	       |j                  dddt        d             |j                  dddt        d             |j                  ddt         j                         |j                  dddt         j                  d        |j                         }t        j                  | _        d| _        |j                  | _        t        t!        | j                              | _        |j$                  | _        |j&                  | _        |j(                  | _        |j*                  | _        d | _        d| _        d| _        d| _        d| _        t7        j8                  t6        j:                  t<        j>                  | j@                  d        | j(                  s| jC                          y | jE                          y )Nr	   )descriptionT)requiredz--logoutmodestore_constzLog out)destactionconsthelpz--power-offz	Power offz--rebootz--forceforce
store_truez Ignoring any existing inhibitors)r3   r4   r6   z--no-prompt	no_promptz"Don't prompt for user confirmationz
--sm-owned)r4   r6   z--sm-bus-idbus_idstore)r3   r4   r6   defaultFr   )#argparseArgumentParseradd_mutually_exclusive_groupadd_argumentr   r   _r   r   SUPPRESS
parse_argsr   r%   dialog_response	inhibitedr1   intdefault_responser7   r9   sm_ownedr:   proxysignal_handler_iddelay_durationcurrent_timetimer_idr   unix_signal_addPRIORITY_HIGHsignalSIGTERMon_terminateforward_to_sminteract)selfparsergroupargss       r   __init__zQuitDialog.__init__5   s   ((5LM33T3B:F=PVP]P]!"9 	 	/=vmSYSbSb!"; 	 	1:F=PVP^P^!* 	 	,IGL!"#E!F 	 	HML!"#G!H 	 	JLHDUDUV 	MxO`O`jno  "+00II	 ,S^ <ZZ
kk
!"T//ARARTXY}}   MMOr   c           	      0   d }	 t         j                  j                  t         j                  j                  t         j
                  j                  d dddd       }d }| j                  t        j                  k(  rt        j                  }| j                  r|t        j                  z  }| j                  r|t        j                  z  }|j!                  dt#        j$                  d|g      t         j&                  j(                  dd |       n| j                  t        j*                  k(  r/|j!                  dd t         j&                  j(                  dd |       nK| j                  t        j,                  k(  r.|j!                  dd t         j&                  j(                  dd |       t5        j8                  d       y # t"        j.                  $ rJ}|>t1        d	|j2                  z  t4        j6                  d 
       t5        j8                  d       Y d }~nd }~ww xY w)Norg.gnome.SessionManager/org/gnome/SessionManagerc                     	 | j                  |       y # t        j                  $ r3}t        d|j                  z  t
        j                  d        Y d }~y d }~ww xY w)Nz7An error occurred forwarding to the session manager: %sfileend)call_finishr   Errorprintmessagesysstderr)rI   reses      r   async_cbz*QuitDialog.forward_to_sm.<locals>.async_cbs   sP    |%%c*zz |SVWV_V__fifpfpvz{{|s    A)AALogoutz(u)ShutdownRebootz<Could not forward to org.cinnamon.SessionManager.Manager: %sr^   r   r   )r   	DBusProxynew_for_bus_syncBusTypeSESSIONDBusProxyFlagsDO_NOT_AUTO_STARTr1   r   r   r'   r)   r9   r*   r7   r+   callr   VariantDBusCallFlagsNO_AUTO_STARTr   r   rb   rc   rd   re   rf   exit)rU   sm_proxyri   argrh   s        r   rS   zQuitDialog.forward_to_sme   s   7	}}55##""44*+*H| yyFMM)"))>><111C::<---CLL.%%33 foo-%%33 fnn,%%33 	 zz 	TWXW`W``gjgqgqw{|	s   FF8 8HA HHc                 D    | j                          | j                          y N)setup_proxy
run_dialogrU   s    r   rT   zQuitDialog.interact   s    r   c           	         d }	 | j                   t        j                  j                  | j                   t        j                  j
                  d d       }t        j                  j                  |t        j                  j                  d d ddd       | _
        nZt        j                  j                  t        j                  j                  t        j                  j                  d dddd       | _
        | j                  j                  d| j                         y # t         j"                  $ r}|>t%        d|j&                  z  t(        j*                  d        t)        j,                  d       | j                  Ct%        d	|j&                  z  t(        j*                  d        t)        j,                  d       Y d }~y Y d }~y d }~ww xY w)
Nr\   z)org.cinnamon.SessionManager.DialogPrivater[   z,org.cinnamon.SessionManager.EndSessionDialogzg-signalz.Could not connect to session dialog server: %sr^   r   z6Could not create proxy to session dialog interface: %s)r:   r   DBusConnectionnew_for_address_syncDBusConnectionFlagsAUTHENTICATION_CLIENTrn   new_syncrr   rs   rI   ro   rp   rq   connectinhibitor_info_receivedr   rb   rc   rd   re   rf   rx   )rU   
connectionrh   s      r   r}   zQuitDialog.setup_proxy   s_   
%	{{& //DDKK++AA$
 !]]33&&88/?
 !]];;KK''&&88./B
 JJz4+G+GHzz 	!FRY\YcYcimnzz!NQRQZQZZadakakquv "		s   DD G+B
F??Gc                    |d   }| j                   t        j                  k(  rt        dt        j
                  d        y t        dt        |      |fz  t        j
                  d        |rd| _        | j                  |       y | j                  r;| j                  | j                  t        j                         | j                          y y )Nr   zDIgnoring inhibitor info, still waiting on initial response from userr^   z+Inhibitor info received (%d inhibitors): %sT)rD   r   r%   rc   re   rf   lenrE   show_inhibit_viewhandle_responsewindowr$   	finish_up)rU   rI   senderrP   params
inhibitorss         r   r   z"QuitDialog.inhibitor_info_received   s    AY
<#4#44X_b_i_iost;s:PV>WW^a^h^hnrs!DN"":.~~$$T[[,2G2GH  r   c                 b    t         j                  j                  t        j                  j                  t        j                  d             _         j                  j                  d       _
         j                  j                  d fd        j                  j                  d       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d	       _         j                  j                  d
       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d       _         j                  j                  d       _        t0        j2                  j5                  dd j                    j"                   j$                   j&                   j*                   j,                   j.                  g       _         j                  j                  d       _         j                  j                  d       _        	  j=                         \  }}}}}}}d }	 jF                  tH        jJ                  k(  r j                  jM                  tO        d              j&                  jQ                          j*                  jQ                  d        j*                  }	 j                  jS                  dt         jT                  jV                          j                  jY                  d       n jF                  tH        jZ                  k(  r j                  jM                  tO        d              j                   jQ                          j"                  jQ                          j$                  jQ                          j,                  jQ                          j,                  }	 j                  jS                  dt         jT                  jV                          j                  jY                  d       n jF                  tH        j\                  k(  rs1tA        dtB        jD                  d        t        j^                          y  j                  jM                  tO        d              j$                  jQ                  d        j$                  }	 j                  jS                  dt         jT                  jV                          j                  jY                  d       |	ja                         jc                  d        te        jf                  d!"      }
|
ji                  d#       _5        |
jm                  d$      rF j                  jo                           j                  jq                  d%        js                          n j                  ju                           j                  jw                   jx                          j                  j                  d& jz                          j                  j}                  d        j                  j                           j                  j                  d'       y # t>        $ r'}tA        |tB        jD                  d        Y d }~Ld }~ww xY w)(Nzcinnamon-session-quit.glader   zdelete-eventc                 &    j                  d      S Nr   )quit)wrh   rU   s     r   <lambda>z'QuitDialog.run_dialog.<locals>.<lambda>   s    1 r   still_running_displayprogress_bardialog_labelaction_iconbutton_suspendbutton_hibernatebutton_restartbutton_switchuserbutton_cancelbutton_logoutbutton_shutdownbutton_continueFT
view_stackinhibitor_treeviewr^   zLog out of this system now?zsystem-log-out-symboliczsystem-log-outzShut down this system now?zsystem-shutdown-symboliczsystem-shutdownzRestart not availablezRestart this system now?zsystem-reboot-symboliczsystem-rebootzdestructive-actionzorg.cinnamon.SessionManager)	schema_idzquit-time-delayzquit-delay-toggleg      ?responser   )Ar   Buildernew_from_fileospathjoinconfigPKG_DATADIRbuilder
get_objectr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   VisibilityGroupnewdynamic_buttonsr   r   get_session_capabilities	Exceptionrc   re   rf   r1   r   r   set_textrA   set_visibleset_from_icon_nameIconSizeDIALOGset_icon_namer   r   	main_quitget_style_context	add_classr   Settingsget_intrK   get_booleanshowset_fractionstart_timerhideset_default_responserG   r   set_keep_abovestickpresent_with_time)rU   can_switch_usercan_stopcan_restartcan_hybrid_sleepcan_suspendcan_hibernate
can_logoutrh   default_buttonsession_settingss   `          r   r~   zQuitDialog.run_dialog   s@   {{00f>P>PRo1pqll--h7N,EF%)\\%<%<=T%U" LL33NC LL33NC<<22=A"ll556FG $ 7 78J K"ll556FG!%!8!89L!M!\\44_E!\\44_E#||667HI#||667HI#3377t!!""    F
   ,,11,?"&,,"9"9:N"O	0os  pM  pM  pOlOX{4DkS`bl 99%&&q)F'GH""..?**40!//N//0I3<<K^K^_KK%%&67YY&//)&&q)E'FG++K8!!--m<++K8  ,,X6!11N//0JCLLL_L_`KK%%&78YY&..(-CJJDI&&q)C'DE++D1!00N//0H#,,J]J]^KK%%o6((*445IJ<<2OP.667HI''(;<""$**3/""$(()>)>?J(<(<=""4(%%a(a  	0!#**$//	0s   [> >	\.\))\.c                    	 | j                   j                  dd t        j                  j                  dd       }|d   S # t
        j                  $ r3}t        d|j                  z  t        j                  d        Y d }~y d }~ww xY w)NGetCapabilitiesrk   r   z+Could not retrieve session capabilities: %sr^   )rI   	call_syncr   rv   rw   r   rb   rc   rd   re   rf   )rU   capsrh   s      r   r   z#QuitDialog.get_session_capabilities5  sy    
	h::''!!!//D 7Nzz 	h?!))KRUR\R\bfgg	hs   ;> B)A??Bc                     | j                   dkD  rt        j                  | j                          | j                  | _        | j                          t        j                  d| j
                         y )Nr   i  )rM   r   source_removerK   rL   update_timertimeout_addr   s    r   r   zQuitDialog.start_timerB  sP    ==1t}}- //t001r   c                 p    | j                   dkD  r't        j                  | j                          d| _         y y r   )rM   r   r   r   s    r   
stop_timerzQuitDialog.stop_timerK  s,    ==1t}}-DM r   c                    | j                   dk(  r'| j                  | j                  | j                         y | j                  t
        j                  k(  r/t        j                  dd| j                         | j                   z  }n| j                  t
        j                  k(  r/t        j                  dd| j                         | j                   z  }nK| j                  t
        j                  k(  r.t        j                  dd| j                         | j                   z  }| j                  j                         | j                  j                  | j                   | j                  z         | xj                   dz  c_         t        j                   S )	Nr   z2You will be automatically logged out in %d second.z%You will be logged out in %d seconds.z9This system will be automatically shut down in %d second.z,This system will be shut down in %d seconds.z9This system will be automatically restarted in %d second.z,This system will be restarted in %d seconds.r   )rL   r   r   rG   r1   r   r   gettextngettextr   r   r   r   r   rK   r   SOURCE_CONTINUE)rU   seconds_warnings     r   r   zQuitDialog.update_timerP  sd   !  d.C.CD99%%.. 1D1E040A0A	C FJEVEV	WO
 YY&//)%.. 1J1K040A0A	C FJEVEV	WO
 YY&..(%.. 1J1K040A0A	C FJEVEV	WO 	""?3&&t'8'84;N;N'NOQ###r   c                    | j                          | j                  j                  d       | j                  r|t        j
                  k(  r>t        dt        j                  d        | j                  d       | j                          y |t        j                  t        j                  j                  t        j                  j                  fv r=t        dt        j                  d        | j                  d       | j!                          y || _        |t        j$                  k(  r| j                  d       y |t        j&                  k(  r| j                  d       y |t        j(                  k(  r| j                  d	       y |t        j*                  k(  r| j                  d
       y |t        j,                  k(  r| j                  d       y |t        j.                  k(  r| j                  d       y |t        j                  t        j                  j                  t        j                  j                  fv r#| j                  d       | j!                  d       y t        d|z  t        j                  d        y )NbusyzSending ignore inhibitorsr^   IgnoreInhibitorsz%Canceling action during inhibit phaseCancelSuspendRestart	Hibernate
SwitchUserrj   rl   r   zInvalid response code: %d)r   r   set_visible_child_namerE   r   r$   rc   re   rf   send_commandr   r#   r   ResponseTyper%   DELETE_EVENTr   rD   r    r   r!   r"   r   r   )rU   dialogcodes      r   r   zQuitDialog.handle_responseo  s   ..v6>>|,,,1

M!!"45 
 	 ,--s/?/?/D/DcFVFVFcFcdd=CJJTXY!!(+		#<'''i(\)))i(\+++k*\---l+\(((h'\***j)l))3+;+;+@+@#BRBRB_B_``h'IIaL-43::4Pr   c                 <   	 | j                   j                  |d t        j                  j                  dd d        d| _        y # t
        j                  $ rF}t        dt        |      d|j                  t        j                  d        Y d }~d| _        y d }~ww xY w)Nrk   zCould not send command 'z' to session manager: r^   T)rI   rt   r   rv   rw   r   rb   rc   strrd   re   rf   command_sent)rU   commandrh   s      r   r   zQuitDialog.send_command  s    
	JJOO!!// ! zz 	#g,XYXaXabilisisy}~~ 	s   8A B5BBc                    t        j                  t        t        t              | _        | j                  j                  | j                         |D ])  }| j                  j                  dddg|d   |d   g       + | j                  j                          | j                  j                          | j                  j                  d       y )Nrk   r   r   r   inhibit)r   	ListStorer   inhibit_modelr   	set_modelinsert_with_valuesr   r   r   r   r   r   )rU   info	inhibitors      r   r   zQuitDialog.show_inhibit_view  s     ]]3S9))$*<*<= 	\I11"q!fy|YWX\>Z[	\ 	!!#!!#..y9r   Nc                 ^    t        dt        j                  d        | j                  d       y )Nz/Received SIGTERM from cinnamon-session, exitingr^   r   )rc   re   rf   r   )rU   datas     r   rR   zQuitDialog.on_terminate  s    ?cjjVZ[		!r   c                     | j                   dkD  rt        j                  | j                          | j                  j	                  d       t        j
                  d| j                         y )Nr   r   r   )rM   r   r   r   r   timeout_add_secondsr   r   s    r   r   zQuitDialog.finish_up  sF    ==1t}}-..v6  DII.r   c                     | j                   j                          t        j                         dk(  rt	        j
                  |       y || _        t        j                          y r   )r   destroyr   
main_levelre   rx   ecoder   )rU   r   s     r   r   zQuitDialog.quit  s<    >>q HHTNDJMMOr   r|   r(   )r   r   r   rY   rS   rT   r}   r   r~   r   r   r   r   r   r   r   rR   r   r   r   r   r   r-   r-   4   sZ    .`<|(T!"Q)fh2
$>"QH! 
:/r   r-   __main__)!rP   r=   r   setproctitler   re   localeenumr   r   girequire_versiongi.repositoryr   r   r   r   r   SIGINTSIG_DFLbindtextdomainPACKAGE
LOCALE_DIR
textdomainrA   r   r   r'   r-   r   r   mainrx   r   r   r   <module>r     s.       	 
    	   5%     65 ! 3 3 fmmV^^ ,   fnnf&7&7 8   v~~v'8'8 9   6>> "OO   1 2W 
	7 	7 
N N` z\FCHHJCHHQK r   