
    eh                    F   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j                  dd        ej                  dd        ej                  dd        ej                  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 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jZ                  j\                  j_                  d       ej`                  dk  r ejb                           e2d      \  Z3Z4Z5 e6 e2d            \  Z7Z8dZ9dZ: e6 e2d            \  Z;Z<Z=Z>Z? e2d      \  Z@ZAZBZCd ZDd!ZEd"ZF G d# d$eG      ZHd% ZId& ZJ G d' d(e%e      ZKy))    N)gettextGdkz3.0GtkHandy1PackageKitGlibz1.0)r   )GObjectr   r   GioGLibr   )Deb822SourceEntry   )SimpleGtkbuilderApp)	DialogAdd)DialogMirror)
DialogEdit)DialogEditDeb822)DialogCacheOutdated)DialogAddSourcesList)UbuntuProPage)SoftwareProperties)get_ua_statusget_ua_service_statuscurrent_distrois_current_distro_lts)detectT)set_as_default)   	   r   r            securityupdates	backportsc                   &    e Zd ZdZdZdZdZdZd Zy)UpdateSubscriptionsFc                 .   | 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selfs    N/usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py
get_statuszUpdateSubscriptions.get_statusv   s`    ::!!==T\\dnn]]t||DNN&&]]4<<##    N)	__name__
__module____qualname__r"   r#   r$   r)   inconsistentr1    r2   r0   r&   r&   o   s     HGIEL	r2   r&   c                 N    | j                   dk(  rt        j                  d       yy)zLog 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)_dbus_error_nameloggingerror)dbus_exceptions    r0   'maybe_log_authentication_canceled_errorr=      s(     &&>?LMr2   c                 6   t        j                  | t         j                  j                  t         j                  j
                  t         j                  j                  d      }|j                  d|d|       |j                          |j                          y)z show a error dialog N)parentflagstypebuttonsmessage_formatz<big><b>z</b></big>

F)r   MessageDialogDialogFlagsMODALMessageTypeERRORButtonsTypeOK
set_markuprundestroy)parent_windowsummarymsgdialogs       r0   r;   r;      si    m%(__%:%:$'OO$9$9'*'9'9.2	4F
 gsCD
JJL
NNr2   c                      e Zd ZdJdZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd ZdKdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdLdZd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;dLd;Z<d< Z=d= Z>dLd>Z?d? Z@d@ ZAdA ZBdB ZCdC ZDdLdDZEdE ZFdF ZGdG ZHdH ZIdI ZJy)MSoftwarePropertiesGtkNc                 H   t        j                  | ||d       t        j                  j	                  d       t        j                          t
        j                  j                         }|j                  t
        j                  j                         t        j                  | t        j                  j                  |dd      d       |ri| j                   j#                  t$        j&                  j(                         | j                   j+                          	 | j                   j-                  |       || _        |r|j0                  dk7  r| j                   j#                  t$        j&                  j(                         | j                   j+                          	 t%        j2                  t5        |j0                              }|r	 | j                   j-                  |       t8        j:                  j=                         }d|v rEt8        j:                  j?                  d      | _         | j@                  jC                  d	      | _"        n)d| _         d
| _"        | jF                  jI                  d       tK        jL                         }|jO                  dd      }	tK        jP                  |	d      | _)        | jR                  jU                  d| jV                         | jR                  jU                  d| jX                         | jR                  jU                  d| jZ                         | jR                  jU                  d| j\                         | jR                  jU                  d| j^                         | jR                  ja                          | j                   j+                          i | _1        | je                          d| _3        | ji                          | jk                          | jm                          | jo                          | jq                          | js                          | ju                          | jw                          | jy                          | j{                          | j}                          t               r| j                          | j                  j                  d| j                         |r:|j                  r.| j                  j                  t5        |j                               |dk7  rqt        j                  j                  |      t        j                  j                  d      t        j                  j                  d      k7  r| j                  |       | j                   j                  dd       y#  Y QxY w# t6        $ r d}Y w xY w#  Y xY w)z Provide a GTK based graphical user interface to configure
            the used software repositories, corresponding authentication keys
            and update automation T)optionsdatadirdeb822zsoftware-properties
gtkbuilderzmain.ui)domainNzcom.ubuntu.update-notifierregular-auto-launch-intervalr   Fzcom.ubuntu.SoftwareProperties/SourcesListModifiedConfigModifiedKeysModified
AuthFailedCdromScanFailedzswitch-pagezDir::EtczDir::Etc::sourcelistr   )Mr   __init__r   Windowset_default_icon_namer   initStyleManagerget_defaultset_color_schemeColorSchemePREFER_LIGHTr   ospathjoinwindow_mainset_type_hintr   WindowTypeHintDIALOGshowset_transient_forrU   toplevelwindow_foreign_newintAttributeErrorr
   Settingslist_schemasnewsettingsget_intinitial_auto_launchcombobox_other_updatesset_sensitivedbus	SystemBus
get_object	Interfacebackendconnect_to_signalon_sources_list_modifiedon_config_modifiedon_keys_modifiedon_auth_failedon_cdrom_scan_failed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_driversr   init_ubuntu_pronotebook_mainconnecton_main_notebook_page_switchedopen_tabset_current_pageabspathapt_pkgconfigfind_dirfind	open_fileresize)
r/   rV   rU   filer?   style_managerrs   all_schemasbusproxys
             r0   ra   zSoftwarePropertiesGtk.__init__   sP    	##D'7+/	1

(()>? 	

**668&&u'8'8'E'EF$$T%'WW\\'<%S,A	C **3+=+=+D+DE!!#  226:
 w''4/**3+=+=+D+DE!!# 11#g6F6F2GH $$66x@
 ll//1';6LL,,-IJDM'+}}'<'<=['\D$ DM'(D$''55e< nn>D~~e-LM&&!4#@#@	B&&d55	7&&D11	3&&$--	/&&t88	: 	 	  	 	""$##%! "  " 	""=$2U2UVw''//G4D4D0EF DLGGOOD!w~~/F/Fz/R/6~~/B/BCY/Z&\ \NN4  	1%E "   
s*   V (V
 V V
VVV!c                      | j                   k(  rA j                  j                  d        j                  st	        j
                   fd       y y  j                  j                  d       y )NFc                  `    t        j                   j                        j                         S )N)target)	threadingThreaddetect_driversstartr.   s   r0   <lambda>zFSoftwarePropertiesGtk.on_main_notebook_page_switched.<locals>.<lambda>  s!    i&6&6d>Q>Q&R&X&X&Z r2   T)vbox_driversbutton_revertset_visibledetect_calledr   idle_add)r/   notebookpagepage_nums   `   r0   r   z4SoftwarePropertiesGtk.on_main_notebook_page_switched  sV    4$$$**51%%Z[ & **40r2   c                     t        j                         r*t        j                          t        j                         r)yy)z) abstract interface to keep the UI alive N)r   events_pendingmain_iterationr.   s    r0   update_interfacez&SoftwarePropertiesGtk.update_interface"  s(      "    "r2   c                     | j                         }| j                  j                  |       | j                  j                  d| j                        | j
                  | j                  <   y)z? setup the widgets that allow configuring the release upgrades changedN)get_release_upgrades_policycombobox_release_upgrades
set_activer   $on_combobox_release_upgrades_changedr   )r/   is     r0   r   z+SoftwarePropertiesGtk.init_release_upgrades'  sX    ,,.&&11!4++33I484]4]_ 	d445r2   c                    t        j                          t        j                          t        j                  d       | _        t        j
                  | j                        | _        t        j                  | j                        | _        y r(   )	r   init_configinit_systemCache	apt_cacheDepCachedepcachePackageRecordsrecordsr.   s    r0   r   z$SoftwarePropertiesGtk.init_apt_cache.  sV     t,((8--dnn=r2   c                     t        j                  d       | _        t        j                  | j                        | _        t        j
                  | j                        | _        y r(   )r   r   r   r   r   r   r   r.   s    r0   update_apt_cachez&SoftwarePropertiesGtk.update_apt_cache5  s>     t,((8--dnn=r2   c                    | j                   j                          | j                   j                         }i | _        t	        |      D ]0  \  }}|j                  |j                  d      }|| j                  |<   2 | j                         }|| j                  j                         vr;|dkD  r6| j                   j                  t        d      |z         || j                  d<   | j                  D ]1  }| j                  |   |k(  s| j                   j                  |        n | j                   j                  d| j                        | j                  | j                   <   y)zB Set up the widgets that allow to configure the update automation r   r   zEvery %s daysr   N)combobox_update_intervalrq   	get_modelcombobox_interval_mapping	enumerate	get_valueiterget_update_intervalvaluesappend_text_r   r   #on_combobox_update_interval_changedr   )r/   modelr   rowvalueupdate_dayskeys          r0   r   z&SoftwarePropertiesGtk.init_auto_update:  sH   %%**,
 --779)+&!%( 	6HQOOCHHa0E05D**1-	6 ..0 d<<CCEEQ--99!O:L<G;H I5@..r211 	C--c2kA--88=	 **229373[3[] 	d334r2   c                 <   | j                          | j                  r| j                  j                  d      }| j                  j	                         }t        |      D ]C  \  }}|j                  |j                  d      }||k(  s(| j                  j                  |        n | j                  j                  d| j                        | j                  | j                  <   | j                  j                  d| j                        | j                  | j                  <   y)z>Represent the level of update automation in the user interfacerZ   r   r   N)set_security_update_levelrz   r{   r}   r   r   r   r   r   combobox_security_updatesr   set_sec_update_automation_levelr   !set_other_update_automation_level)r/   level_otherr   r   r   levels         r0   r   z,SoftwarePropertiesGtk.show_auto_update_level[  s     	&&( ==--//0NOK//99;E%e, C!4%'//::1=	 ++33I484X4XZ 	d445
 ((00151W1WY 	d112r2   c                    | j                         }|dk(  r| j                  j                  d       n| j                  j                  d       |t        j                  k(  s|t        j
                  k(  r| j                  j                  d       y|t        j                  k(  r| j                  j                  d       y|t        j                  k(  r| j                  j                  d       yy)zHFetch the security level, Enable/Disable and set the value appropriatelyNFTr   r   r   )	get_update_automation_levelr   r~   softwarepropertiesUPDATE_MANUALUPDATE_NOTIFYr   UPDATE_DOWNLOADUPDATE_INST_SEC)r/   	level_secs     r0   r   z/SoftwarePropertiesGtk.set_security_update_levels  s     446	**88?**88>+999/===**55a8,<<<**55a8,<<<**55a8 =r2   c                 r   | j                   j                  t        d      | j                  j                  z         | j
                  j                  d| j                        | j                  | j
                  <   | j                  j                         D ]  }| j                  j                  |        | j                  j                  j                  D ]  }t        d      |j                         |j                  fz  }t!        j"                  |      }||_        |j                  d| j&                  |j                        | j                  |<   | j                  j)                  |       |j+                           | j,                  j                         D ]  }| j,                  j                  |        | j                  j                  j.                  D ]  }|j0                  dk(  rd|j                  v s"t!        j"                  |j2                  d|j                  d      }||_        |j                  d| j6                  |      | j                  |<   | j,                  j)                  |       |j+                           t9               }t;               sd	}d	}n5t=        d
|      \  }	}
t=        d|      \  }}t?        |	xs |      }d|
|fv }tA               }|r`t        d      }	 |jC                  dd      jE                  d      \  }}}tF        jF                  jI                  |d      jK                         }nt        d      }|jP                  }| jR                  jU                  |       d}tF        jF                  jW                         jK                         }||k\  rQ|r1|jX                  j[                  dd      }d|j[                  dd      z  }t        d      |j]                  d      z  }nW||tG        j^                  d      z
  k\  rt        d      |j]                  d      z  }nt        d      |j]                  d      z  }| j`                  j                  |       | jb                  jU                  d |d!t        d"      d#       | jb                  je                  |xr |        t        d$      |j]                  d      z  }| jf                  }|j                  d%| jh                        | j                  |<   t!        jj                         }| jl                  jo                  |d&       | jl                  jq                  |d'd(       | jl                  j                  d%| jr                        | j                  | jl                  <   t!        jt                  tv        jx                  tv        jx                  tv        jz                        }| jl                  j}                  |       | jl                  j                  | j                  d)       y*# tL        $ r tO        d       |jP                  }Y w xY w)+z9Setup the user interface elements to represent the distroz%s Softwaretoggledz%s (%s)labeldeb-srcproposedz ()Fz	esm-infra)statuszesm-appsenabledzExtended Security Maintenance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="z">u	   Extend…z</a>zEnded %sr   Ttextr   r   N)Alabel_dist_name	set_labelr   distroidcheckbutton_source_coder   "on_checkbutton_source_code_toggledr   vbox_dist_compsget_childrenremovesource_template
componentsget_descriptionnamer   CheckButtoncompon_component_toggledaddrq   dev_boxchildrenrA   descriptiontemplateon_checkbutton_child_toggledr   r   r   boolr   get	partitiondatetimestrptimedate
ValueErrorprinteollabel_esm_statusrK   nowversionreplacestrftime	timedelta	label_eollabel_esm_subscriber   combobox_updates_subscription(on_combobox_updates_subscription_changedCellRendererTextcombobox_server
pack_start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   esm_availableesm_enabledinfra_availableinfra_statusapps_availableapps_statusr  eol_textdt_sep_tzeol_dateesm_urltoday
distro_vereol_expiry_textcomboboxcellserver_stores                             r0   r   z!SoftwarePropertiesGtk.init_distro  sL    	&&q'7$++..'HI #::BB9CGCjCjl 	d223
  //<<> 	5K  ''4	5KK//:: 	D iLD$8$8$:DII#FFEU3H HM&.&6&6y373L3L3799'>DMM(#   $$X.MMO	   <<446 	-KLL,	-33<< 	 H}}	)X]]*??h>R>R>Fmm2M N$,!$$Y%)%F%F%-/ h'   *	  $& %#2G\b2c/,0EjY_0`- $_%F G'L++FF!<=
	. )/

9b(A(K(KC(PD##+#4#4#=#= 3$$& ! 9:!::((2*!!%%',,.H %+^^%;%;FB%G
"9J<N<NsTW<X"X"#$F"G(J[J[\`Ja"ah!3!3!<<<"#$F"G(J[J[\`Ja"a"#$5"69J9J49P"P  1  +++2AkNC	
 	  ,,1k/	
 J-(*;*;D*AA 55"*"2"2tDD#Fh ##%''d3**4;.2.B.B.J.J9;?;Z;Z/\d**+}}W%8%8%,%8%8%,%9%9; 	&&|433D4I4I1MW " .FG#)::.s   ,AX  X65X6c                     | j                   D ]?  }|j                  | j                   |         s"|j                  | j                   |          A y r(   )r   handler_is_connectedhandler_blockr/   widgets     r0   block_handlersz$SoftwarePropertiesGtk.block_handlers  sC    mm 	<F**4==+@A$$T]]6%:;	<r2   c                     | j                   D ]?  }|j                  | j                   |         s"|j                  | j                   |          A y r(   )r   rL  handler_unblockrN  s     r0   unblock_handlersz&SoftwarePropertiesGtk.unblock_handlers  sC    mm 	>F**4==+@A&&t}}V'<=	>r2   c                    | j                          | j                  j                         D ]B  }| j                  |j                        \  }}|j                  |       |j                  |       D | j                  j                         D ]B  }| j                  |j                        \  }}|j                  |       |j                  |       D t               }| j                  j                  j                  D ]  }|j                  dk(  r|j                  j!                  d      d   }| j                  |      \  }}|xj"                  |z  c_        |s]|t$        k(  rd|_        n|t(        k(  rd|_        |t,        k(  rd|_        d|_         |j3                         }| j4                  }|j7                         }	|t8        k(  r 	 |	j;                  t=        t8                     n.	 |	jE                  |	j;                  t=        t8                           |j                  |       |jG                  |j"                          tI        | j                  jJ                        dk  rR| j4                  jG                  d       | j                  jG                  d       | jL                  jG                  d       n6| j                  jG                  d       | jL                  jG                  d       | jO                         }
|
dk(  r| jL                  j                  d       nr|
dk(  r7| jL                  j                  d       | jL                  j                  d       n6| jL                  j                  d       | jL                  j                  d       tI        | jQ                               d	k(  r5| jR                  jU                          | jV                  jY                          n4| jR                  jY                          | jV                  jU                          | jZ                  j7                         }|j]                          g }| j                  j_                         D ]  \  }}}|jA                  ||dg       ||g| j`                  v r| j`                  jE                  ||g       n|dk7  r|jA                  ||g       |dk(  sgtI        |      dz
  | _1        | jZ                  j                  | jb                          | j`                  D ]  \  }}|jA                  ||dg        || _0        | j                  j                  jd                  r0|jA                  g d
       |jA                  tC        d      ddg       | jg                          | jh                  jj                  dk(  s| jh                  jl                  dk(  rto        d| j                  jJ                  z         to        d| j                  jp                  z         to        d       | j                  jr                  D ]  }| ju                  |        to        d       | j                  jv                  D ]  }| ju                  |        to        d       | j                  jx                  D ]  }| ju                  |        to        d       | j                  jz                  D ]  }| ju                  |        to        d       | j                  j|                  D ]  }| ju                  |        to        d       | j~                  D ]  }| ju                  |        yy# t>        $ r |	jA                  tC        d      g       Y Uw xY w# t>        $ r Y ew xY w)z(Fill the distro user interface with lifer   r   r   TCustomr   FNr   )sepNTOther...zENABLED COMPS: %szINTERNET COMPS: %szMAIN SOURCESzCHILD SOURCESzCDROM SOURCESzSOURCE CODE SOURCESzDISABLED SOURCESISV)@rP  r  r
  get_comp_child_stater  r   set_inconsistentr	  get_comp_download_stater  r&   r  r  r  rA   r  splitr6   POCKET_SECURITYr"   POCKET_UPDATESr#   POCKET_BACKPORTSr$   r)   r1   r*  r   r*   get_iter_from_stringstrr  appendr   r  r~   lenenabled_compsr  get_source_code_stateget_cdrom_sourcesscrolledwindow_cdhidescrolledwindow_no_cdrq   r-  clearget_server_listseen_serveractive_server
mirror_setrS  rU   debugmassive_debugr   download_compsmain_sourcesprint_source_entrychild_sourcescdrom_sourcessource_code_sourcesdisabled_sourcessourceslist_visible)r/   r8  activer6   subscriptionsr  pocketr   rH  r   source_code_staterJ  seen_server_newr  urisources                   r0   r   z!SoftwarePropertiesGtk.show_distro  s]    113 	4H%)%>%>x?P?P%Q"V\'%%l3	4 ,,99; 	(H%)%A%A(--%P"V\%%l3'		( ,-33<< 	/H}}	)]]((-b1F%)%>%>x%H"V\&&,6&_,-1M*~-,0M)//.2M+*.M'	/" ))+55""$^#,**3~+>?U77N8KLM 	F#=#=#==> t{{(()A-..<<UCLL&&u-((66u=LL&&t,((66t< !668$((99$?$&((33D9((99%@((33E:((99%@ t%%'(A-""'')%%**,""'')%%**, ++557#';;#>#>#@ 	DT3sE 23c{d...  ''s4&&c{3~%(%6%:"$$//0B0BC	D  ++ 	4KT3sE 23	4* ;;&&11 34:e <= 	 <<%)C)Ct)K%(A(AAB&)C)CCD.!++22 0''/0/"++33 0''/0/"++33 0''/0'(++99 0''/0$%++66 0''/0%L22 0''/0' *LC  ,ak]+,
  s$   ] (-]. $]+*]+.	];:];c                 (   |j                         }d}|dk(  rt        j                  }n+|dk(  rt        j                  }n|dk(  rt        j                  }	 || j                         k7  r| j                  j                  |       yy# t        j                  $ ry}t        |      rd| j                  | j                     }| j                  j                  |       | j                          | j                  j                  |       Y d}~yY d}~yd}~ww xY 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   r   SetUpdateAutomationLevelr   DBusExceptionr=   r   r   rM  r   rR  )r/   rO  indexstateecombo_handlers         r0   r   z5SoftwarePropertiesGtk.set_sec_update_automation_level  s     !!#A:&44EaZ&66EaZ&66E	N88::55e< ;!! 	N6q9 $d.L.L M..<<]K..0..>>}MM	 :	Ns   .B DA*DDc                     |j                         }| j                  j                         }||   d   }| j                  j	                  d|       y)zBSet the other update automation level to the given value via gconfr   rZ   N)r  r}   r   rz   set_int)r/   rO  r  r   r  s        r0   r   z7SoftwarePropertiesGtk.set_other_update_automation_level  sF    !!#++557U|A<dCr2   c                 &    |j                  ||      S )z% Check if a given row is a separator )r   )r/   r   r   columns       r0   r6  z&SoftwarePropertiesGtk.is_row_separator  s    tV,,r2   c                    |j                         }	 | j                  j                  |       y# t        j                  $ r}t        |      r| j                  | j                     }| j                  j                  |       | j                         }| j                  j                  |       | j                  j                  |       Y d}~yY d}~yd}~ww xY w)z! set the release upgrades policy N)r  r   SetReleaseUpgradesPolicyr   r  r=   r   r   rM  r   r   rR  )r/   rH  r   r  r  s        r0   r   z:SoftwarePropertiesGtk.on_combobox_release_upgrades_changed  s     !	NLL11!4!! 	N6q9 $d.L.L M..<<]K446..99!<..>>}MM :	Ns   . CBCCc                 :    |j                         }|t        k7  r>|j                         }	 |j                  |j	                  t        t                            fd}	 |t        k(  r( |t        d        |t        d        |t        d       na|t        k(  r( |t        d        |t        d        |t        d       n0|t        k(  r' |t        d        |t        d        |t        d        j                  j                  j                  D ]M  }|j                   dk(  r|j"                  j%                  d      d   }|t        t        t        fvsE ||d       O y # t        $ r Y w xY w# t&        j(                  $ r}t+        |       Y d }~y d }~ww xY w)Nc                 T   dj                  j                  j                  |       }|r@t        j                  dj                  |             j
                  j                  |       y t        j                  dj                  |             j
                  j                  |       y )Nz{}-{}zenabling {}zdisabling {})formatr  codenamer:   infor   EnableChildSourceDisableChildSource)r{  r   r  r/   s      r0   _toggle_child_sourcez\SoftwarePropertiesGtk.on_combobox_updates_subscription_changed.<locals>._toggle_child_source  sr    ^^DKK$8$8&AF]11&9:..v6^226:;//7r2   TFr   r   r   )r  r*   r   r  r`  ra  r  r+   r]  r^  r_  r,   r-   r  r  r  rA   r  r\  r   r  r=   )r/   rH  r  r   r  r  r{  r  s   `       r0   r+  z>SoftwarePropertiesGtk.on_combobox_updates_subscription_changed  s`   ##%N"&&(EU77N8KLM	8	7#$_d;$^T:$%5t<--$_d;$^T:$%5u=**$_d;$^U;$%5u= KK77@@ 8==I-!,,S1"5/>CS!TT(783  > !! 	73A66	7s0   -E" C6E2 E2 "	E/.E/2FFFc                    |j                         | j                  k(  ry|j                         }|j                         }|j	                  |d      }|j	                  |d      }	 |t        d      k(  rt        | j                  | j                  | j                  | j                        }|j                         }|dk7  r| j                  j                  |       y|j                  | j                         y|dk7  rTt        | j                  j                         dkD  r1|j                         | _        | j                  j                  |       yyy# t"        j$                  $ r}t'        |       Y d}~yd}~ww xY w)zg
        Replace the servers used by the main and update sources with
        the selected one
        Nr   r   rW  )r  rm  r   get_active_iterr   r   r   rm   rV   r  custom_mirrorsrL   r   ChangeMainDownloadServerr   rc  used_serversr   r  r=   )	r/   rH  rJ  r   r~  r  rQ   resr  s	            r0   r0  z0SoftwarePropertiesGtk.on_combobox_server_changed  s=   
  D$6$66))+'')$$T1-%%dA.	7q}$%d&6&6&*ll&*kk&*&9&9; jjl$;LL99#>''(:(:;T[[%=%=!>!B%-%8%8%:"55c: "C !! 	73A66	7s&   $A4E E 5AE E7"E22E7c                     	 |j                         dk(  r| j                  j                  |       y| j                  j                  |       y# t        j
                  $ r}t        |       Y d}~yd}~ww xY w)z{
        Sync the components of all main sources (excluding cdroms),
        child sources and source code sources
        TN)r  r   EnableComponentDisableComponentr   r  r=   )r/   r7  r  r  s       r0   r  z*SoftwarePropertiesGtk.on_component_toggled  s]    
	7%%'4/,,T2--d3!! 	73A66	7s   .A A A5 A00A5c                    	 |j                         dk(  r&| j                  j                  |j                         y| j                  j	                  |j                         y# t
        j                  $ r}t        |       Y d}~yd}~ww xY w)zT
        Enable or disable a child repo of the distribution main repository
        FN)r  r   r  r  r  r   r  r=   )r/   r7  r  r  s       r0   r  z2SoftwarePropertiesGtk.on_checkbutton_child_toggled  se    	7%%'50//>..x}}=!! 	73A66	7s   8A! %A! !B	4BB	c                     	 |j                         dk(  r| j                  j                          y| j                  j                          y# t        j
                  $ r}t        |       Y d}~yd}~ww xY w)z3 Disable or enable the source code for all sources TN)r  r   EnableSourceCodeSourcesDisableSourceCodeSourcesr   r  r=   )r/   r7  r  s      r0   r  z8SoftwarePropertiesGtk.on_checkbutton_source_code_toggled  sY    	7%%'4/446557!! 	73A66	7s   -A A A3A..A3c                     | j                         }|j                         |k7  r+	 | j                  j                  |j                                yy# t        j
                  $ r}t        |       Y d}~yd}~ww xY w)z5 The user clicked on the popcon paritipcation button N)get_popcon_participationr  r   SetPopconPariticipationr   r  r=   )r/   rO  	do_popconr  s       r0   on_checkbutton_popcon_toggledz3SoftwarePropertiesGtk.on_checkbutton_popcon_toggled  sk     113	)+;44V5F5F5HI , %% ;7::;s   )A A8#A33A8c                    	 t        | j                  | j                  | j                  | j                  | j
                  |      }|j                         \  }}|t        k(  rLg | j                  _        |t        t        fv r,|D ]&  }| j                  j                  t        |             ( yyy# t        j                  $ r}t        |       Y d}~yd}~ww xY w)zAShow a confirmation for adding the channels of the specified fileN)r   rm   sourceslistrender_sourceget_comparablerV   rL   RESPONSE_REPLACElistRESPONSE_ADDr   AddSourceFromLinera  r   r  r=   )r/   r   rQ   r  new_sourcesr  r  s          r0   r   zSoftwarePropertiesGtk.open_file(  s    	7)$*:*:*.*:*:*.*<*<*.*=*=*.,,*.0F "(S+&&(*  %<)9::"- D66s6{CD ; '
 !! 	73A66	7s   B(B- -C CCc                     |j                   j                         }|j                         }	t        |	      dkD  r| j	                  |	d          yy)z=Extract the dropped file pathes and open the first file, onlyr   N)datastripr\  rc  r   )
r/   rO  contextxy	selectiontarget_type	timestampr~  uri_splitteds
             r0   on_sources_drag_data_receivedz3SoftwarePropertiesGtk.on_sources_drag_data_received:  sC     nn""$yy{|q NN<?+ !r2   c                 8    | j                   j                          y r(   )rm   rh  r.   s    r0   rh  zSoftwarePropertiesGtk.hideB  s    r2   c                     |j                  |t              j                         j                  |j                               dk(  S )Nr   )r   COLUMN_DESClowerr   )r/   storer  r   r   r  s         r0   source_search_functionz,SoftwarePropertiesGtk.source_search_functionE  s2    t[1779>>syy{KrQQr2   c           	      *	   t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                        | _        | j                  j                  | j                         t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                        | _	        | j                  j                  | j                         | j                  j                  | j                  t               t        j                         }|j                  dd       |j                  dd       t        j                   t#        d      |t$              }|j'                  d       t        j(                         }|j                  dd       |j                  dd       |j+                  d| j,                  | j                        | j.                  |<   t        j                   t#        d      |t0        	      }| j                  j3                  |       | j                  j3                  |       t        j                         }|j                  dd       |j                  dd       t        j                   t#        d      |t$              }|j'                  d       t        j(                         }|j                  dd       |j                  dd       |j+                  d| j,                  | j                        | j.                  |<   t        j                   t#        d      |t0        	      }| j                  j3                  |       | j                  j3                  |       | j                  j5                  t$               | j                  j7                  | j8                  d
       	 t        j:                  | j                  t         j<                  j>                  t         j@                  jC                  ddd      gtD        jF                  jH                         | j                  j+                  d| jJ                         y
# tL        $ r Y y
w xY w)z;
        Read all valid sources into our ListStore
        xpadr   ypadzSoftware Sources)markupi  r   Active)ry  Nztext/uri-listr   drag_data_received)'r   r1  r	   r3  r2  TYPE_PYOBJECTcdrom_storetreeview_cdromsr4  source_storetreeview_sourcesr5  is_separatorSTORE_SEPARATORr,  set_propertyTreeViewColumnr   r  set_max_widthCellRendererToggler   on_isv_source_toggledr   COLUMN_ACTIVEappend_columnset_search_columnset_search_equal_funcr  drag_dest_setDestDefaultsALLTargetEntryry   r   
DragActionCOPYr  rv   )r/   	cell_desccol_desccell_toggle
col_actives        r0   r   z&SoftwarePropertiesGtk.init_isv_sourcesI  s    ==)=)=)0)<)<)0)>)>)0)=)=)0)=)=	?
 	&&t'7'78MM'*>*>*1*=*=*1*?*?*1*>*>*1*>*>	@
 	''(9(9:44T5F5F5D	F ((*	vq)vq)%%a(:&;Y-8:t$,,.  +  +%0%8%8262L2L262B2B&Dk" ''([/<>
 	**:6**84((*	vq)vq)%%a(:&;Y-8:t$,,.  +  +%0%8%8262L2L262C2C&Ek" ''([/<>
 	++J7++H5//<33D4O4OQUV	d33S5E5E5I5I"22?AqIJ!nn113 !!))*>*.*L*LN 		s   -BR 	RRc                 &    | j                  |       y)4Open the edit dialog if a channel was double clickedN)on_edit_clickedr/   treeviewrk   r  s       r0   on_isv_source_activatez,SoftwarePropertiesGtk.on_isv_source_activate  s    X&r2   c                 0   t        j                  d       |j                  t        |      f      }|j	                  |t
              }	 | j                  j                  t        |             y# t        j                  $ r}t        |       Y d}~yd}~ww xY w)z&Enable or disable the selected channelg333333?N)timesleepget_iterru   r   STORE_SOURCEr   ToggleSourceUsera  r   r  r=   )r/   r  rk   r  r   source_entryr  s          r0   r  z+SoftwarePropertiesGtk.on_isv_source_toggled  sp     	

3~~s4yl+t\:	7LL((\):;!! 	73A66	7s   $A- -B BBc                 L   t        j                  t              | _        | j                  j                  | j                         t        j                         }t        j                  t        d      |d      }| j                  j                  |       	 | j                  j                  dgt        j                  j                         | j                  j                  d| j                         | j                  j                  d| j"                         y# t         $ r Y 2w xY w)z:Setup the user interface parts needed for the key handlingKeyr   )r  )z
text/plainr   r   r  zbutton-press-eventN)r   r1  ra  
keys_storetreeview_authr4  r,  r  r   r  enable_model_drag_destr   r  r  r   on_auth_drag_data_receivedrv   show_auth_context_menu)r/   trkeys_cols      r0   r   zSoftwarePropertiesGtk.init_keys  s    --,$$T__5!!#%%ah;((2	55%&(;(;=&&';'+'F'FH 	""#7#'#>#>	@	  		s   AD 	D#"D#c                    |j                   t        j                  j                  k(  r|j                  dk(  rt        j                         }t        j                  t        d            }|j                  d| j                         |j                  |       |j                          |j                  d d d d |j                  |j                         yy y )Nr   z_Add key from paste datar   activateT)rA   r   	EventTypeBUTTON_PRESSbuttonr   MenuMenuItemr   r   on_auth_add_key_from_pasterb  show_allpopupr  )r/   rO  eventmenu
item_pastes        r0   r  z,SoftwarePropertiesGtk.show_auth_context_menu  s    ::3338I88:DA.H,IJJz4+J+JKKK
#MMOJJtT4u||UZZH 9J3r2   c                     t        j                         j                         }|sy | j                  |      s)t	        | j
                  t        d      t        d             | j                          y )NError importing keyCThe selected data may not be a GPG key file or it might be corrupt.)r   	Clipboardwait_for_textadd_key_from_datar;   rm   r   r   )r/   rO  keydatas      r0   r  z0SoftwarePropertiesGtk.on_auth_add_key_from_paste  s\    --///1%%g.$"")* . /0 	r2   c                     |j                         j                         }| j                  |      s)t        | j                  t        d      t        d             | j                          y)z1Extract the dropped key and add it to the keyringr  r  N)get_datar  r
  r;   rm   r   r   )	r/   rO  r  r  r  r  r  r  r  s	            r0   r  z0SoftwarePropertiesGtk.on_auth_drag_data_received  s[     $$&,,.%%g.$"")* . /0 	r2   c                 8    | j                   j                  |      S r(   )r   AddKeyFromData)r/   r  s     r0   r
  z'SoftwarePropertiesGtk.add_key_from_data  s    ||**733r2   c                 X   	 | j                   j                          | j
                  r&| j
                  j                  d| j                         | j                          | j                  j                  d       d| _        y# t        j                  $ r}t	        |       Y d}~d}~ww xY w)z6Restore the source list from the startup of the dialogNrZ   F)r   Revertr   r  r=   rz   r  r|   r   r   r~   modified_sourceslist)r/   r  r  s      r0   on_button_revert_clickedz.SoftwarePropertiesGtk.on_button_revert_clicked  s    	7LL! ==MM!!"@$BZBZ[##%((/$)! !! 	73A66	7s   B B)B$$B)c                 b    t        j                          | j                  j                  d       y)z=The config was changed and now needs to be saved and reloadedTN)r   r   r   r~   r.   s    r0   r   z(SoftwarePropertiesGtk.on_config_modified  s"    ((.r2   c                 $    | j                          y)z6 The apt keys have changed and need to be redisplayed N)r   r.   s    r0   r   z&SoftwarePropertiesGtk.on_keys_modified  s    r2   c                     | j                          | j                          | j                          | j                          | j                  j                  d       d| _        y)zCThe sources list was changed and now needs to be saved and reloadedTN)reload_sourceslistr   r   r   r   r~   r  r.   s    r0   r   z.SoftwarePropertiesGtk.on_sources_list_modified  sN    !!((.$(!r2   c                 d    | j                          | j                          | j                          y)z% send when the authentication failed N)r   r   r   r.   s    r0   r   z$SoftwarePropertiesGtk.on_auth_failed  s(     	%%'!r2   c                 V    t        | j                  t        d      t        d             y )NzError scanning the CDzCould not find a suitable CD.)r;   rm   r   r.   s    r0   r   z*SoftwarePropertiesGtk.on_cdrom_scan_failed  s$    d'(/0	2r2   c                    | j                   j                          | j                         D ]>  }| j                  |      }| j                   j	                  |j
                   ||ddg       @ | j                  j                         \  }}t        | j                         dk  s|7| j                  j                  d       | j                  j                  d       yy)zi Show the repositories of independent software vendors in the
            third-party software tree view FTr   N)r  rj  get_isv_sourcesr  rb  disabledr  
get_cursorrc  button_remover~   button_edit)r/   r  contentspath_xpath_ys        r0   r   z&SoftwarePropertiesGtk.show_isv_sources  s     	!**, 	<F))&1H$$&//&98&,eT&; <	<
  00;;=t  !A%,,U3**51 *8r2   c                     | j                   j                          | j                         D ]>  }| j                  |      }| j                   j	                  |j
                   ||ddg       @ y)zm Show CD-ROM/DVD based repositories of the currently used distro in
            the CDROM based sources list FTN)r  rj  rf  r  rb  r  )r/   r  r   s      r0   r   z(SoftwarePropertiesGtk.show_cdrom_sources  si     	 ,,. 	:F))&1H##%8($*E4%9 :	:r2   c                 p    	 |j                  ||      S # t        $ r}t        d|z         Y d}~yd}~ww xY w)z0 Return true if the selected row is a separator zis_seperator returned '%s' NF)r   	Exceptionr   )r/   r   r   r  r  s        r0   r  z"SoftwarePropertiesGtk.is_separator#  s9    	??400 	/!34	s    	505c                     | j                   j                          | j                  j                         D ]  }| j                   j	                  |g         y r(   )r  rj  apt_keyr  rb  )r/   r   s     r0   r   zSoftwarePropertiesGtk.show_keys+  sB    <<$$& 	*COO""C5)	*r2   c                 B   | j                   j                         }|dk7  r,| j                  |   }	 | j                  j	                  |       yy# t
        j                  $ r}t        |      r| j                         }| j                  | j                      }| j                  D ]g  }| j                  |   |k(  s| j                   j                  |       | j                   j                  |       | j                   j                  |        n Y d}~yY d}~yY d}~yd}~ww xY w)z4Set the update automation interval to the chosen oner   N)r   r  r   r   SetUpdateIntervalr   r  r=   r   r   rM  r   rR  )r/   rO  r   r   r  r   r  r   s           r0   r   z9SoftwarePropertiesGtk.on_combobox_update_interval_changed0  s    ))44672215E..u5  %% 	:1="&":":"<K$(MM$2O2O$PM#== 66s;{J66DD]S66AA#F66FF}U
  >	s   A D AD6ADDc                 *   t        | j                  | j                  | j                  | j                        }|j                         }|dk7  r	 | j                  j                  |       yy# t        j                  $ r}t        |       Y d}~yd}~ww xY w)zDShow a dialog that allows to enter the apt line of a to be used repoN)r   rm   r  rV   r  rL   r   r  r   r  r=   )r/   rO  rQ   liner  s        r0   on_add_clickedz$SoftwarePropertiesGtk.on_add_clickedB  sz    4++T-=-=<<6zz|4<;..t4  %% ;7::;s   A* *B=BBc                    | j                   j                         }|j                         \  }}|sy|j                  |t              }t        |t              r-t        | j                  | j                  || j                        }n,t        | j                  | j                  || j                        }|j                         t        j                  j                  k(  r:	 | j                   j#                  t%        |      t%        |j&                               yy# t(        j*                  $ r}t-        |       Y d}~yd}~ww xY w)z#Show a dialog to edit an ISV sourceN)r  get_selectionget_selectedr   LIST_ENTRY_OBJ
isinstancer   r   rm   r  rV   r   rL   r   ResponseTyperJ   r   ReplaceSourceEntryra  new_source_entryr   r  r=   )r/   rO  selr   r   old_source_entryrQ   r  s           r0   r  z%SoftwarePropertiesGtk.on_edit_clickedM  s   ##113((* ??4@&(9:%d&6&68H8H&6FF   0 0$2B2B 0$,,@F::<3++...;//4D0E03F4K4K0LN / %% ;7::;s   8D D>)D99D>c                 d    | j                   j                  d      dk(  r| j                  |       yy)r  	sensitiveTN)r  get_propertyr  r  s       r0   on_isv_source_activatedz-SoftwarePropertiesGtk.on_isv_source_activatedc  s0     ((5=  * >r2   c                    | j                   j                         }|sy|j                         \  }}|s7| j                  j	                  d       | j
                  j	                  d       y| j
                  j	                  d       |j                  |t              }|j                  j                  d      r| j                  j	                  d       y| j                  j	                  d       y)zdset the sensitiveness of the edit and remove button
           corresponding to the selected channelNFTzcdrom:)
r  r.  r/  r  r~   r  r   r0  r~  
startswith)r/   r  r5  r   r   r  s         r0   "on_treeview_sources_cursor_changedz8SoftwarePropertiesGtk.on_treeview_sources_cursor_changedi  s     ##113((***51,,U3((.t^<&&x0**51**40r2   c                 f   | j                   j                         }| j                   j                         \  }}|j                  |      }|r<|j	                  |t
              }	 | j                  j                  t        |             yy# t        j                  $ r}t        |       Y d}~yd}~ww xY w)zRemove the selected sourceN)r  r   r  r  r   r0  r   RemoveSourcera  r   r  r=   )r/   rO  r   rk   r  r   r  r  s           r0   on_remove_clickedz'SoftwarePropertiesGtk.on_remove_clicked~  s    %%//1..99;v~~d# ??4@L;))#l*;<  %% ;7::;s   "$B B0B++B0c                     t        j                  t        d      | j                  t         j                  t         j
                  j                  t         j                  t         j
                  j                  f      }dt        j                  v rDt        j                  j                  dt        j                  d   z        }|j                  |       |j                         }|j                          |t         j
                  j                  k(  rU	 | j                   j#                  |j%                               s*t'        | j                  t        d      t        d             yyy# t(        j*                  $ r}t-        |       Y d}~yd}~ww xY w)z[Provide a file chooser that allows to add the gnupg of a trusted
           software vendorz
Import key)titler?   rB   	SUDO_USERz~%szError importing selected filezCThe selected file may not be a GPG key file or it might be corrupt.N)r   FileChooserDialogr   rm   STOCK_CANCELr2  REJECTSTOCK_OKACCEPTrj   environrk   
expanduserset_current_folderrL   rh  r   AddKeyget_filenamer;   r   r  r=   )r/   rO  chooserhomer  r  s         r0   add_key_clickedz%SoftwarePropertiesGtk.add_key_clicked  s1    ''ao/3/?/?141A1A141A1A1H1H14s?O?O?V?V1XY
 "**$77%%ebjj.E&EFD&&t,kkm#"")));||**7+?+?+AB$**;< 6 78 C * %% ;7::;s   AE% %F8FFc                 v   | j                   j                         }|j                         \  }}|dk(  ry|j                  |d      }	 | j                  j                  |dd       s*t        | j                  t        d      t        d             yy# t        j                  $ r}t        |       Y d}~yd}~ww xY 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.)r  r.  r/  r   r   	RemoveKeyr;   mainr   r   r  r=   )r/   rO  r  r   a_iterr   r  s          r0   remove_key_clickedz(SoftwarePropertiesGtk.remove_key_clicked  s    &&446	#002T>oofa(	7<<))#cr(3dii01 7 89 4
 !! 	73A66	7s   AB B8#B33B8c                     	 | j                   j                          y# t        j                  $ r}t	        |       Y d}~yd}~ww xY w)zRestore the original keysN)r   
UpdateKeysr   r  r=   r/   rO  r  s      r0   on_restore_clickedz(SoftwarePropertiesGtk.on_restore_clicked  s8    	7LL##%!! 	73A66	7    AA  Ac                 &    | j                  |       y)zClose the window if requestedF)on_close_button)r/   rO  argss      r0   on_delete_eventz%SoftwarePropertiesGtk.on_delete_event  s    V$r2   c                     | j                   dk(  rI| j                  j                  dk(  r0t        | j                  | j
                        }|j                          | j                          y)zpShow a dialog that a reload of the channel information is required
           only if there is no parent definedTFN)r  rU   	no_updater   rm   rV   rL   quit)r/   rO  ds      r0   r]  z%SoftwarePropertiesGtk.on_close_button  sO     %%-&&%/#D$4$4$(LL2AEEG		r2   c                     	 | j                   j                          y# t        j                  $ r}t	        |       Y d}~yd}~ww xY w)z& when a cdrom is requested for adding N)r   AddCdromSourcer   r  r=   rY  s      r0   on_button_add_cdrom_clickedz1SoftwarePropertiesGtk.on_button_add_cdrom_clicked  s8    	7LL'')!! 	73A66	7r[  c                 *   | j                   j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j
                  j                  d       | j
                  j                  d       | j                  j                  t        d             |t        j                  j                  k(  r0|j                  d      }| j
                  j                  |dz         y y )NFTzApplying changes...
percentageg      Y@)button_driver_revertr   button_driver_applybutton_driver_restartbutton_driver_cancelprogress_barlabel_driver_actionr  r   
packagekitProgressType
PERCENTAGEr9  set_fraction)r/   progressptyper  
prog_values        r0   on_driver_changes_progressz0SoftwarePropertiesGtk.on_driver_changes_progress  s    !!--e4  ,,U3""..u5!!--d3%%d+%%d+  **1-B+CDJ++666!..|<J**:+=> 7r2   c                 p   	 | j                   j                  |       |s| j                  j                  d       | j                          | j                          | j                          | j                          | j                  j                  d       | j                  j                  d       | j                   j                  d       | j"                  j%                  d       y y # t        $ rD}| j                          t	        | j
                  t        d      t        |             Y d }~d }~ww xY w)NzError while applying changesFT)r   generic_finishr%  on_driver_changes_revertr;   rm   r   ra  rm  r   clear_changesr   set_driver_action_status"update_label_and_icons_from_statusri  rj  rl  scrolled_window_driversr~   )r/   r  resultinstalls_pendingr  s        r0   on_driver_changes_finishz.SoftwarePropertiesGtk.on_driver_changes_finish  s    	OLL''/  ))%0 !!#))+335%%11$7$$006%%11%8((66t<    	O))+$""A&D$Es1vNN	Os   C( (	D519D00D5c           
         t        j                         | _        g }g }d}| j                  D ]  }|j                  r|j                  | j                  | j                  |             d|j                  v sId}| j                  | j                  |d      D ]:  }|j                  s|j                  | j                  | j                  |             < |j                  | j                  | j                  |              t        j                         | _        	 |rFd}|rd}| j                  j                  |dd| j                  | j                  d| j                  |       |rn|r.g }|D ]'  }	|	j!                  d      d   }
|j                  |
       ) | j                  j#                  || j                  | j                  d| j                  d       | j$                  j'                  d       | j(                  j'                  d       | j*                  j'                  d       y # t,        $ r$}t/        dj1                  |             Y d }~y d }~ww xY w)NFnvidiaTr(   ;r   z;Warning: install transaction not completed successfully: {})ro  Taskr   driver_changescurrent_verrb  get_package_idr   r  get_dependenciesr
   Cancellablecancellableremove_packages_asyncrv  r  r\  install_packages_asyncri  r~   rj  r}  r%  r   r  )r/   r  installsremovals
has_nvidiapkgdepr  
to_installitemr  r  s               r0   on_driver_changes_applyz-SoftwarePropertiesGtk.on_driver_changes_apply  s   !(
&& 	JC 3 3DNNC HI sxx'!%J#44T^^S(S V??$OOD,?,?PS,TUV  3 3DNNC HI	J ??, 	[#( '+$228!  ,, ;;$ 99, !#J ( 0#zz#q1"))$/0 33H((77 55 %%33E:$$2259((66u= 	[OVVWXYZZ	[s   D	H# #	I,IIc                 6   | j                   D ]  }|j                  d        | j                  D ]"  }| j                  |   }|j                  d       $ | j                          | j                  j                  d       | j                  j                  d       y )NTF)no_drvr   orig_selectionrz  ri  r~   rj  )r/   r   r  aliass       r0   ry  z.SoftwarePropertiesGtk.on_driver_changes_revert%  s     kk 	$Fd#	$ (( 	$E((/Fd#	$ 	!!//6  ..u5r2   c                 X    | j                   j                          | j                          y r(   )r  cancelrz  )r/   button_cancels     r0   on_driver_changes_cancelz.SoftwarePropertiesGtk.on_driver_changes_cancel5  s     !r2   c                 0   dt         j                  v rt         j                  d   }nd}|dk(  r7t         j                  j                  d      rt	        j
                  ddg       y |dk(  r6t         j                  j                  d      rt	        j
                  d	g       y |d
k(  r6t         j                  j                  d      rt	        j
                  dg       y |dk(  r7t         j                  j                  d      rt	        j
                  dg       y y y )NXDG_CURRENT_DESKTOPUnknownzubuntu:GNOMEz/usr/bin/gnome-session-quitzgnome-session-quitz--rebootXFCEz/usr/bin/xfce4-session-logoutzxfce4-session-logoutLXDEz/usr/bin/lubuntu-logoutzlubuntu-logoutLXQtz/usr/bin/lxqt-leavez
lxqt-leave)rj   rI  rk   exists
subprocesscall)r/   button_restartdesktops      r0   on_driver_restart_clickedz/SoftwarePropertiesGtk.on_driver_restart_clicked9  s     BJJ.jj!67GG~%<=OO1:>?ggnn<=OO345ggnn67OO-./ggnn23OO\N+ 4  r2   c                      i | _         g | _        y r(   )r  r  r.   s    r0   rz  z#SoftwarePropertiesGtk.clear_changesM  s      r2   c                    t        j                  t        d      d      | _        | j                  j	                  d| j
                         t        j                  t        d      d      | _        | j                  j	                  d| j                         t        j                  t        d      d      | _        | j                  j	                  d| j                         t        j                  t        d      d      | _
        | j                  j	                  d| j                         | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  | j                  ddd	       | j                  j                  | j                  ddd	       | j                  j                  | j                  ddd	       | j                  j                  | j                  ddd	       t         j                   j"                  t         j                   j"                  ddd
}t        j$                  ddt        d      i|| _        | j(                  j+                  | j&                         t        j,                         | _        | j                  j                  | j.                  ddd	       | j.                  j                  d       i | _        d| _        g | _        i | _        g | _        d	| _        d| _        y)zAdditional Drivers tabRe_vertT)r   use_underlineclickedz_Apply Changes_Cancelz_Restart...Fr   )halignvalignvexpandvisibler   z"Searching for available drivers...Nr7   )r   Buttonr   ri  r   ry  rj  r  rl  r  rk  r  r~   r   box_driver_actionpack_endAlignCENTERLabellabel_driver_detailbox_driver_detailr  ProgressBarrm  devicesr   r  r  r  nonfree_driversui_building)r/   propss     r0   r   z"SoftwarePropertiesGtk.init_driversQ  s    %(JJQy\QU$V!!!)))T5R5RS#&::A6F4GW[#\   ((D4P4PQ$'JJQy\QU$V!!!)))T5R5RS%(ZZa6FVZ%["""**9d6T6TU!!//6!!--d3  ..u5  ,,T2!!--e4""..u5''(@(@%PQR''(A(A5%QRS''(B(BE5RST''(A(A5%QRS))**SYY5E5E41#&99 $M1 6B 4C $MFK$M ""4#;#;<OO-''(9(95%K%%e,"     r2   c                 V   d| _         	 t        j                  | j                        | _        t        j                  | j                         y #  t        j                  | j                  j                  t        d             t        j                  t        j                           Y y xY w)NTz.An error occurred while searching for drivers.)r   r   system_device_driversr   r  r   r   r  set_textr   sys
excepthookexc_infoshow_driversr.   s    r0   r   z$SoftwarePropertiesGtk.detect_drivers~  s{    !
	!77GDL 	d''(	MM$22;;LMO
 NNCLLN+s   $A AB(c                    | j                   ry d }|rh| j                  |   }	 t        j                  | j                  |      }| j                  |   }|r'|j                  s| j
                  j                  |       |j                         rf|| j
                  v r| j
                  j                  |       ||| j                  v r|| j                  |   ur| j
                  j                  |       n}|| j
                  v r| j
                  j                  |       || j                  vr|| j                  |<   |5|| j
                  vr'|j                  r| j
                  j                  |       | j                  j                  t        | j
                               | j                  j                  t        | j
                               y # t        t        f$ r Y bw xY wr(   )r  r   r   get_linux_modules_metapackager  r  rb  KeyError	TypeErrorr  r  r  ri  r~   r  rj  )r/   r  modaliaspkg_namer  modules_packagemodules_package_objs          r0   on_driver_selection_changedz1SoftwarePropertiesGtk.on_driver_selection_changed  s   ..*C"("F"Ft~~W_"`&*nn_&E#"+>+J+J''../BC d)))##**3/ 3 33d&9&9(&CC##**3/d)))##**3/ t22206##H-t222##**3/!!//T5H5H0IJ  ..tD4G4G/HI3 i( s   AG
 
GGc                    t        d      dft        d      dft        d      dft        d      dfd}i i i i d}d	}d	}	 |d
   rddt        d      di|d<   |d   D ]F  }|d   |   }d}	 |d   r|d   rd}d	}		 |d   rd}	d}	 | j                  |   }
|
j                  }| j                  j                  |
      }|X| j                  j                  |j                  d          t        d      j                  | j                  j                  |      }nt        d      j                  |      }|d   rt        d      }nt        d      }|dk(  rt        d      }nt        d      }|j                  ||      }d	}|	s|d   s|}|rd}d}||   j                  ||||	d       I |sd	}|sd}d|t        d      di|d <   n*|s(d!D ]#  }||   D ]  }||   |   d   sd||   |   d"<    % |D ]   }||   D ]  }||   |   d"   s||   \  }} " |fS # t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r t        dj                  ||             Y w xY w)#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_driverFmanual_installTz*Continue using a manually installed driver)selectedr  r  driversr  r  from_distrobuiltinr   zUsing {} from {}zUsing {}zHWARNING: a driver ({}) doesn't have any available package associated: {}freezopen sourceproprietaryz&{base_description} ({licence}, tested)z{base_description} ({licence}))base_descriptionlicence)r  r  r  zDo not use the devicer  )r  r  r  )r   r  r   r  r   get_candidate_verr   lookup	file_listr  
short_descr   
setdefault)r/   devicepossible_overall_statusreturned_drivershave_builtinone_selectedpkg_driver_namecurrent_driverdriver_statusr  r  	installed	candidater  r  base_stringr  sectionr  keysoverall_statusicons                         r0   gather_device_dataz(SoftwarePropertiesGtk.gather_device_data  ss   & LMOcdKLn]#$%X#Y[i"j9:<LM	#
 ,.bXZikl	&':>TIJKwIxAz :{ !56
  &i0 6	^O#I.?N *M!-0^M5R$1M G!),"G#'Lnn_5OO	 MM;;C@	(LL''	(;(;A(>?"#$6"7">">t||?V?VXg"hK"#J-"6"6"GK f%M*M*- HI @A%,,kSZ,[KH#34H#I$#H#'L]+66U]XcT[I] ^i6	^r H-1CDE\C]4_ -`[)  = SG$4W$= S+G4X>yINR,W5h?
KSS ( 	NG(1 N#G,T2:>-DW-M*^TN	N
 &677a  		      `gghw  zH  I  JsI    H ,H';	H7B*I	H$#H$'	H43H47	II$I/.I/c                    | j                   s%| j                  j                  t        d             y | j                  j                  | j                         d| _        i | _        t        | j                   j                               D ]  }| j                  | j                   |         \  }}}t        j                         }|j                  t        j                  j                         |j!                  t        j                  j"                         |j%                  |t        j&                  j(                         t        j*                  dt        j,                  j.                        }|j1                  |ddd       t        j*                  dt        j,                  j2                        }|j1                  |ddd       t        j4                  j7                  dj9                  | j                   |   j;                  dt        d	            | j                   |   j;                  d
t        d	                        }|j!                  t        j                  j                         |j1                  |ddd       t        j4                  j7                  dj9                  |            }|j!                  t        j                  j                         |j=                  d       |j1                  |ddd       ||f| j                  |<   d }	dD ]  }
||
   D ]  }t        j>                  jA                  d ||
   |   d         }|	r|jC                  |	       n|}	|j1                  |ddd       |jE                  ||
   |   d          |
dk(  r| jF                  jI                  |       |
dv sd||
   |   v r)||
   |   d   r|jK                  d| jL                  |       n|jK                  d| jL                  ||       |d   s|
dk7  s|jO                  d         | j                  j1                  |ddd        d| _        | j                  jQ                          | jS                          y )Nz No additional drivers available.T   )spacingorientationFr   z{}: {}vendorr  r   <small>{}</small>r  r  r  r  )manually_installr  r  r   r  )*r  r  r  r   r  r  r  dynamic_device_statussortedr  r  r   Image
set_valignr  START
set_halignr  set_from_icon_nameIconSizeMENUBoxOrientation
HORIZONTALr.  VERTICALr  ry   r  r  set_use_markupRadioButtonnew_with_label
join_groupr   r  rb  r   r  r~   r   r{  )r/   r  r  r  r  r  
device_boxdevice_detailrO  option_groupr  driverradio_buttons                r0   r  z"SoftwarePropertiesGtk.show_drivers)  s   ||$$--a0R.ST""))$*B*BC%'"T\\..01 *	KF.2.E.EdllSYFZ.[+^T7IIKM$$SYY__5$$SYY%5%56,,T3<<3D3DE8R8RSJ!!-qAGGA3??;S;STM!!-tQ?YY]]8??4<<3G3K3KHVWXaVb3ceieqeqrxeye}e}  F  HI  JS  HT  fU  $V  WFciioo.$$VT5!<YY]]#6#=#=n#MNFciioo.!!$'$$VT5!<2?1HD&&v.L\ :%g. :F#&??#A#A$PWHXY_H`anHo#pL#$//='3!,,\4J ++GG,<V,DZ,PQ+-**<8"CC	U\]dUeflUmHmry  {B  sC  DJ  sK  LU  sV$,,Y8X8XZ`a$,,Y8X8XZ`bhi34DX9X$2259!::& ""--j%JU*	KX !'')%%'r2   c                 "   | j                   D ]  }| j                  | j                   |         \  }}}| j                  |   \  }}|j                  |t        j
                  j                         |j                  dj                  |              y)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  rO  s          r0   r|  z8SoftwarePropertiesGtk.update_label_and_icons_from_statusb  s     ll 	IF.2.E.EdllSYFZ.[+^T7&*&@&@&H#]F,,T3<<3D3DE077GH	Ir2   c                    t         j                  j                  d      r[| j                  j	                  t        d             | j                  j                  d       | j                  j                  d       y d| _
        | j                  D ]b  }| j                  |   d   D ]K  }| j                  |   }| j                  |   d   |   d   r+|j                  s8| j                  dz   | _
        M d | j                  dkD  rJ| j                  j	                  t        j                  dd	| j                        d
| j                  iz         y | j                  j	                  t        d             y )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.)rj   rk   r  rn  r  r   rk  r   rm   set_urgency_hintr  r  r   r  r   ngettext)r/   r  r  r  s       r0   r{  z.SoftwarePropertiesGtk.set_driver_action_statusl  sJ   GGNN56$$..q1s/tu&&2248--d3 ll 	DF LL0; DnnX.||F+I6x@HS__+/+?+?!+CD(D	D !#$$..w/?/?/U/V/3/C/C0E 3:4;O;O1P	0Q R $$..q1U/VWr2   c                 $    t        |       | _        y r(   )r   ubuntu_pro_pager.   s    r0   r   z%SoftwarePropertiesGtk.init_ubuntu_pro  s    ,T2r2   )NNNN)r   r(   )Kr3   r4   r5   ra   r   r   r   r   r   r   r   r   r   rP  rS  r   r   r   r6  r   r+  r0  r  r  r  r  r   r  rh  r  r   r  r  r   r  r  r  r
  r  r   r   r   r   r   r   r   r  r   r   r,  r  r:  r=  r@  rP  rV  rZ  r_  r]  rf  rv  r  r  ry  r  r  rz  r   r   r  r  r  r|  r{  r   r7   r2   r0   rS   rS      s   x&t1!
_>>
]BY09&pNd<
>
0BN,D-N&7P7@7
77;7$, RIV'7"@&		4
*/
) 22:*
$	;;,+1*
;;.7 7
	7?="5[n6 ,(!+!Z)"&JPp8d7(rIX03r2   rS   )Lr   r  r   	dbus.glibdbus.mainloop.glibr   r   rj   r  r:   r   r  r  girequire_versiongi.repositoryr   ro  r	   r   r   r
   r   r   aptsources.sourceslistr   r   r   r   r   r   r   r   r   r   softwareproperties.distro%softwareproperties.SoftwarePropertiesr   softwareproperties.gtk.utilsr   r   r   r   UbuntuDriversr   mainloopglibDBusGMainLooppyglib_versionthreads_initrangeLIST_MARKUPLIST_ENABLEDr0  r  r  r  r  r  STORE_ACTIVESTORE_DESCRIPTIONr  r  STORE_VISIBLEr+   r,   r-   r*   r]  r^  r_  objectr&   r=   r;   rS   r7   r2   r0   <module>r.     s  6         	    
  	   5%     5%     7C     #U + 6 = = 4 4   & " . 4 6 (    D ,  !          5"D.3Ah +lN
 	qN   	qN 
!H  & &
h3.0C h3r2   