Esempio n. 1
0
    def setupPrinter(self):
        QApplication.setOverrideCursor(QApplication.waitCursor)

        cups.setPasswordPrompt("You do not have permission to add a printer.")
        #if self.ppd_file.startswith("foomatic:"):
        if not os.path.exists(self.ppd_file): # assume foomatic: or some such
            status, status_str = cups.addPrinter(self.printer_name.encode('utf8'), self.device_uri,
                self.location, '', self.ppd_file, self.desc)
        else:
            status, status_str = cups.addPrinter(self.printer_name.encode('utf8'), self.device_uri,
                self.location, self.ppd_file, '', self.desc)

        log.debug("addPrinter() returned (%d, %s)" % (status, status_str))
        self.installed_print_devices = device.getSupportedCUPSDevices(['hp'])

        log.debug(self.installed_print_devices)

        if self.device_uri not in self.installed_print_devices or \
            self.printer_name not in self.installed_print_devices[self.device_uri]:

            self.FailureUI(self.__tr("<b>Printer 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.device_uri, self.printer_name)

        QApplication.restoreOverrideCursor()
Esempio n. 2
0
    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()
Esempio n. 3
0
    def setupPrinter(self):
        status = cups.IPP_BAD_REQUEST
        QApplication.setOverrideCursor(QApplication.waitCursor)

        #if self.ppd_file.startswith("foomatic:"):
        if not os.path.exists(self.ppd_file):  # assume foomatic: or some such
            add_prnt_args = (self.printer_name.encode('utf8'), self.device_uri,
                             self.location, '', self.ppd_file, self.desc)
        else:
            add_prnt_args = (self.printer_name.encode('utf8'), self.device_uri,
                             self.location, self.ppd_file, '', self.desc)

        status, status_str = cups.cups_operation(cups.addPrinter, GUI_MODE,
                                                 'qt3', self, *add_prnt_args)

        log.debug("addPrinter() returned (%d, %s)" % (status, status_str))
        log.debug(device.getSupportedCUPSDevices(['hp']))

        if status != cups.IPP_OK:
            self.FailureUI(
                self.__tr("<b>Printer 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.device_uri,
                            self.printer_name)

        QApplication.restoreOverrideCursor()
        return status
Esempio n. 4
0
    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
Esempio n. 5
0
    def setupPrinter(self):
        status = cups.IPP_BAD_REQUEST
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:
            if not os.path.exists(self.print_ppd[0]): # assume foomatic: or some such
                add_prnt_args = (self.printer_name.encode('utf8'), self.device_uri, self.print_location, '', self.print_ppd[0], self.print_desc)
            else:
                add_prnt_args = (self.printer_name.encode('utf8'), self.device_uri, self.print_location, self.print_ppd[0], '', self.print_desc)

            status, status_str = cups.cups_operation(cups.addPrinter, GUI_MODE, 'qt4', self, *add_prnt_args)
            log.debug(device.getSupportedCUPSDevices(['hp']))

            if status != cups.IPP_OK:
                QApplication.restoreOverrideCursor()
                FailureUI(self, self.__tr("<b>Printer 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.device_uri, self.printer_name)

        finally:
            QApplication.restoreOverrideCursor()
        return status
Esempio n. 6
0
    def setupPrinter(self):
        status = cups.IPP_BAD_REQUEST
        QApplication.setOverrideCursor(QApplication.waitCursor)

        # if self.ppd_file.startswith("foomatic:"):
        if not os.path.exists(self.ppd_file):  # assume foomatic: or some such
            add_prnt_args = (self.printer_name, self.device_uri, self.location, "", self.ppd_file, self.desc)
        else:
            add_prnt_args = (self.printer_name, self.device_uri, self.location, self.ppd_file, "", self.desc)

        status, status_str = cups.cups_operation(cups.addPrinter, GUI_MODE, "qt3", self, *add_prnt_args)

        log.debug("addPrinter() returned (%d, %s)" % (status, status_str))
        log.debug(device.getSupportedCUPSDevices(["hp"]))

        if status != cups.IPP_OK:
            self.FailureUI(self.__tr("<b>Printer 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.device_uri, self.printer_name)

        QApplication.restoreOverrideCursor()
        return status
Esempio n. 7
0
    def setupFax(self):
        status = cups.IPP_BAD_REQUEST
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:
            if not os.path.exists(self.fax_ppd):
                status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                    self.fax_uri, self.fax_location, '', self.fax_ppd,  self.fax_desc)
            else:
                status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                    self.fax_uri, self.fax_location, self.fax_ppd, '', self.fax_desc)

            log.debug(device.getSupportedCUPSDevices(['hpfax']))

            if status != cups.IPP_OK:
                QApplication.restoreOverrideCursor()
                FailureUI(self, 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)
                
        finally:
            QApplication.restoreOverrideCursor()

        return status
Esempio n. 8
0
            log.warn("Failed to import Password Object")
        else:
            cups.setPasswordCallback(password.showPasswordPrompt)

        #Removing Queue
        if remove:
            tui.header("REMOVING PRINT/FAX QUEUE")
            sts, printer_name, device_uri = mod.getPrinterName(selected_device_name,None,['hp','hpfax'])
            selected_device_name = printer_name
            log.info (log.bold("Removing '%s : %s' Queue"%(printer_name, device_uri)))

            status, status_str = cups.cups_operation(cups.delPrinter, INTERACTIVE_MODE, '', None, selected_device_name)

            if cups.IPP_OK == status:
                log.info("Successfully deleted %s Print/Fax queue"%selected_device_name)
                utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED,device_uri, printer_name)
                clean_exit(0)
            else:
                log.error("Failed to delete %s Print/Fax queue. Error : %s"%(selected_device_name,status_str))
                clean_exit(1)

        if not auto:
            log.info("(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)")
            log.info("")

        # ******************************* MAKEURI
        if param:
            device_uri, sane_uri, fax_uri = device.makeURI(param, jd_port)

        # ******************************* CONNECTION TYPE CHOOSER
        if not device_uri and bus is None:
Esempio n. 9
0
                    print_ppd, '', info)

            log.debug("addPrinter() returned (%d, %s)" % (status, status_str))

            installed_print_devices = device.getSupportedCUPSDevices(['hp'])

            if print_uri not in installed_print_devices or \
                printer_name not in installed_print_devices[print_uri]:

                log.error(
                    "Printer queue setup failed. Please restart CUPS and try again."
                )
                sys.exit(1)
            else:
                # sending Event to add this device in hp-systray
                utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED, print_uri,
                                printer_name)

        # ******************************* FAX QUEUE SETUP
        if setup_fax and not prop.fax_build:
            log.error("Cannot setup fax - HPLIP not built with fax enabled.")
            setup_fax = False

        if setup_fax:

            try:
                from fax import fax
            except ImportError:
                # This can fail on Python < 2.3 due to the datetime module
                setup_fax = False
                log.warning("Fax setup disabled - Python 2.3+ required.")
Esempio n. 10
0
            remove_device = mod.getPrinterName(selected_device_name, None,
                                               ['hp', 'hpfax'])
            selected_device_name = remove_device[0]
            log.info(
                log.bold("Removing '%s : %s' Queue" %
                         (remove_device[0], remove_device[1])))

            status, status_str = cups.cups_operation(cups.delPrinter,
                                                     INTERACTIVE_MODE, '',
                                                     None,
                                                     selected_device_name)

            if cups.IPP_OK == status:
                log.info("Successfully deleted %s Print/Fax queue" %
                         selected_device_name)
                utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED, remove_device[1],
                                remove_device[0])
                clean_exit(0)
            else:
                log.error("Failed to delete %s Print/Fax queue. Error : %s" %
                          (selected_device_name, status_str))
                clean_exit(1)

        if not auto:
            log.info(
                "(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)"
            )
            log.info("")

        # ******************************* MAKEURI
        if param:
            device_uri, sane_uri, fax_uri = device.makeURI(param, jd_port)
Esempio n. 11
0
            else:
                status, status_str = cups.addPrinter(printer_name.encode('utf8'), print_uri,
                    location, print_ppd, '', info)

            log.debug("addPrinter() returned (%d, %s)" % (status, status_str))

            installed_print_devices = device.getSupportedCUPSDevices(['hp'])

            if print_uri not in installed_print_devices or \
                printer_name not in installed_print_devices[print_uri]:

                log.error("Printer queue setup failed. Please restart CUPS and try again.")
                sys.exit(1)
            else:
                # sending Event to add this device in hp-systray
                utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED,print_uri, printer_name)


        # ******************************* FAX QUEUE SETUP
        if setup_fax and not prop.fax_build:
            log.error("Cannot setup fax - HPLIP not built with fax enabled.")
            setup_fax = False

        if setup_fax:

            try:
                from fax import fax
            except ImportError:
                # This can fail on Python < 2.3 due to the datetime module
                setup_fax = False
                log.warning("Fax setup disabled - Python 2.3+ required.")
Esempio n. 12
0
    def NextButton_clicked(self):
        p = self.StackedWidget.currentIndex()
        if p == PAGE_DISCOVERY:
            self.manual = self.ManualGroupBox.isChecked()
            self.param = unicode(self.ManualParamLineEdit.text())
            self.jd_port = self.JetDirectSpinBox.value()
            self.search = unicode(self.SearchLineEdit.text())
            self.device_desc = int(self.DeviceTypeComboBox.itemData(self.DeviceTypeComboBox.currentIndex()).toInt()[0])
            self.discovery_method = self.NetworkDiscoveryMethodComboBox.currentIndex()

            if self.WirelessButton.isChecked():
                dlg = WifiSetupDialog(self, device_uri=None, standalone=False)
                dlg.exec_()

                if dlg.success == SUCCESS_CONNECTED:
                    self.manual = True
                    self.param = dlg.hn
                    self.bus = 'net'
            if not self.WirelessButton.isChecked():
                self.showDevicesPage()
           
        elif p == PAGE_DEVICES:
            row = self.DevicesTableWidget.currentRow()
            self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri
            self.mq = device.queryModelByURI(self.device_uri)
            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri)
            self.model = models.normalizeModelName(model).lower()
            self.showAddPrinterPage()

        elif p == PAGE_ADD_PRINTER:
            self.print_test_page = self.SendTestPageCheckBox.isChecked()
            self.print_desc = unicode(self.PrinterDescriptionLineEdit.text()).encode('utf8')
            self.print_location = unicode(self.PrinterLocationLineEdit.text()).encode('utf8')
            self.fax_setup = self.SetupFaxGroupBox.isChecked()
            self.fax_desc = unicode(self.FaxDescriptionLineEdit.text())
            self.fax_location = unicode(self.FaxLocationLineEdit.text())
            self.fax_name_company = unicode(self.NameCompanyLineEdit.text())
            self.fax_number = unicode(self.FaxNumberLineEdit.text())
            self.addPrinter()

        elif p == PAGE_REMOVE:
            for row in xrange(self.RemoveDevicesTableWidget.rowCount()):
                widget = self.RemoveDevicesTableWidget.cellWidget(row, 0)
                if widget.checkState() == Qt.Checked:
                    item = self.RemoveDevicesTableWidget.item(row, 1)
                    printer = unicode(item.data(Qt.UserRole).toString()).encode('utf-8')
                    uri = device.getDeviceURIByPrinterName(printer)
                    log.debug("Removing printer: %s" % printer)
                    status, status_str = cups.cups_operation(cups.delPrinter, GUI_MODE, 'qt4', self, printer)

                    if  status != cups.IPP_OK:
                        FailureUI(self, self.__tr("<b>Unable to delete '%s' queue. </b><p>Error : %s"%(printer,status_str)))
                        if status == cups.IPP_FORBIDDEN or status == cups.IPP_NOT_AUTHENTICATED or status == cups.IPP_NOT_AUTHORIZED:
                            break
                    else:
                        # sending Event to add this device in hp-systray
                        utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED, uri, printer)

            self.close()

        else:
            log.error("Invalid page!") # shouldn't happen!
Esempio n. 13
0
            log.warn("Failed to import Password Object")
        else:
            cups.setPasswordCallback(password.showPasswordPrompt)

        #Removing Queue
        if remove:
            tui.header("REMOVING PRINT/FAX QUEUE")
            remove_device = mod.getPrinterName(selected_device_name,None,['hp','hpfax'])
            selected_device_name = remove_device[0]
            log.info (log.bold("Removing '%s : %s' Queue"%(remove_device[0],remove_device[1])))

            status, status_str = cups.cups_operation(cups.delPrinter, INTERACTIVE_MODE, '', None, selected_device_name)

            if cups.IPP_OK == status:
                log.info("Successfully deleted %s Print/Fax queue"%selected_device_name)
                utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED,remove_device[1], remove_device[0])
                clean_exit(0)
            else:
                log.error("Failed to delete %s Print/Fax queue. Error : %s"%(selected_device_name,status_str))
                clean_exit(1)

        if not auto:
            log.info("(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)")
            log.info("")

        # ******************************* MAKEURI
        if param:
            device_uri, sane_uri, fax_uri = device.makeURI(param, jd_port)

        # ******************************* CONNECTION TYPE CHOOSER
        if not device_uri and bus is None: