Add a simple dialog to enter the web hex key. Several typo fixed.

Merged a patch from Dan.
This commit is contained in:
Marco Pesenti Gritti 2006-11-12 22:44:28 +01:00
parent f677eea6e3
commit 4cd09ed5f8
3 changed files with 75 additions and 9 deletions

View File

@ -30,6 +30,7 @@ from sugar.graphics.menu import Menu
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics.iconcolor import IconColor from sugar.graphics.iconcolor import IconColor
from sugar.graphics.timeline import Timeline from sugar.graphics.timeline import Timeline
from wepkeydialog import WEPKeyDialog
from bubble import Bubble from bubble import Bubble
import nminfo import nminfo
@ -784,6 +785,20 @@ class NMClientApp:
# Auth algorithm should be a dropdown of: [Open System, Shared Key], # Auth algorithm should be a dropdown of: [Open System, Shared Key],
# mapping to the values [IW_AUTH_ALG_OPEN_SYSTEM, IW_AUTH_ALG_SHARED_KEY] # mapping to the values [IW_AUTH_ALG_OPEN_SYSTEM, IW_AUTH_ALG_SHARED_KEY]
# above # above
dialog = WEPKeyDialog()
response = dialog.run()
dialog.destroy()
if response == gtk.RESPONSE_OK:
key = dialog.get_key()
self.nminfo.get_key_for_network_cb(key, wep_auth_alg, canceled=False)
else:
self.nminfo.get_key_for_network_cb(None, None, canceled=True)
def cancel_get_key_for_network(self):
# Close the wireless key dialog and just have it return
# with the 'canceled' argument set to true
pass pass
def device_activation_stage_sig_handler(self, device, stage): def device_activation_stage_sig_handler(self, device, stage):

View File

@ -22,6 +22,8 @@ import time
import os import os
import binascii import binascii
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
import nmclient
try: try:
from sugar import env from sugar import env
except ImportError: except ImportError:
@ -371,18 +373,18 @@ class NMInfo(object):
del net del net
def get_key_for_network(self, dev_op, net_op, ssid, attempt, new_key, async_cb, async_err_cb): def get_key_for_network(self, dev_op, net_op, ssid, attempt, new_key, async_cb, async_err_cb):
if self._networks.has_key(ssid) and not new_key: if self._allowed_networks.has_key(ssid) and not new_key:
# We've got the info already # We've got the info already
net = self._networks[ssid] net = self._allowed_networks[ssid]
async_cb(tuple(net.get_security())) async_cb(tuple(net.get_security()))
return return
# Otherwise, ask the user for it # Otherwise, ask the user for it
net = None net = None
dev = self._nm_client.get_dev(dev_op) dev = self._nmclient.get_device(dev_op)
if not dev: if not dev:
async_err_cb(NotFoundError("Device was unknown.")) async_err_cb(NotFoundError("Device was unknown."))
if dev.get_type() == DEVICE_TYPE_802_3_ETHERNET: if dev.get_type() == nmclient.DEVICE_TYPE_802_3_ETHERNET:
# We don't support wired 802.1x yet... # We don't support wired 802.1x yet...
async_err_cb(UnsupportedError("Device type is unsupported by NMI.")) async_err_cb(UnsupportedError("Device type is unsupported by NMI."))
@ -390,10 +392,16 @@ class NMInfo(object):
if not net: if not net:
async_err_cb(NotFoundError("Network was unknown.")) async_err_cb(NotFoundError("Network was unknown."))
try: self._nmclient.get_key_for_network(net)
(key, auth_alg) = self._nm_client.get_key_for_network()
except CanceledKeyRequestError, e: def get_key_for_network_cb(self, key, auth_alg, canceled=False):
# user canceled the key dialog; send the error back to NM """
Called by the NMClient when the Wireless Network Key dialog
is closed.
"""
if canceled:
e = CanceledKeyRequestError("Request was canceled.")
# key dialog dialog was canceled; send the error back to NM
async_err_cb(e) async_err_cb(e)
return return
@ -417,4 +425,5 @@ class NMInfo(object):
async_cb(tuple(sec.get_properties())) async_cb(tuple(sec.get_properties()))
def cancel_get_key_for_network(self): def cancel_get_key_for_network(self):
pass # Tell the NMClient to close the key request dialog
self._nmclient.cancel_get_key_for_network()

View File

@ -0,0 +1,42 @@
import gtk
class WEPKeyDialog(gtk.Dialog):
def __init__(self):
gtk.Dialog.__init__(self)
self.set_has_separator(False)
self._entry = gtk.Entry()
self._entry.props.visibility = False
self._entry.connect('changed', self._entry_changed_cb)
self.vbox.pack_start(self._entry)
self._entry.show()
self.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK)
self.set_default_response(gtk.RESPONSE_OK)
self._update_response_sensitivity()
def get_key(self):
return self._entry.get_text()
def _entry_changed_cb(self, entry):
self._update_response_sensitivity()
def _update_response_sensitivity(self):
key = self.get_key()
is_hex = True
for c in key:
if not 'a' <= c <= 'f' and not '0' <= c <= '9':
is_hex = False
valid_len = (len(key) == 10 or len(key) == 26)
self.set_response_sensitive(gtk.RESPONSE_OK, is_hex and valid_len)
if __name__ == "__main__":
dialog = WEPKeyDialog()
dialog.run()
print dialog.get_key()