1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2008 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 import device, utils
29 from base.codes import *
30 from ui_utils import *
33 from PyQt4.QtCore import *
34 from PyQt4.QtGui import *
37 from infodialog_base import Ui_Dialog
38 from deviceuricombobox import DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX
41 class InfoDialog(QDialog, Ui_Dialog):
42 def __init__(self, parent, device_uri):
43 QDialog.__init__(self, parent)
44 self.device_uri = device_uri
49 QTimer.singleShot(0, self.updateUi)
53 # connect signals/slots
54 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
55 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
56 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
59 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
62 self.DeviceComboBox.setInitialDevice(self.device_uri)
64 self.DeviceComboBox.setType(DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX)
66 self.headers = [self.__tr("Key"), self.__tr("Value")]
67 self.history_headers = [self.__tr("Date/Time"), None,
68 self.__tr("Event Code"), self.__tr("Description"),
69 self.__tr("User"), self.__tr("CUPS Job ID"),
70 self.__tr("Doc. Title")]
74 self.DeviceComboBox.updateUi()
75 #self.updateInfoTable()
78 def updateInfoTable(self):
79 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
80 self.DynamicTableWidget.clear()
81 self.DynamicTableWidget.setRowCount(0)
82 self.DynamicTableWidget.setColumnCount(0)
83 flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
85 while self.TabWidget.count() > 3:
86 self.TabWidget.removeTab(3)
88 self.DynamicTableWidget.clear()
89 self.DynamicTableWidget.setRowCount(0)
90 self.DynamicTableWidget.setColumnCount(len(self.headers))
91 self.DynamicTableWidget.setHorizontalHeaderLabels(self.headers)
98 d = device.Device(self.device_uri, None)
100 QApplication.restoreOverrideCursor()
101 FailureUI(self, self.__tr("<b>Unable to open device %1.</b>").arg(self.device_uri))
105 self.StaticTableWidget.clear()
107 self.StaticTableWidget.setColumnCount(len(self.headers))
108 self.StaticTableWidget.setHorizontalHeaderLabels(self.headers)
110 mq_keys = d.mq.keys()
113 self.StaticTableWidget.setRowCount(len(mq_keys))
115 for row, key in enumerate(mq_keys):
116 i = QTableWidgetItem(QString(key))
118 self.StaticTableWidget.setItem(row, 0, i)
120 i = QTableWidgetItem(QString(str(d.mq[key])))
122 self.StaticTableWidget.setItem(row, 1, i)
124 self.StaticTableWidget.resizeColumnToContents(0)
125 self.StaticTableWidget.resizeColumnToContents(1)
126 self.StaticTableWidget.setSortingEnabled(True)
127 self.StaticTableWidget.sortItems(0)
138 QApplication.restoreOverrideCursor()
139 FailureUI(self, self.__tr("<b>Unable to open device %1.</b>").arg(self.device_uri))
143 dq_keys = d.dq.keys()
146 self.DynamicTableWidget.setRowCount(len(dq_keys))
148 for row, key in enumerate(dq_keys):
149 i = QTableWidgetItem(QString(key))
151 self.DynamicTableWidget.setItem(row, 0, i)
153 i = QTableWidgetItem(QString(str(d.dq[key])))
155 self.DynamicTableWidget.setItem(row, 1, i)
158 self.DynamicTableWidget.resizeColumnToContents(0)
159 self.DynamicTableWidget.resizeColumnToContents(1)
160 self.DynamicTableWidget.setSortingEnabled(True)
161 self.DynamicTableWidget.sortItems(0)
170 self.HistoryTableWidget.clear()
171 self.HistoryTableWidget.setRowCount(0)
173 if d.device_type == DEVICE_TYPE_FAX:
174 self.history_headers[1] = self.__tr("Fax")
176 self.history_headers[1] = self.__tr("Printer")
178 self.HistoryTableWidget.setColumnCount(len(self.history_headers))
179 self.HistoryTableWidget.setHorizontalHeaderLabels(self.history_headers)
181 history = d.queryHistory()
183 self.HistoryTableWidget.setRowCount(len(history))
185 for row, h in enumerate(history):
187 dt.setTime_t(int(h.timedate))
190 ess = device.queryString(h.event_code, 0)
192 for col, t in enumerate([dt, h.printer_name,
193 unicode(h.event_code), ess,
194 h.username, unicode(h.job_id),
197 i = QTableWidgetItem(QString(t))
199 self.HistoryTableWidget.setItem(row, col, i)
201 self.HistoryTableWidget.resizeColumnToContents(0)
202 self.HistoryTableWidget.resizeColumnToContents(1)
203 self.HistoryTableWidget.setSortingEnabled(True)
204 self.HistoryTableWidget.sortItems(0)
210 printers = cups.getPrinters()
213 if p.device_uri == self.device_uri:
215 Tab.setObjectName(QString(p.name))
217 GridLayout = QGridLayout(Tab)
218 GridLayout.setObjectName(QString("GridLayout-%s" % p.name))
220 Table = QTableWidget(Tab)
221 Table.setAlternatingRowColors(True)
222 Table.setSelectionMode(QAbstractItemView.SingleSelection)
223 Table.setSelectionBehavior(QAbstractItemView.SelectRows)
224 Table.setVerticalScrollMode(QAbstractItemView.ScrollPerItem)
225 Table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
226 Table.setGridStyle(Qt.DotLine)
227 Table.setObjectName(QString("Table-%s" % p.name))
228 GridLayout.addWidget(Table, 0, 0, 1, 1)
229 self.TabWidget.addTab(Tab, QString(p.name))
231 Table.setColumnCount(len(self.headers))
232 Table.setHorizontalHeaderLabels(self.headers)
236 current_options = dict(cups.getOptions())
238 #current_options['cups_error_log_level'] = cups.getErrorLogLevel()
241 f = file(os.path.expanduser('~/.cups/lpoptions'))
244 current_options['lpoptions_file_data'] = QString("(%1)").arg(str(e))
247 for d in text.splitlines():
249 current_options['lpoptions_file_data'] = d
252 current_options['lpoptions_file_data'] = self.__tr("(no data)")
254 keys = current_options.keys()
257 Table.setRowCount(len(keys))
259 for row, key in enumerate(keys):
260 i = QTableWidgetItem(QString(key))
262 Table.setItem(row, 0, i)
264 if key == 'printer-state':
265 state = int(current_options[key])
266 if state == cups.IPP_PRINTER_STATE_IDLE:
267 i = QTableWidgetItem(self.__tr("idle (%1)").arg(state))
268 elif state == cups.IPP_PRINTER_STATE_PROCESSING:
269 i = QTableWidgetItem(self.__tr("busy/printing (%1)").arg(state))
270 elif state == cups.IPP_PRINTER_STATE_STOPPED:
271 i = QTableWidgetItem(self.__tr("stopped (%1)").arg(state))
273 i = QTableWidgetItem(QString(str(state)))
275 i = QTableWidgetItem(QString(str(current_options[key])))
278 Table.setItem(row, 1, i)
280 Table.resizeColumnToContents(0)
281 Table.resizeColumnToContents(1)
282 Table.setSortingEnabled(True)
286 self.TabWidget.setCurrentIndex(0)
287 QApplication.restoreOverrideCursor()
290 def DeviceUriComboBox_currentChanged(self, device_uri):
291 self.device_uri = device_uri
292 self.updateInfoTable()
295 def DeviceUriComboBox_noDevices(self):
296 FailureUI(self, self.__tr("<b>No devices found.</b>"))
300 def CancelButton_clicked(self):
307 def __tr(self,s,c = None):
308 return qApp.translate("InfoDialog",s,c)