o
    ×EGb³ ã                   @   s,  d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlmZ	 d dlZd dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZe dd¡ e dd¡ e dd¡ e d	d
¡ d dlmZ d dlmZmZmZmZmZ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!m!Z! d dl"Z"d dl#Z"d dl$m%Z% d dl$Z"d dl&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, ej-j.j/dd ej0dk rÏe 1¡  e2dƒ\Z3Z4Z5e6e2dƒƒ\Z7Z8dZ9dZ:e6e2dƒƒ\Z;Z<Z=Z>Z?e2dƒ\Z@ZAZBZCdZDd ZEd!ZFG d"d#„ d#eGƒZHd$d%„ ZId&d'„ ZJG d(d)„ d)e%eƒZKdS )*é    )Úabsolute_importÚprint_functionN)ÚgettextÚGdkz3.0ÚGtkÚHandyÚ1ÚPackageKitGlibz1.0)r	   )ÚGObjectr   r   ÚGioÚGLibr   é   )ÚSimpleGtkbuilderApp)Ú	DialogAdd)ÚDialogMirror)Ú
DialogEdit)ÚDialogCacheOutdated)ÚDialogAddSourcesList)ÚUbuntuProPage)ÚSoftwareProperties)Úget_ua_statusÚget_ua_service_statusÚcurrent_distroÚis_current_distro_lts)ÚdetectT)Zset_as_default)é   é	   r   r   é   é   é   ÚsecurityÚupdatesÚ	backportsc                   @   s(   e Zd ZdZdZdZdZdZdd„ ZdS )ÚUpdateSubscriptionsFc                 C   sP   | j rtS | jr| jr| jrtS | jr| jr| jstS | jr&| js&| js&tS tS ©N)ÚotherÚUPDATES_CUSTOMr    r!   r"   ÚUPDATES_ALLÚUPDATES_RECOMMENDEDÚUPDATES_SECURITY©Úself© r,   úN/usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.pyÚ
get_statusu   s   zUpdateSubscriptions.get_statusN)	Ú__name__Ú
__module__Ú__qualname__r    r!   r"   r%   Úinconsistentr.   r,   r,   r,   r-   r#   n   s    r#   c                 C   s   | j dkrt d¡ dS dS )zùLog an error if the DBus exception was raised because the user canceled
    the authentication prompt shown when changing apt sources/configuration.

    Return True if it is, so that calling code can do further processing,
    False otherwise.
    z6com.ubuntu.SoftwareProperties.PermissionDeniedByPolicyz4Authentication canceled, changes have not been savedTF)Z_dbus_error_nameÚloggingÚerror)Zdbus_exceptionr,   r,   r-   Ú'maybe_log_authentication_canceled_error   s   ÿ
r5   c                 C   sF   t j| t jjt jjt jjdd}| d||f ¡ | 	¡  | 
¡  dS )z show a error dialog N)ÚparentÚflagsÚtypeÚbuttonsZmessage_formatz<big><b>%s</b></big>

%sF)r   ZMessageDialogZDialogFlagsZMODALZMessageTypeZERRORZButtonsTypeÚOKÚ
set_markupÚrunZdestroy)Zparent_windowZsummaryÚmsgÚdialogr,   r,   r-   r4      s   ür4   c                   @   sX  e Zd Zd“dd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd”d!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd•d7d8„Zd9d:„ Zd;d<„ Zd=d>„ Z d?d@„ Z!dAdB„ Z"dCdD„ Z#dEdF„ Z$dGdH„ Z%dIdJ„ Z&dKdL„ Z'dMdN„ Z(dOdP„ Z)dQdR„ Z*dSdT„ Z+dUdV„ Z,dWdX„ Z-dYdZ„ Z.d[d\„ Z/d]d^„ Z0d_d`„ Z1dadb„ Z2dcdd„ Z3dedf„ Z4dgdh„ Z5didj„ Z6dkdl„ Z7dmdn„ Z8dodp„ Z9dqdr„ Z:dsdt„ Z;d•dudv„Z<dwdx„ Z=dydz„ Z>d•d{d|„Z?d}d~„ Z@dd€„ ZAdd‚„ ZBdƒd„„ ZCd…d†„ ZDd•d‡dˆ„ZEd‰dŠ„ ZFd‹dŒ„ ZGddŽ„ ZHdd„ ZId‘d’„ ZJdS )–ÚSoftwarePropertiesGtkNc           
      C   sÄ  t j| ||d tj d¡ t ¡  tj ¡ }| 	tj
j¡ tj| tj |dd¡dd |rH| j tjj¡ | j ¡  z| j |¡ W n   Y || _|r„|jdkr„| j tjj¡ | j ¡  z
t t|jƒ¡}W n tyt   d}Y nw |r„z| j |¡ W n   Y tj ¡ }d|v rœtj d¡| _ | j  !d¡| _"nd| _ d	| _"| j# $d
¡ t% &¡ }| 'dd¡}	t% (|	d¡| _)| j) *d| j+¡ | j) *d| j,¡ | j) *d| j-¡ | j) *d| j.¡ | j) *d| j/¡ | j) 0¡  | j ¡  i | _1|  2¡  d| _3|  4¡  |  5¡  |  6¡  |  7¡  |  8¡  |  9¡  |  :¡  |  ;¡  |  <¡  |  =¡  |  >¡  |  ?¡  | j@ Ad| jB¡ |r=|jCr=| j@ Dt|jCƒ¡ |dkr^tj E|¡dtFjG Hd¡tFjG Id¡f kr`|  J|¡ dS dS dS )z« Provide a GTK based graphical user interface to configure
            the used software repositories, corresponding authentication keys
            and update automation )ÚoptionsÚdatadirzsoftware-propertiesZ
gtkbuilderzmain.ui)ÚdomainNzcom.ubuntu.update-notifierúregular-auto-launch-intervalr   Fzcom.ubuntu.SoftwarePropertiesú/ZSourcesListModifiedZConfigModifiedZKeysModifiedZ
AuthFailedZCdromScanFailedzswitch-pagez%s%szDir::EtczDir::Etc::sourcelist)Kr   Ú__init__r   ZWindowZset_default_icon_namer   ZinitZStyleManagerÚget_defaultZset_color_schemeZColorSchemeZPREFER_LIGHTr   ÚosÚpathÚjoinÚwindow_mainZset_type_hintr   ZWindowTypeHintZDIALOGÚshowZset_transient_forr@   ÚtoplevelZwindow_foreign_newÚintÚAttributeErrorr   ZSettingsZlist_schemasÚnewÚsettingsÚget_intÚinitial_auto_launchÚcombobox_other_updatesÚset_sensitiveÚdbusZ	SystemBusZ
get_objectZ	InterfaceÚbackendZconnect_to_signalÚon_sources_list_modifiedÚon_config_modifiedÚon_keys_modifiedÚon_auth_failedÚon_cdrom_scan_failedZReloadÚhandlersÚinit_apt_cacheÚpk_taskÚinit_auto_updateÚinit_release_upgradesÚshow_auto_update_levelÚ	init_keysÚ	show_keysÚinit_isv_sourcesÚshow_isv_sourcesÚshow_cdrom_sourcesÚinit_distroÚshow_distroÚinit_driversÚinit_ubuntu_proZnotebook_mainÚconnectÚon_main_notebook_page_switchedZopen_tabZset_current_pageÚabspathÚapt_pkgZconfigZfind_dirÚfindÚ	open_file)
r+   rA   r@   Úfiler6   Zstyle_managerrL   Zall_schemasZbusÚproxyr,   r,   r-   rE   ž   s¤   
þ

ÿ
ÿÿÿÿÿ


	
ÿÿýzSoftwarePropertiesGtk.__init__c                    sF   |ˆ j krˆ j d¡ ˆ jst ‡ fdd„¡ d S d S ˆ j d¡ d S )NFc                      s   t jˆ jd ¡ S )N)Útarget)Ú	threadingZThreadÚdetect_driversÚstartr,   r*   r,   r-   Ú<lambda>  s    zFSoftwarePropertiesGtk.on_main_notebook_page_switched.<locals>.<lambda>T)Zvbox_driversÚbutton_revertÚset_visibleÚdetect_calledr   Úidle_add)r+   ZnotebookZpageZpage_numr,   r*   r-   rl     s   
ÿz4SoftwarePropertiesGtk.on_main_notebook_page_switchedc                 C   s    t  ¡ rt  ¡  t  ¡ sdS dS )z) abstract interface to keep the UI alive N)r   Zevents_pendingZmain_iterationr*   r,   r,   r-   Úupdate_interface  s   ÿz&SoftwarePropertiesGtk.update_interfacec                 C   s0   |   ¡ }| j |¡ | j d| j¡| j| j< dS )z? setup the widgets that allow configuring the release upgrades ÚchangedN)Úget_release_upgrades_policyÚcombobox_release_upgradesÚ
set_activerk   Ú$on_combobox_release_upgrades_changedr\   )r+   Úir,   r,   r-   r`   !  s   ÿÿz+SoftwarePropertiesGtk.init_release_upgradesc                 C   s<   t  ¡  t  ¡  t  d ¡| _t  | j¡| _t  | j¡| _d S r$   )	rn   Úinit_configZinit_systemÚCacheÚ	apt_cacheÚDepCacheÚdepcacheÚPackageRecordsÚrecordsr*   r,   r,   r-   r]   (  s
   z$SoftwarePropertiesGtk.init_apt_cachec                 C   s,   t  d ¡| _t  | j¡| _t  | j¡| _d S r$   )rn   r„   r…   r†   r‡   rˆ   r‰   r*   r,   r,   r-   Úupdate_apt_cache/  s   z&SoftwarePropertiesGtk.update_apt_cachec                 C   sÆ   | j  ¡  | j  ¡ }i | _t|ƒD ]\}}| |jd¡}|| j|< q|  ¡ }|| j ¡ vr@|dkr@| j  	t
dƒ| ¡ || jd< | jD ]}| j| |krT| j  |¡  nqC| j  d| j¡| j| j < dS )zB Set up the widgets that allow to configure the update automation r   r   zEvery %s dayséÿÿÿÿr}   N)Úcombobox_update_intervalrK   Ú	get_modelÚcombobox_interval_mappingÚ	enumerateÚ	get_valueÚiterÚget_update_intervalÚvaluesZappend_textÚ_r€   rk   Ú#on_combobox_update_interval_changedr\   )r+   Úmodelr‚   ÚrowÚvalueÚupdate_daysÚkeyr,   r,   r-   r_   4  s,   

ÿ

þÿÿz&SoftwarePropertiesGtk.init_auto_updatec                 C   s   |   ¡  | jr.| j d¡}| j ¡ }t|ƒD ]\}}| |jd¡}||kr-| j |¡  nq| j	 
d| j¡| j| j	< | j 
d| j¡| j| j< dS )z>Represent the level of update automation in the user interfacerC   r   r}   N)Úset_security_update_levelrP   rQ   rS   r   r   r   r‘   r€   Úcombobox_security_updatesrk   Úset_sec_update_automation_levelr\   Ú!set_other_update_automation_level)r+   Zlevel_otherr–   r‚   r—   Úlevelr,   r,   r-   ra   U  s$   
þÿ
ÿÿÿz,SoftwarePropertiesGtk.show_auto_update_levelc                 C   s†   |   ¡ }|dkr| j d¡ n| j d¡ |tjks|tjkr'| j d¡ dS |tjkr4| j d¡ dS |tjkrA| j d¡ dS dS )zHFetch the security level, Enable/Disable and set the value appropriatelyNFTr   r   r   )	Úget_update_automation_levelrœ   rT   ÚsoftwarepropertiesZUPDATE_MANUALÚUPDATE_NOTIFYr€   ÚUPDATE_DOWNLOADÚUPDATE_INST_SEC)r+   Z	level_secr,   r,   r-   r›   m  s   
ÿ

ÿz/SoftwarePropertiesGtk.set_security_update_levelc                 C   sj  | j  tdƒ| jj ¡ | j d| j¡| j| j< | j	 
¡ D ]}| j	 |¡ q| jjjD ],}tdƒ| ¡ |jf }tj|d}||_| d| j|j¡| j|< | j	 |¡ | ¡  q+| j 
¡ D ]}| j |¡ q]| jjjD ]1}|jdkrsqkd|jv rœtjd|j|jf d}||_| d| j|¡| j|< | j |¡ | ¡  qktƒ }tƒ s¨d}d}ntd|d	\}	}
td
|d	\}}t|	p¼|ƒ}d|
|fv }t ƒ }|rõtdƒ}z| !dd¡ "d¡\}}}t#j# $|d¡ %¡ }W n t&yô   t'dƒ |j(}Y nw tdƒ}|j(}| j) *|¡ d}t#j# +¡  %¡ }||kr,|r"|j, -dd¡}d| -dd¡ }tdƒ| .d¡ }n||t#j/dd krAtdƒ| .d¡ }n	tdƒ| .d¡ }| j0 |¡ | j1 *d|tdƒf ¡ | j1 2|od| ¡ td ƒ| .d¡ }| j3}| d!| j4¡| j|< t 5¡ }| j6 7|d"¡ | j6 8|d#d$¡ | j6 d!| j9¡| j| j6< t :t;j<t;j<t;j=¡}| j6 >|¡ | j6 ?| j@d%¡ d&S )'z9Setup the user interface elements to represent the distroz%s SoftwareÚtoggledz%s (%s)©Úlabelúdeb-srcZproposedFz	esm-infra)Ústatuszesm-appsÚenabledzExtended Security MaintenanceZexpiresÚ ú+z%Y-%m-%dT%H:%M:%Sz&Unable to determine UA contract expiryzBasic Security Maintenancezhttps://ubuntu.com/esmz LTSzhttps://ubuntu.com/%sÚ.ú-z Ended %s - extend or upgrade nowz%xé<   )Údaysz Ends %s - extend or upgrade soonzActive until %sz<a href="%s">%s</a>u	   Extendâ€¦zEnded %sr}   TÚtextr   r   N)AZlabel_dist_nameÚ	set_labelr”   ÚdistroÚidÚcheckbutton_source_coderk   Ú"on_checkbutton_source_code_toggledr\   Úvbox_dist_compsÚget_childrenÚremoveÚsource_templateZ
componentsZget_descriptionÚnamer   ZCheckButtonÚcompÚon_component_toggledÚaddrK   Údev_boxÚchildrenr8   ÚdescriptionÚtemplateÚon_checkbutton_child_toggledr   r   r   Úboolr   ÚgetÚ	partitionÚdatetimeÚstrptimeÚdateÚ
ValueErrorÚprintZeolZlabel_esm_statusr;   ZnowÚversionÚreplaceÚstrftimeZ	timedeltaZ	label_eolZlabel_esm_subscribery   Úcombobox_updates_subscriptionÚ(on_combobox_updates_subscription_changedÚCellRendererTextÚcombobox_serverÚ
pack_startZadd_attributeÚon_combobox_server_changedÚ	ListStorer
   ÚTYPE_STRINGÚTYPE_BOOLEANÚ	set_modelÚset_row_separator_funcÚis_row_separator)r+   Úcheckbuttonr¼   r§   ÚcheckboxrÂ   r©   Zesm_availableZesm_enabledZinfra_availableZinfra_statusZapps_availableZapps_statusr³   Zeol_textZdtZ_sepZ_tzZeol_dateZesm_urlZtodayZ
distro_verZeol_expiry_textÚcomboboxZcellÚserver_storer,   r,   r-   rg   €  s¼   ÿ
ÿ
þ




ÿþÿ€ÿþ
þ
ÿ
ÿ
ÿÿþz!SoftwarePropertiesGtk.init_distroc                 C   ó0   | j D ]}| | j | ¡r| | j | ¡ qd S r$   )r\   Úhandler_is_connectedÚhandler_block©r+   Úwidgetr,   r,   r-   Úblock_handlersò  ó
   
€þz$SoftwarePropertiesGtk.block_handlersc                 C   rß   r$   )r\   rà   Úhandler_unblockrâ   r,   r,   r-   Úunblock_handlers÷  rå   z&SoftwarePropertiesGtk.unblock_handlersc                 C   s~  |   ¡  | j ¡ D ]}|  |j¡\}}| |¡ | |¡ q	| j ¡ D ]}|  |j	¡\}}| |¡ | |¡ q#t
ƒ }| jjjD ];}|jdkrHq@|j d¡d }|  |¡\}}| j|O  _|r{|tkrhd|_q@|tkrpd|_q@|tkrxd|_q@d|_q@| ¡ }| j}| ¡ }	|tkr¦z	|	 ttƒ¡ W n' ty¥   |	  t!dƒg¡ Y nw z|	 "|	 ttƒ¡¡ W n	 ty»   Y nw | |¡ | #|j ¡ t$| jj%ƒdk rã| j #d¡ | j #d¡ | j& #d¡ n| j #d¡ | j& #d¡ |  '¡ }
|
dkrþ| j& d¡ n|
dkr| j& d¡ | j& d¡ n| j& d¡ | j& d¡ t$|  (¡ ƒd	kr0| j) *¡  | j+ ,¡  n
| j) ,¡  | j+ *¡  | j- ¡ }| .¡  g }| j /¡ D ]>\}}}|  ||dg¡ ||g| j0v rh| j0 "||g¡ n|dkrt|  ||g¡ |dkr‡t$|ƒd | _1| j- | j1¡ qJ| j0D ]\}}|  ||dg¡ qŒ|| _0| jjj2r´|  g d
¢¡ |  t!dƒddg¡ |  3¡  | j4j5dksÆ| j4j6dkr;t7d| jj% ƒ t7d| jj8 ƒ t7dƒ | jj9D ]}|  :|¡ qÞt7dƒ | jj;D ]}|  :|¡ qït7dƒ | jj<D ]}|  :|¡ q t7dƒ | jj=D ]}|  :|¡ qt7dƒ | jj>D ]}|  :|¡ q"t7dƒ | j?D ]
}|  :|¡ q2dS dS )z(Fill the distro user interface with lifer¨   r®   r‹   TZCustomr   FNr   )ÚsepNTúOther...zENABLED COMPS: %szINTERNET COMPS: %szMAIN SOURCESzCHILD SOURCESzCDROM SOURCESzSOURCE CODE SOURCESzDISABLED SOURCESZISV)@rä   r¿   r¸   Zget_comp_child_staterÂ   r€   Zset_inconsistentr·   Zget_comp_download_stater¼   r#   r³   rº   rÀ   r8   r»   Úsplitr2   ÚPOCKET_SECURITYr    ÚPOCKET_UPDATESr!   ÚPOCKET_BACKPORTSr"   r%   r.   rÏ   r   r&   Úget_iter_from_stringÚstrrÊ   Úappendr”   r¹   rT   ÚlenZenabled_compsrµ   Zget_source_code_stateÚget_cdrom_sourcesZscrolledwindow_cdÚhideZscrolledwindow_no_cdrK   rÒ   ÚclearZget_server_listZseen_serverÚactive_serverZ
mirror_setrç   r@   ÚdebugZmassive_debugrË   Zdownload_compsZmain_sourcesZprint_source_entryZchild_sourcesZcdrom_sourcesZsource_code_sourcesZdisabled_sourcesZsourceslist_visible)r+   rÜ   Úactiver2   ZsubscriptionsrÂ   Úpocketr©   rÝ   r–   Zsource_code_staterÞ   Zseen_server_newr»   ÚuriÚsourcer,   r,   r-   rh   ü  sÎ   


€ÿÿ







€
ìz!SoftwarePropertiesGtk.show_distroc              
   C   sÊ   |  ¡ }d}|dkrtj}n|dkrtj}n|dkrtj}z||  ¡ kr-| j |¡ W dS W dS  tj	yd } z(t
|ƒrY| j| j }| j |¡ |  ¡  | j |¡ W Y d}~dS W Y d}~dS d}~ww )zZCall the backend to set the security update automation level to the given
           valuer‹   r   r   r   N)Ú
get_activer¡   r¢   r£   r¤   r    rV   ZSetUpdateAutomationLevelrU   ÚDBusExceptionr5   r\   rœ   rá   r›   ræ   )r+   rã   ÚindexÚstateÚeÚcombo_handlerr,   r,   r-   r   }  s*   ÿü€ÿz5SoftwarePropertiesGtk.set_sec_update_automation_levelc                 C   s0   |  ¡ }| j ¡ }|| d }| j d|¡ dS )zBSet the other update automation level to the given value via gconfr   rC   N)rû   rS   r   rP   Úset_int)r+   rã   rý   r–   r°   r,   r,   r-   rž   “  s   
z7SoftwarePropertiesGtk.set_other_update_automation_levelr   c                 C   s   |  ||¡S )z% Check if a given row is a separator )r   )r+   r–   r‘   Úcolumnr,   r,   r-   rÚ   ›  ó   z&SoftwarePropertiesGtk.is_row_separatorc              
   C   s’   |  ¡ }z	| j |¡ W dS  tjyH } z.t|ƒr=| j| j }| j |¡ |  	¡ }| j 
|¡ | j |¡ W Y d}~dS W Y d}~dS d}~ww )z! set the release upgrades policy N)rû   rV   ZSetReleaseUpgradesPolicyrU   rü   r5   r\   r   rá   r~   r€   ræ   )r+   rÝ   r‚   rÿ   r   r,   r,   r-   r   Ÿ  s   û€ÿz:SoftwarePropertiesGtk.on_combobox_release_upgrades_changedc              
      sB  |  ¡ }|tkr"| ¡ }z| | ttƒ¡¡ W n	 ty!   Y nw ‡ fdd„}z`|tkr=|tdƒ |t	dƒ |t
dƒ n'|tkrQ|tdƒ |t	dƒ |t
dƒ n|tkrd|tdƒ |t	dƒ |t
dƒ ˆ jjjD ]}|jdkrqqi|j d¡d }|tt	t
fvr…||dƒ qiW d S  tjy  } zt|ƒ W Y d }~d S d }~ww )Nc                    sT   d  ˆ jj| ¡}|rt d  |¡¡ ˆ j |¡ d S t d  |¡¡ ˆ j |¡ d S )Nz{}-{}zenabling {}zdisabling {})Úformatr³   Zcodenamer3   ÚinforV   ÚEnableChildSourceÚDisableChildSource)rø   rª   rú   r*   r,   r-   Ú_toggle_child_source¶  s   z\SoftwarePropertiesGtk.on_combobox_updates_subscription_changed.<locals>._toggle_child_sourceTFr¨   r®   r‹   )rû   r&   r   r¹   rî   rï   rÊ   r'   rë   rì   rí   r(   r)   r³   rº   rÀ   r8   r»   rê   rU   rü   r5   )r+   rÝ   rý   r–   r  rÂ   rø   rÿ   r,   r*   r-   rÐ   ­  sD   ÿ	








€û€ÿz>SoftwarePropertiesGtk.on_combobox_updates_subscription_changedc           	   
   C   s  |  ¡ | jkr	dS | ¡ }| ¡ }| |d¡}| |d¡}zK|tdƒkrIt| j| j| j	| j
ƒ}| ¡ }|dkr@| j |¡ W dS | | j¡ W dS |dkrct| j	jƒdkrf|  ¡ | _| j |¡ W dS W dS W dS  tjy€ } zt|ƒ W Y d}~dS d}~ww )zg
        Replace the servers used by the main and update sources with
        the selected one
        Nr   r   ré   )rû   rõ   r   Zget_active_iterr   r”   r   rJ   rA   r³   Zcustom_mirrorsr<   rV   ZChangeMainDownloadServerr€   rñ   Zused_serversrU   rü   r5   )	r+   rÝ   rÞ   r‘   rù   r»   r>   Úresrÿ   r,   r,   r-   rÔ   Õ  s2   ý
þ€ÿz0SoftwarePropertiesGtk.on_combobox_server_changedc              
   C   sb   z|  ¡ dkr| j |¡ W dS | j |¡ W dS  tjy0 } zt|ƒ W Y d}~dS d}~ww )z{
        Sync the components of all main sources (excluding cdroms),
        child sources and source code sources
        TN)rû   rV   ZEnableComponentZDisableComponentrU   rü   r5   )r+   rÛ   r¼   rÿ   r,   r,   r-   r½   õ  s   €ÿz*SoftwarePropertiesGtk.on_component_toggledc              
   C   sf   z|  ¡ dkr| j |j¡ W dS | j |j¡ W dS  tjy2 } zt|ƒ W Y d}~dS d}~ww )zT
        Enable or disable a child repo of the distribution main repository
        FN)rû   rV   r  r»   r  rU   rü   r5   )r+   rÛ   rÂ   rÿ   r,   r,   r-   rÃ     s   €ÿz2SoftwarePropertiesGtk.on_checkbutton_child_toggledc              
   C   s^   z|  ¡ dkr| j ¡  W dS | j ¡  W dS  tjy. } zt|ƒ W Y d}~dS d}~ww )z3 Disable or enable the source code for all sources TN)rû   rV   ZEnableSourceCodeSourcesZDisableSourceCodeSourcesrU   rü   r5   )r+   rÛ   rÿ   r,   r,   r-   r¶     s   €ÿz8SoftwarePropertiesGtk.on_checkbutton_source_code_toggledc              
   C   s`   |   ¡ }| ¡ |kr.z| j | ¡ ¡ W dS  tjy- } zt|ƒ W Y d}~dS d}~ww dS )z5 The user clicked on the popcon paritipcation button N)Zget_popcon_participationrû   rV   ZSetPopconPariticipationrU   rü   r5   )r+   rã   Z	do_popconrÿ   r,   r,   r-   Úon_checkbutton_popcon_toggled  s   €ÿýz3SoftwarePropertiesGtk.on_checkbutton_popcon_toggledc              
   C   s¢   z8t | j| j| j| j| j|ƒ}| ¡ \}}|tkr0g | j_|t	tfv r3|D ]}| j
 t|ƒ¡ q%W dS W dS W dS  tjyP } zt|ƒ W Y d}~dS d}~ww )zAShow a confirmation for adding the channels of the specified fileN)r   rJ   ÚsourceslistÚrender_sourceZget_comparablerA   r<   ÚRESPONSE_REPLACEÚlistÚRESPONSE_ADDrV   ÚAddSourceFromLinerï   rU   rü   r5   )r+   rq   r>   r	  Znew_sourcesrú   rÿ   r,   r,   r-   rp   "  s*   ûü€ÿzSoftwarePropertiesGtk.open_filec           
      C   s4   |j  ¡ }| ¡ }	t|	ƒdkr|  |	d ¡ dS dS )z=Extract the dropped file pathes and open the first file, onlyr   N)ÚdataÚstriprê   rñ   rp   )
r+   rã   ÚcontextÚxÚyÚ	selectionÚtarget_typeÚ	timestamprù   Zuri_splittedr,   r,   r-   Úon_sources_drag_data_received4  s
   
ÿz3SoftwarePropertiesGtk.on_sources_drag_data_receivedc                 C   s   | j  ¡  d S r$   )rJ   ró   r*   r,   r,   r-   ró   <  ó   zSoftwarePropertiesGtk.hidec                 C   s   |  |t¡ ¡  | ¡ ¡dkS )Nr‹   )r   ÚCOLUMN_DESCÚlowerro   )r+   Ústorer  rš   r‘   r  r,   r,   r-   Úsource_search_function?  s   z,SoftwarePropertiesGtk.source_search_functionc              	   C   s  t  tjtjtjtjtj¡| _| j | j¡ t  tjtjtjtjtj¡| _	| j
 | j	¡ | j
 | jt¡ t  ¡ }| dd¡ | dd¡ t jtdƒ|td}| d¡ t  ¡ }| dd¡ | dd¡ | d| j| j¡| j|< t jtdƒ|td	}| j |¡ | j |¡ t  ¡ }| dd¡ | dd¡ t jtdƒ|td}| d¡ t  ¡ }| dd¡ | dd¡ | d| j| j	¡| j|< t jtdƒ|td	}| j
 |¡ | j
 |¡ | j
 t¡ | j
 | jd
¡ zt  | j
t jjt j  !ddd¡gt"j#j$¡ | j
 d| j%¡ W d
S  t&y   Y d
S w )z;
        Read all valid sources into our ListStore
        Zxpadr   ZypadzSoftware Sources)Zmarkupiè  r¥   ZActive)r÷   Nztext/uri-listr   Údrag_data_received)'r   rÕ   r
   r×   rÖ   ZTYPE_PYOBJECTÚcdrom_storeZtreeview_cdromsrØ   Úsource_storeÚtreeview_sourcesrÙ   Úis_separatorÚSTORE_SEPARATORrÑ   Zset_propertyÚTreeViewColumnr”   r  Zset_max_widthZCellRendererTogglerk   Úon_isv_source_toggledr\   ÚCOLUMN_ACTIVEÚappend_columnZset_search_columnZset_search_equal_funcr  Zdrag_dest_setZDestDefaultsZALLZTargetEntryrO   r   Ú
DragActionÚCOPYr  rN   )r+   Z	cell_descZcol_descÚcell_toggleZ
col_activer,   r,   r-   rd   C  sˆ   	üü
ÿÿ

þÿÿ

þÿþ
ÿþz&SoftwarePropertiesGtk.init_isv_sourcesc                 C   ó   |   |¡ dS )ú4Open the edit dialog if a channel was double clickedN)Úon_edit_clicked©r+   ÚtreeviewrH   r  r,   r,   r-   Úon_isv_source_activateŽ  s   z,SoftwarePropertiesGtk.on_isv_source_activatec              
   C   sn   t  d¡ | t|ƒf¡}| |t¡}z| j t|ƒ¡ W dS  t	j
y6 } zt|ƒ W Y d}~dS d}~ww )z&Enable or disable the selected channelg333333Ó?N)ÚtimeÚsleepÚget_iterrM   r   ÚSTORE_SOURCErV   ZToggleSourceUserï   rU   rü   r5   )r+   r+  rH   r  r‘   Úsource_entryrÿ   r,   r,   r-   r&  ’  s   
€ÿz+SoftwarePropertiesGtk.on_isv_source_toggledc                 C   s’   t  t¡| _| j | j¡ t  ¡ }t jtdƒ|dd}| j 	|¡ z| j 
dgtjj¡ | j d| j¡ W n	 ty>   Y nw | j d| j¡ dS )z:Setup the user interface parts needed for the key handlingZKeyr   )r±   )z
text/plainr   r   r  zbutton-press-eventN)r   rÕ   rï   Ú
keys_storeÚtreeview_authrØ   rÑ   r%  r”   r(  Zenable_model_drag_destr   r)  r*  rk   Úon_auth_drag_data_receivedrN   Úshow_auth_context_menu)r+   ÚtrZkeys_colr,   r,   r-   rb   £  s$   
ÿÿþÿzSoftwarePropertiesGtk.init_keysc                 C   st   |j tjjkr6|jdkr8t ¡ }tjtdƒd}| 	d| j
¡ | |¡ | ¡  | d d d d |j|j¡ dS d S d S )Nr   z_Add key from paste datar¦   ZactivateT)r8   r   Z	EventTypeZBUTTON_PRESSÚbuttonr   ZMenuZMenuItemr”   rk   Úon_auth_add_key_from_pasterð   Úshow_allZpopupr2  )r+   rã   ZeventZmenuZ
item_paster,   r,   r-   r:  ¶  s   
ùz,SoftwarePropertiesGtk.show_auth_context_menuc                 C   s@   t  ¡  ¡ }|s
d S |  |¡st| jtdƒtdƒƒ |  ¡  d S )NúError importing keyúCThe selected data may not be a GPG key file or it might be corrupt.)r   Z	ClipboardZwait_for_textÚadd_key_from_datar4   rJ   r”   rc   )r+   rã   Úkeydatar,   r,   r-   r=  À  s   
þz0SoftwarePropertiesGtk.on_auth_add_key_from_pastec           	      C   s8   |  ¡  ¡ }|  |¡st| jtdƒtdƒƒ |  ¡  dS )z1Extract the dropped key and add it to the keyringr?  r@  N)Úget_datar  rA  r4   rJ   r”   rc   )	r+   rã   r  r  r  r  r  r  rB  r,   r,   r-   r9  Ë  s   
þz0SoftwarePropertiesGtk.on_auth_drag_data_receivedc                 C   s   | j  |¡S r$   )rV   ZAddKeyFromData)r+   rB  r,   r,   r-   rA  Ö  s   z'SoftwarePropertiesGtk.add_key_from_datac              
   C   sr   z| j  ¡  W n tjy } z
t|ƒ W Y d}~nd}~ww | jr*| j d| j¡ |  ¡  | j	 
d¡ d| _dS )z6Restore the source list from the startup of the dialogNrC   F)rV   ZRevertrU   rü   r5   rP   r  rR   ra   rx   rT   Úmodified_sourceslist)r+   r<  rÿ   r,   r,   r-   Úon_button_revert_clickedÙ  s   €ÿ
z.SoftwarePropertiesGtk.on_button_revert_clickedc                 C   s   t  ¡  | j d¡ dS )z=The config was changed and now needs to be saved and reloadedTN)rn   rƒ   rx   rT   r*   r,   r,   r-   rX   æ  s   z(SoftwarePropertiesGtk.on_config_modifiedc                 C   s   |   ¡  dS )z6 The apt keys have changed and need to be redisplayed N)rc   r*   r,   r,   r-   rY   ë  r  z&SoftwarePropertiesGtk.on_keys_modifiedc                 C   s6   |   ¡  |  ¡  |  ¡  |  ¡  | j d¡ d| _dS )zCThe sources list was changed and now needs to be saved and reloadedTN)Zreload_sourceslistrh   re   rf   rx   rT   rD  r*   r,   r,   r-   rW   ï  s   
z.SoftwarePropertiesGtk.on_sources_list_modifiedc                 C   s   |   ¡  |  ¡  |  ¡  dS )z% send when the authentication failed N)rW   rX   rY   r*   r,   r,   r-   rZ   ø  s   z$SoftwarePropertiesGtk.on_auth_failedc                 C   s   t | jtdƒtdƒƒ d S )NzError scanning the CDzCould not find a suitable CD.)r4   rJ   r”   r*   r,   r,   r-   r[   ÿ  s   þz*SoftwarePropertiesGtk.on_cdrom_scan_failedc                 C   s€   | j  ¡  |  ¡ D ]}|  |¡}| j  |j ||ddg¡ q	| j ¡ \}}t| j ƒdk s0|du r>| j	 
d¡ | j 
d¡ dS dS )zi Show the repositories of independent software vendors in the
            third-party software tree view FTr   N)r!  rô   Zget_isv_sourcesr  rð   Údisabledr"  Ú
get_cursorrñ   Úbutton_removerT   Úbutton_edit)r+   rú   ÚcontentsZpath_xZpath_yr,   r,   r-   re     s   

ÿþz&SoftwarePropertiesGtk.show_isv_sourcesc                 C   s@   | j  ¡  |  ¡ D ]}|  |¡}| j  |j ||ddg¡ q	dS )zm Show CD-ROM/DVD based repositories of the currently used distro in
            the CDROM based sources list FTN)r   rô   rò   r  rð   rF  )r+   rú   rJ  r,   r,   r-   rf     s   

ÿþz(SoftwarePropertiesGtk.show_cdrom_sourcesc              
   C   sB   z|  ||¡W S  ty  } ztd| ƒ W Y d}~dS d}~ww )z0 Return true if the selected row is a separator zis_seperator returned '%s' NF)r   Ú	ExceptionrË   )r+   r–   r‘   r  rÿ   r,   r,   r-   r#    s   €þz"SoftwarePropertiesGtk.is_separatorc                 C   s,   | j  ¡  | j ¡ D ]	}| j  |g¡ q
d S r$   )r7  rô   Zapt_keyr  rð   )r+   rš   r,   r,   r-   rc   %  s   
ÿzSoftwarePropertiesGtk.show_keysc              
   C   sÖ   | j  ¡ }|dkri| j| }z	| j |¡ W dS  tjyh } zDt|ƒrO|  ¡ }| j	| j  }| jD ]$}| j| |krN| j  
|¡ | j  |¡ | j  |¡  nq1W Y d}~dS W Y d}~dS W Y d}~dS d}~ww dS )z4Set the update automation interval to the chosen oner‹   N)rŒ   rû   rŽ   rV   ZSetUpdateIntervalrU   rü   r5   r’   r\   rá   r€   ræ   )r+   rã   r‚   r˜   rÿ   r™   r   rš   r,   r,   r-   r•   *  s,   


üü€÷üz9SoftwarePropertiesGtk.on_combobox_update_interval_changedc              
   C   sn   t | j| j| j| jƒ}| ¡ }|dkr5z	| j |¡ W dS  tj	y4 } zt
|ƒ W Y d}~dS d}~ww dS )zDShow a dialog that allows to enter the apt line of a to be used repoN)r   rJ   r  rA   r³   r<   rV   r  rU   rü   r5   )r+   rã   r>   Úlinerÿ   r,   r,   r-   Úon_add_clicked<  s   
ÿ€ÿýz$SoftwarePropertiesGtk.on_add_clickedc              
   C   s¢   | j  ¡ }| ¡ \}}|sdS | |t¡}t| j| j|| jƒ}| 	¡ t
jjkrOz| j t|ƒt|jƒ¡ W dS  tjyN } zt|ƒ W Y d}~dS d}~ww dS )z#Show a dialog to edit an ISV sourceN)r"  Úget_selectionÚget_selectedr   ÚLIST_ENTRY_OBJr   rJ   r  rA   r<   r   ÚResponseTyper:   rV   ZReplaceSourceEntryrï   Znew_source_entryrU   rü   r5   )r+   rã   Úselr–   r‘   Zold_source_entryr>   rÿ   r,   r,   r-   r.  G  s$   

ÿ
ÿ€ÿüz%SoftwarePropertiesGtk.on_edit_clickedc                 C   s"   | j  d¡dkr|  |¡ dS dS )r-  Z	sensitiveTN)rI  Úget_propertyr.  r/  r,   r,   r-   Úon_isv_source_activatedX  s   ÿz-SoftwarePropertiesGtk.on_isv_source_activatedc                 C   s‚   | j  ¡ }|s	dS | ¡ \}}|s| j d¡ | j d¡ dS | j d¡ | |t¡}|j 	d¡r9| j d¡ dS | j d¡ dS )zdset the sensitiveness of the edit and remove button
           corresponding to the selected channelNFTzcdrom:)
r"  rN  rO  rI  rT   rH  r   rP  rù   Ú
startswith)r+   r0  rR  r–   r‘   r6  r,   r,   r-   Ú"on_treeview_sources_cursor_changed^  s   
z8SoftwarePropertiesGtk.on_treeview_sources_cursor_changedc              
   C   s~   | j  ¡ }| j  ¡ \}}| |¡}|r=| |t¡}z| j t|ƒ¡ W dS  t	j
y< } zt|ƒ W Y d}~dS d}~ww dS )zRemove the selected sourceN)r"  r   rG  r4  r   rP  rV   ZRemoveSourcerï   rU   rü   r5   )r+   rã   r–   rH   r  r‘   r6  rÿ   r,   r,   r-   Úon_remove_clickeds  s   

€ÿüz'SoftwarePropertiesGtk.on_remove_clickedc              
   C   sØ   t jtdƒ| jt jt jjt jt jjfd}dt	j
v r*t	j dt	j
d  ¡}| |¡ | ¡ }| ¡  |t jjkrjz| j | ¡ ¡sOt| jtdƒtdƒƒ W dS W dS  tjyi } zt|ƒ W Y d}~dS d}~ww dS )z[Provide a file chooser that allows to add the gnupg of a trusted
           software vendorz
Import key)Útitler6   r9   Z	SUDO_USERz~%szError importing selected filezCThe selected file may not be a GPG key file or it might be corrupt.N)r   ZFileChooserDialogr”   rJ   ZSTOCK_CANCELrQ  ZREJECTZSTOCK_OKZACCEPTrG   ÚenvironrH   Ú
expanduserZset_current_folderr<   ró   rV   ZAddKeyÚget_filenamer4   rU   rü   r5   )r+   rã   ZchooserÚhomer	  rÿ   r,   r,   r-   Úadd_key_clicked  s2   

þþ


þÿ€ÿùz%SoftwarePropertiesGtk.add_key_clickedc              
   C   s–   | j  ¡ }| ¡ \}}|dkrdS | |d¡}z| j |dd… ¡s0t| jtdƒtdƒƒ W dS W dS  t	j
yJ } zt|ƒ W Y d}~dS d}~ww )z$Remove a trusted software vendor keyNr   é   zError removing the keyzGThe key you selected could not be removed. Please report this as a bug.)r8  rN  rO  r   rV   Z	RemoveKeyr4   Úmainr”   rU   rü   r5   )r+   rã   r  r–   Za_iterrš   rÿ   r,   r,   r-   Úremove_key_clicked–  s    

þÿ€ÿz(SoftwarePropertiesGtk.remove_key_clickedc              
   C   óB   z| j  ¡  W dS  tjy  } zt|ƒ W Y d}~dS d}~ww )zRestore the original keysN)rV   Z
UpdateKeysrU   rü   r5   ©r+   rã   rÿ   r,   r,   r-   Úon_restore_clicked¦  ó   €ÿz(SoftwarePropertiesGtk.on_restore_clickedc                 C   r,  )zClose the window if requestedF)Úon_close_button)r+   rã   Úargsr,   r,   r-   Úon_delete_event­  s   
z%SoftwarePropertiesGtk.on_delete_eventc                 C   s8   | j dkr| jjdkrt| j| jƒ}| ¡  |  ¡  dS )zpShow a dialog that a reload of the channel information is required
           only if there is no parent definedTFN)rD  r@   Z	no_updater   rJ   rA   r<   Úquit)r+   rã   Údr,   r,   r-   re  ²  s   

ÿÿz%SoftwarePropertiesGtk.on_close_buttonc              
   C   ra  )z& when a cdrom is requested for adding N)rV   ZAddCdromSourcerU   rü   r5   rb  r,   r,   r-   Úon_button_add_cdrom_clicked½  rd  z1SoftwarePropertiesGtk.on_button_add_cdrom_clickedc                 C   s†   | j  d¡ | j d¡ | j d¡ | j d¡ | j d¡ | j d¡ | j tdƒ¡ |t	j
jkrA| d¡}| j |d ¡ d S d S )NFTzApplying changes...Z
percentageg      Y@)Úbutton_driver_revertry   Úbutton_driver_applyÚbutton_driver_restartÚbutton_driver_cancelÚprogress_barÚlabel_driver_actionr²   r”   Ú
packagekitZProgressTypeZ
PERCENTAGErS  Zset_fraction)r+   ZprogressZptyper  Z
prog_valuer,   r,   r-   Úon_driver_changes_progressÄ  s   
þz0SoftwarePropertiesGtk.on_driver_changes_progressc              
   C   s¼   z| j  |¡ W n! ty) } z|  ¡  t| jtdƒt|ƒƒ W Y d }~nd }~ww |s\| j 	d¡ |  
¡  |  ¡  |  ¡  |  ¡  | j 	d¡ | j 	d¡ | j 	d¡ | j d¡ d S d S )NzError while applying changesFT)r^   Zgeneric_finishrK  Úon_driver_changes_revertr4   rJ   r”   rï   ro  ry   Úclear_changesrŠ   Úset_driver_action_statusÚ"update_label_and_icons_from_statusrk  rl  rn  Úscrolled_window_driversrT   )r+   rú   ÚresultÚinstalls_pendingrÿ   r,   r,   r-   Úon_driver_changes_finishÒ  s$   "€þ÷z.SoftwarePropertiesGtk.on_driver_changes_finishc              
   C   st  t  ¡ | _g }g }d}| jD ]9}|jr=| |  | j|¡¡ d|jv r<d}|  	| j|d¡D ]}|jr;| |  | j|¡¡ q,q| |  | j|¡¡ qt
 ¡ | _zR|rfd}|rVd}| j |dd| j| jd| j|¡ |r‹|r}g }|D ]}	|	 d¡d }
| |
¡ qn| j || j| jd| jd¡ | j d¡ | j d¡ | j d¡ W d S  ty¹ } ztd |¡ƒ W Y d }~d S d }~ww )NFZnvidiaTr$   ú;r   z;Warning: install transaction not completed successfully: {})rq  ZTaskr^   Údriver_changesÚcurrent_verrð   Zget_package_idr…   r»   Zget_dependenciesr   ZCancellableÚcancellableZremove_packages_asyncrr  rz  rê   Zinstall_packages_asyncrk  rT   rl  rw  rK  rË   r  )r+   r<  ZinstallsZremovalsZ
has_nvidiaÚpkgZdepry  Z
to_installÚitemr»   rÿ   r,   r,   r-   Úon_driver_changes_applyã  sb   


€
ù	û€ÿz-SoftwarePropertiesGtk.on_driver_changes_applyc                 C   sZ   | j D ]}| d¡ q| jD ]}| j| }| d¡ q|  ¡  | j d¡ | j d¡ d S )NTF)Úno_drvr€   Úorig_selectionrt  rk  rT   rl  )r+   rx   r<  Úaliasr,   r,   r-   rs    s   


z.SoftwarePropertiesGtk.on_driver_changes_revertc                 C   s   | j  ¡  |  ¡  d S r$   )r~  Zcancelrt  )r+   Zbutton_cancelr,   r,   r-   Úon_driver_changes_cancel*  s   
z.SoftwarePropertiesGtk.on_driver_changes_cancelc                 C   s´   dt jv rt jd }nd}|dkr t j d¡r t ddg¡ d S |dkr2t j d¡r2t d	g¡ d S |d
krDt j d¡rDt dg¡ d S |dkrVt j d¡rXt dg¡ d S d S d S )NZXDG_CURRENT_DESKTOPÚUnknownzubuntu:GNOMEz/usr/bin/gnome-session-quitzgnome-session-quitz--rebootZXFCEz/usr/bin/xfce4-session-logoutzxfce4-session-logoutZLXDEz/usr/bin/lubuntu-logoutzlubuntu-logoutZLXQtz/usr/bin/lxqt-leavez
lxqt-leave)rG   rY  rH   ÚexistsÚ
subprocessÚcall)r+   Zbutton_restartZdesktopr,   r,   r-   Úon_driver_restart_clicked.  s(   

ÿ
ÿ
ÿ
ÿþz/SoftwarePropertiesGtk.on_driver_restart_clickedc                 C   s   i | _ g | _d S r$   )rƒ  r|  r*   r,   r,   r-   rt  B  s   
z#SoftwarePropertiesGtk.clear_changesc                 C   s¾  t jtdƒdd| _| j d| j¡ t jtdƒdd| _| j d| j¡ t jtdƒdd| _| j d| j	¡ t jtdƒdd| _
| j
 d| j¡ | j d¡ | j d¡ | j d¡ | j d¡ | j d¡ | j
 d¡ | j | jddd	¡ | j | jddd	¡ | j | j
ddd	¡ | j | jddd	¡ t jjt jjddd
œ}t jddtdƒi|¤Ž| _| j | j¡ t  ¡ | _| j | jddd	¡ | j d¡ i | _d| _g | _i | _g | _d	| _d| _dS )zAdditional Drivers tabZRe_vertT)r§   Zuse_underlineZclickedz_Apply ChangesZ_Cancelz_Restart...Fr   )ZhalignZvalignZvexpandZvisibler§   z"Searching for available drivers...Nr,   )r   ZButtonr”   rk  rk   rs  rl  r  rn  r…  rm  rŠ  rT   ry   Zbox_driver_actionZpack_endÚAlignÚCENTERÚLabelÚlabel_driver_detailÚbox_driver_detailr¾   ZProgressBarro  Údevicesrz   r|  rƒ  r‚  Únonfree_driversÚui_building)r+   Zpropsr,   r,   r-   ri   F  sF   ÿÿ

z"SoftwarePropertiesGtk.init_driversc                 C   sX   d| _ z	t | j¡| _W n   t | jjt	dƒ¡ t
jt
 ¡ Ž  Y d S t | j¡ d S )NTz.An error occurred while searching for drivers.)rz   r   Zsystem_device_driversr…   r  r   r{   rŽ  Úset_textr”   ÚsysÚ
excepthookÚexc_infoÚshow_driversr*   r,   r,   r-   ru   s  s   
ÿz$SoftwarePropertiesGtk.detect_driversc                 C   s$  | j rd S d }|r1| j| }zt | j|¡}| j| }|r&|js&| j |¡ W n	 ty0   Y nw | ¡ rW|| jv r@| j 	|¡ |d urV|| j
v rV|| j
| urV| j |¡ n'|| jv rb| j 	|¡ || j
vrl|| j
|< |d ur~|| jvr~|jr~| j |¡ | j t| jƒ¡ | j t| jƒ¡ d S r$   )r’  r…   r   Zget_linux_modules_metapackager}  r|  rð   ÚKeyErrorrû   r¹   rƒ  rk  rT   rÄ   rl  )r+   r<  ZmodaliasÚpkg_namer  Zmodules_packageZmodules_package_objr,   r,   r-   Úon_driver_selection_changed„  sH   


€ÿ
ÿþ€


ÿþz1SoftwarePropertiesGtk.on_driver_selection_changedc              	   C   sž  t dƒdft dƒdft dƒdft dƒdfdœ}i i i i dœ}d	}d	}z|d
 r2ddt dƒdœi|d< W n	 ty<   Y nw |d D ]´}|d | }d}z|d rV|d rVd}W n	 ty`   Y nw d	}	z
|d rld}	d}W n	 tyv   Y nw z/| j| }
|
j}| j |
¡}|durž| j |jd ¡ t dƒ 	| jj
|¡}nt dƒ 	|¡}W n ty·   td 	||¡ƒ Y qAw |d rÁt dƒ}nt dƒ}|dkrÎt dƒ}nt dƒ}|j	||d}d	}|	sé|d sé|}|réd}d}||  ||||	dœ¡ qA|sd	}|sÿd}d|t d ƒdœi|d!< n"|s-d"D ]}|| D ]}|| | d r)d|| | d#< qq|D ]}|| D ]}|| | d# rF|| \}}q5q/|||fS )$a£  Get various device data used to build the GUI.

          return a tuple of (overall_status string, icon, drivers dict).
          the drivers dict is using this form:
            {"recommended/alternative": {pkg_name: {
                                                      'selected': True/False
                                                      'description': 'description'
                                                      'builtin': True/False
                                                    }
                                         }}
             "manually_installed": {"manual": {'selected': True, 'description': description_string}}
             "no_driver": {"no_driver": {'selected': True/False, 'description': description_string}}

             Please note that either manually_installed and no_driver are set to None if not applicable
             (no_driver isn't present if there are builtins)
        z,This device is using the recommended driver.zrecommended-driverz+This device is using an alternative driver.zother-driverz1This device is using a manually-installed driver.zThis device is not working.zdisable-device©ÚrecommendedÚalternativeÚmanually_installedÚ	no_driverFZmanual_installTz*Continue using a manually installed driver)ÚselectedrÁ   rž  Údriversr  rœ  Zfrom_distroÚbuiltinNr   zUsing {} from {}zUsing {}zHWARNING: a driver ({}) doesn't have any available package associated: {}Úfreezopen sourceZproprietaryz&{base_description} ({licence}, tested)z{base_description} ({licence}))Zbase_descriptionÚlicence)r   rÁ   r¢  zDo not use the devicerŸ  )rœ  r  r   )r”   r˜  r…   r}  r‡   Zget_candidate_verr‰   ÚlookupZ	file_listr  Z
short_descrË   Ú
setdefault)r+   ÚdeviceZpossible_overall_statusZreturned_driversZhave_builtinZone_selectedZpkg_driver_nameZcurrent_driverÚdriver_statusr¢  r  Z	installedÚ	candidaterÁ   r¤  Zbase_stringr   Úsectionr™  ÚkeysÚoverall_statusÚiconr,   r,   r-   Úgather_device_data¬  s®   



üÿ€ÿ€ÿ€ÿ
€þ


þÿ€þ€þ
z(SoftwarePropertiesGtk.gather_device_datac                 C   s˜  | j s| j tdƒ¡ d S | j | j¡ d| _i | _t| j  	¡ ƒD ]}|  
| j | ¡\}}}t ¡ }| tjj¡ | tjj¡ | |tjj¡ tjdtjjd}| |ddd¡ tjdtjjd}| |ddd¡ tj d | j |  dtd	ƒ¡| j |  d
td	ƒ¡¡¡}| tjj¡ | |ddd¡ tj d |¡¡}| tjj¡ | d¡ | |ddd¡ ||f| j|< d }	dD ]u}
||
 D ]n}tj  d ||
 | d ¡}|	rÛ| !|	¡ n|}	| |ddd¡ | "||
 | d ¡ |
dkrú| j# $|¡ |
dv sd||
 | v r||
 | d r| %d| j&|¡ n	| %d| j&||¡ |d r2|
dkr2| 'd¡ qÄq¾| j |ddd¡ q!d| _| j (¡  |  )¡  d S )Nz No additional drivers available.Té   )ZspacingZorientationFr   z{}: {}Zvendorr†  r–   ú<small>{}</small>r›  rÁ   r   rŸ  )Zmanually_installrŸ  r¢  r¥   rž  )*r  rŽ  r“  r”   r  r¹   r’  Údynamic_device_statusÚsortedr«  r®  r   ZImageZ
set_valignr‹  ZSTARTZ
set_halignrŒ  Úset_from_icon_nameÚIconSizeÚMENUZBoxZOrientationZ
HORIZONTALrÓ   ZVERTICALr  rO   r  rÅ   Zset_use_markupZRadioButtonZnew_with_labelZ
join_groupr€   r‚  rð   rk   rš  rT   r>  ru  )r+   r§  r¬  r­  r¡  r¨  Z
device_boxZdevice_detailrã   Zoption_grouprª  ZdriverZradio_buttonr,   r,   r-   r—    s\   8
.
€ð
z"SoftwarePropertiesGtk.show_driversc                 C   sT   | j D ]$}|  | j | ¡\}}}| j| \}}| |tjj¡ | d |¡¡ qdS )zBUpdate the current label and icon, computing the new device statusr°  N)	r  r®  r±  r³  r   r´  rµ  r²   r  )r+   r§  r¬  r­  r¡  r¨  rã   r,   r,   r-   rv  W  s   
ûz8SoftwarePropertiesGtk.update_label_and_icons_from_statusc                 C   sÔ   t j d¡r| j tdƒ¡ | j d¡ | j 	d¡ d S d| _
| jD ]%}| j| d D ]}| j| }| j| d | d sF|jrF| j
d | _
q+q"| j
dkr`| j t dd	| j
¡d
| j
i ¡ d S | j tdƒ¡ d S )Nz/var/run/reboot-requiredz@You need to restart the computer to complete the driver changes.Tr   r¡  r£  r   z$%(count)d proprietary driver in use.z%%(count)d proprietary drivers in use.Úcountz"No proprietary drivers are in use.)rG   rH   r‡  rp  r²   r”   rm  ry   rJ   Zset_urgency_hintr‘  r  r…   r}  r   Úngettext)r+   r§  r™  r  r,   r,   r-   ru  a  s,   

€ý

ý
üz.SoftwarePropertiesGtk.set_driver_action_statusc                 C   s   t | ƒ| _d S r$   )r   Zubuntu_pro_pager*   r,   r,   r-   rj   y  r  z%SoftwarePropertiesGtk.init_ubuntu_pro)NNNN)r   r$   )Kr/   r0   r1   rE   rl   r|   r`   r]   rŠ   r_   ra   r›   rg   rä   rç   rh   r   rž   rÚ   r   rÐ   rÔ   r½   rÃ   r¶   r
  rp   r  ró   r  rd   r1  r&  rb   r:  r=  r9  rA  rE  rX   rY   rW   rZ   r[   re   rf   r#  rc   r•   rM  r.  rT  rV  rW  r]  r`  rc  rg  re  rj  rr  rz  r  rs  r…  rŠ  rt  ri   ru   rš  r®  r—  rv  ru  rj   r,   r,   r,   r-   r?   œ   s”    
u	!r 
( 


K
		

7-
(r9
r?   )LZ
__future__r   r   rn   rÇ   rU   Z	dbus.glibZdbus.mainloop.glibr   r”   rG   rˆ  r3   rt   r”  r2  ZgiZrequire_versionZgi.repositoryr	   rq  r
   r   r   r   r   r   r   r   r   r   r   r   r   r¡   Zsoftwareproperties.distroZ%softwareproperties.SoftwarePropertiesr   Zsoftwareproperties.gtk.utilsr   r   r   r   ZUbuntuDriversr   ZmainloopZglibZDBusGMainLoopZpyglib_versionZthreads_initÚrangeZLIST_MARKUPZLIST_ENABLEDrP  r  r'  r  r  r  ZSTORE_ACTIVEZSTORE_DESCRIPTIONr5  r$  ZSTORE_VISIBLEr'   r(   r)   r&   rë   rì   rí   Úobjectr#   r5   r4   r?   r,   r,   r,   r-   Ú<module>   s€    

ý
	ú	û