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

« back to all changes in this revision

Viewing changes to ui4/devmgr5.py

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-14 20:08:44 UTC
  • mfrom: (2.1.118 lucid)
  • Revision ID: james.westby@ubuntu.com-20091214200844-z8qhqwgppbu3t7ze
Tags: 3.9.10-4
KBSD patch from KiBi (Closes: #560796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from prnt import cups
36
36
from base.codes import *
37
37
from ui_utils import *
 
38
import hpmudext
38
39
 
39
40
# Qt
40
41
from PyQt4.QtCore import *
49
50
    log.error("Unable to load DBus libraries. Please check your installation and try again.")
50
51
    sys.exit(1)
51
52
 
 
53
import warnings
 
54
# Ignore: .../dbus/connection.py:242: DeprecationWarning: object.__init__() takes no parameters
 
55
# (occurring on Python 2.6/dBus 0.83/Ubuntu 9.04)
 
56
warnings.simplefilter("ignore", DeprecationWarning)
 
57
 
 
58
 
52
59
# Main form
53
60
from devmgr5_base import Ui_MainWindow
54
61
 
82
89
DEF_AUTO_REFRESH_RATE = 30
83
90
 
84
91
 
85
 
device_list = {}    # { Device_URI : device.Device(, ... }
 
92
device_list = {}    # { Device_URI : device.Device(), ... }
86
93
model_obj = models.ModelData() # Used to convert dbus xformed data back to plain Python types
87
94
 
88
95
 
99
106
        self.tooltip_text = tooltip_text
100
107
        self.cmd = cmd
101
108
 
102
 
 
 
109
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
103
110
 
104
111
class DeviceViewItem(QListWidgetItem):
105
112
    def __init__(self, parent, text, pixmap, device_uri, is_avail=True):
108
115
        self.is_avail = is_avail
109
116
        self.setTextAlignment(Qt.AlignHCenter)
110
117
 
111
 
 
 
118
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
112
119
 
113
120
class PluginInstall(QObject):
114
121
    def __init__(self, parent, plugin_type, plugin_installed):
129
136
                                QMessageBox.NoButton) == QMessageBox.Yes
130
137
 
131
138
        if install_plugin:
132
 
            ok = pkit.run_plugin_command(self.plugin_type == PLUGIN_REQUIRED)
133
 
            if not ok:
 
139
            ok, sudo_ok = pkit.run_plugin_command(self.plugin_type == PLUGIN_REQUIRED, self.parent.cur_device.mq['plugin-reason'])
 
140
            if not sudo_ok:
134
141
                QMessageBox.critical(self.parent,
135
142
                    self.parent.windowTitle(),
136
143
                    self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"),
228
235
    def initUI(self):
229
236
        # Setup device icon list
230
237
        self.DeviceList.setSortingEnabled(True)
 
238
        self.DeviceList.setContextMenuPolicy(Qt.CustomContextMenu)
 
239
        self.setDeviceListViewMode(QListView.IconMode)
 
240
 
 
241
        self.connect(self.ViewAsIconsAction, SIGNAL("triggered()"), lambda: self.setDeviceListViewMode(QListView.IconMode))
 
242
        self.connect(self.ViewAsListAction, SIGNAL("triggered()"), lambda: self.setDeviceListViewMode(QListView.ListMode))
 
243
 
 
244
        self.connect(self.DeviceList, SIGNAL("customContextMenuRequested(const QPoint &)"), self.DeviceList_customContextMenuRequested)
231
245
 
232
246
        # Setup main menu
233
247
        self.DeviceRefreshAction.setIcon(QIcon(load_pixmap("refresh1", "16x16")))
511
525
        self.rescanDevices()
512
526
 
513
527
 
 
528
    def setDeviceListViewMode(self, mode):
 
529
        if mode == QListView.ListMode:
 
530
            self.DeviceList.setViewMode(QListView.ListMode)
 
531
            self.ViewAsListAction.setEnabled(False)
 
532
            self.ViewAsIconsAction.setEnabled(True)
 
533
        else:
 
534
            self.DeviceList.setViewMode(QListView.IconMode)
 
535
            self.ViewAsListAction.setEnabled(True)
 
536
            self.ViewAsIconsAction.setEnabled(False)
 
537
 
 
538
 
514
539
    def createDeviceIcon(self, dev=None):
515
540
        if dev is None:
516
541
            dev = self.cur_device
713
738
                self.updateWindowTitle()
714
739
 
715
740
 
716
 
 
717
741
    def updateWindowTitle(self):
718
742
        if self.cur_device.device_type == DEVICE_TYPE_FAX:
719
743
                self.setWindowTitle(self.__tr("HP Device Manager - %1 (Fax)").arg(self.cur_device.model_ui))
821
845
    #
822
846
    # ***********************************************************************************
823
847
 
824
 
    def DeviceList_rightButtonClicked(self, item, pos):
825
 
        popup = QPopupMenu(self)
826
 
 
827
 
        if item is not None and item is self.DeviceList.currentItem():
828
 
            if self.cur_device.error_state != ERROR_STATE_ERROR:
829
 
                if self.cur_device.device_type == DEVICE_TYPE_PRINTER:
830
 
                    popup.insertItem(self.__tr("Print..."), self.PrintButton_clicked)
831
 
 
832
 
                    if self.cur_device.scan_type:
833
 
                        popup.insertItem(self.__tr("Scan..."), self.ScanButton_clicked)
834
 
 
835
 
                    if self.cur_device.pcard_type:
836
 
                        popup.insertItem(self.__tr("Access Photo Cards..."), self.PCardButton_clicked)
837
 
 
838
 
                    if self.cur_device.copy_type:
839
 
                        popup.insertItem(self.__tr("Make Copies..."), self.MakeCopiesButton_clicked)
840
 
 
841
 
                elif self.cur_device.device_type == DEVICE_TYPE_FAX:
842
 
                    if self.cur_device.fax_type:
843
 
                        popup.insertItem(self.__tr("Send Fax..."), self.SendFaxButton_clicked)
844
 
 
845
 
                popup.insertSeparator()
 
848
    def DeviceList_customContextMenuRequested(self, p):
 
849
        d = self.cur_device
 
850
 
 
851
        if d is not None:
 
852
            avail = d.device_state != DEVICE_STATE_NOT_FOUND and d.supported
 
853
            printer = d.device_type == DEVICE_TYPE_PRINTER and avail
 
854
 
 
855
            fax = d.fax_type > FAX_TYPE_NONE and prop.fax_build and d.device_type == DEVICE_TYPE_FAX and \
 
856
                sys.hexversion >= 0x020300f0 and avail
 
857
 
 
858
            scan = d.scan_type > SCAN_TYPE_NONE and prop.scan_build and \
 
859
                            printer and self.user_settings.cmd_scan
 
860
 
 
861
            cpy = d.copy_type > COPY_TYPE_NONE and printer
 
862
 
 
863
            popup = QMenu(self)
 
864
 
 
865
            item = self.DeviceList.currentItem()
 
866
            if item is not None:
 
867
                if self.cur_device.error_state != ERROR_STATE_ERROR:
 
868
                    if printer:
 
869
                        popup.addAction(self.__tr("Print..."), lambda: self.contextMenuFunc(PrintDialog(self, self.cur_printer)))
 
870
 
 
871
                        if scan:
 
872
                            popup.addAction(self.__tr("Scan..."),  lambda: self.contextMenuFunc(self.user_settings.cmd_scan)) #self.ScanButton_clicked)
 
873
 
 
874
                        if cpy:
 
875
                            popup.addAction(self.__tr("Make Copies..."),  lambda: MakeCopiesDialog(self, self.cur_device_uri)) #self.MakeCopiesButton_clicked)
 
876
 
 
877
                    else: # self.cur_device.device_type == DEVICE_TYPE_FAX:
 
878
                        if fax:
 
879
                            popup.addAction(self.__tr("Send Fax..."),  lambda: self.contextMenuFunc(SendFaxDialog(self, self.cur_printer, self.cur_device_uri))) #self.SendFaxButton_clicked)
 
880
 
 
881
                    popup.addSeparator()
 
882
 
 
883
                if not self.updating:
 
884
                    popup.addAction(self.__tr("Refresh Device"),  self.requestDeviceUpdate) #self.DeviceRefreshAction_activated)
846
885
 
847
886
            if not self.updating:
848
 
                popup.insertItem(self.__tr("Refresh Device"), self.DeviceRefreshAction_activated)
849
 
 
850
 
        if not self.updating:
851
 
            popup.insertItem(self.__tr("Refresh All"), self.RefreshAllAction_activated)
852
 
 
853
 
        popup.popup(pos)
 
887
                popup.addAction(self.__tr("Refresh All"),  self.rescanDevices) #self.RefreshAllAction_activated)
 
888
 
 
889
            popup.addSeparator()
 
890
 
 
891
            if self.DeviceList.viewMode() == QListView.IconMode:
 
892
                popup.addAction(self.__tr("View as List"), lambda: self.setDeviceListViewMode(QListView.ListMode))
 
893
            else:
 
894
                popup.addAction(self.__tr("View as Icons"), lambda: self.setDeviceListViewMode(QListView.IconMode))
 
895
 
 
896
            popup.exec_(self.DeviceList.mapToGlobal(p))
 
897
 
 
898
 
 
899
    def contextMenuFunc(self, f):
 
900
        self.sendMessage('', '', EVENT_DEVICE_STOP_POLLING)
 
901
        try:
 
902
            try:
 
903
                f.exec_() # Dialog
 
904
            except AttributeError:
 
905
                beginWaitCursor()
 
906
 
 
907
                if f.split(':')[0] in ('http', 'https', 'file'):
 
908
                    log.debug("Opening browser to: %s" % item.cmd)
 
909
                    utils.openURL(f)
 
910
                else:
 
911
                    self.runExternalCommand(f)
 
912
 
 
913
                QTimer.singleShot(1000, self.unlockClick)
 
914
        finally:
 
915
            self.sendMessage('', '', EVENT_DEVICE_START_POLLING)
 
916
 
854
917
 
855
918
 
856
919
    # ***********************************************************************************
867
930
        if self.cur_device is not None and \
868
931
            self.cur_device.supported:
869
932
 
 
933
            self.cur_device.updateCUPSPrinters()
 
934
 
870
935
            for c in self.cur_device.cups_printers:
871
936
                self.PrintSettingsPrinterNameCombo.insertItem(0, c.decode("utf-8"))
872
937
                self.PrintControlPrinterNameCombo.insertItem(0, c.decode("utf-8"))
907
972
 
908
973
            if d is not None:
909
974
                avail = d.device_state != DEVICE_STATE_NOT_FOUND and d.supported
910
 
                fax = d.fax_type and prop.fax_build and d.device_type == DEVICE_TYPE_FAX and \
 
975
                fax = d.fax_type > FAX_TYPE_NONE and prop.fax_build and d.device_type == DEVICE_TYPE_FAX and \
911
976
                    sys.hexversion >= 0x020300f0 and avail
912
977
                printer = d.device_type == DEVICE_TYPE_PRINTER and avail
 
978
                scan = d.scan_type > SCAN_TYPE_NONE and prop.scan_build and \
 
979
                        printer and self.user_settings.cmd_scan
 
980
                cpy = d.copy_type > COPY_TYPE_NONE and printer
913
981
                req_plugin = d.plugin == PLUGIN_REQUIRED
914
982
                opt_plugin = d.plugin == PLUGIN_OPTIONAL
915
983
 
916
984
                try:
917
 
                    back_end, is_hp, bus, model, serial, dev_file, host, port = \
 
985
                    back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
918
986
                        device.parseDeviceURI(self.cur_device_uri)
919
987
                except Error:
920
988
                    return
960
1028
                    self.__tr("Print documents or files."),    # Tooltip
961
1029
                    lambda : PrintDialog(self, self.cur_printer)),  # command/action
962
1030
 
963
 
                    (lambda : d.scan_type > SCAN_TYPE_NONE and prop.scan_build and \
964
 
                        printer and self.user_settings.cmd_scan,
 
1031
                    (lambda :scan,
965
1032
                    self.__tr("Scan"),
966
1033
                    "scan",
967
1034
                    self.__tr("Scan a document, image, or photograph.<br>"),
968
1035
                    self.user_settings.cmd_scan),
969
1036
 
970
 
                    (lambda : d.copy_type and printer,
 
1037
                    (lambda : cpy,
971
1038
                    self.__tr("Make Copies"),
972
1039
                    "makecopies",
973
1040
                    self.__tr("Make copies on the device controlled by the PC.<br>"),
1049
1116
                    self.__tr("Your printer can print a test page <br>to help diagnose print quality problems."),
1050
1117
                    lambda : PQDiagDialog(self, self.cur_device_uri)),
1051
1118
 
 
1119
                    (lambda: printer and d.wifi_config >= WIFI_CONFIG_USB_XML and bus == 'usb',
 
1120
                     self.__tr("Wireless/wifi setup using USB"),
 
1121
                     "wireless",
 
1122
                     self.__tr("Configure your wireless capable printer using a temporary USB connection."),
 
1123
                     'hp-wificonfig -d %s' % self.cur_device_uri),
 
1124
 
1052
1125
                    # FIRMWARE
1053
1126
 
1054
1127
                    (lambda : printer and d.fw_download ,
1077
1150
                     self.__tr("Open printer's web page in a browser"),
1078
1151
                     "ews",
1079
1152
                     self.__tr("The printer's web page has supply, status, and other information."),
1080
 
                     "http://%s" % host),
 
1153
                     openEWS(host, zc)),
1081
1154
 
1082
1155
                    # HELP/WEBSITE
1083
1156
 
1118
1191
            self.click_lock = item
1119
1192
 
1120
1193
            if item.cmd and callable(item.cmd):
1121
 
 
1122
1194
                dlg = item.cmd()
1123
1195
                self.sendMessage('', '', EVENT_DEVICE_STOP_POLLING)
1124
1196
                try:
1332
1404
        self.TYPE_TO_PIX_MAP = {
1333
1405
                               AGENT_TYPE_UNSPECIFIED : [black],
1334
1406
                               AGENT_TYPE_BLACK: [black],
 
1407
                               AGENT_TYPE_BLACK_B8800: [black],
1335
1408
                               AGENT_TYPE_CMY: [cyan, magenta, yellow],
1336
1409
                               AGENT_TYPE_KCM: [light_cyan, light_magenta, light_yellow],
1337
1410
                               AGENT_TYPE_GGK: [dark_grey],
1965
2038
        log.debug(cmd)
1966
2039
        utils.run(cmd, log_output=True, password_func=None, timeout=1)
1967
2040
        self.rescanDevices()
 
2041
        self.updatePrinterCombos()
1968
2042
 
1969
2043
 
1970
2044
    def RemoveDeviceAction_activated(self):
1979
2053
        log.debug(cmd)
1980
2054
        utils.run(cmd, log_output=True, password_func=None, timeout=1)
1981
2055
        self.rescanDevices()
 
2056
        self.updatePrinterCombos()
1982
2057
 
1983
2058
 
1984
2059
    # ***********************************************************************************
2033
2108
        return qApp.translate("DevMgr5",s,c)
2034
2109
 
2035
2110
 
 
2111
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
2112
 
2036
2113
class PasswordDialog(QDialog):
2037
2114
    def __init__(self, prompt, parent=None, name=None, modal=0, fl=0):
2038
2115
        QDialog.__init__(self, parent)
 
2116
        self.prompt = prompt
2039
2117
 
2040
2118
        Layout= QGridLayout(self)
2041
2119
        Layout.setMargin(11)
2078
2156
 
2079
2157
 
2080
2158
    def languageChange(self):
2081
 
        self.setWindowTitle(self.__tr("HP Device Manager - Enter Password"))
2082
 
        self.PromptTextLabel.setText(self.__tr("You do not have authorization for this function."))
 
2159
        self.setWindowTitle(self.__tr("HP Device Manager - Enter Username/Password"))
 
2160
        self.PromptTextLabel.setText(self.__tr(self.prompt))
2083
2161
        self.UsernameTextLabel.setText(self.__tr("Username:"))
2084
2162
        self.PasswordTextLabel.setText(self.__tr("Password:"))
2085
2163
        self.OkPushButton.setText(self.__tr("OK"))
2088
2166
    def __tr(self,s,c = None):
2089
2167
        return qApp.translate("DevMgr5",s,c)
2090
2168
 
2091
 
 
 
2169
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2092
2170
 
2093
2171
def showPasswordUI(prompt):
2094
2172
    try:
2101
2179
        pass
2102
2180
 
2103
2181
    return ("", "")
 
2182
 
 
2183
 
 
2184
def openEWS(host, zc):
 
2185
    if zc:
 
2186
        status, ip = hpmudext.get_zc_ip_address(zc)
 
2187
        if status != hpmudext.HPMUD_R_OK:
 
2188
            ip = "hplipopensource.com"
 
2189
    else:
 
2190
        ip = host
 
2191
    return "http://%s" % ip