3
NZ0                 @   s   d dl T d dlmZmZ d dlmZ d dlT ddlT d dlm	Z	 d dl
mZ d dlT d dlT d dlT ddlmZ d dlZd ZdZG d	d
 d
eeZdS )    )*)deviceutils)cups   )pluginhandler)
to_unicode)	Ui_DialogNc               @   s   e Zd Zeef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$d%Zd#S )'PluginDialogc             C   sn   t j| | || _|| _d| _d| _tj | _| j	|  t
 | _| jj  | jj  | j  tjd| j d S )N Fr   )QDialog__init__install_modeplugin_reasonplugin_pathresultr   ZPluginHandle	pluginObjZsetupUiZUserSettingsuser_settingsloaddebuginitUiZQTimerZ
singleShotshowSourcePage)selfparentr   r    r   $/usr/share/hplip/ui5/plugindialog.pyr   0   s    



zPluginDialog.__init__c             C   s
   | j j S )N)r   Z	getStatus)r   r   r   r   isPluginInstalledB   s    zPluginDialog.isPluginInstalledc              C   s   | j jj| j | jjj| j | jttdd t	d t
| jdt| jdt| jdt| jdtd td t| jdt| jdt| jd	td td t| jd
t| jdtd td i| _d S )NZhp_logoZ128x128z)This plugin will enable printing support.z%This plugin will enhance print speed.z'This plugin will enhance print quality.z'This plugin will add printing features.z)This plugin will enable scanning support.z(This plugin will enhance scanning speed.z0This plugin will enhance scanning image quality.z'This plugin will enable faxing support.z)This plugin will enhnace faxing features.)ZCancelButtonclickedconnectCancelButton_clicked
NextButtonNextButton_clickedZsetWindowIconQIconload_pixmapPLUGIN_REASON_NONEZPLUGIN_REASON_PRINTING_SUPPORT_PluginDialog__trZPLUGIN_REASON_FASTER_PRINTINGZ PLUGIN_REASON_BETTER_PRINTING_PQZPLUGIN_REASON_PRINTING_FEATURESZPLUGIN_REASON_RESERVED_10ZPLUGIN_REASON_RESERVED_20ZPLUGIN_REASON_SCANNING_SUPPORTZPLUGIN_REASON_FASTER_SCANNINGZ PLUGIN_REASON_BETTER_SCANNING_IQZPLUGIN_REASON_RESERVED_200ZPLUGIN_REASON_RESERVED_400ZPLUGIN_REASON_FAXING_SUPPORTZPLUGIN_REASON_FAX_FEATURESZPLUGIN_REASON_RESERVED_20000ZPLUGIN_REASON_RESERVED_40000PLUGIN_REASON_TEXT)r   r   r   r   r   F   s&    








zPluginDialog.initUic             C   s  | j  }| jtkrJ| jjd d}|d k	r6|d| 7 }| jj| j| n4| jtkr~d}|d k	rl|d| 7 }| jj| j| | j	j
t j| j | jj
t j| j | jj
t j| j | jjd j| j | jjj| j tjtjtj | jjttdd | jt d S )NFzAn additional driver plug-in is required to operate this printer. You may download the plug-in directly from an HP authorized server (recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced).z
<br><br>%sa(  An optional driver plug-in is available to enhance the operation of this printer. You may download the plug-in directly from an HP authorized server (recommended), skip this installation (not recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced).zconst QString &Zfolder_openZ16x16)plugin_reason_textr   ZPLUGIN_REQUIREDSkipRadioButton
setEnabledZ
TitleLabelsetTextr%   ZPLUGIN_OPTIONALZDownloadRadioButtonZtoggledboolr   DownloadRadioButton_toggledZCopyRadioButtonCopyRadioButton_toggledSkipRadioButton_toggledPathLineEditZtextChangedPathLineEdit_textChangedBrowseToolButtonr   BrowseToolButton_clickedsignalSIGINTSIG_DFLZsetIconr"   r#   displayPagePAGE_SOURCE)r   Zreason_textmsgr   r   r   r   f   s(    

zPluginDialog.showSourcePagec             C   sX   |rT| j jd | jjd | jjd y| j jd W n tk
rL   Y nX d | _d S )NFTr   )r/   r)   r1   r    setStyleSheetAttributeErrorr   )r   br   r   r   r,      s    z(PluginDialog.DownloadRadioButton_toggledc             C   s8   |r4| j jd | jjd t| j j | _| j  d S )NT)r/   r)   r1   r   textr   setPathIndicators)r   r;   r   r   r   r-      s
    z$PluginDialog.CopyRadioButton_toggledc             C   sX   |rT| j jd | jjd | jjd y| j jd W n tk
rL   Y nX d | _d S )NFTr   )r/   r)   r1   r    r9   r:   r   )r   r;   r   r   r   r.      s    z$PluginDialog.SkipRadioButton_toggledc             C   s   t || _| j  d S )N)r   r   r=   )r   tr   r   r   r0      s    
z%PluginDialog.PathLineEdit_textChangedc             C   s   d}| j  s | j rBtjj| j rB| jj| jd| jj   d}n8tjj	| j | jj krz| jj| jd| jj   d}|sy| jj
d W n tk
r   Y nX | jjd n>y| jj
d W n tk
r   Y nX | jjd | jjd d S )NTz)You must specify a path to the '%s' file.Fz!The plugin filename must be '%s'.zbackground-color: yellow; r   )r   ospathisdirr/   Z
setToolTipr%   r   ZgetFileNamebasenamer9   r:   r    r)   )r   okr   r   r   r=      s&    zPluginDialog.setPathIndicatorsc             C   sz   t | jj }d}tjj|s>tj| | jd| j	j
| jd}|rn|d | _| jj| j | j| j	_
| j	j  | j  d S )Nr   zSelect Plug-in FilezPlugin Files (*.run)r   )r   r/   r<   r?   r@   existsZQFileDialogZgetOpenFileNamer%   r   Zworking_dirr   r*   Zsaver=   )r   r>   r@   r   r   r   r2      s    


z%PluginDialog.BrowseToolButton_clickedc             C   s   | j | | jj| d S )N)updateStepTextZStackedWidgetZsetCurrentIndex)r   Zpager   r   r   r6      s    
zPluginDialog.displayPagec             C   s   | j   d S )N)close)r   r   r   r   r      s    z!PluginDialog.CancelButton_clickedc       	      C   s  | j j r tjd | j  d S t  z:| jrJ| jjdsd| j | _nBtjd t	j
 }|stjd t  t| | jd | j  d S tjd| j  | jj| j| j\}}}|ttfkrt  tj| d| jd| tjtjB tjkr>| jj| | j  d S n2|tkr>| jj| t  t| | | j  d S | jj|ts|| jj| t  t| | jd	 | j  d S tjd
g}x|D ]}tj|}|jddrtjtj d|  zd }ytj!|}W n> t"k
r   tjd t  t| | jd|  wY nX |j# r(tjd nt  t| | jd|  W d |d k	rX|j  X qW W d t  X | jj| t$| | jd d| _%| j  d S )NzSkipping plug-in installation.zhttp://zfile://z"Checking for network connection...z Network connection not detected.zDownloading plug-in from: %s z<b>%s</b><p>Without this, it is not possible to authenticate and validate the plug-in prior to installation.</p>Do you still want to install the plug-in?zPlug-in install failed.Zhpzfw-downloadFz%
Downloading firmware to device %s...zError opening device.z3<b>Firmware download to device failed.</b><p>%s</p>zFirmware download successful.
z&<b>Plug-in installation successful</b>T)&r(   Z	isCheckedlogr   rF   ZbeginWaitCursorr   
startswithinfor   Zcheck_network_connectionerrorZendWaitCursorZ	FailureUIr%   r   Zdownloadplugin_download_callbackZERROR_UNABLE_TO_RECV_KEYSZERROR_DIGITAL_SIGN_NOT_FOUNDZQMessageBoxZquestionZYesZNoZdeleteInstallationFilesZERROR_SUCCESSZ
run_pluginZGUI_MODEr   ZgetSupportedCUPSDevicesZqueryModelByURIgetZboldZDeviceErrorZdownloadFirmwareZ	SuccessUIr   )	r   rC   ZstatusZdownload_plugin_fileZ	error_strZcups_devicesZdevZmqdr   r   r   r!      s    











zPluginDialog.NextButton_clickedc             C   s   d S )Nr   )r   csr>   r   r   r   rL   6  s    z%PluginDialog.plugin_download_callbackc             C   s   t | d S )N)print)r   rQ   r   r   r   plugin_install_callback:  s    z$PluginDialog.plugin_install_callbackc             C   s&   | j j| jd|d td f  d S )NzStep %s of %sr   )ZStepTextr*   r%   PAGE_MAX)r   pr   r   r   rE   >  s    zPluginDialog.updateStepTextc             C   s&   y| j | j S  tk
r    d S X d S )N)r&   r   KeyError)r   r   r   r   r'   B  s    zPluginDialog.plugin_reason_textNc             C   s   t jd||S )Nr
   )ZqApp	translate)r   rQ   rP   r   r   r   Z__trI  s    zPluginDialog.__tr)N)__name__
__module____qualname__ZPLUGIN_NONEr$   r   r   r   r   r,   r-   r.   r0   r=   r2   r6   r   r!   rL   rS   rE   r'   r%   r   r   r   r   r
   /   s$    Xr
   )Zbase.gbaser   r   Zprntr   Z
base.codesZui_utilsZ	installerr   Zbase.sixextr   ZPyQt5.QtCoreZPyQt5.QtGuiZPyQt5.QtWidgetsZplugindialog_baser	   r3   r7   rT   r   r
   r   r   r   r   <module>   s   