~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to ui/setupform.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-10-06 15:03:44 UTC
  • mfrom: (1.6.1) (20.1.16 quantal)
  • Revision ID: package-import@ubuntu.com-20121006150344-2p3xz26br0t3hu2q
Tags: 3.12.10-1
* New upstream release
  - Fixes "Network scanning fails (Closes: #683033)
* quilt refresh hplip-syslog-fix-debug-messages-to-error.dpatch
* Fix "error in clean build env" updated debian/rules (Closes: #687129)

Show diffs side-by-side

added added

removed removed

Lines of Context:
233
233
 
234
234
            norm_model = models.normalizeModelName(model).lower()
235
235
 
236
 
            core = core_install.CoreInstall()
 
236
            core = core_install.CoreInstall(core_install.MODE_CHECK)
237
237
            core.set_plugin_version()
238
238
            plugin = self.mq.get('plugin', PLUGIN_NONE)
239
239
            plugin_reason = self.mq.get('plugin-reason', PLUGIN_REASON_NONE)
240
 
            if plugin > PLUGIN_NONE and not core.check_for_plugin():
 
240
            if plugin > PLUGIN_NONE and core.check_for_plugin() != PLUGIN_INSTALLED:
241
241
                ok, sudo_ok = pkit.run_plugin_command(plugin == PLUGIN_REQUIRED, plugin_reason)
242
242
                if not sudo_ok:
243
243
                    self.FailureUI(self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"))
244
244
                    return
245
 
                if not ok or not core.check_for_plugin():
 
245
                if not ok or core.check_for_plugin() != PLUGIN_INSTALLED:
246
246
                    if plugin == PLUGIN_REQUIRED:
247
247
                        self.FailureUI(self.__tr("<b>The printer you are trying to setup requires a binary driver plug-in and it failed to install.</b><p>Please check your internet connection and try again.</p><p>Visit <u>http://hplipopensource.com</u> for more information.</p>"))
248
248
                        return
536
536
        if ppds is None or not ppds:
537
537
            ppds = cups.getSystemPPDs()
538
538
 
539
 
        #print ppds
540
 
 
541
 
        default_model = utils.xstrip(model.replace('series', '').replace('Series', ''), '_')
542
 
        stripped_model = cups.stripModel2(models.normalizeModelName(model).lower())
543
 
 
544
 
        self.ppd = cups.getPPDFile2(stripped_model, ppds)
 
539
        self.ppd = cups.getPPDFile2(self.mq,  model , ppds)
545
540
        log.debug(self.ppd)
546
541
        self.ppdListView.clear()
547
542
 
548
543
        if self.ppd is not None:
549
 
            #for ppd in self.ppd_dict:
550
544
            PPDListViewItem(self.ppdListView, self.ppd[0], self.ppd[1])
551
545
 
552
 
#            i = self.ppdListView.firstChild()
553
 
#            self.ppdListView.setCurrentItem(i)
554
 
#            self.ppdListView.setSelected(i, True)
555
 
#            self.ppd_file = self.ppdListView.currentItem().ppd_file
556
546
            self.ppd_file = self.ppd[0]
557
547
            log.debug(self.ppd_file)
558
548
 
596
586
 
597
587
        printer_name = default_model
598
588
 
 
589
        installed_printer_names = device.getSupportedCUPSPrinterNames(['hp'])
599
590
        # Check for duplicate names
600
 
        if self.device_uri in self.installed_print_devices and \
601
 
            printer_name in self.installed_print_devices[self.device_uri]:
 
591
        if (self.device_uri in self.installed_print_devices and printer_name in self.installed_print_devices[self.device_uri]) \
 
592
           or (printer_name in installed_printer_names):
602
593
                i = 2
603
594
                while True:
604
595
                    t = printer_name + "_%d" % i
605
 
                    if t not in self.installed_print_devices[self.device_uri]:
 
596
                    if (t not in installed_printer_names) and (self.device_uri not in self.installed_print_devices or t not in self.installed_print_devices[self.device_uri]):
606
597
                        printer_name += "_%d" % i
607
598
                        break
608
599
                    i += 1
703
694
        default_model = utils.xstrip(model.replace('series', '').replace('Series', ''), '_')
704
695
 
705
696
        fax_name = default_model + "_fax"
 
697
        installed_fax_names = device.getSupportedCUPSPrinterNames(['hpfax'])
706
698
 
707
699
        # Check for duplicate names
708
 
        if self.fax_uri in self.installed_fax_devices and \
709
 
            fax_name in self.installed_fax_devices[self.fax_uri]:
 
700
        if (self.fax_uri in self.installed_fax_devices and fax_name in self.installed_fax_devices[self.fax_uri]) \
 
701
           or (fax_name in installed_fax_names):
710
702
        #if fax_name in self.installed_queues or fax_name == self.printer_name:
711
703
                i = 2
712
704
                while True:
713
705
                    t = fax_name + "_%d" % i
714
 
                    if t not in self.installed_fax_devices[self.fax_uri]:
 
706
                    if (t not in installed_fax_names) and (self.fax_uri not in self.installed_fax_devices or t not in self.installed_fax_devices[self.fax_uri]):
715
707
                        fax_name += "_%d" % i
716
708
                        break
717
709
                    i += 1
876
868
 
877
869
            self.FailureUI(self.__tr("<b>Printer queue setup failed.</b><p>Please restart CUPS and try again."))
878
870
        else:
879
 
            # TODO:
880
 
            #service.sendEvent(self.hpssd_sock, EVENT_CUPS_QUEUES_CHANGED, device_uri=self.device_uri)
881
 
            pass
 
871
            # sending Event to add this device in hp-systray
 
872
            utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED,self.device_uri, self.printer_name)
882
873
 
883
874
        QApplication.restoreOverrideCursor()
884
875
 
885
876
    def setupFax(self):
886
877
        QApplication.setOverrideCursor(QApplication.waitCursor)
887
 
 
888
 
        if self.mq.get('fax-type', FAX_TYPE_NONE) == FAX_TYPE_MARVELL:
889
 
            fax_ppd_name = "HP-Fax3-hplip" # Fixed width (2528 pixels) and 300dpi rendering
890
 
            nick = "HP Fax 3"
891
 
        if self.mq.get('fax-type', FAX_TYPE_NONE) == FAX_TYPE_SOAP or self.mq.get('fax-type', FAX_TYPE_NONE) == FAX_TYPE_LEDMSOAP:
892
 
            fax_ppd_name = "HP-Fax2-hplip" # Fixed width (2528 pixels) and 300dpi rendering
893
 
            nick = "HP Fax 2"
894
 
        if self.mq.get('fax-type', FAX_TYPE_NONE) == FAX_TYPE_LEDM:
895
 
            fax_ppd_name = "HP-Fax4-hplip" # Fixed width (1728 pixels) and 200dpi rendering
896
 
            nick = "HP Fax 4"
897
 
        else:
898
 
            fax_ppd_name = "HP-Fax-hplip" # Standard
899
 
            nick = "HP Fax"
900
 
 
901
 
        ppds = []
902
 
 
903
 
        log.debug("Searching for fax file %s..." % fax_ppd_name)
904
 
 
905
 
        ppd_dir = sys_conf.get('dirs', 'ppd')
906
 
        for f in utils.walkFiles(ppd_dir, pattern="HP-Fax*.ppd*", abs_paths=True):
907
 
            ppds.append(f)
908
 
 
909
 
        for f in ppds:
910
 
            if f.find(fax_ppd_name) >= 0:
911
 
                fax_ppd = f
912
 
                log.debug("Found PDD file: %s" % fax_ppd)
913
 
                log.debug("Nickname: %s" % cups.getPPDDescription(fax_ppd))
914
 
                break
915
 
        else:
 
878
        back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
 
879
                device.parseDeviceURI(self.device_uri)
 
880
        norm_model = models.normalizeModelName(model).lower()
 
881
        fax_ppd,fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, norm_model)
 
882
        # Fax ppd not found
 
883
        if not fax_ppd:
916
884
            QApplication.restoreOverrideCursor()
917
885
            log.error("Fax PPD file not found.")
918
886
 
961
929
 
962
930
            self.FailureUI(self.__tr("<b>Fax queue setup failed.</b><p>Please restart CUPS and try again."))
963
931
        else:
964
 
            pass
965
 
            # TODO:
966
 
            #service.sendEvent(self.hpssd_sock, EVENT_CUPS_QUEUES_CHANGED, device_uri=self.fax_uri)
 
932
            # sending Event to add this device in hp-systray
 
933
            utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED,self.fax_uri, self.fax_name)
967
934
 
968
935
        QApplication.restoreOverrideCursor()
969
936
 
1060
1027
 
1061
1028
        self.connect(self.okPushButton,SIGNAL("clicked()"),self.accept)
1062
1029
        self.connect(self.passwordLineEdit,SIGNAL("returnPressed()"),self.accept)
 
1030
 
 
1031
    def setDefaultUsername(self, defUser, allowUsernameEdit = True):
 
1032
        self.usernameLineEdit.setText(defUser)
 
1033
        if not allowUsernameEdit:
 
1034
            self.usernameLineEdit.setReadOnly(True)
 
1035
            self.usernameLineEdit.setPaletteBackgroundColor(QColor("lightgray"))
 
1036
 
1063
1037
    def getUsername(self):
1064
1038
        return unicode(self.usernameLineEdit.text())
1065
1039
 
1077
1051
        return qApp.translate("PasswordDialog",s,c)
1078
1052
 
1079
1053
 
1080
 
 
1081
 
def showPasswordUI(prompt):
 
1054
def showPasswordUI(prompt, userName=None, allowUsernameEdit=True):
1082
1055
    try:
1083
1056
        dlg = PasswordDialog(prompt, None)
1084
1057
 
 
1058
        if userName != None:
 
1059
            dlg.setDefaultUsername(userName, allowUsernameEdit)
 
1060
 
1085
1061
        if dlg.exec_loop() == QDialog.Accepted:
1086
1062
            return (dlg.getUsername(), dlg.getPassword())
1087
1063