1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2003-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
27 from base.codes import *
28 from base import utils, device
30 from ui_utils import load_pixmap
37 # This can fail on Python < 2.3 due to the datetime module
38 log.error("Fax send disabled - Python 2.3+ required.")
44 from scrollfax import ScrollFaxView
55 class FaxSendJobForm(QMainWindow):
57 def __init__(self, device_uri, printer_name, args,
58 parent=None, name=None,
61 QMainWindow.__init__(self,parent,name,fl)
63 self.setIcon(load_pixmap('hp_logo', '128x128'))
65 self.init_failed = False
66 self.device_uri = device_uri
68 self.printer_name = printer_name
71 self.username = prop.username
73 self.setCentralWidget(QWidget(self,"qt_central_widget"))
74 self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout")
75 self.resize(QSize(600,480).expandedTo(self.minimumSizeHint()))
76 self.clearWState(Qt.WState_Polished)
79 # if self.device_uri and self.printer_name:
80 # log.error("You may not specify both a printer (-p) and a device (-d).")
81 # self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d)."))
82 # self.device_uri, self.printer_name = None, None
83 # self.init_failed = True
85 self.cups_printers = cups.getPrinters()
86 log.debug(self.cups_printers)
90 for p in self.cups_printers:
91 if p.name == printer_name:
92 self.device_uri = p.device_uri
97 self.FailureUI(self.__tr("<b>Unknown printer name: %1</b><p>Please check the printer name and try again.").arg(self.printer_name))
99 if found and not p.device_uri.startswith('hpfax:/'):
100 self.FailureUI(self.__tr("You must specify a printer that has a device URI in the form 'hpfax:/...'"))
101 self.init_failed = True
103 if not self.device_uri and not self.printer_name:
104 t = device.probeDevices(bus=bus, filter={'fax-type':(operator.gt, FAX_TYPE_NONE)})
109 probed_devices.append(d.replace('hp:/', 'hpfax:/'))
111 #print probed_devices
113 probed_devices = utils.uniqueList(probed_devices)
114 log.debug(probed_devices)
116 max_deviceid_size, x, devices = 0, 0, {}
118 for d in probed_devices:
120 for p in self.cups_printers:
121 #print p.device_uri, d
122 if p.device_uri == d:
124 printers.append(p.name)
126 devices[x] = (d, printers)
128 max_deviceid_size = max(len(d), max_deviceid_size)
135 from nodevicesform import NoDevicesForm
136 self.FailureUI(self.__tr("<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again."))
137 self.init_failed = True
140 log.info(log.bold("Using device: %s" % devices[0][0]))
141 self.device_uri = devices[0][0]
144 from chooseprinterdlg import ChoosePrinterDlg
145 dlg = ChoosePrinterDlg(self.cups_printers, ['hpfax'])
147 if dlg.exec_loop() == QDialog.Accepted:
148 self.device_uri = dlg.device_uri
150 self.init_failed = True
152 self.dbus_avail, self.service, session_bus = device.init_dbus()
154 self.FaxView = ScrollFaxView(self.service, self.centralWidget(), self)
155 self.FormLayout.addWidget(self.FaxView,0,0)
157 if not self.init_failed:
158 if not self.device_uri or not self.device_uri.startswith("hpfax:"):
159 log.error("Invalid device URI: %s" % repr(device_uri))
160 self.FailureUI(self.__tr("<b>Invalid device URI %1.</b><p>Please check the parameters to hp-print and try again.").arg(repr(device_uri)));
161 self.init_failed = True
165 self.cur_device = device.Device(device_uri=self.device_uri,
166 printer_name=self.printer_name)
168 log.error("Invalid device URI or printer name.")
169 self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.")
170 self.init_failed = True
173 self.device_uri = self.cur_device.device_uri
174 user_conf.set('last_used', 'device_uri', self.device_uri)
176 log.debug(self.device_uri)
178 self.statusBar().message(self.device_uri)
181 QTimer.singleShot(0, self.InitialUpdate)
184 def InitialUpdate(self):
189 self.FaxView.onDeviceChange(self.cur_device)
191 if self.args is not None:
193 self.FaxView.processFile(f)
195 if self.printer_name is not None:
196 self.FaxView.onPrinterChange(self.printer_name)
199 def languageChange(self):
200 self.setCaption(self.__tr("HP Device Manager - Send Fax"))
202 def closeEvent(self, event):
204 #print self.FaxView.lock_file
205 utils.unlock(self.FaxView.lock_file)
209 QMessageBox.information(self,
211 self.__tr("<p><b>Fax send completed successfully.</b>"),
213 QMessageBox.NoButton,
214 QMessageBox.NoButton)
216 def FailureUI(self, error_text):
217 log.error(unicode(error_text).replace("<b>", "").replace("</b>", "").replace("<p>", " "))
218 QMessageBox.critical(self,
222 QMessageBox.NoButton,
223 QMessageBox.NoButton)
225 def WarningUI(self, error_text):
226 log.warn(unicode(error_text).replace("<b>", "").replace("</b>", "").replace("<p>", " "))
227 QMessageBox.warning(self,
231 QMessageBox.NoButton,
232 QMessageBox.NoButton)
234 def __tr(self,s,c = None):
235 return qApp.translate("FaxSendJobForm", s, c)