3
NZ}                 @   s   d dl Z d dlZd dlT d dlmZmZmZmZ d dlT d dl	m
Z
 ddlT d dlT d dlT ddlm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G dd deZG dd deeZ dS )    N)*)devicemodelswifiLedmWifi)
to_unicode   )	Ui_Dialog               c               @   s   e Zd Zdd ZdS )DeviceTableWidgetItemc             C   s   t j| |t j || _d S )N)QTableWidgetItem__init__ZUserType
device_uri)selftextr    r   '/usr/share/hplip/ui5/wifisetupdialog.pyr   >   s    zDeviceTableWidgetItem.__init__N)__name__
__module____qualname__r   r   r   r   r   r   =   s   r   c               @   sR  e Zd Ze ZdPd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" 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d7d8 Ze d9fd:d;Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&e'fdFdGZ(dHdI Z)dJdK Z*dQdLdMZ+dNdO Z,dS )RWifiSetupDialogNTc             C   s   t j| | | j|  || _i | _i | _d| _d| _d| _d| _	d| _
t| _i | _d | _t| _d| _d| _|| _| j  d| _t| _tjd| j d S )N FZusbz0.0.0.0ZWifi0r   )QDialogr   ZsetupUir   devicesnetworksssiddirectedshow_extendedbussearch	PAGE_EXITmax_pagelocation_cachedevSUCCESS_NOT_CONNECTEDsuccessiphn
standaloneinitUiadapterNamer   wifiObjQTimer
singleShotshowIntroPage)r   parentr   r,   r   r   r   r   F   s*    
zWifiSetupDialog.__init__c             C   s   | j ttdd | jjj| j | jjj| j | j	jj| j
 tjtjtj | j  | j  | j  | j  | j  d S )NZhp_logoZ128x128)ZsetWindowIconQIconload_pixmapCancelButtonclickedconnectCancelButton_clicked
BackButtonBackButton_clicked
NextButtonNextButton_clickedsignalSIGINTSIG_DFLinitIntroPageinitDevicesPageinitNetworkPageinitConfigWifiPageinitExitPage)r   r   r   r   r-   i   s    zWifiSetupDialog.initUic             C   sT   | j jtdd | jjtdd | jr>| jj| jd n| jj| jd d S )NZusb_connectionotherinfo16x16a  This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete.

<p><i>Note: This configuration utility does not setup (install) your printer on this computer. Use hp-setup to setup your printer after it has been configured on the network by this utility.</i></p>
<p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>a  This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete.

<p><i>Note: Printer setup (installation) will continue after your printer is configured on the network.</i></p>
<p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>)ZPicture	setPixmapr5   ZInfoIconr,   ZMainTitleLabelsetText_WifiSetupDialog__tr)r   r   r   r   rA   }   s    


zWifiSetupDialog.initIntroPagec             C   s&   | j jd | jjd | jt d S )NFT)r:   
setEnabledr<   displayPage
PAGE_INTRO)r   r   r   r   r2      s    zWifiSetupDialog.showIntroPagec             C   s   | j jj| j d S )N)ZRefreshButtonr7   r8   RefreshButton_clicked)r   r   r   r   rB      s    zWifiSetupDialog.initDevicesPagec             C   sn  | j jd | jt t  z| jstjd dtj	t
fi}yddlm} W n tk
rj   tjd Y nX t  |jtd t  tj| jgdd|| j| _W d t  X | j  | jr | jjd | jjtdd	 t| jd
kr| jj| jd n| jj| jdt| j  | j  n@| jjd | jjtdd	 tjd| j  | jj| jd | j t! d S )NTzSearching on USB bus...zwifi-configr   )smart_installz+Failed to Import smart_install.py from baseZqt4rG   rH   r   zF<b>1 wireless capable device found.</b> Click <i>Next</i> to continue.zi<b>%s wireless capable devices found.</b> Select the device to install and click <i>Next</i> to continue.FerrorzNo devices found on bus: %sz|<b>No wireless capable devices found.</b><br>Plug in your printer with a USB cable and click <i>Refresh</i> to search again.)"r:   rL   setNextButtonBUTTON_NEXTbeginWaitCursorr   logrG   operatorgtZWIFI_CONFIG_NONEbaserP   ImportErrorrQ   endWaitCursordisableZGUI_MODEr   ZprobeDevicesr"   r#   clearDevicesTabler<   ZDevicesFoundIconrI   r5   lenZDevicesFoundLabelrJ   rK   loadDevicesTablerM   PAGE_DEVICES)r   Zfilter_dictrP   r   r   r   showDevicesPage   s:    


zWifiSetupDialog.showDevicesPagec          
   C   s  | j jd | j jt| j | jd| jdg}d}| j jt| | j j| tj	tj
B }xt| jD ]|\}}tj|\	}}}}	}
}}}}tj|	}tt||}|j| | j j|d| tt|}|j| | j j||| qjW | j j  | j jd | j jd | j jd d S )NFZModelz
Device URIr   r   T)DevicesTableWidgetsetSortingEnabledsetRowCountr]   r   rK   setColumnCountsetHorizontalHeaderLabelsQtItemIsSelectableItemIsEnabled	enumerater   parseDeviceURIr   ZnormalizeModelUINamer   strsetFlagssetItemr   resizeColumnsToContents	sortItems	selectRow)r   headersZdevice_uri_colflagsrowdback_endis_hpr"   modelserialdev_filehostzcportZmodel_uiir   r   r   r^      s(    



z WifiSetupDialog.loadDevicesTablec             C   s&   | j j  | j jd | j jd d S )Nr   )ra   clearrc   rd   )r   r   r   r   r\      s    
z!WifiSetupDialog.clearDevicesTablec             C   s    | j   g | _tjd| j d S )Nr   )r\   r   r0   r1   r`   )r   r   r   r   rO      s    z%WifiSetupDialog.RefreshButton_clickedc             C   s~   | j jtdd | jjd | jjt j| j | j	jj| j
 | jjt j| j | jjt j| j | j jj| j d S )N"   r   F)NetworksTableWidgetZsetIconSizeZQSizeZShowExtendedCheckBox
setCheckedr7   boolr8   ShowExtendedCheckBox_clickedZSearchPushButtonSearchPushButton_clickedZUndirectedRadioButtonUndirectedRadioButton_clickedZDirectedRadioButtonDirectedRadioButton_clickeditemSelectionChanged(NetworksTableWidget_itemSelectionChanged)r   r   r   r   rC      s    zWifiSetupDialog.initNetworkPagec          .   C   s  | j d kr|ytj| j| _ W n^ tk
rz } zBt| | jd| jt|d f  | j d k	rd| j j  | j  d S d }~X nX | j	j
  d| _y| jj| j }W n* tk
r } z| j| d S d }~X nX t|dkrt| | jd | j d k	 r| j j  | j  tjd y | jj| j |\| _| _}}W n, tk
r\ } z| j| d S d }~X nX | jdkrt| | jd | j d k	r| j j  tjd| j  tjd| j  tjd	|  tjd
|  | j  | jt | jt d S )Nz0<b>Error opening device:</b><p>%s</p><p>(%s)</p>r   z4<b>Unable to locate wireless hardware on device.</b>zTurning on wireless radio...r   z*<b>Unable to turn on wireless adaptor.</b>zAdaptor ID: %szAdaptor name: %szAdaptor state: %szAdaptor presence: %s)r'   r   ZDevicer   Error	FailureUIrK   rk   closer   r~   num_networksr/   ZgetWifiAdaptorIDshowIOErrorr]   rU   debugZsetAdaptorPower
adaptor_idr.   performScanrR   rS   rM   PAGE_NETWORK)r   eZadaptor_liststateZpresencer   r   r   showNetworkPage  sL    
"





 


zWifiSetupDialog.showNetworkPagec             C   s  t   zt| jj | _| jrn| jrny| jj| j| j	| j| _
W q tk
rj } z| j| d S d }~X qX nDy| jj| j| j	| _
W n* tk
r } z| j| d S d }~X nX W d | jj  t  X | j
d | _| j  | jrD| jjd | jjtdd | jdkr"| jj| jd n| jj| jd| j  | j  n:| jjd | jjtd	d tjd
 | jj| jd d S )NZnumberofscanentriesTrG   rH   r   z<b>1 wireless network found. </b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again.z<b>%d wireless networks found.</b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again.FrQ   zNo wireless networks found.zo<b>No wireless networks found.</b><br>Enter a wireless network name and/or press <i>Search</i> to search again.)rT   r   SSIDLineEditr   r   r    r/   r   r'   r.   r   r   r   r   rZ   r   clearNetworksTabler<   rL   ZNetworksFoundIconrI   r5   ZNetworksFoundLabelrJ   rK   loadNetworksTablerU   warning)r   r   r   r   r   r   3  s:    




zWifiSetupDialog.performScanc             C   s   || _ | j  d S )N)r!   r   )r   br   r   r   r   [  s    z,WifiSetupDialog.ShowExtendedCheckBox_clickedc             C   s   | j   | j  d S )N)r   r   )r   r   r   r   r   `  s    z(WifiSetupDialog.SearchPushButton_clickedc             C   s   | | _ | jj|  d S )N)r    r   rL   )r   r   r   r   r   r   e  s    z-WifiSetupDialog.UndirectedRadioButton_clickedc             C   s   || _ | jj| d S )N)r    r   rL   )r   r   r   r   r   r   j  s    z+WifiSetupDialog.DirectedRadioButton_clickedc             C   s  dt d | _| _| jrt  z| jrxt| jD ]}| jd|  }| jd|  }y| j|  W n~ t	k
r   t
j||}|jdd }| jd| < |jdd }| jd	| < |jd
d }| jd| < |||f| j|< Y q8X | j| \| jd| < | jd	| < | jd| < q8W | jjd | jj| j | jd| jd| jd| jdg}| jr|j| jd| jd| jd| jdg | jjt| | jj| tjtjB }	xt| jD ]}| jd|  }
|
dkrd }n|	}| jd|  }| jd|  }| jd|  }tjd||
|||f  | jr| jd|  }| jd|  }| jd|  }| jd|  }| jd|  }| jd	|  }tjd|||||||f  tt|
}|d k	r|j| |jtj| | jj|d| t d| d}| jrtt!|| jd||f }ntt!|| jd | }|d k	r>|j| | jj|d!| tt|}|d k	rn|j| | jj|d"| tt|}|d k	r|j| | jj|d#| | jrttt|}|d k	r|j| | jj|d$| tt|}|d k	r
|j| | jj|d%| tt|}|d k	r:|j| | jj|d&| ttd'||f }|d k	rr|j| | jj|d(| qW | jj"  | jjd) | jj#d!tj$ | jj%d | jj&j'  W d t(  | j)j*d) X n| j)j*d d S )*Nr   r   zbssid-%dzsignalstrength-%dZlatitudeUnknownzlatitude-%dZ	longitudezlongitude-%daddressz
address-%dFzNetwork Name (SSID)zSignal StrengthZSecurityZModeZChannelzAddress (BSSID)ZLocationzLat/Longzssid-%dz	(unknown)zencryptiontype-%dzcommunicationmode-%dz.%d: Name=%s, strength=%s, security=%s, mode=%sz
channel-%dzdbm-%dz8%d: channel=%d bssid=%s dbm=%s lat=%s long=%s address=%szsignal%drF   z%s/5 (%s dBm)z%s/5r   r
   r   r         z%s/%s   T)+r   nnetworkr   rT   r!   ranger   r&   KeyErrorr   ZgetLocationgetr   rb   rc   rK   extendrd   r]   re   rf   rg   rh   rU   r   r   rk   rl   ZsetDataUserRolerm   r5   r4   rn   ro   ZDescendingOrderrp   r   emitrZ   r<   rL   )r   r   ZbssidsslocationZlatZlngr   rq   Zenabled_flagsnamerr   secmodeZchnZdbmr}   pixmapr   r   r   r   o  s    2

 

 

 

 

 

 

 

 

z!WifiSetupDialog.loadNetworksTablec             C   sd   | j j }| j j|d}t|jtj\}}|r`| jd|  }|j dkrV| j	t
 n
| j	t d S )Nr   zencryptiontype-%dnone)r   
currentRowitem	value_intdatarf   r   r   lowerrR   BUTTON_CONNECTrS   )r   rs   r   r   okr   r   r   r   r     s    
z8WifiSetupDialog.NetworksTableWidget_itemSelectionChangedc             C   s&   | j j  | j jd | j jd d S )Nr   )ra   r~   rc   rd   )r   r   r   r   r     s    
z"WifiSetupDialog.clearNetworksTablec             C   s    | j   i | _tjd| j d S )Nr   )r   r   r0   r1   r   )r   r   r   r   RefreshButton2_clicked  s    z&WifiSetupDialog.RefreshButton2_clickedc             C   s   | j jt j| j d S )N)ShowKeyCheckBoxZtoggledr   r8   ShowKeyCheckBox_toggled)r   r   r   r   rD     s    z"WifiSetupDialog.initConfigWifiPagec             C   s   | j t | jj| j t }|jd | jj| | jjt	  | j
jd | jjtd| j d | jjtdd | jjtdd d	| jj kr| jjd
 nd| jj kr| jjd
 | jj  | jjtj | jt d S )N   Fzsignal%drF   rG   rH   keysZ32x32ZwpaTZwep)rR   r   Z	SSIDLabelrJ   r   ZQFontZsetPointSizeZsetFontKeyLineEditrk   r   r   ZStrengthIconrI   r5   r   ZConfigureIconZKeysIconsecurityr   ZWPARadioButtonZWEPRadioButtonZsetFocussetEchoMode	QLineEditPasswordrM   PAGE_CONFIGURE_WIFI)r   Zfontr   r   r   showConfigWifiPage  s"    


z"WifiSetupDialog.showConfigWifiPagec             C   s&   |r| j jtj n| j jtj d S )N)r   r   r   ZNormalr   )r   r   r   r   r   r     s    z'WifiSetupDialog.ShowKeyCheckBox_toggledc             C   sJ   | j jt j| j t| | _| jjj| j g | _	d| _
| j jd d S )Nr   r   )PageSpinBoxZvalueChangedintr8   PageSpinBox_valueChangedr0   RefreshTimerZtimeoutRefreshTimer_timeoutpages
page_indexZ
setMinimum)r   r   r   r   rE   %  s    
zWifiSetupDialog.initExitPagec             C   sV  | j t | jjd | jjd | jjt| j d| _	d| _
t| _t  zy| jj| j| j\| _	}}}}}}| j	dkr| jj| j| j\| _	}}}}}| jj| j| j}| jj| j| j| j| j\}	}
}}| jj| j| _
W n, tk
r } z| j| d S d }~X nX W d | jj  t  X ds:d|j krBt| _n|j dkrVt| _| j	dkrht| _g | _| jtkr| jj | j!dt" t#d	d
f | j$j%t"d  n| jtkr| jj | j!d| j	 t#dd
f | jjd | j&jd | j$j'  nD| jj | j!d| j	 t#dd
f | jjd | j&jd | j$j'  |d kr`| j(j| j!d n| j(jt| | j
d kr| j)j| j!d n| j)jt| j
 | j*jt| j	 | j+jt| | j,jt| | jjd | j-jtd||	|f  | j.j/t#d| d x|D ]\}}|r|j }|j0drDt#dd
}n:|j0dr\t#dd
}n"|j0drtt#d	d
}n
t#dd
}| jj t1j2dt|j3d |f qW t4| j}| j5j6| | j5j|dk | j5j7d | j8j|dk | j9j|dk | j8j| j!dt| d| _:| j;j| j| j: d  | j<j/| j| j: d  | j=t> d S )NFTz0.0.0.0r   ZdhcpdefaultZautoipa,  <b>Your printer has not been connected to the wireless network.</b> A valid connection to a wireless network can take up to 2 minutes. This screen will automatically refresh every %s seconds.<p>If your printer fails to connect within a reasonable time, there may be a problem with your configuration.rQ   rH   i  zYour printer has been connected to the wireless network and has been assinged a IP. Now run <pre>hp-setup %s</pre>  If IP is not accessible, try again for another IP.r   zYour printer has been successfully configured on the wireless network. You may now unplug the USB cable. To setup the printer, now run <pre>hp-setup %s</pre>rG   r   z%s/%s (%s dBm)zsignal%drF   warnZcritzvsa_%sr   r   zof %sr   )?rR   BUTTON_FINISHr<   rL   r6   ZSSIDLabel_2rJ   rk   r   r*   r+   r(   r)   rT   r/   ZgetIPConfigurationr'   r.   ZwifiobjZgetwifiotherdetailsZgetVSACodesZgetSignalStrengthr   ZgetHostnamer   r   r   rZ   r   SUCCESS_CONNECTEDSUCCESS_AUTO_IPr   appendrK   REFRESH_INTERVALr5   r   startr:   stopZAddressModeLabelZHostnameLabelZIPAddressLabelZGatewayLabelZDNSLabelZSignalStrengthLabelZSignalStrengthIconrI   
startswithr   ZqueryStringzfillr]   r   Z
setMaximumsetValueZ	PageLabelZ
PageLabel2r   	ExitLabelExitIconrM   r$   )r   _ZaddressmodeZ
subnetmaskZgatewayZpridnsZsec_dnsZpri_dnsZ	vsa_codesZss_maxZss_minZss_valZss_dbmr   csr   r   Z	num_pagesr   r   r   showExitPage/  s    
"
 "

 ""


*
zWifiSetupDialog.showExitPagec             C   s>   |d | _ | jj| j| j  d  | jj| j| j  d  d S )Nr   r   )r   r   rJ   r   r   rI   )r   r}   r   r   r   r     s    
z(WifiSetupDialog.PageSpinBox_valueChangedc             C   s   | j   d S )N)r   )r   r   r   r   r     s    z$WifiSetupDialog.RefreshTimer_timeoutr   c          *   C   s   t   zhy| jj| j| j\}}}W n* tk
rN } z| j| d S d }~X nX tjd|  tjd|  W d t	  X t   zTy$| jj
| j| j| j| j| j| W n* tk
r } z| j| d S d }~X nX W d t	  X d S )NzCrypto algorithm: %szCrypto mode: %s)rT   r/   ZgetCryptoSuiter'   r.   r   r   rU   r   rZ   	associater   r   r   )r   keyZalgr   Zsecretidr   r   r   r   r     s$    
$
zWifiSetupDialog.associatec          	   C   s*  | j j }|tkr| j  n|tkr| jj }|dkr| jj|dj| _t	j
| j| _| j| jd  t	j| j\	}}}}}}}	}
}tj|j | _| j  n|tkrd| _d| _d| _| jj }|dkr| jj|d}|d k	rt|j | _tjd| j  t|jtj \| _!}|r| j"d| j!  | _tjd| j  | j"d	| j!  | _tjd
| j  | j"d| j!  | _tjd| j  | jj dkr| j#  n| j$  | j%  | j&  nh|t'krt| j(j }| j$| | j%  | j&  n4|t)kr| j*d k	r| j*j+  | j+  n
tj,d d S )Nr   r   zwifi-configNoneZInfrastructurezSelected network SSID: %szencryptiontype-%dzSecurity: %szcommunicationmode-%dzMode: %szsignalstrength-%dzSignal strength: %sr   zInvalid page!r   r   )-StackedWidgetcurrentIndexrN   r`   r_   ra   r   r   r   r   ZqueryModelByURIZmqgetWifiObjectrj   r   ZnormalizeModelNamer   rw   r   r   r   r   r   r   r   r   r   rU   r   r   r   rf   r   r   r   r   r   showAssociateProgressDialogr   r   r   r$   r'   r   rQ   )r   prs   ru   rv   r"   rw   rx   ry   rz   r{   r|   r}   r   r   r   r   r   r=     sZ    













z"WifiSetupDialog.NextButton_clickedc             C   s   t | jd| jddt| }|j| jd |jtj |jd |j  d}x:t	tD ].}|j
| tjd tj  |j rXd}P qXW |j
t |j  |r| jd k	r| jj  | j  d S )Nz9Waiting for printer to connect to the wireless network...ZCancelr   z"HP Device Manager - Please wait...Fr   T)ZQProgressDialogrK   ASSOCIATE_DELAYZsetWindowTitleZsetWindowModalityrf   ZWindowModalZsetMinimumDurationZ	forceShowr   r   ZQThreadZsleepqAppZprocessEventsZwasCanceledr   r'   )r   ZAssociateProgressDialogZcanceledxr   r   r   r     s&    





z+WifiSetupDialog.showAssociateProgressDialogc             C   s   | j j }|tkr"i | _| j  nb|tkr4| j  nP|tkrF| j  n>|t	krz| j
j  | jj dkrp| j  q| j  n
tjd d S )Nr   zInvalid page!)r   r   r_   r   r2   r   r`   r   r   r$   r   r   r   r   r   rU   rQ   )r   r   r   r   r   r;     s    






z"WifiSetupDialog.BackButton_clickedc             C   s    | j d k	r| j j  | j  d S )N)r'   r   )r   r   r   r   r9   /  s    

z$WifiSetupDialog.CancelButton_clickedc             C   s   | j j| | j| d S )N)r   ZsetCurrentIndexupdateStepText)r   Zpager   r   r   rM   6  s    zWifiSetupDialog.displayPagec             C   sV   |t kr| jj| jd n6|tkr8| jj| jd n|tkrR| jj| jd d S )NzNext >ZFinishZConnect)rS   r<   rJ   rK   r   r   )r   typr   r   r   rR   ;  s    zWifiSetupDialog.setNextButtonc             C   s(   | j j| jd|d | jd f  d S )NzStep %s of %sr   )ZStepTextrJ   rK   r%   )r   r   r   r   r   r   F  s    zWifiSetupDialog.updateStepTextc             C   s<   t | | jdt|d   | jd k	r0| jj  | j  d S )Nzf<b>An I/O error occurred.</b><p>Please check the USB connection to your printer and try again.</p>(%s)r   )r   rK   rk   r'   r   )r   r   r   r   r   r   J  s    

zWifiSetupDialog.showIOErrorc             C   s   t jd||S )Nr   )r   	translate)r   r   r   r   r   r   Z__trS  s    zWifiSetupDialog.__trc             C   s   |t krt| _nt| _d S )N)ZWIFI_CONFIG_LEDMr   r/   r   )r   ZwifiConfValr   r   r   r   X  s    zWifiSetupDialog.getWifiObject)NT)N)-r   r   r   Z
pyqtSignalr   r   r-   rA   r2   rB   r`   r^   r\   rO   rC   r   r   r   r   r   r   r   r   r   r   rD   r   r   rE   r   r   r   r   r   r=   r   r;   r9   rM   r   rR   r   r   rK   r   r   r   r   r   r   C   sN   
#.

2(t

f>	
r   )!rV   r>   Zbase.grX   r   r   r   r   Z
base.codesZbase.sixextr   Zui_utilsZPyQt5.QtCoreZPyQt5.QtGuiZwifisetupdialog_baser	   rN   r_   r   r   r$   rS   r   r   r(   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s0   