
    kd                        d Z dZd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 ej                  dd        ej                  dd        ej                  d	d       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 ddlmZ ddlmZ ddl ddlmZ ddlmZ d Z e ed            \  ZZ G d dej<                        Z G d de      Z  G d de      Z! G d dejD                        Z# G d d ejD                        Z$ G d! d"ejJ                        Z& G d# d$ejN                        Z( G d% d&ejR                        Z* G d' d(ejV                        Z, G d) d*ejZ                        Z. G d+ d,ej^                        Z0 G d- d.ej^                        Z1 G d/ d0ejd                        Z3 G d1 d2ej^                        Z4 G d3 d4e1      Z5d5Z6 G d6 d7ejn                        Z8 G d8 d9e1      Z9 G d: d;e9      Z:y)<zE
This module provides widgets to use aptdaemon in a GTK application.
z%Sebastian Heinlein <devel@glatzor.de>)AptConfigFileConflictDialogAptCancelButtonAptConfirmDialogAptProgressDialogAptTerminalExpanderAptStatusIconAptRoleIconAptStatusAnimationAptRoleLabelAptStatusLabelAptMediumRequiredDialogAptMessageDialogAptErrorDialogAptProgressBarDiffViewAptTerminal    NVtez2.91Gdkz3.0Gtk)GObject)GLib)r   )r   )Pango)r      )client)*)inline_callbacks)	deferablec                 .    t        j                  d|       S )N	aptdaemon)gettextdgettext)msgs    7/usr/lib/python3/dist-packages/aptdaemon/gtk3widgets.py<lambda>r$   ;   s      c2        c                   V    e Zd ZdZdej
                  j                  fdZd Zd Z	d Z
y)r   zi
    Provides a Gtk.Image which shows an icon representing the status of a
    aptdaemon transaction
    Nc                     t         j                  j                  |        || _        d | _        g | _        | j                  dd       || j                  |       y y Nr   )r   Image__init__
_icon_size	icon_name_signalsset_alignmentset_transaction)selftransactionsizes      r#   r+   zAptStatusIcon.__init__F   sT    		4  1a "  - #r%   c                     | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               y)z Connect to the given transactionstatus-changedN)r.   r   source_removeappendconnect_on_status_changedr1   r2   sigs      r#   r0   zAptStatusIcon.set_transactionQ   sW    == 	$Cs#	$[001A151H1HJ 	Kr%   c                     || _         y)z.Set the icon size to gtk stock icon size valueN)r,   )r1   r3   s     r#   set_icon_sizezAptStatusIcon.set_icon_sizeY   s	    r%   c                     t        |      }|t        j                  }|| j                  k7  r$| j	                  || j
                         || _        yy)z3Set the status icon according to the changed statusN)get_status_icon_name_from_enumr   STOCK_MISSING_IMAGEr-   set_from_icon_namer,   )r1   r2   statusr-   s       r#   r9   z AptStatusIcon._on_status_changed]   sI    26:	//I&##It?&DN 'r%   )__name__
__module____qualname____doc__r   IconSizeDIALOGr+   r0   r=   r9    r%   r#   r   r   A   s-     $(cll.A.A 	.K'r%   r   c                       e Zd ZdZd Zd Zy)r   zh
    Provides a Gtk.Image which shows an icon representing the role of an
    aptdaemon transaction
    c                     | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               | j                  ||j                         y )Nrole-changed)r.   r   r6   r7   r8   _on_role_changedroler:   s      r#   r0   zAptRoleIcon.set_transactionl   sl    == 	$Cs#	$[00151F1FH 	Ik;+;+;<r%   c                     t        |      }|t        j                  }|| j                  k7  r$| j	                  || j
                         || _        yy)z"Show an icon representing the roleN)get_role_icon_name_from_enumr   r@   r-   rA   r,   )r1   r2   	role_enumr-   s       r#   rM   zAptRoleIcon._on_role_changedt   sI    0;	//I&##It?&DN 'r%   N)rC   rD   rE   rF   r0   rM   rI   r%   r#   r   r   g   s    ='r%   r   c                   d    e Zd ZdZdej
                  j                  fdZd	dZd Z	d Z
d Zd Zy)
r	   z_
    Provides a Gtk.Image which shows an animation representing the
    transaction status
    Nc                     t         j                  | ||       g | _        d| _        d| _        d| _        t        t              }t        t              }| j                  ||       y r)   )
r   r+   	animationtickerframe_counteriter#get_status_animation_name_from_enumSTATUS_WAITINGr?   set_animation)r1   r2   r3   namefallbacks        r#   r+   zAptStatusAnimation.__init__   sU    t[$7	2>B1.A4*r%   c           
         || j                   k(  ry||| _        | j                          g }t        j                  | j                        \  }}t        j
                  j                         }||j                  |      r|j                  ||d      }|j                         |z  }	|j                         |z  }
t        |	      D ];  }t        |
      D ]+  }|j                  |j                  ||z  ||z  ||             - = t        |      dkD  rD|| _        d| _        | j#                  | j                  d          | j%                          || _         y| j#                  |       || _         y|5|j                  |      r$| j'                  || j                         || _         y| j'                  t        j(                         y)z7Show and start the animation of the given name and sizeNr   )r-   r,   stop_animationr   icon_size_lookup	IconThemeget_defaulthas_icon	load_icon
get_height	get_widthranger7   	subpixbuflenrT   rW   set_from_pixbufstart_animationrA   r@   )r1   r[   r\   r3   rT   widthheightthemepixbufrowscolsrcs                r#   rZ   z AptStatusAnimation.set_animation   s   4>>!"DO	..t?))+t 4__T5!4F$$&/D##%-D4[ Ft FA$$V%5%5a%iV6;V&E FFF 9~!!*	$$T^^A%67$$& "DN $$V,!DN!ennX&>##Hdoo>%DN##C$;$;<r%   c                 n    | j                   dk(  r&t        j                  d| j                        | _         yy)zStart the animationr      N)rU   r   timeout_add_advancer1   s    r#   rj   z"AptStatusAnimation.start_animation   s+    ;;!**3>DK r%   c                 p    | j                   dk7  r't        j                  | j                          d| _         yy)zStop the animationr   N)rU   r   r6   rw   s    r#   r^   z!AptStatusAnimation.stop_animation   s,    ;;!t{{+DK r%   c                    | j                  d      du rd| _        y| j                  dz   | _        | j                  t        | j                        k\  rd| _        | j                  | j                  | j                            y)zx
        Show the next frame of the animation and stop the animation if the
        widget is no longer visible
        visibleFr   r   T)get_propertyrU   rW   rh   rT   ri   rw   s    r#   rv   zAptStatusAnimation._advance   sj    
 Y'50DKIIM	99DNN++DIT^^DII67r%   c                 T    t        |      }t        |      }| j                  ||       y)zC
        Set the animation according to the changed status
        N)rX   r?   rZ   )r1   r2   rB   r[   r\   s        r#   r9   z%AptStatusAnimation._on_status_changed   s(     36:1&94*r%   NN)rC   rD   rE   rF   r   rG   rH   r+   rZ   rj   r^   rv   r9   rI   r%   r#   r	   r	   ~   s7     $(cll.A.A +=@?
+r%   r	   c                   $    e Zd ZdZddZd Zd Zy)r
   <
    Status label for the running aptdaemon transaction
    Nc                     t         j                  |        | j                  dd       | j                  t        j
                  j                         | j                  d       g | _        || j                  |       y y Nr      )
GtkLabelr+   r/   set_ellipsizer   EllipsizeModeENDset_max_width_charsr.   r0   r1   r2   s     r#   r+   zAptRoleLabel.__init__   sh    $1a 5..223  $"  - #r%   c                     | j                   D ]  }t        j                  |        g | _         | j                  ||j                         | j                   j                  |j                  d| j                               y);Connect the status label to the given aptdaemon transactionrL   N)r.   r   r6   rM   rN   r7   r8   r:   s      r#   r0   zAptRoleLabel.set_transaction   sl    == 	$Cs#	$k;+;+;<[00151F1FH 	Ir%   c                 8    | j                  t        |             y)zSet the role text.N)
set_markup$get_role_localised_present_from_enum)r1   r2   rN   s      r#   rM   zAptRoleLabel._on_role_changed   s    <TBCr%   N)rC   rD   rE   rF   r+   r0   rM   rI   r%   r#   r
   r
      s    .IDr%   r
   c                   *    e Zd ZdZddZd Zd Zd Zy)r   r   Nc                    t         j                  j                  |        | j                  dd       | j	                  t
        j                  j                         | j                  d       g | _	        || j                  |       y y r   )r   Labelr+   r/   r   r   r   r   r   r.   r0   r   s     r#   r+   zAptStatusLabel.__init__   sl    		4 1a 5..223  $"  - #r%   c                 2   | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               | j                   j                  |j	                  d| j                               y)r   r5   zstatus-details-changedN)r.   r   r6   r7   r8   r9   _on_status_details_changedr:   s      r#   r0   zAptStatusLabel.set_transaction   s    == 	$Cs#	$ 0$2I2IJ	L 8 $ ? ?A	Br%   c                 8    | j                  t        |             y)z3Set the status text according to the changed statusN)r   get_status_string_from_enumr1   r2   rB   s      r#   r9   z!AptStatusLabel._on_status_changed  s    3F;<r%   c                 &    | j                  |       y)z.Set the status text to the one reported by aptN)r   )r1   r2   texts      r#   r   z)AptStatusLabel._on_status_details_changed  s    r%   r   )rC   rD   rE   rF   r+   r0   r9   r   rI   r%   r#   r   r      s    .	B=r%   r   c                   0    e Zd ZdZddZd Zd Zd Zd Zy)	r   z`
    Provides a Gtk.Progress which represents the progress of an aptdaemon
    transactions
    Nc                    t         j                  j                  |        | j                  t        j
                  j                         | j                  d       | j                  d       g | _	        || j                  |       y y )N g?)r   ProgressBarr+   r   r   r   r   set_textset_pulse_stepr.   r0   r   s     r#   r+   zAptProgressBar.__init__  sh      &5..223cD!"  - #r%   c                    | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               | j                   j                  |j	                  d| j                               | j                   j                  |j	                  d| j                               y)z;Connect the progress bar to the given aptdaemon transactionfinishedzprogress-changedzprogress-details-changedN)r.   r   r6   r7   r8   _on_finished_on_progress_changed_on_progress_detailsr:   s      r#   r0   zAptProgressBar.set_transaction  s    == 	$Cs#	$
D,=,=>	@ 2D4M4MN	P[001K151J1JL 	Mr%   c                 X    |dkD  r| j                          y| j                  |dz         y)zR
        Update the progress according to the latest progress information
        d   g      Y@N)pulseset_fraction)r1   r2   progresss      r#   r   z#AptProgressBar._on_progress_changed%  s'     c>JJLh./r%   c                    |dk(  r|dk(  r| j                  d       y|dk7  rZ| j                  t        d      t        j                  |      t        j                  |      t        j                  |      fz         y| j                  t        d      t        j                  |      t        j                  |      fz         y)zW
        Update the progress bar text according to the latest progress details
        r   r   NzDownloaded %sB of %sB at %sB/sDownloaded %sB of %sB)r   _r   get_size_string)r1   r2   
items_doneitems_total
bytes_donebytes_totalspeedetas           r#   r   z#AptProgressBar._on_progress_details.  s    
 !q 0MM#A:MM!<=!11*=!11+>!11%8:: ;
 MM!34!11*=!11+>@@ Ar%   c                 &    | j                  d       y)z9Set the progress to 100% when the transaction is completer   N)r   )r1   r2   exits      r#   r   zAptProgressBar._on_finished@  s    !r%   r   )	rC   rD   rE   rF   r+   r0   r   r   r   rI   r%   r#   r   r     s"    .
M0A$r%   r   c                   &    e Zd ZddZd Zd Zd Zy)AptDetailsExpanderNc                    t         j                  j                  | t        d             || _        g | _        | j                  d       | j                  d       | j                  rt               | _	        nd | _	        t               | _        t        j                         | _        | j                  j                  t         j                  j                          | j                  j#                  t         j$                  j&                  t         j$                  j(                         | j                  j+                  | j                         | j                  j-                  d       t        j.                         }|j1                  | j                  ddd       | j                  r|j1                  | j                  ddd       | j+                  |       || j3                  |       y y )NDetailslabelFrt   Tr   )r   Expanderr+   r   show_terminalr.   set_sensitiveset_expandedr   terminalAptDownloadsViewdownload_viewScrolledWindowdownload_scrolledset_shadow_type
ShadowType	ETCHED_IN
set_policy
PolicyTypeNEVER	AUTOMATICaddset_min_content_heightHBox
pack_startr0   )r1   r2   r   hboxs       r#   r+   zAptDetailsExpander.__init__G  s[   d!I,7%5!% 'MDM DM-/!$!3!3!5..s~~/G/GH))#..*>*>*-..*B*B	D""4#5#5655c:xxz..dA>==OODMM4q9"  - #r%   c                    | j                   D ]  }t        j                  |        | j                   j                  |j	                  d| j
                               | j                   j                  |j	                  d| j                               | j                  r| j                  j                  |       | j                  j                  |       y)r   r5   terminal-attached-changedN)
r.   r   r6   r7   r8   r9   _on_terminal_attached_changedr   r0   r   r:   s      r#   r0   z"AptDetailsExpander.set_transaction`  s    == 	$Cs#	$ 0$2I2IJ	L ; $ B BD	E ==MM))+6**;7r%   c                    |t         t        fv rS| j                  d       | j                  j	                          | j
                  r| j
                  j                          y y |t        k(  ru| j                  j                          | j
                  r,| j
                  j	                          | j                  d       y | j                  d       | j                  d       y | j                  j                          | j
                  r| j
                  j                          | j                  d       | j                  d       y )NTF)	STATUS_DOWNLOADINGSTATUS_DOWNLOADING_REPOr   r   showr   hideSTATUS_COMMITTINGr   r1   transrB   s      r#   r9   z%AptDetailsExpander._on_status_changedm  s    (*ABBt$""'')}}""$ ((""'')}}""$""4(!!%(""5)""'')}}""$u%e$r%   c                 F    |r| j                   r| j                  d       yyy)z&Connect the terminal to the pty deviceTN)r   r   r1   r2   attacheds      r#   r   z0AptDetailsExpander._on_terminal_attached_changed  s     t$ &8r%   NT)rC   rD   rE   r+   r0   r9   r   rI   r%   r#   r   r   E  s    .28%*%r%   r   c                        e Zd ZddZd Zd Zy)r   Nc                    t         j                  j                  |        g | _        t	        j
                         \  | _        | _        t        j                  | j                        | _
        | j                  dd       | j                  d       | j                  t         j                  j                  | j                               || j!                  |       y y )NP      T)r   Terminalr+   r.   ptyopenpty_master_slaveosttyname_ttynameset_sizeset_vexpandset_ptyPtynew_foreign_syncr0   r   s     r#   r+   zAptTerminal.__init__  s    d#$'KKM!dk

4;;/b"SWW--dll;<"  - #r%   c                    | j                   D ]  }t        j                  |        | j                   j                  |j	                  d| j
                               || _        | j                  j                  | j                         y)r   r   N)	r.   r   r6   r7   r8   r   _transactionset_terminalr   r:   s      r#   r0   zAptTerminal.set_transaction  ss    == 	$Cs#	$ ; $ B BD	E (&&t}}5r%   c                 &    | j                  |       y)zShow the terminalNr   r   s      r#   r   z)AptTerminal._on_terminal_attached_changed  s    8$r%   r   )rC   rD   rE   r+   r0   r   rI   r%   r#   r   r     s    	.6%r%   r   c                   0    e Zd ZdZddZd Zd Zd Zd Zy)	r   zZ
    Provides a Gtk.Button which allows to cancel a running aptdaemon
    transaction
    Nc                     t         j                  j                  |        | j                  d       | j	                  t         j
                         | j                  d       g | _        || j                  |       y y r   )	r   Buttonr+   set_use_stock	set_labelSTOCK_CANCELr   r.   r0   r   s     r#   r+   zAptCancelButton.__init__  sb    

D!4 s''(4 "  - #r%   c                 l   | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               | j                   j                  |j	                  d| j                               | j	                  d| j                  |       y)r   r   zcancellable-changedclickedN)r.   r   r6   r7   r8   r   _on_cancellable_changed_on_clickedr:   s      r#   r0   zAptCancelButton.set_transaction  s    == 	$Cs#	$
D,=,=>	@ 5 $ < <>	? 	Y 0 0+>r%   c                 &    | j                  |       y)zY
        Enable the button if cancel is allowed and disable it in the other case
        Nr   )r1   r2   cancellables      r#   r   z'AptCancelButton._on_cancellable_changed  s     	;'r%   c                 &    | j                  d       y NFr   r   s      r#   r   zAptCancelButton._on_finished  s    5!r%   c                 F    |j                          | j                  d       y r  )cancelr   )r1   buttonr2   s      r#   r   zAptCancelButton._on_clicked  s    5!r%   r   )	rC   rD   rE   rF   r+   r0   r   r   r   rI   r%   r#   r   r     s     .
?(""r%   r   c                   N    e Zd ZdZ e ed            \  ZZZddZ	d Z
d Zd Zy)	r   z`A Gtk.TreeView which displays the progress and status of each dowload
    of a transaction.
       Nc                    t         j                  j                  |        t        j                  t        j
                  t        j                  t        j
                        }| j                  |       d| j                  _	        | j                  d       i | _        g | _        || j                  |       t        j                         }t        j                   j"                  |j                  _        t        j&                  t)        d            }|j+                  |d       |j-                  |d| j.                         t        j0                         }t        j&                  t)        d            }|j+                  |d       |j3                  || j4                  d        | j7                  |       | j7                  |       | j9                  | j:                         y )NFTFilemarkup%)r   TreeViewr+   	ListStorer   TYPE_STRINGTYPE_INT	set_modelpropsheaders_visibleset_rules_hint_download_mapr.   r0   CellRendererTextr   r   r   	ellipsizeTreeViewColumnr   r   add_attributeCOL_TEXTCellRendererProgressset_cell_data_func_data_progressappend_columnset_tooltip_columnCOL_URI)r1   r2   modelcell_uricolumn_downloadcell_progresscolumn_progresss          r#   r+   zAptDownloadsView.__init__  s_   d#g1173C3C%113u%*

"D!"  -'')#(#6#6#:#: ,,QvY7""8T2%%h$--H002,,QsV4""=$7**=$:M:M+/	1?+?+-r%   c                     | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               y)z<Connect the download view to the given aptdaemon transactionzprogress-download-changedN)r.   r   r6   r7   r8   _on_download_changedr:   s      r#   r0   z AptDownloadsView.set_transaction  sW    == 	$Cs#	$[001L151J1JL 	Mr%   c                    	 t        |dz  |z        }|t        k(  rd}|dkD  rd}|dd }	|	dz  }	|t        k(  r:|	t	        d      t        j                  |      t        j                  |      fz  z  }	nP|t        k(  r9|dk7  r%|	t	        d      t        j                  |      z  z  }	n|	t	        d      z  }	n|	t        |      z  }	|	d	z  }	| j                         }
|
sy	 | j                  |   }|
j                  || j                  |	       |
j                  || j                  |       y# t        $ r d}Y  w xY w# t        $ r |
j                  |	||f      }|| j                  |<   | j                         }|r\|j!                         |j#                         z   |j%                         k(  }|r&| j'                  |
j)                  |      dd
d
d
       Y yY yY yw xY w)z)Callback for a changed download progress.r   N
<small>r   r   zDownloaded %sB
Downloaded</small>F)intZeroDivisionErrorDOWNLOAD_DONEDOWNLOAD_FETCHINGr   r   r   get_download_status_from_enum	get_modelr  	set_valuer  COL_PROGRESSKeyErrorr7   get_vadjustment	get_valueget_page_size	get_upperscroll_to_cellget_path)r1   r2   urirB   desc	full_size
downloadedmessager   r   r   rW   adjis_scrolled_downs                 r#   r&  z%AptDownloadsView._on_download_changed  s   	:+i78H ]"Hc>HAw&&Q./,,Z8,,Y799 :D }$A~+,//	:; < ,'1&99D
  	?%%c*D" OOD$--6OOD$"3"3X>] ! 	H	:  	I<<x 56D&*Ds#&&(CMMOc&7&7&99S]]_L !# ''t,dE5%I $ 	Is$   D% D7 %D43D47BGGc                     |j                  || j                        }|dk(  r||j                  _        y ||j                  _        y )Nr(  )r6  r3  r  r   value)r1   columncellr   rW   datar   s          r#   r  zAptDownloadsView._data_progress+  s7    ??4):):;r>'DJJ'DJJr%   r   )rC   rD   rE   rF   listrf   r  r3  r  r+   r0   r&  r  rI   r%   r#   r   r     s3     '+58n#HlG.4M3?j(r%   r   c                       e Zd ZdZdej
                  j                  ej                  dfiZ	 	 ddZ	d Z
d Zd Zd	 Ze	 	 dd
       Zed        Zd Zd Zd Zd Zd Zy)r   z
    Complete progress dialog for long taking aptdaemon transactions, which
    features a progress bar, cancel button, status icon and label
    r   rI   Nc                    t         j                  j                  | |       d | _        || _        | j                  d       | j                  d       | j                         j                  d       t        |      | _
        | j                         j                  | j                  ddd       t        j                         }|j                  d       |j                  d       t               | _        |j                  | j                  ddd       t        j                          }|j                  d       t        j"                         | _        | j$                  j'                  dd       |j                  | j$                  ddd       t        j                          }|j                  d       t)               | _        |j                  | j*                  ddd       t-               | _        | j.                  j1                  d t2               |j                  | j.                  ddd       |j                  |ddd       |j                  |ddd       t5        |      | _        | j6                  j9                  d| j:                         |j                  | j6                  ddd       | j                         j                  |ddd       d | _        g | _        | jA                  d	       | jC                          | j*                  jE                  d
d       tF        jH                  jJ                  tF        jH                  jL                  z  }	 | jO                         jQ                  |       || jU                  |       | j9                  d| jV                         y # tR        $ r5 | jO                         jQ                  tG        jH                  |             Y mw xY w)Nparent   Fr      T)r   notify::expanded ^  r(  zdelete-event),r   Dialogr+   _expanded_sizedebconfset_border_widthset_resizableget_content_areaset_spacingr   button_cancelget_action_arear   r   r   iconVBoxr   
label_roler/   r   r   r   r   r9   rY   r   expanderr8   _on_expandedr   r.   	set_titlerealizeset_size_requestr   
WMFunctionMOVERESIZE
get_windowset_functions	TypeErrorr0   _on_dialog_delete_event)	r1   r2   rK  r   rS  r   vboxvbox_progress	functionss	            r#   r+   zAptProgressDialog.__init__<  s   

D0"a 5!++A.,[9))$*<*<eUANxxza M			5$2xxz))+%%a+a8
!!!$&(  tQ?#%


%%dN;  UD!<udA6dD!,*H=0$2C2CDtT15**4tQ? r&&sB/NN''#..*?*??		GOO++I6 "  -^T%A%AB  	GOO++CNN9,EF	Gs   N ;OOc                 8    | j                   j                          yr   )rX  r   )r1   dialogevents      r#   rh  z)AptProgressDialog._on_dialog_delete_eventp  s    ""$r%   c                    |j                         sK| j                  j                  j                         | j	                         f| _        | j                  d       y | j
                  rn| j                  d       | j
                  \  }\  }}|| j                  j                  j                         k7  r| j                          y | j                  ||       y | j                  d       | j                          y )NFT)	get_expandedr]  r   get_visibleget_sizerR  rU  _resize_to_show_detailsresize)r1   r]  paramterm_visiblestored_widthstored_heights         r#   r^  zAptProgressDialog._on_expandedt  s     $$&#'==#9#9#E#E#G#'==?#4Du%  t$:>:M:M7L7< t}}55AACC ,,.L-8t$((*r%   c                    | j                         \  }}| j                  j                         j                  }| j                  j                         j                  }| j                  j
                  j                         rm| j                  j
                  j                         dz  }| j                  j
                  j                         dz  }| j                  ||z
  |z   ||z
  |z          y| j                  |dz   |dz          y)a  Resize the window to show the expanded details.

        Unfortunately the expander only expands to the preferred size of the
        child widget (e.g showing all 80x24 chars of the Vte terminal) if
        the window is rendered the first time and the terminal is also visible.
        If the expander is expanded afterwards the window won't change its
        size anymore. So we have to do this manually. See LP#840942
        r   r   r   rt   N)
rr  r]  get_allocationrk   rl   r   rq  get_char_widthget_char_heightrt  )r1   	win_width
win_height	exp_width
exp_heightterminal_widthterminal_heights          r#   rs  z)AptProgressDialog._resize_to_show_details  s     !%	:MM00288	]]113::
==!!--/!]]33BBDrIN"mm44DDFKOKK2Y>'*4zAC KK	Cc)9:r%   c                     |t         k(  r6| j                  j                  j                         r| j	                          y y y r   )r   r]  r   rq  rs  r   s      r#   r9   z$AptProgressDialog._on_status_changed  s9     ''&&224((* 5 (r%   c                 ,    | j                  |||||      S )ax  Run the transaction and show the progress in the dialog.

        Keyword arguments:
        attach -- do not start the transaction but instead only monitor
                  an already running one
        close_on_finished -- if the dialog should be closed when the
                  transaction is complete
        show_error -- show a dialog with the error message
        )_run)r1   attachclose_on_finished
show_errorreply_handlererror_handlers         r#   runzAptProgressDialog.run  s!     yy!2J&7 	7r%   c              #     K   	 | j                   j                  d| j                  ||      }| j                  j	                  |       |r| j                   j                          nE| j                  r| j                   j                  d       | j                   j                          | j                          |r |        y y # t        $ r}|r	 ||       n Y d }~y d }~ww xY ww)Nr   gnome)r   r8   r   r.   r7   syncrS  set_debconf_frontendr  show_all	Exception)r1   r  r  r  r  r  r;   errors           r#   r  zAptProgressDialog._run  s     	 ##++J8I8I,=zKCMM  %'',,..<<++@@II''++--MMO    	e$ %	s/   C(B7C ;C(	C%C C( C%%C(c                 x    t        |      }| j                  |       | j                  j                  d|z         y)z8Show the role of the transaction in the dialog interfacez<big><b>%s</b></big>N)r   r_  r\  r   )r1   r2   rQ   rN   s       r#   rM   z"AptProgressDialog._on_role_changed  s0    3I>t""#9D#@Ar%   c                 $   | j                   D ]  }t        j                  |        g | _         | j                   j                  |j	                  d| j
                               | j                   j                  |j                  d| j                               | j                   j                  |j                  d| j                               | j                   j                  |j                  d| j                               | j                  ||j                         | j                  j                  |       | j                  j                  |       | j                  j                  |       | j                  j                  |       || _        y)z5Connect the dialog to the given aptdaemon transactionr5   rL   zmedium-requiredzconfig-file-conflictN)r.   r   r6   r7   connect_afterr9   r8   rM   _on_medium_required_on_config_file_conflictrN   r   r0   rZ  r   r]  r   r:   s      r#   r0   z!AptProgressDialog.set_transaction  sC   == 	$Cs#	$%%&6&*&=&=?	@ 	[00151F1FH 	I[001B151I1IK 	L[001G!::< 	=k;+;+;<%%k2		!!+.

"";/%%k2'r%   c                    t        |||       }|j                         }|j                          |t        j                  j
                  k(  r| j                  j                  |       y | j                  j                          y r   )	r   r  r   r   ResponseTypeOKr   provide_mediumr  )r1   r2   mediumdriverm  ress         r#   r  z%AptProgressDialog._on_medium_required  s^    (=jjl#""%%%,,V4$$&r%   c                 
   t        |||       }|j                         }|j                          |t        j                  j
                  k(  r| j                  j                  |d       y | j                  j                  |d       y )Nreplacekeep)r   r  r   r   r  YESr   resolve_config_file_conflict)r1   r2   oldnewrm  r  s         r#   r  z*AptProgressDialog._on_config_file_conflict  sd    ,S#t<jjl#""&&&::3	J::3Gr%   c                     |r| j                          |t        k(  rB|r@t        | j                  j                  |       }|j                          |j                          | j                  d       y )Nr   )r   EXIT_FAILEDr   r   r  r  emit)r1   r2   rB   closer  err_dias         r#   r   zAptProgressDialog._on_finished  sN    IIK[ Z$T%6%6%<%<dCGKKMLLN		*r%   )NNTT)FTTNN)rC   rD   rE   rF   r   SignalFlags	RUN_FIRST	TYPE_NONE__gsignals__r+   rh  r^  rs  r9   r   r  r   r  rM   r0   r  r  r   rI   r%   r#   r   r   3  s    
 !4!4!>!>!(!2!2B!8 9L @D2Ch+,;(+ CG.27 7    ,B(*'Hr%   r   c                   "    e Zd ZdZ	 	 ddZd Zy)_ExpandableDialogzDialog with an expander.Nc                    |s*t         j                  t         j                  j                  f}t         j                  j                  | |       | j                  d        | j                  |  | j                  d       | j                  d       | j                         j                  d       |st         j                  }t         j                  j                  |t         j                  j                         }|j#                  dd       t        j$                         }	|	j                  d       |	j                  d       t        j&                         }
|
j                  d       |	j)                  |ddd       |	j)                  |
ddd       t        j*                         | _        | j,                  j/                  d       | j,                  j#                  dd       | j,                  j1                  d       |
j)                  | j,                  ddd       | j                         j)                  |	ddd       t        j2                  |      | _        | j4                  j                  d       | j4                  j7                  d       | j4                  j9                  d	| j:                         d
| _        |
j)                  | j4                  ddd       d}|rd|z  }|r|r|dz  }||z  }| j,                  j?                  |       |r| j4                  jA                  |       y
| j4                  jC                  d       y
)a3  Return an _AptDaemonDialog instance.

        Keyword arguments:
        parent -- set the dialog transient for the given Gtk.Window
        stock_type -- type of the Dialog, defaults to Gtk.STOCK_DIALOG_QUESTION
        expanded_child -- Widget which should be expanded
        expander_label -- label for the expander
        title -- a news header like title of the dialog
        message -- the message which should be shown in the dialog
        buttons -- tuple containing button text/reponse id pairs, defaults
                   to a close button
        rJ  rO  FrL  rM  r   Tr   rN  Nz<b><big>%s</big></b>z

)"r   STOCK_CLOSEr  CLOSErQ  r+   r_  add_buttonsrU  rT  rV  rW  STOCK_DIALOG_QUESTIONr*   new_from_stockrG   rH   r/   r   r[  r   r   r   set_selectableset_line_wrapr   r]  set_use_underliner8   r^  rR  r   r   r   )r1   rK  
stock_typeexpanded_childexpander_labeltitler?  buttonsrZ  	hbox_base	vbox_leftr   s               r#   r+   z_ExpandableDialog.__init__  sy    (8(8(>(>?G

D0r'"5!a ++B/22Jyy''
CLL4G4GH1a HHJ	b!""1%HHJ	b!T5$2YdA6YY[


!!$'

  A&

  &TZZa8**9dD!D>:!!!$''-0$2C2CD"T]]D$:)E1DGOD

d#MMn-MM''.r%   c                 2   |j                         rL| j                  d       | j                  r.	 | j                  | j                  d   | j                  d          y y | j                         | _        | j                  d       y # t        t
        f$ r Y y w xY w)NTr   r   F)rp  rU  rR  rt  
IndexErrorrg  rr  )r1   r]  ru  s      r#   r^  z_ExpandableDialog._on_expandedB  s      "t$""KK 3 3A 68K8KA8NO # #'--/Du%	 #I. s   ,B BB)NNNNNNN)rC   rD   rE   rF   r+   r^  rI   r%   r#   r  r    s    "DHHL:/x&r%   r  c                       e Zd ZdZddZy)r   z Dialog to ask for medium change.Nc                    t         j                  j                  | |t         j                  j                         t        d      |z  }t        d      |z  }| j                  d|d|       | j                  t         j                  t         j                  j                  t        d      t         j                  j                         | j                  t         j                  j                         y )N)rK  typezCD/DVD '%s' is requiredzXPlease insert the above CD/DVD into the drive '%s' to install software packages from it.z<big><b>z</b></big>

	C_ontinue)r   MessageDialogr+   MessageTypeINFOr   r   r  r   r  CANCELr  set_default_response)r1   r  r  rK  r   r<  s         r#   r+   z AptMediumRequiredDialog.__init__X  s    ""4(+(<(< 	# 	> *+f4 6 79>?dCD))3+;+;+B+B;)9)9)<)<	>!!#"2"2"5"56r%   r   rC   rD   rE   rF   r+   rI   r%   r#   r   r   T  s
    *7r%   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
r   zODialog to confirm the changes that would be required by a
    transaction.
    Nc                 6
   t         j                  j                  | |       | j                  t         j                  t         j
                  j                         | j                  t        d      t         j
                  j                         || _	        || _
        t        |t        j                        r,| j                          | j                  j!                  |       n| j!                  |       | j#                  d       | j%                  d       | j'                         j)                  d       t         j*                  j-                  t         j.                  t         j0                  j2                        }|j5                  dd       t        j6                         }|j)                  d       |j%                  d       t        j8                         }|j)                  d       |j;                  |ddd       |j;                  |ddd       t        j<                         | _        | j>                  jA                  d       | j>                  j5                  dd       |j;                  | j>                  ddd       | j'                         j;                  |ddd       t        jB                  tD        jF                        | _$        t         jJ                  jM                  | jH                        | _'        | jN                  jQ                  d       | jN                  jS                  d       t        jT                         | _+        | jN                  jY                  | jV                         t        jZ                         }| jV                  j;                  |d       | jV                  j]                  || j^                  d       t        j`                         }| jV                  j;                  |d       | jV                  j]                  || jb                  d       t        jd                         | _3        | jf                  ji                  t         jj                  jl                  t         jj                  jl                         | jf                  jo                  t         jp                  jr                         | jf                  ju                  | jN                         |j;                  | jf                  ddd       | jw                  t         j
                  j                         y)	aH  Return an AptConfirmDialog instance.

        Keyword arguments:
        trans -- the transaction of which the dependencies should be shown
        cache -- an optional apt.cache.Cache() instance to provide more details
                 about packages
        parent -- set the dialog transient for the given Gtk.Window
        rJ  r  TrL  rM  r   FN)<r   rQ  r+   
add_buttonr   r  r  r   r  cacher   
isinstancer   Windowr`  windowset_transient_forrU  rT  rV  rW  r*   r  r  rG   rH   r/   r   r[  r   r   r   r  	TreeStorer   r  	treestorer  new_with_modeltreeviewset_headers_visibler  r  rD  r  CellRendererPixbufr  render_package_iconr  render_package_descr   scrolledr   r   r   r   r   r   r   r  )	r1   r   r  rK  rZ  r  r  	cell_icon	cell_descs	            r#   r+   zAptConfirmDialog.__init__l  su    	

D0((#*:*:*A*AB+(8(8(;(;<

fcjj)LLNKK))&1""6*4 a ++B/yy''(A(A(+(;(;=1a HHJ	b!""1%HHJ	b!T5$2YdA6YY[


!!$'

  A&TZZa8**9dD!Dw':':;33DNNC))%0$$T*((*##DKK0**,	y%0&&y$2J2J'+	-((*	y$/&&y$2J2J'+	-**,  !9!9!$!9!9	;%%cnn&>&>?$--(T]]D$:!!#"2"2"9"9:r%   c                 z	   | j                   j                          t        t        d      t        d      t        d      t        d      t        d      t        d      t        d      g      D ]  \  }}| j                  j
                  |   s | j                   j                  dd	|z  g      }| j                  j
                  |   D ]>  }| j                  |      D ](  }| j                   j                  |t        |      g       * @  t        d
      }t        | j                         dk(  r.| j                   j                  t        j                  j                               }| j                  j                          | j                  j!                  |       | j                  j#                  d       | j                  j
                  t$           rt        d      }n| j                  j
                  t&           rt        d      }n| j                  j
                  t(           rt        d      }n| j                  j
                  t*           rt        d      }nz| j                  j
                  t,           rt        d      }nQ| j                  j
                  t.           rt        d      }n(| j                  j
                  t0           rt        d      }t        |      dk  r^| j3                  d       | j4                  j7                  t        j8                  j:                  t        j8                  j<                         n^| j                  j?                  dd       nAt        d      }| j                  j?                  dd       | j                  jA                          | j                  jB                  r=|dz  }|t        d      tE        jF                  | j                  jB                        z  z  }| j                  jH                  dk  r>|dz  }|t        d      tE        jF                  | j                  jH                        z  z  }nV| j                  jH                  dkD  r=|dz  }|t        d      tE        jF                  | j                  jH                        z  z  }| jJ                  jM                  dd|       y)z2Show a message and the dependencies in the dialog.Install	ReinstallRemovePurgeUpgrade	DowngradezSkip upgradeNz	<b>%s</b>z0Please take a look at the list of changes below.r   Fz'Additional software has to be installedz*Additional software has to be re-installedz%Additional software has to be removedz$Additional software has to be purgedz&Additional software has to be upgradedz(Additional software has to be downgradedzUpdates will be skippedrL  rP  rt   zAdditional changes are required
z %sB will be downloaded in total.r   z %sB of disk space will be freed.z!%sB more disk space will be used.z<b><big>z</big></b>

)'r  clear	enumerater   r   dependenciesr7   map_packagestrrh   
filter_newr   TreePath	new_firstr  
expand_allr  set_show_expandersPKGS_INSTALLPKGS_REINSTALLPKGS_REMOVE
PKGS_PURGEPKGS_UPGRADEPKGS_DOWNGRADE	PKGS_KEEPrU  r  r   r   r   r   ra  collapse_alldownloadr   r   spacer   r   )r1   indexr"   piterpkgobjectfiltered_storer  s           r#   _show_changeszAptConfirmDialog._show_changes  s   #Qy\%&{^%&x[%&wZ%&y\%&{^%&~%6%8 9 	DJE3 zz&&u---d[35F4GH::2259 DC"&"2"23"7 D--ec&k]CDD	D" BCt~~!#!^^66&&(*NMM$$&MM##N3MM,,U3zz&&|4CD((8FG((5AB((4@A((6BC((8DE((334>"Q&""5)(()A)A),)=)=? ..sC878EMM**34MM&&(::4KCA89**4::+>+>?@ AC::a4KCA89**4::+;+;<= >CZZ!4KCA9:**4::+;+;<= >C

eSIJr%   c                     |gS )a  Map a package to a different object type, e.g. applications
        and return a list of those.

        By default return the package itself inside a list.

        Override this method if you don't want to store package names
        in the treeview.
        rI   )r1   r  s     r#   r  zAptConfirmDialog.map_package  s     ur%   c                     |j                  |      }|j                         dk(  rd|j                  _        nd|j                  _        d|j                  _        y)zData func for the Gtk.CellRendererPixbuf which shows the package.

        Override this method if you want to show custom icons for
        a package or map it to applications.
        r   FTzapplications-otherN)r:  	get_depthr  rz   r-   )r1   rD  rE  r   rW   rF  paths          r#   r  z$AptConfirmDialog.render_package_icon  sE     ~~d#>>q !&DJJ!%DJJ3

r%   c                 |   |j                  |d      }|sy	 |j                  d      dd \  }}	 |r#|d|d| j                  |   j                  d}	n|d| j                  |   j                  d}	|j                  d|	       y# t        $ r |}d}Y gw xY w# t
        t        f$ r |r	|d|d	}	nd
|z  }	Y Gw xY w)zData func for the Gtk.CellRendererText which shows the package.

        Override this method if you want to show more information about
        a package or map it to applications.
        r   N=r&   z (z	)
<small>r+  r)  )z%sr
  )r6  split
ValueErrorr  summaryr4  rg  set_property)
r1   rD  rE  r   rW   rF  rC  pkg_namepkg_versionr   s
             r#   r  z$AptConfirmDialog.render_package_desc   s     a(	$)KK$4Qq$9!Hk	'k4::h+?+G+GI djj2::< 	(D)  	HK	 )$ 	'$,k:h		's#   B AB BBB;:B;c                     | j                          | j                          t        j                  j	                  |       S r   )r  r  r   rQ  r  rw   s    r#   r  zAptConfirmDialog.run  s*    zz~~d##r%   r}   )
rC   rD   rE   rF   r+   r  r  r  r  r  rI   r%   r#   r   r   f  s(    9;v?KB	4*8$r%   r   c                       e Zd ZdZddZd Zy)r   zSDialog to resolve conflicts between local and shipped
    configuration files.
    Nc                 
   || _         || _        t        d      |z  }t        d      }t        j                  dd      }|j                  t        j                  j                  t        j                  j                         |j                  t        j                  j                         t               | _        | j                  j                  dd       |j                  | j                         t        j!                  | |t        d      |||t        d      t        j"                  j$                  t        d	      t        j"                  j&                  f
       | j)                  t        j"                  j&                         y )NzLReplace your changes in '%s' with a later version of the configuration file?zRIf you don't know why the file is there already, it is usually safe to replace it.T)hexpandvexpandr(  rt   _Changes_Keep_Replace)rK  r  r  r  r?  r  )	from_pathto_pathr   r   r   r   r   r   r   r   r   r   diffviewra  r   r  r+   r  NOr  r  )r1   r  r  rK  r  r"   r  s          r#   r+   z$AptConfigFileConflictDialog.__init__(  s%   " , -/89 . /%%dDACNN44cnn6N6NO  !9!9: 
&&r3/T]]#""423J-2:).,-gJ8H8H8K8K,-jM,/,<,<,@,@,B	 	# 	C 	!!#"2"2"6"67r%   c                     | j                          | j                  j                  | j                  | j                         t
        j                  |       S r   )r  r  	show_diffr  r  r  r  rw   s    r#   r  zAptConfigFileConflictDialog.run?  s8    = $$T**r%   r   )rC   rD   rE   rF   r+   r  rI   r%   r#   r   r   "  s    8.+r%   r   zp^@@ \-(?P<from_start>[0-9]+)(?:,(?P<from_context>[0-9]+))? \+(?P<to_start>[0-9]+)(?:,(?P<to_context>[0-9]+))? @@c                        e Zd ZdZdZd Zd Zy)r   z'Shows the difference between two files.u   […]
c                    t        j                         | _        t         j                  j	                  | | j                         | j                  dd       | j                  d       | j                  j                         }t         j                  j                  d      }|j                  d       |j                  |       t         j                  j                  d      }|j                  dd	       |j                  |       t         j                  j                  d
      }|j                  dd	       |j                  |       t         j                  j                  d      }|j                  dd	       |j                  |       y )N)buffereditableFdefaultMono)fontr   z#8ae234)r#  
backgroundremovez#ef2929numberz#eee)r   
TextBuffer
textbufferTextViewr+   r  set_cursor_visibleget_tag_tableTextTagr  set_propertiesr   )r1   tagstag_defaulttag_add
tag_removetag_nums         r#   r+   zDiffView.__init__O  s,   ..*d4??;*e,&,,.kkooi0"""/++//%(F*3 	 	5[[__X.
!!v-6 	" 	8++//(+F*0 	 	2r%   c                     	 t        |      5 }|j                         }ddd       t        |      5 }|j                         }ddd        fd}d} j                  j	                         }t        j                  d      D ]/  }	|	j                  d      rRt        j                  t        |	      }
|
s2t        |
j                  d            }|dkD  sR || j                  d	       g|	j                  d
      s|	j                  d      r|	j                  d      r#|dz  } ||t        |      d        |||	d	       |	j                  d      r#|dz  } ||t        |      d        |||	d       |	j                  d      sdt        t        |            z  } |||d        |||	d       2 y# 1 sw Y   xY w# 1 sw Y   xY w# t        $ r Y yw xY w)z&Show the difference between two files.Nc                     | j                         }j                  j                  | |       j                  j                  |j                  j	                  |      |        y r   )
get_offsetr(  insertapply_tag_by_nameget_iter_at_offset)rW   r   tagoffsetr1   s       r#   insert_tagged_textz.DiffView.show_diff.<locals>.insert_tagged_texts  sL    __&FOO""4.OO--T__77?Gr%   r   rO  )linetermz@@
from_startr   r!  z---z+++r   r&  -r%  +r   )open	readlinesIOErrorr(  get_start_iterdifflibunified_diff
startswithrematchREGEX_RANGEr,  groupELLIPSISr  rh   )r1   r  r  fp
from_linesto_linesr;  line_numberrW   linerH  spacess   `           r#   r  zDiffView.show_difff  s   	i ,B\\^
,g *"<<>*	G --/((XK 	6Dt$d3!%++l";<?&tT]]IF'4??5+A%q "4[)98D"4y9%q "4[)98D"4x8%s3{#344"4:"4u5+	6%, ,* * 		s>   G F8G GG 8G=G G
G 	GGN)rC   rD   rE   rF   rK  r+   r  rI   r%   r#   r   r   I  s    1H.+6r%   r   c                       e Zd ZdZddZy)_DetailsExpanderMessageDialogz*
    Common base class for Apt*Dialog
    Nc           	         t        j                         }|j                  t         j                  j                  t         j                  j                         |j                  t         j                  j                         t        j                         }|j                  t         j                  j                         |j                         }|j                  |       t        j                  | |t!        d      ||||       | j#                          |r|j%                  |       y | j&                  j)                  d       y )N_Details)rK  r  r  r  r?  r  F)r   r   r   r   r   r   r   r   r)  set_wrap_modeWrapModeWORD
get_bufferr   r  r+   r   r  insert_at_cursorr]  set_visible)	r1   r   r<  r  detailsrK  r  textviewr  s	            r#   r+   z&_DetailsExpanderMessageDialog.__init__  s    %%'CNN44cnn6N6NO  !9!9:<<>s||001$$&X""423J-2:)-t.2	 	# 	4
 	##G,MM%%e,r%   r}   r  rI   r%   r#   rS  rS    s    -r%   rS  c                       e Zd ZdZddZy)r   zM
    Dialog for aptdaemon errors with details in an expandable text view
    Nc                     t        |j                        }t        |j                        }t        j	                  | ||t
        j                  |j                  |       y r   )get_error_string_from_enumcodeget_error_description_from_enumrS  r+   r   STOCK_DIALOG_ERRORr\  )r1   r  rK  r   r<  s        r#   r+   zAptErrorDialog.__init__  sD    )%**5.uzz:%..$c44emmV	Mr%   r}   r  rI   r%   r#   r   r     s    Mr%   r   );rF   
__author____all__rD  r    r   r   rG  girequire_versionapt_pkggi.repositoryr   r   r   r   r   r   rO  r   enumsdeferr   defer.utilsr   r   rG  rf   	COLUMN_IDCOLUMN_PACKAGEr*   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   r  r   rQ  r   r  r  r   r   r   rI  r)  r   rS  r   rI   r%   r#   <module>ro     s  * 5
   	 
 	 	   5& !   5%     5%    !        " !2 a>#'CII #'L'- '.N+ N+bD399 D6SYY B7S__ 7t@% @%F%#,, %8%"cjj %"Pd(s|| d(NL

 L^O&

 O&d7c// 7$y$szz y$x +"3  +FGH6s|| H6V-$5 -2M2 Mr%   