1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-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
28 from base import utils, device
30 from ui_utils import load_pixmap
34 from scrollunload import ScrollUnloadView
37 class UnloadForm(QMainWindow):
38 def __init__(self, bus=['usb', 'par'], device_uri=None, printer_name=None,
39 parent=None, name=None, fl=0):
41 QMainWindow.__init__(self,parent,name,fl)
44 self.device_uri = device_uri
45 self.printer_name = printer_name
46 self.init_failed = False
48 self.setIcon(load_pixmap('hp_logo', '128x128'))
50 self.setCentralWidget(QWidget(self,"qt_central_widget"))
51 self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout")
55 self.resize(QSize(600,480).expandedTo(self.minimumSizeHint()))
56 self.clearWState(Qt.WState_Polished)
58 if self.device_uri and self.printer_name:
59 log.error("You may not specify both a printer (-p) and a device (-d).")
60 self.device_uri, self.printer_name = None, None
62 if not self.device_uri and not self.printer_name:
63 probed_devices = device.probeDevices(bus=bus, filter={'pcard-type': (operator.eq, 1)})
64 cups_printers = cups.getPrinters()
65 log.debug(probed_devices)
66 log.debug(cups_printers)
67 max_deviceid_size, x, devices = 0, 0, {}
69 for d in probed_devices:
70 if d.startswith('hp:'):
72 for p in cups_printers:
74 printers.append(p.name)
75 devices[x] = (d, printers)
77 max_deviceid_size = max(len(d), max_deviceid_size)
80 from nodevicesform import NoDevicesForm
81 self.FailureUI(self.__tr("<p><b>No devices found that support photo card access.</b><p>Please make sure your device is properly installed and try again."))
82 self.init_failed = True
85 log.info(log.bold("Using device: %s" % devices[0][0]))
86 self.device_uri = devices[0][0]
89 from choosedevicedlg import ChooseDeviceDlg
90 dlg = ChooseDeviceDlg(devices)
91 if dlg.exec_loop() == QDialog.Accepted:
92 self.device_uri = dlg.device_uri
94 self.init_failed = True
96 self.dbus_avail, self.service, session_bus = device.init_dbus()
98 self.UnloadView = ScrollUnloadView(self.service,
99 self.centralWidget(), self, "UnloadView")
101 self.FormLayout.addWidget(self.UnloadView,0,0)
104 if not self.init_failed:
106 self.cur_device = device.Device(device_uri=self.device_uri,
107 printer_name=self.printer_name)
109 log.error("Invalid device URI or printer name.")
110 self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.")
111 self.init_failed = True
114 self.device_uri = self.cur_device.device_uri
115 user_conf.set('last_used', 'device_uri', self.device_uri)
117 log.debug(self.device_uri)
119 self.statusBar().message(self.device_uri)
122 QTimer.singleShot(0, self.initialUpdate)
125 def initialUpdate(self):
130 self.UnloadView.onDeviceChange(self.cur_device)
132 def FailureUI(self, error_text):
133 log.error(unicode(error_text).replace("<b>", "").replace("</b>", "").replace("<p>", " "))
134 QMessageBox.critical(self,
138 QMessageBox.NoButton,
139 QMessageBox.NoButton)
142 def languageChange(self):
143 self.setCaption(self.__tr("HP Device Manager - Unload Photo Card"))
145 def __tr(self,s,c = None):
146 return qApp.translate("UnloadForm",s,c)