Add back wep key dialog

This commit is contained in:
Marco Pesenti Gritti 2007-02-25 12:44:54 +01:00
parent 7c135804bc
commit c0c753d169
3 changed files with 132 additions and 2 deletions

View File

@ -3,4 +3,5 @@ sugar_PYTHON = \
__init__.py \
hardwaremanager.py \
nmclient.py \
nminfo.py
nminfo.py \
wepkeydialog.py

View File

@ -22,7 +22,9 @@ import dbus
import dbus.glib
import dbus.decorators
import gobject
import gtk
from hardware.wepkeydialog import WEPKeyDialog
from hardware import nminfo
IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001
@ -438,7 +440,53 @@ class NMClient(gobject.GObject):
raise dbus.DBusException(e)
def get_key_for_network(self, net, async_cb, async_err_cb):
pass
# Throw up a dialog asking for the key here, and set
# the authentication algorithm to the given one, if any
#
# Key needs to be limited to _either_ 10 or 26 digits long,
# and contain _only_ _hex_ digits, 0-9 or a-f
#
# 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]
# above
self._key_dialog = WEPKeyDialog(net, async_cb, async_err_cb)
self._key_dialog.connect("response", self._key_dialog_response_cb)
self._key_dialog.connect("destroy", self._key_dialog_destroy_cb)
self._key_dialog.show_all()
def _key_dialog_destroy_cb(self, widget, foo=None):
if widget != self._key_dialog:
return
self._key_dialog_response_cb(widget, gtk.RESPONSE_CANCEL)
def _key_dialog_response_cb(self, widget, response_id):
if widget != self._key_dialog:
return
key = self._key_dialog.get_key()
wep_auth_alg = self._key_dialog.get_auth_alg()
net = self._key_dialog.get_network()
(async_cb, async_err_cb) = self._key_dialog.get_callbacks()
# Clear self._key_dialog before we call destroy(), otherwise
# the destroy will trigger and we'll get called again by
# self._key_dialog_destroy_cb
self._key_dialog = None
widget.destroy()
if response_id == gtk.RESPONSE_OK:
self.nminfo.get_key_for_network_cb(
net, key, wep_auth_alg, async_cb, async_err_cb, canceled=False)
else:
self.nminfo.get_key_for_network_cb(
net, None, None, async_cb, async_err_cb, 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
if not self._key_dialog:
return
self._key_dialog_destroy_cb(self._key_dialog)
def device_activation_stage_sig_handler(self, device, stage):
logging.debug('Device Activation Stage "%s" for device %s' % (NM_DEVICE_STAGE_STRINGS[stage], device))

View File

@ -0,0 +1,81 @@
# vi: ts=4 ai noet
#
# Copyright (C) 2006, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gtk
IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001
IW_AUTH_ALG_SHARED_KEY = 0x00000002
class WEPKeyDialog(gtk.Dialog):
def __init__(self, net, async_cb, async_err_cb):
gtk.Dialog.__init__(self)
self.set_title("Wireless Key Required")
self._net = net
self._async_cb = async_cb
self._async_err_cb = async_err_cb
self.set_has_separator(False)
label = gtk.Label("A wireless encryption key is required for\n" \
" the wireless network '%s'." % net.get_ssid())
self.vbox.pack_start(label)
self._entry = gtk.Entry()
self._entry.props.visibility = False
self._entry.connect('changed', self._entry_changed_cb)
self.vbox.pack_start(self._entry)
self.vbox.show_all()
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 get_auth_alg(self):
return IW_AUTH_ALG_OPEN_SYSTEM
def get_network(self):
return self._net
def get_callbacks(self):
return (self._async_cb, self._async_err_cb)
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()