Tizen 2.1 base
[platform/upstream/hplip.git] / ui / firmwaredialog.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2011 Hewlett-Packard Development Company, L.P.
4 #
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.
9 #
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.
14 #
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
18 #
19 # Author: Sarbeswar Meher
20 #
21
22 # Std Lib
23 import operator
24
25 # Local
26 from base.g import *
27 from base import device, utils
28 from prnt import cups
29 from base.codes import *
30 from ui_utils import *
31
32 # Qt
33 from qt import *
34
35 # Ui
36 from firmwaredialog_base import FirmwareDialog_Base
37
38 class FirmwareDialog(QDialog, FirmwareDialog_Base):
39     def __init__(self, parent, device_uri):
40         QDialog.__init__(self, parent)        
41         self.setupUi(self)        
42         self.device_uri = device_uri
43         self.initUi()
44         QTimer.singleShot(0, self.updateUi)
45         
46     def initUi(self):
47         self.DeviceComboBox.setFilter({'fw-download' : (operator.gt, 0)})
48         self.DeviceComboBox.setParent(self)
49         self.connect(self.CancelButton, SIGNAL("clicked()"), self.close)
50         self.connect(self.DownloadFirmwareButton, SIGNAL("clicked()"), self.downloadFirmware)
51
52         # Application icon
53         self.setIcon(load_pixmap('hp_logo', '128x128'))
54
55         if self.device_uri:
56             self.DeviceComboBox.setInitialDevice(self.device_uri)
57
58
59     def updateUi(self):
60         self.DeviceComboBox.updateUi()
61
62
63     def DeviceUriComboBox_currentChanged(self, device_uri):
64         self.device_uri = device_uri
65         # Update
66
67
68     def DeviceUriComboBox_noDevices(self):
69         self.FailureUI(self.__tr("<b>No devices that support firmware download found.</b>"))
70         self.close()
71
72
73     def downloadFirmware(self):
74         d = None
75
76         try:
77             try:
78                 d = device.Device(self.device_uri)
79             except Error:
80                 self.CheckDeviceUI()
81                 return
82
83             try:
84                 d.open()
85             except Error:
86                 self.CheckDeviceUI()
87             else:
88                 if d.isIdleAndNoError():
89                     ok = d.downloadFirmware()
90
91                 else:
92                     self.CheckDeviceUI()
93
94         finally:
95             if d is not None:
96                 d.close()
97
98         self.close()
99
100
101
102     def __tr(self,s,c = None):
103         return qApp.translate("FirmwareDialog",s,c)
104
105     def FailureUI(self, error_text):
106         
107         QMessageBox.critical(self,
108                 self.caption(),
109                 error_text,
110                 QMessageBox.Ok,
111                 QMessageBox.NoButton,
112                 QMessageBox.NoButton)
113
114
115     def CheckDeviceUI(self):
116          return self.FailureUI(self.__tr("<b>Unable to communicate with device or device is in an error state.</b><p>Please check device setup and try again.</p>"))
117