1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 from base import device
24 from installer import core_install
25 from installer.core_install import PLUGIN_INSTALL_ERROR_NONE, \
26 PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND, \
27 PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND, \
28 PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD, \
29 PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR, \
30 PLUGIN_INSTALL_ERROR_NO_NETWORK, \
31 PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR, \
32 PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS
35 from pluginform2_base import PluginForm2_base
37 class PluginForm2(PluginForm2_base):
38 def __init__(self,parent = None,name = None,modal = 0,fl = 0):
39 PluginForm2_base.__init__(self,parent,name,modal,fl)
41 self.version = prop.installed_version
42 self.bg = self.pathLineEdit.paletteBackgroundColor()
44 self.titleTextLabel.setFont(QFont('Helvetica', 16))
46 self.sourceGroup.emit(SIGNAL("clicked(int)"), (0,))
48 def sourceGroup_clicked(self, item):
49 self.pathLineEdit.setEnabled(item == 1)
50 self.browsePushButton.setEnabled(item == 1)
52 if item == 0: # download
53 QToolTip.remove(self.pathLineEdit)
54 self.actionPushButton.setText(self.__tr("Download and Install"))
55 self.actionPushButton.setEnabled(True)
58 self.path = unicode(self.pathLineEdit.text())
59 self.pathLineEdit.emit(SIGNAL("textChanged(const QString&)"), (self.path,))
61 if self.path.startswith(u"http://"):
62 self.actionPushButton.setText(self.__tr("Download and Install"))
64 self.actionPushButton.setText(self.__tr("Copy and Install"))
67 def browsePushButton_clicked(self):
68 dlg = QFileDialog(user_conf.workingDirectory(), self.__tr("HPLIP %s Plug-in (*.run)" %
69 self.version), None, None, True)
71 dlg.setCaption("openfile")
72 dlg.setMode(QFileDialog.ExistingFile)
75 if dlg.exec_loop() == QDialog.Accepted:
76 results = dlg.selectedFile()
77 working_directory = unicode(dlg.dir().absPath())
78 log.debug("results: %s" % results)
79 user_conf.setWorkingDirectory(working_directory)
82 self.path = unicode(results)
83 self.pathLineEdit.setText(self.path)
86 def pathLineEdit_textChanged(self, path):
87 path, ok = unicode(path), True
89 if not path.startswith(u'http://'):
90 self.actionPushButton.setText(self.__tr("Copy and Install"))
92 if not path or not os.path.exists(path):
93 QToolTip.add(self.pathLineEdit, self.__tr('File not found.'))
96 elif os.path.basename(path) != u'hplip-%s-plugin.run' % self.version:
97 log.error("Incorrect file: %s (should be: %s)" % (path, 'hplip-%s-plugin.run' % self.version))
98 QToolTip.add(self.pathLineEdit, self.__tr("Incorrect file. Must be '%1'")\
99 .arg('hplip-%s-plugin.run' % self.version))
104 self.actionPushButton.setText(self.__tr("Download and Install"))
106 self.actionPushButton.setEnabled(ok)
109 self.pathLineEdit.setPaletteBackgroundColor(QColor(0xff, 0x99, 0x99))
112 QToolTip.remove(self.pathLineEdit)
113 self.pathLineEdit.setPaletteBackgroundColor(self.bg)
117 def actionPushButton_clicked(self):
118 core = core_install.CoreInstall()
119 core.set_plugin_version() #self.version)
121 if self.path is None: # download
122 # read plugin.conf (local or on sf.net) to get plugin_path (http://)
123 plugin_conf_url = core.get_plugin_conf_url()
125 if plugin_conf_url.startswith('file://'):
130 log.info("Checking for network connection...")
131 ok = core.check_network_connection()
134 log.error("Network connection not detected.")
135 self.FailureUI(self.__tr("Network connection not detected."))
140 log.info("Downloading configuration file from: %s" % plugin_conf_url)
142 self.path, size, checksum, timestamp, ok = core.get_plugin_info(plugin_conf_url,
143 self.plugin_download_callback)
145 log.debug("path=%s, size=%d, checksum=%s, timestamp=%f, ok=%s" %
146 (self.path, size, checksum, timestamp, ok))
148 if not self.path.startswith('http://') and not self.path.startswith('file://'):
149 self.path = 'file://' + self.path
153 if not self.path.startswith('http://'):
154 self.path = 'file://' + self.path
156 size, checksum, timestamp = 0, '', 0
159 if self.path.startswith('file://'):
163 log.info("Checking for network connection...")
164 ok = core.check_network_connection()
167 log.error("Network connection not detected.")
168 self.FailureUI(self.__tr("Network connection not detected."))
172 log.info("Downloading plug-in from: %s" % self.path)
174 status, ret = core.download_plugin(self.path, size, checksum, timestamp,
175 self.plugin_download_callback)
177 if status != PLUGIN_INSTALL_ERROR_NONE:
179 if status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND:
180 desc = self.__tr("<b>ERROR: Plug-in file not found (server returned 404 or similar error).</b><p>Error code: %1</p>").arg(str(ret))
182 elif status == PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND:
183 desc = self.__tr("<b>ERROR: Plug-in digital signature file not found (server returned 404 or similar error).</b><p>Error code: %1</p>").arg(str(ret))
185 elif status == PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD:
186 desc = self.__tr("<b>ERROR: Plug-in file does not match its digital signature.</b><p>File may have been corrupted or altered.</p><p>Error code: %1</p>").arg(str(ret))
188 elif status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR:
189 desc = self.__tr("<b>ERROR: Plug-in file does not match its checksum. File may have been corrupted or altered.")
191 elif status == PLUGIN_INSTALL_ERROR_NO_NETWORK:
192 desc = self.__tr("<b>ERROR: Unable to connect to network to download the plug-in.</b><p>Please check your network connection and try again.</p>")
194 elif status == PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR:
195 desc = self.__tr("<b>ERROR: Unable to create the plug-in directory.</b><p>Please check your permissions and try again.</p>")
197 elif status == PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS:
198 desc = self.__tr("<b>ERROR: Unable to download the public HPLIP keys from the keyserver.</b><p>Error code: %1</p>").arg(str(ret))
207 if not core.run_plugin(GUI_MODE, self.plugin_install_callback):
209 self.FailureUI(self.__tr("Plug-in install failed."))
213 cups_devices = device.getSupportedCUPSDevices(['hp']) #, 'hpfax'])
215 for dev in cups_devices:
216 mq = device.queryModelByURI(dev)
218 if mq.get('fw-download', False):
220 # Download firmware if needed
221 log.info(log.bold("\nDownloading firmware to device %s..." % dev))
223 d = device.Device(dev)
225 log.error("Error opening device.")
228 if d.downloadFirmware():
229 log.info("Firmware download successful.\n")
235 self.SuccessUI("Plug-in install successful.")
239 def FailureUI(self, error_text):
240 QMessageBox.critical(self,
244 QMessageBox.NoButton,
245 QMessageBox.NoButton)
247 def SuccessUI(self, text):
248 QMessageBox.information(self,
252 QMessageBox.NoButton,
253 QMessageBox.NoButton)
257 def plugin_download_callback(self, c, s, t):
261 def plugin_install_callback(self, s):
265 def cancelPushButton_clicked(self):
269 def __tr(self,s,c = None):
270 return qApp.translate("PluginForm_base",s,c)