Debian Codegraph @

ui4/wifisetupdialog.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2015 HP 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 # Authors: Don Welch
20 #
21
22 # StdLib
23 import operator
24 import signal
25
26 # Local
27 from base.g import *
28 from base import device, models, wifi, LedmWifi, CdmWifi
29 from base.codes import *
30 from base.sixext import to_unicode
31 from .ui_utils import *
32 from base.sixext import PY3, to_bytes_utf8, to_unicode, to_string_latin, to_string_utf8, xStringIO
33
34 # Qt
35 from PyQt4.QtCore import *
36 from PyQt4.QtGui import *
37
38 # Ui
39 from .wifisetupdialog_base import Ui_Dialog
40
41 PAGE_INTRO = 0 # Ask user to plugin temp USB connection
42 PAGE_DEVICES = 1 # Select a probed USB device
43 PAGE_NETWORK = 2 # Select a discovered SSID
44 PAGE_CONFIGURE_WIFI = 3 # Configure USB device on network
45 PAGE_EXIT = 4 # Tell user if successful, unplug USB onnection
46
47
48 BUTTON_NEXT = 0
49 BUTTON_FINISH = 1
50 BUTTON_CONNECT = 3
51
52 SUCCESS_NOT_CONNECTED = 0
53 SUCCESS_AUTO_IP = 1
54 SUCCESS_CONNECTED = 2
55
56 ASSOCIATE_DELAY = 30
57 REFRESH_INTERVAL = 20
58
59
60 class PasswordDialog(QDialog):
61 def __init__(self, prompt, parent=None, name=None, modal=0, fl=0):
62 QDialog.__init__(self, parent)
63 # Application icon
64 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
65 self.prompt = prompt
66
67 Layout= QGridLayout(self)
68 Layout.setMargin(11)
69 Layout.setSpacing(6)
70
71 self.PromptTextLabel = QLabel(self)
72 Layout.addWidget(self.PromptTextLabel,0,0,1,3)
73
74 self.UsernameTextLabel = QLabel(self)
75 Layout.addWidget(self.UsernameTextLabel,1,0)
76
77 self.UsernameLineEdit = QLineEdit(self)
78 self.UsernameLineEdit.setEchoMode(QLineEdit.Normal)
79 Layout.addWidget(self.UsernameLineEdit,1,1,1,2)
80
81 self.PasswordTextLabel = QLabel(self)
82 Layout.addWidget(self.PasswordTextLabel,2,0)
83
84 self.PasswordLineEdit = QLineEdit(self)
85 self.PasswordLineEdit.setEchoMode(QLineEdit.Password)
86 Layout.addWidget(self.PasswordLineEdit,2,1,1,2)
87
88 self.OkPushButton = QPushButton(self)
89 Layout.addWidget(self.OkPushButton,3,2)
90
91 self.languageChange()
92
93 self.resize(QSize(420,163).expandedTo(self.minimumSizeHint()))
94
95 self.connect(self.OkPushButton, SIGNAL("clicked()"), self.accept)
96 self.connect(self.PasswordLineEdit, SIGNAL("returnPressed()"), self.accept)
97
98 def setDefaultUsername(self, defUser, allowUsernameEdit = True):
99 self.UsernameLineEdit.setText(defUser)
100 if not allowUsernameEdit:
101 self.UsernameLineEdit.setReadOnly(True)
102 self.UsernameLineEdit.setStyleSheet("QLineEdit {background-color: lightgray}")
103
104 def getUsername(self):
105 return to_unicode(self.UsernameLineEdit.text())
106
107
108 def getPassword(self):
109 return to_unicode(self.PasswordLineEdit.text())
110
111
112 def languageChange(self):
113 self.setWindowTitle(self.__tr("HP Device Manager - Enter Username/Password"))
114 self.PromptTextLabel.setText(self.__tr(self.prompt))
115 self.UsernameTextLabel.setText(self.__tr("Username:"))
116 self.PasswordTextLabel.setText(self.__tr("Password:"))
117 self.OkPushButton.setText(self.__tr("OK"))
118
119
120 def __tr(self,s,c = None):
121 return qApp.translate("SetupDialog",s,c)
122
123 def showPasswordUI(prompt, userName=None, allowUsernameEdit=True):
124 try:
125 dlg = PasswordDialog(prompt, None)
126
127 if userName != None:
128 dlg.setDefaultUsername(userName, allowUsernameEdit)
129
130 if dlg.exec_() == QDialog.Accepted:
131 return (1,dlg.getUsername(), dlg.getPassword())
132 else:
133 return (0,"", "")
134 finally:
135 pass
136
137 return (0,"", "")
138
139
140 class DeviceTableWidgetItem(QTableWidgetItem):
141 def __init__(self, text, device_uri):
142 QTableWidgetItem.__init__(self, text, QTableWidgetItem.UserType)
143 self.device_uri = device_uri
144
145
146 class WifiSetupDialog(QDialog, Ui_Dialog):
147 def __init__(self, parent, device_uri=None, standalone=True):
148 QDialog.__init__(self, parent)
149 self.setupUi(self)
150
151 self.device_uri = device_uri
152 self.devices = {}
153 self.networks = {}
154 self.ssid = ''
155 self.directed = False
156 self.show_extended = False
157 self.bus = 'usb'
158 self.search = ''
159 self.max_page = PAGE_EXIT
160 self.location_cache = {} # { 'bssid' : <location>, ... }
161 self.dev = None
162 self.success = SUCCESS_NOT_CONNECTED
163 self.ip = '0.0.0.0'
164 self.hn = ''
165 self.standalone = standalone
166 self.initUi()
167 self.adapterName = 'Wifi0'
168 self.wifiObj = wifi
169
170 #if self.device_uri is None:
171 # QTimer.singleShot(0, self.showIntroPage)
172 #else:
173 # QTimer.singleShot(0, self.showNetworkPage)
174
175 QTimer.singleShot(0, self.showIntroPage)
176
177
178 #
179 # INIT
180 #
181
182 def initUi(self):
183 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
184
185 # connect signals/slots
186 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
187 self.connect(self.BackButton, SIGNAL("clicked()"), self.BackButton_clicked)
188 self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
189 signal.signal(signal.SIGINT, signal.SIG_DFL)
190
191 self.initIntroPage()
192 self.initDevicesPage()
193 self.initNetworkPage()
194 self.initConfigWifiPage()
195 self.initExitPage()
196
197 #
198 # INTRO PAGE
199 #
200
201 def initIntroPage(self):
202 self.Picture.setPixmap(load_pixmap("usb_connection", "other"))
203 self.InfoIcon.setPixmap(load_pixmap("info", "16x16"))
204
205 if self.standalone:
206 self.MainTitleLabel.setText(self.__tr("This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete. <p><i>Note: This configuration utility does not setup (install) your printer on this computer. Use hp-setup to setup your printer after it has been configured on the network by this utility.</i></p> <p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>"))
207 else:
208 self.MainTitleLabel.setText(self.__tr("This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete. <p><i>Note: Printer setup (installation) will continue after your printer is configured on the network.</i></p> <p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>"))
209
210
211 def showIntroPage(self):
212 self.BackButton.setEnabled(False)
213 self.NextButton.setEnabled(True)
214
215 self.displayPage(PAGE_INTRO)
216
217
218 #
219 # DEVICES PAGE
220 #
221
222 def initDevicesPage(self):
223 self.connect(self.RefreshButton, SIGNAL("clicked()"), self.RefreshButton_clicked)
224
225
226 def showDevicesPage(self):
227 self.BackButton.setEnabled(True)
228 self.setNextButton(BUTTON_NEXT)
229
230 beginWaitCursor()
231 try:
232 if not self.devices:
233 log.info("Searching on USB bus...")
234 filter_dict = {'wifi-config' : (operator.gt, WIFI_CONFIG_NONE)}
235
236 try:
237 from base import smart_install
238 except ImportError:
239 log.error("Failed to Import smart_install.py from base")
240 else:
241 endWaitCursor()
242 smart_install.disable(GUI_MODE, 'qt4')
243 beginWaitCursor()
244
245 self.devices = device.probeDevices([self.bus], 0, 0, filter_dict, self.search)
246
247 finally:
248 endWaitCursor()
249
250 self.clearDevicesTable()
251
252 if self.devices:
253 self.NextButton.setEnabled(True)
254 self.DevicesFoundIcon.setPixmap(load_pixmap('info', '16x16'))
255
256 if len(self.devices) == 1:
257 self.DevicesFoundLabel.setText(self.__tr("<b>1 wireless capable device found.</b> Click <i>Next</i> to continue."))
258 else:
259 self.DevicesFoundLabel.setText(self.__tr("<b>%s wireless capable devices found.</b> Select the device to install and click <i>Next</i> to continue." % len(self.devices)))
260
261 self.loadDevicesTable()
262
263 else:
264 self.NextButton.setEnabled(False)
265 self.DevicesFoundIcon.setPixmap(load_pixmap('error', '16x16'))
266 log.error("No devices found on bus: %s" % self.bus)
267 self.DevicesFoundLabel.setText(self.__tr("<b>No wireless capable devices found.</b><br>Plug in your printer with a USB cable and click <i>Refresh</i> to search again."))
268
269 self.displayPage(PAGE_DEVICES)
270
271
272 def loadDevicesTable(self):
273 self.DevicesTableWidget.setSortingEnabled(False)
274 self.DevicesTableWidget.setRowCount(len(self.devices))
275
276 headers = [self.__tr('Model'), self.__tr('Device URI')]
277 device_uri_col = 1
278
279 self.DevicesTableWidget.setColumnCount(len(headers))
280 self.DevicesTableWidget.setHorizontalHeaderLabels(headers)
281 flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
282
283 for row, d in enumerate(self.devices):
284 back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(d)
285 model_ui = models.normalizeModelUIName(model)
286
287 i = DeviceTableWidgetItem(QString(model_ui), d)
288 i.setFlags(flags)
289 self.DevicesTableWidget.setItem(row, 0, i)
290
291 i = QTableWidgetItem(QString(d))
292 i.setFlags(flags)
293 self.DevicesTableWidget.setItem(row, device_uri_col, i)
294
295 self.DevicesTableWidget.resizeColumnsToContents()
296 self.DevicesTableWidget.setSortingEnabled(True)
297 self.DevicesTableWidget.sortItems(0)
298 self.DevicesTableWidget.selectRow(0)
299
300
301 def clearDevicesTable(self):
302 self.DevicesTableWidget.clear()
303 self.DevicesTableWidget.setRowCount(0)
304 self.DevicesTableWidget.setColumnCount(0)
305
306
307 def RefreshButton_clicked(self):
308 self.clearDevicesTable()
309 self.devices = []
310 QTimer.singleShot(0, self.showDevicesPage)
311
312
313 #
314 # NETWORK
315 #
316
317 def initNetworkPage(self):
318 self.NetworksTableWidget.setIconSize(QSize(34, 20))
319 self.ShowExtendedCheckBox.setChecked(False)
320 self.connect(self.ShowExtendedCheckBox, SIGNAL("clicked(bool)"), self.ShowExtendedCheckBox_clicked)
321 self.connect(self.SearchPushButton, SIGNAL("clicked()"), self.SearchPushButton_clicked)
322 self.connect(self.UndirectedRadioButton, SIGNAL("clicked(bool)"), self.UndirectedRadioButton_clicked)
323 self.connect(self.DirectedRadioButton, SIGNAL("clicked(bool)"), self.DirectedRadioButton_clicked)
324 self.connect(self.NetworksTableWidget, SIGNAL("itemSelectionChanged()"), self.NetworksTableWidget_itemSelectionChanged)
325
326
327 def showNetworkPage(self):
328 if self.dev is None:
329 try:
330 self.dev = device.Device(self.device_uri)
331 except Error as e:
332 FailureUI(self, self.__tr("<b>Error opening device:</b><p>%s</p><p>(%s)</p>") %(self.device_uri, QString(e[0])))
333
334 if self.dev is not None:
335 self.dev.close()
336
337 self.close()
338 return
339
340 self.networks.clear()
341 self.num_networks = 0
342
343 #Get authentication token
344 if self.wifiObj == CdmWifi:
345 if self.wifiObj.getCDMToken_pushbutton(self.dev):
346 log.debug("authenticated via getCDMToken_pushbutton")
347 else:
348 prompt = "Enter printer's username and password"
349 while True:
350 rtnvalue,uname, password = showPasswordUI(prompt,userName="administrator")
351 if rtnvalue == 0:
352 return
353 ret = self.wifiObj.getCDMToken(self.dev, uname, password)
354 if ret == True:
355 break
356 prompt = "Invalid Username/Password\n.Please renter printer's username and password"
357
358 #Get adaptor_id
359
360 try:
361 adaptor_list = self.wifiObj.getWifiAdaptorID(self.dev)
362 except Error as e:
363 self.showIOError(e)
364 return
365
366 if len(adaptor_list) == 0:
367 FailureUI(self, self.__tr("<b>Unable to locate wireless hardware on device.</b>"))
368 if self.dev is not None:
369 self.dev.close()
370
371 self.close()
372
373 log.debug("Turning on wireless radio...")
374 try:
375 self.adaptor_id, self.adapterName, state, presence = self.wifiObj.setAdaptorPower(self.dev, adaptor_list)
376 except Error as e:
377 self.showIOError(e)
378 return
379 if self.adaptor_id == -1:
380 FailureUI(self, self.__tr("<b>Unable to turn on wireless adaptor.</b>"))
381 if self.dev is not None:
382 self.dev.close()
383
384 log.debug("Adaptor ID: %s" % self.adaptor_id)
385 log.debug("Adaptor name: %s" % self.adapterName)
386 log.debug("Adaptor state: %s" % state)
387 log.debug("Adaptor presence: %s" % presence)
388 self.performScan()
389 self.setNextButton(BUTTON_NEXT)
390 self.displayPage(PAGE_NETWORK)
391
392
393 def performScan(self):
394 beginWaitCursor()
395 try:
396 self.ssid = to_unicode(self.SSIDLineEdit.text())
397 if self.directed and self.ssid:
398 try:
399 self.networks = self.wifiObj.performScan(self.dev, self.adapterName, self.ssid)
400 except Error as e:
401 self.showIOError(e)
402 return
403 else:
404 try:
405 self.networks = self.wifiObj.performScan(self.dev, self.adapterName)
406 except Error as e:
407 self.showIOError(e)
408 return
409 finally:
410 self.dev.close()
411 endWaitCursor()
412 self.num_networks = self.networks['numberofscanentries']
413 self.clearNetworksTable()
414
415 if self.num_networks:
416 self.NextButton.setEnabled(True)
417 self.NetworksFoundIcon.setPixmap(load_pixmap('info', '16x16'))
418
419 if self.num_networks == 1:
420 self.NetworksFoundLabel.setText(self.__tr("<b>1 wireless network found. </b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again."))
421 else:
422 self.NetworksFoundLabel.setText(self.__tr("<b>%d wireless networks found.</b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again." %self.num_networks))
423
424 self.loadNetworksTable()
425
426 else:
427 self.NextButton.setEnabled(False)
428 self.NetworksFoundIcon.setPixmap(load_pixmap('error', '16x16'))
429 log.warning("No wireless networks found.")
430 self.NetworksFoundLabel.setText(self.__tr("<b>No wireless networks found.</b><br>Enter a wireless network name and/or press <i>Search</i> to search again."))
431
432
433 def ShowExtendedCheckBox_clicked(self, b):
434 self.show_extended = b
435 self.loadNetworksTable()
436
437
438 def SearchPushButton_clicked(self):
439 self.performScan()
440 self.loadNetworksTable()
441
442
443 def UndirectedRadioButton_clicked(self, b):
444 self.directed = not b
445 self.SSIDLineEdit.setEnabled(not b)
446
447
448 def DirectedRadioButton_clicked(self, b):
449 self.directed = b
450 self.SSIDLineEdit.setEnabled(b)
451
452
453 def loadNetworksTable(self):
454 self.n, self.network = 0, to_unicode('')
455 if self.num_networks:
456 beginWaitCursor()
457 try:
458 if self.show_extended:
459 for n in range(self.num_networks):
460 bssid = self.networks['bssid-%d' % n]
461 ss = self.networks['signalstrength-%d' % n]
462 try:
463 self.location_cache[bssid]
464 except KeyError:
465 location = wifi.getLocation(bssid, ss)
466 lat = self.networks['latitude-%d' % n] = location.get('latitude', 'Unknown')
467 lng = self.networks['longitude-%d' % n] = location.get('longitude', 'Unknown')
468 address = self.networks['address-%d' % n] = location.get('address', 'Unknown')
469 self.location_cache[bssid] = (lat, lng, address)
470 else:
471 self.networks['latitude-%d' % n], self.networks['longitude-%d' % n], self.networks['address-%d' % n] = \
472 self.location_cache[bssid]
473
474 self.NetworksTableWidget.setSortingEnabled(False)
475 self.NetworksTableWidget.setRowCount(self.num_networks)
476
477 headers = [self.__tr('Network Name (SSID)'), self.__tr('Signal Strength'),
478 self.__tr("Security"), self.__tr("Mode")]
479
480 if self.show_extended:
481 headers.extend([self.__tr('Channel'),
482 self.__tr("Address (BSSID)"), self.__tr("Location"),
483 self.__tr("Lat/Long")])
484
485 self.NetworksTableWidget.setColumnCount(len(headers))
486 self.NetworksTableWidget.setHorizontalHeaderLabels(headers)
487 enabled_flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
488 for n in range(self.num_networks):
489 name = self.networks['ssid-%d' % n]
490
491 if name == '(unknown)':
492 flags = None
493 else:
494 flags = enabled_flags
495
496 ss = self.networks['signalstrength-%d' % n]
497 sec = self.networks['encryptiontype-%d' % n]
498 mode = self.networks['communicationmode-%d' % n]
499
500 log.debug("%d: Name=%s, strength=%s, security=%s, mode=%s" % #, channel=%d bssid=%s" %
501 (n, name, ss, sec, mode))
502
503 if self.show_extended:
504 chn = self.networks['channel-%d' % n]
505 dbm = self.networks['dbm-%d' % n]
506 bssid = self.networks['bssid-%d' % n]
507 address = self.networks['address-%d' % n]
508 lat = self.networks['latitude-%d' % n]
509 lng = self.networks['longitude-%d' % n]
510
511 log.debug("%d: channel=%d bssid=%s dbm=%s lat=%s long=%s address=%s" %
512 (n, chn, bssid, dbm, lat, lng, address))
513
514 i = QTableWidgetItem(QString(name))
515 if flags is not None: i.setFlags(flags)
516 i.setData(Qt.UserRole, n)
517 self.NetworksTableWidget.setItem(n, 0, i)
518
519 pixmap = load_pixmap('signal%d' % ss, 'other')
520 if self.show_extended:
521 i = QTableWidgetItem(QIcon(pixmap), self.__tr("%s/5 (%s dBm)" %(ss, dbm)))
522 else:
523 i = QTableWidgetItem(QIcon(pixmap), self.__tr("%s/5" % ss))
524 if flags is not None: i.setFlags(flags)
525 self.NetworksTableWidget.setItem(n, 1, i)
526
527 i = QTableWidgetItem(QString(sec))
528 if flags is not None: i.setFlags(flags)
529 self.NetworksTableWidget.setItem(n, 2, i)
530
531 i = QTableWidgetItem(QString(mode))
532 if flags is not None: i.setFlags(flags)
533 self.NetworksTableWidget.setItem(n, 3, i)
534
535 if self.show_extended:
536 i = QTableWidgetItem(QString(str(chn)))
537 if flags is not None: i.setFlags(flags)
538 self.NetworksTableWidget.setItem(n, 4, i)
539
540 i = QTableWidgetItem(QString(bssid))
541 if flags is not None: i.setFlags(flags)
542 self.NetworksTableWidget.setItem(n, 5, i)
543
544 i = QTableWidgetItem(QString(address))
545 if flags is not None: i.setFlags(flags)
546 self.NetworksTableWidget.setItem(n, 6, i)
547
548 i = QTableWidgetItem(QString("%s/%s" % (lat, lng)))
549 if flags is not None: i.setFlags(flags)
550 self.NetworksTableWidget.setItem(n, 7, i)
551
552
553 self.NetworksTableWidget.resizeColumnsToContents()
554 self.NetworksTableWidget.setSortingEnabled(True)
555 self.NetworksTableWidget.sortItems(1, Qt.DescendingOrder)
556 self.NetworksTableWidget.selectRow(0)
557 self.NetworksTableWidget.emit(SIGNAL("itemSelectionChanged()"))
558
559 finally:
560 endWaitCursor()
561 self.NextButton.setEnabled(True)
562
563 else:
564 self.NextButton.setEnabled(False)
565
566
567 def NetworksTableWidget_itemSelectionChanged(self):
568 row = self.NetworksTableWidget.currentRow()
569 item = self.NetworksTableWidget.item(row, 0)
570 n, ok = value_int(item.data(Qt.UserRole))
571 if ok:
572 sec = self.networks['encryptiontype-%d' % n]
573 if sec.lower() == 'none':
574 self.setNextButton(BUTTON_CONNECT)
575 else:
576 self.setNextButton(BUTTON_NEXT)
577
578
579 def clearNetworksTable(self):
580 self.DevicesTableWidget.clear()
581 self.DevicesTableWidget.setRowCount(0)
582 self.DevicesTableWidget.setColumnCount(0)
583
584
585 def RefreshButton2_clicked(self):
586 self.clearNetworksTable()
587 self.networks = {}
588 QTimer.singleShot(0, self.showNetworkPage)
589
590
591 #
592 # CONFIGURE WIFI
593 #
594
595 def initConfigWifiPage(self):
596 self.connect(self.ShowKeyCheckBox, SIGNAL("toggled(bool)"), self.ShowKeyCheckBox_toggled)
597
598
599 def showConfigWifiPage(self):
600 self.setNextButton(BUTTON_CONNECT)
601 self.SSIDLabel.setText(self.network)
602 font = QFont()
603 font.setPointSize(12)
604 self.SSIDLabel.setFont(font)
605 self.KeyLineEdit.setText(QString())
606 self.ShowKeyCheckBox.setChecked(False)
607 self.StrengthIcon.setPixmap(load_pixmap('signal%d' % self.ss, 'other'))
608 self.ConfigureIcon.setPixmap(load_pixmap('info', '16x16'))
609 self.KeysIcon.setPixmap(load_pixmap('keys', '32x32'))
610
611 if 'wpa' in self.security.lower():
612 self.WPARadioButton.setChecked(True)
613
614 elif 'wep' in self.security.lower():
615 self.WEPRadioButton.setChecked(True)
616
617 self.KeyLineEdit.setFocus()
618 self.KeyLineEdit.setEchoMode(QLineEdit.Password)
619 self.displayPage(PAGE_CONFIGURE_WIFI)
620
621
622 def ShowKeyCheckBox_toggled(self, b):
623 if b:
624 self.KeyLineEdit.setEchoMode(QLineEdit.Normal)
625 else:
626 self.KeyLineEdit.setEchoMode(QLineEdit.Password)
627
628
629 #
630 # EXIT/CONNECT PAGE
631 #
632
633 def initExitPage(self):
634 self.connect(self.PageSpinBox, SIGNAL("valueChanged(int)"), self.PageSpinBox_valueChanged)
635 self.RefreshTimer = QTimer(self)
636 self.connect(self.RefreshTimer, SIGNAL('timeout()'), self.RefreshTimer_timeout)
637 self.pages = []
638 self.page_index = 0
639 self.PageSpinBox.setMinimum(1)
640
641
642 def showExitPage(self):
643 self.setNextButton(BUTTON_FINISH)
644 self.NextButton.setEnabled(False)
645 self.CancelButton.setEnabled(True)
646 self.SSIDLabel_2.setText(QString(self.network))
647 self.ip = '0.0.0.0'
648 self.hn = ''
649 ss_max, ss_min, ss_val, ss_dbm = 5, 0, 0, -200
650 vsa_codes = []
651 self.success = SUCCESS_NOT_CONNECTED
652 beginWaitCursor()
653 try:
654 try:
655 self.ip,_,addressmode, subnetmask, gateway, pridns, sec_dns= self.wifiObj.getIPConfiguration(self.dev, self.adapterName)
656 if self.ip == "0.0.0.0":
657 if not self.wifiObj == CdmWifi:
658 self.ip, subnetmask, gateway, pri_dns, sec_dns, addressmode = self.wifiObj.getwifiotherdetails(self.dev,self.adapterName)
659 vsa_codes = self.wifiObj.getVSACodes(self.dev, self.adapterName)
660 ss_max, ss_min, ss_val, ss_dbm = self.wifiObj.getSignalStrength(self.dev, self.adapterName,self.network, self.adaptor_id)
661 self.hn = self.wifiObj.getHostname(self.dev)
662 except Error as e:
663 self.showIOError(e)
664 return
665 finally:
666 self.dev.close()
667 endWaitCursor()
668
669 if 'dhcp' or 'default' in addressmode.lower():
670 self.success = SUCCESS_CONNECTED
671
672 elif addressmode.lower() == 'autoip':
673 self.success = SUCCESS_AUTO_IP
674
675 if self.ip == '0.0.0.0':
676 self.success = SUCCESS_NOT_CONNECTED
677
678 self.pages = []
679
680 if self.success == SUCCESS_NOT_CONNECTED:
681 self.pages.append((self.__tr("<b>Your printer has not been connected to the wireless network.</b> A valid connection to a wireless network can take up to 2 minutes. This screen will automatically refresh every %s seconds.<p>If your printer fails to connect within a reasonable time, there may be a problem with your configuration." % REFRESH_INTERVAL), load_pixmap('error', '16x16')))
682 self.RefreshTimer.start(REFRESH_INTERVAL * 1000)
683
684 elif self.success == SUCCESS_AUTO_IP:
685 # self.pages.append((self.__tr("Your printer has been connected to the wireless network, but it has been assigned an address which may not be usable."), load_pixmap('warning', '16x16')))
686 self.pages.append((self.__tr("Your printer has been connected to the wireless network and has been assinged a IP. Now run <pre>hp-setup %s</pre> If IP is not accessible, try again for another IP."%self.ip), load_pixmap('warning', '16x16')))
687 # self.RefreshTimer.start(REFRESH_INTERVAL * 1000)
688 self.CancelButton.setEnabled(False)
689 self.BackButton.setEnabled(False)
690 self.RefreshTimer.stop()
691
692 else: # SUCCESS_CONNECTED
693 self.pages.append((self.__tr("Your printer has been successfully configured on the wireless network. You may now unplug the USB cable. To setup the printer, now run <pre>hp-setup %s</pre>"%self.ip), load_pixmap('info', '16x16')))
694 self.CancelButton.setEnabled(False)
695 self.BackButton.setEnabled(False)
696 self.RefreshTimer.stop()
697
698 if addressmode is None:
699 self.AddressModeLabel.setText(self.__tr("Unknown"))
700 else:
701 self.AddressModeLabel.setText(QString(addressmode))
702
703 if self.hn is None:
704 self.HostnameLabel.setText(self.__tr("Unknown"))
705 else:
706 self.HostnameLabel.setText(QString(self.hn))
707
708 self.IPAddressLabel.setText(QString(self.ip))
709 self.GatewayLabel.setText(QString(gateway))
710 self.DNSLabel.setText(QString(pridns))
711 self.NextButton.setEnabled(True)
712
713 self.SignalStrengthLabel.setText(QString("%s/%s (%s dBm)" % (ss_val, ss_max, ss_dbm)))
714 self.SignalStrengthIcon.setPixmap(load_pixmap('signal%d' % ss_val, 'other'))
715
716 for c, s in vsa_codes:
717 if c :
718 ss = s.lower()
719 if ss.startswith("info"):
720 pixmap = load_pixmap('info', '16x16')
721
722 elif ss.startswith("warn"):
723 pixmap = load_pixmap('warning', '16x16')
724
725 elif ss.startswith("crit"):
726 pixmap = load_pixmap('error', '16x16')
727
728 else:
729 pixmap = load_pixmap('info', '16x16')
730
731 self.pages.append((device.queryString("vsa_%s" % str(c).zfill(3)), pixmap))
732
733 num_pages = len(self.pages)
734 self.PageSpinBox.setMaximum(num_pages)
735 self.PageSpinBox.setEnabled(num_pages>1)
736 self.PageSpinBox.setValue(1)
737 self.PageLabel.setEnabled(num_pages>1)
738 self.PageLabel2.setEnabled(num_pages>1)
739 self.PageLabel.setText(self.__tr("of %s", str(num_pages)))
740 self.page_index = 0
741 self.ExitLabel.setText(self.pages[self.page_index][0])
742 self.ExitIcon.setPixmap(self.pages[self.page_index][1])
743 self.displayPage(PAGE_EXIT)
744
745
746 def PageSpinBox_valueChanged(self, i):
747 self.page_index = i-1
748 self.ExitLabel.setText(self.pages[self.page_index][0])
749 self.ExitIcon.setPixmap(self.pages[self.page_index][1])
750
751
752 def RefreshTimer_timeout(self):
753 self.showExitPage()
754
755
756 #
757 # ASSOCIATE
758 #
759
760 def associate(self, key=to_unicode('')):
761 beginWaitCursor()
762 try:
763 try:
764 alg, mode, secretid = self.wifiObj.getCryptoSuite(self.dev, self.adapterName)
765 except Error as e:
766 self.showIOError(e)
767 return
768
769 log.debug("Crypto algorithm: %s" % alg)
770 log.debug("Crypto mode: %s" % mode)
771 finally:
772 endWaitCursor()
773
774 beginWaitCursor()
775 try:
776 try:
777 if self.wifiObj == CdmWifi:
778
779 self.wifiObj.associate(self.dev, self.wpaVersionPreference, self.network, self.authenticationMode, self.security, key)
780 else:
781 self.wifiObj.associate(self.dev, self.adapterName, self.network, self.mode, self.security, key)
782 except Error as e:
783 self.showIOError(e)
784 return
785 finally:
786 endWaitCursor()
787
788
789 #
790 # Misc
791 #
792
793 def NextButton_clicked(self):
794 p = self.StackedWidget.currentIndex()
795 if p == PAGE_INTRO:
796 self.showDevicesPage()
797
798 elif p == PAGE_DEVICES:
799 row = self.DevicesTableWidget.currentRow()
800 if row != -1:
801 self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri
802 self.mq = device.queryModelByURI(self.device_uri)
803
804 self.getWifiObject(self.mq['wifi-config'])
805 back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri)
806 self.model = models.normalizeModelName(model).lower()
807
808 self.showNetworkPage()
809
810 elif p == PAGE_NETWORK:
811 self.security = 'None'
812 self.mode = 'Infrastructure'
813 self.ss = 0
814 row = self.NetworksTableWidget.currentRow()
815 if row != -1:
816 i = self.NetworksTableWidget.item(row, 0)
817 if i is not None:
818 self.network = to_unicode(i.text())
819 log.debug("Selected network SSID: %s" % self.network)
820 self.n, ok = value_int(i.data(Qt.UserRole))
821 if ok:
822 self.security = self.networks.get('encryptiontype-%d'%self.n)
823 log.debug("Security: %s" % self.security)
824
825 self.mode = self.networks.get('communicationmode-%d'%self.n)
826 log.debug("Mode: %s" % self.mode)
827
828 self.ss = self.networks.get('signalstrength-%d'%self.n)
829 log.debug("Signal strength: %s" % self.ss)
830
831 self.wpaVersionPreference = self.networks.get('wpaVersionPreference-%d'%self.n)
832 self.authenticationMode = self.networks.get('authenticationMode-%d'%self.n)
833
834
835 if self.security.lower() != 'none':
836 self.showConfigWifiPage()
837 else:
838 # Skip config page if no security to setup
839 self.associate()
840 self.showAssociateProgressDialog()
841 self.showExitPage()
842
843 elif p == PAGE_CONFIGURE_WIFI:
844 key = to_unicode(self.KeyLineEdit.text())
845 self.associate(key)
846 self.showAssociateProgressDialog()
847 self.showExitPage()
848
849 elif p == PAGE_EXIT:
850 if self.dev is not None:
851 self.dev.close()
852
853 self.close()
854
855 else:
856 log.error("Invalid page!") # shouldn't happen!
857
858
859 def showAssociateProgressDialog(self):
860 AssociateProgressDialog = QProgressDialog(self.__tr("Waiting for printer to connect to the wireless network..."), self.__tr("Cancel"), 0, ASSOCIATE_DELAY, self)
861 AssociateProgressDialog.setWindowTitle(self.__tr("HP Device Manager - Please wait..."))
862 AssociateProgressDialog.setWindowModality(Qt.WindowModal)
863 AssociateProgressDialog.setMinimumDuration(0)
864 AssociateProgressDialog.forceShow()
865 canceled = False
866 for x in range(ASSOCIATE_DELAY):
867 AssociateProgressDialog.setValue(x)
868 QThread.sleep(1)
869 qApp.processEvents()
870
871 if AssociateProgressDialog.wasCanceled():
872 canceled = True
873 break
874
875 AssociateProgressDialog.setValue(ASSOCIATE_DELAY)
876 AssociateProgressDialog.close()
877
878 if canceled:
879 if self.dev is not None:
880 self.dev.close()
881
882 self.close()
883
884
885 def BackButton_clicked(self):
886 p = self.StackedWidget.currentIndex()
887 if p == PAGE_DEVICES:
888 self.devices = {}
889 self.showIntroPage()
890
891 elif p == PAGE_NETWORK:
892 self.showDevicesPage()
893
894 elif p == PAGE_CONFIGURE_WIFI:
895 self.showNetworkPage()
896
897 elif p == PAGE_EXIT:
898 self.RefreshTimer.stop()
899 if self.security.lower() != 'none':
900 self.showConfigWifiPage()
901 else:
902 self.showNetworkPage()
903
904 else:
905 log.error("Invalid page!") # shouldn't happen!
906
907
908 def CancelButton_clicked(self):
909 if self.dev is not None:
910 self.dev.close()
911
912 self.close()
913
914
915 def displayPage(self, page):
916 self.StackedWidget.setCurrentIndex(page)
917 self.updateStepText(page)
918
919
920 def setNextButton(self, typ=BUTTON_FINISH):
921 if typ == BUTTON_NEXT:
922 self.NextButton.setText(self.__tr("Next >"))
923
924 elif typ == BUTTON_FINISH:
925 self.NextButton.setText(self.__tr("Finish"))
926
927 elif typ == BUTTON_CONNECT:
928 self.NextButton.setText(self.__tr("Connect"))
929
930
931 def updateStepText(self, p):
932 self.StepText.setText(self.__tr("Step %s of %s" % (p+1, self.max_page+1)))
933
934
935 def showIOError(self, e):
936 FailureUI(self, self.__tr("<b>An I/O error occurred.</b><p>Please check the USB connection to your printer and try again.</p>(%s)" % QString(e[0])))
937
938 if self.dev is not None:
939 self.dev.close()
940
941 self.close()
942
943
944 def __tr(self,s,c = None):
945 return qApp.translate("WifiSetupDialog",s,c)
946
947 # The Wifi object here is not actual object, Dynamically relevant modules are selected based on
948 # wifi-config value in the models file.
949 def getWifiObject(self,wifiConfVal):
950 if wifiConfVal == WIFI_CONFIG_LEDM:
951 self.wifiObj = LedmWifi
952 elif wifiConfVal == WIFI_CONFIG_CDM:
953 self.wifiObj = CdmWifi
954 else:
955 self.wifiObj = wifi
956
957