diff --git a/services/nm/nmclient.py b/services/nm/nmclient.py index ee2b1e93..c30e8a72 100644 --- a/services/nm/nmclient.py +++ b/services/nm/nmclient.py @@ -206,8 +206,9 @@ class Device(gobject.GObject): act_net = self._networks[self._active_net] # Only add the active network if active_only == True - if active_only and act_net: - act_net.add_to_menu(menu, callback, self) + if active_only: + if act_net: + act_net.add_to_menu(menu, callback, self) return # Otherwise, add all networks _except_ the active one @@ -435,6 +436,7 @@ class NMClientApp: self._update_timer = 0 self._active_device = None self._devices = {} + self._key_dialog = None self._icon_theme = gtk.icon_theme_get_default() self._icons = {} @@ -775,7 +777,7 @@ class NMClientApp: self._popdown() - def get_key_for_network(self, net, async_cb, async_err_cb, wep_auth_alg=IW_AUTH_ALG_OPEN_SYSTEM): + def get_key_for_network(self, net, async_cb, async_err_cb): # Throw up a dialog asking for the key here, and set # the authentication algorithm to the given one, if any # @@ -786,12 +788,30 @@ class NMClientApp: # mapping to the values [IW_AUTH_ALG_OPEN_SYSTEM, IW_AUTH_ALG_SHARED_KEY] # above - dialog = WEPKeyDialog() - response = dialog.run() - key = dialog.get_key() - dialog.destroy() + 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() - if response == gtk.RESPONSE_OK: + 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() + (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( key, wep_auth_alg, async_cb, async_err_cb, canceled=False) else: diff --git a/services/nm/nminfo.py b/services/nm/nminfo.py index 592fa398..4d55af17 100644 --- a/services/nm/nminfo.py +++ b/services/nm/nminfo.py @@ -385,13 +385,17 @@ class NMInfo(object): dev = self._nmclient.get_device(dev_op) if not dev: async_err_cb(NotFoundError("Device was unknown.")) + return + if dev.get_type() == nmclient.DEVICE_TYPE_802_3_ETHERNET: # We don't support wired 802.1x yet... async_err_cb(UnsupportedError("Device type is unsupported by NMI.")) + return net = dev.get_network(net_op) if not net: async_err_cb(NotFoundError("Network was unknown.")) + return self._nmclient.get_key_for_network(net, async_cb, async_err_cb) diff --git a/services/nm/wepkeydialog.py b/services/nm/wepkeydialog.py index dd61f1c6..e103fe41 100644 --- a/services/nm/wepkeydialog.py +++ b/services/nm/wepkeydialog.py @@ -1,26 +1,76 @@ +# 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 +import logging + +IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 +IW_AUTH_ALG_SHARED_KEY = 0x00000002 class WEPKeyDialog(gtk.Dialog): - def __init__(self): + 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) + import logging + logging.debug("foobar1") + try: + label = gtk.Label("A wireless encryption key is required for " \ + " the wireless network '%s'." % net.get_ssid()) + except Exception, e: + logging.debug("Exc: %s" % e) + logging.debug("foobar2") + self.vbox.pack_start(label) + logging.debug("foobar3") + + logging.debug("foobar4") self._entry = gtk.Entry() + logging.debug("foobar5") self._entry.props.visibility = False self._entry.connect('changed', self._entry_changed_cb) + logging.debug("foobar6") self.vbox.pack_start(self._entry) - self._entry.show() + logging.debug("foobar7") + self.vbox.show_all() + logging.debug("foobar8") 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() + logging.debug("foobar9") def get_key(self): return self._entry.get_text() + def get_auth_alg(self): + return IW_AUTH_ALG_OPEN_SYSTEM + + def get_callbacks(self): + return (self._async_cb, self._async_err_cb) + def _entry_changed_cb(self, entry): self._update_response_sensitivity()