def setupFax(self): QApplication.setOverrideCursor(QApplication.waitCursor) back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(self.device_uri) norm_model = models.normalizeModelName(model).lower() fax_ppd,fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, norm_model) # Fax ppd not found if not fax_ppd: QApplication.restoreOverrideCursor() log.error("Fax PPD file not found.") if QMessageBox.warning(self, self.__tr("Unable to find HP fax PPD file."), self.__tr("The PPD file (%1.ppd) needed to setup the fax queue was not found.").arg(fax_ppd_name), self.__tr("Browse to file..."), # button 0 self.__tr("Quit") # button 1 ) == 0: # Browse while True: ppd_dir = sys_conf.get('dirs', 'ppd') fax_ppd = unicode(QFileDialog.getOpenFileName(ppd_dir, "HP Fax PPD Files (*.ppd *.ppd.gz);;All Files (*)", self, "open file dialog", "Choose the fax PPD file")) if not fax_ppd: # user hit cancel return if os.path.exists(fax_ppd): n = cups.getPPDDescription(fax_ppd) if n == nick: break else: self.FailureUI(self.__tr("<b>Incorrect fax PPD file.</b><p>The fax PPD file must have a nickname of '%1', not '%1'.").arg(nick).arg(n)) else: self.FailureUI(self.__tr("<b>File not found.</b><p>hp-setup cannot find the file %1").arg(fax_ppd)) else: # Quit return cups.setPasswordPrompt("You do not have permission to add a fax device.") if not os.path.exists(fax_ppd): status, status_str = cups.addPrinter(self.fax_name.encode('utf8'), self.fax_uri, self.fax_location, '', fax_ppd, self.fax_desc) else: status, status_str = cups.addPrinter(self.fax_name.encode('utf8'), self.fax_uri, self.fax_location, fax_ppd, '', self.fax_desc) log.debug("addPrinter() returned (%d, %s)" % (status, status_str)) self.installed_fax_devices = device.getSupportedCUPSDevices(['hpfax']) log.debug(self.installed_fax_devices) if self.fax_uri not in self.installed_fax_devices or \ self.fax_name not in self.installed_fax_devices[self.fax_uri]: self.FailureUI(self.__tr("<b>Fax queue setup failed.</b><p>Please restart CUPS and try again.")) else: # sending Event to add this device in hp-systray utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED,self.fax_uri, self.fax_name) QApplication.restoreOverrideCursor()
def setupFax(self): status = cups.IPP_BAD_REQUEST QApplication.setOverrideCursor(QApplication.waitCursor) back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(self.device_uri) norm_model = models.normalizeModelName(model).lower() fax_ppd,fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, norm_model) # Fax ppd not found if not fax_ppd: QApplication.restoreOverrideCursor() log.error("Fax PPD file not found.") if QMessageBox.warning(self, self.__tr("Unable to find HP fax PPD file."), self.__tr("The PPD file (%1.ppd) needed to setup the fax queue was not found.").arg(fax_ppd_name), self.__tr("Browse to file..."), # button 0 self.__tr("Quit") # button 1 ) == 0: # Browse while True: ppd_dir = sys_conf.get('dirs', 'ppd') fax_ppd = to_unicode(QFileDialog.getOpenFileName(ppd_dir, "HP Fax PPD Files (*.ppd *.ppd.gz);;All Files (*)", self, "open file dialog", "Choose the fax PPD file")) if not fax_ppd: # user hit cancel return if os.path.exists(fax_ppd): n = cups.getPPDDescription(fax_ppd) if n == nick: break else: self.FailureUI(self.__tr("<b>Incorrect fax PPD file.</b><p>The fax PPD file must have a nickname of '%1', not '%1'.").arg(nick).arg(n)) else: self.FailureUI(self.__tr("<b>File not found.</b><p>hp-setup cannot find the file %1").arg(fax_ppd)) else: # Quit return if not os.path.exists(fax_ppd): status, status_str = cups.addPrinter(self.fax_name.encode('utf8'), self.fax_uri, self.fax_location, '', fax_ppd, self.fax_desc) else: status, status_str = cups.addPrinter(self.fax_name.encode('utf8'), self.fax_uri, self.fax_location, fax_ppd, '', self.fax_desc) log.debug("addPrinter() returned (%d, %s)" % (status, status_str)) log.debug(device.getSupportedCUPSDevices(['hpfax'])) if status != cups.IPP_OK: self.FailureUI(self.__tr("<b>Fax queue setup failed.</b><p>Error : %s "%status_str)) else: # sending Event to add this device in hp-systray utils.sendEvent(EVENT_CUPS_QUEUES_ADDED,self.fax_uri, self.fax_name) QApplication.restoreOverrideCursor() return status
def findFaxPPD(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) try: self.fax_ppd, fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, self.model) if self.fax_ppd: self.fax_setup_ok = True else: self.fax_setup_ok = False FailureUI(self, self.__tr("<b>Unable to locate the HPLIP Fax PPD file:</b><p>%1.ppd.gz</p><p>Fax setup has been disabled.").arg(fax_ppd_name)) self.fax_setup = False self.SetupFaxGroupBox.setChecked(False) self.SetupFaxGroupBox.setEnabled(False) finally: QApplication.restoreOverrideCursor()
name_ok = False break for c in fax_name: if c in (' ', '#', '/', '%'): log.error("Invalid character '%s' in fax name. Please enter a name that does not contain this character." % c) name_ok = False if name_ok: break else: fax_name = fax_default_model log.info("Using queue name: %s" % fax_name) fax_ppd,fax_ppd_type,nick = cups.getFaxPPDFile(mq, fax_name) if not fax_ppd: log.error("Unable to find HP fax PPD file! Please check you HPLIP installation and try again.") clean_exit(1) if auto: location, info = '', '%s Fax Device (Automatically setup by HPLIP)'%(default_model.replace('_',' ')) else: while True: location = input(log.bold("Enter a location description for this printer (q=quit) ?")) if location.strip().lower() == 'q': log.info("OK, done.") clean_exit(0)