Activate the network on click

This commit is contained in:
Marco Pesenti Gritti 2007-02-25 12:17:45 +01:00
parent 91722dfebc
commit 38ac42d665
3 changed files with 43 additions and 9 deletions

View File

@ -418,6 +418,21 @@ class NMClient(gobject.GObject):
except dbus.DBusException: except dbus.DBusException:
pass pass
def set_active_device(self, device, network):
net_op = ""
if network:
net_op = network.get_op()
try:
# NM 0.6.4 and earlier have a bug which returns an
# InvalidArguments error if no security information is passed
# for wireless networks
self._nm_obj.setActiveDevice(device.get_op(), network.get_ssid())
except dbus.DBusException, e:
if str(e).find("invalid arguments"):
pass
else:
raise dbus.DBusException(e)
def get_key_for_network(self, net, async_cb, async_err_cb): def get_key_for_network(self, net, async_cb, async_err_cb):
pass pass

View File

@ -23,8 +23,9 @@ from model.BuddyModel import BuddyModel
from hardware import hardwaremanager from hardware import hardwaremanager
class AccessPointModel: class AccessPointModel:
def __init__(self, nm_network): def __init__(self, nm_device, nm_network):
self._nm_network = nm_network self._nm_network = nm_network
self._nm_device = nm_device
def get_id(self): def get_id(self):
return self._nm_network.get_op() return self._nm_network.get_op()
@ -32,6 +33,12 @@ class AccessPointModel:
def get_name(self): def get_name(self):
return self._nm_network.get_ssid() return self._nm_network.get_ssid()
def get_nm_device(self):
return self._nm_device
def get_nm_network(self):
return self._nm_network
class ActivityModel: class ActivityModel:
def __init__(self, activity, bundle, service): def __init__(self, activity, bundle, service):
self._service = service self._service = service
@ -104,22 +111,22 @@ class MeshModel(gobject.GObject):
def _nm_device_activated_cb(self, manager, nm_device): def _nm_device_activated_cb(self, manager, nm_device):
self._add_network_device(nm_device) self._add_network_device(nm_device)
def _nm_network_appeared_cb(self, manager, nm_network): def _nm_network_appeared_cb(self, nm_device, nm_network):
self._add_access_point(nm_network) self._add_access_point(nm_device, nm_network)
def _nm_network_disappeared_cb(self, manager, nm_network): def _nm_network_disappeared_cb(self, nm_device, nm_network):
self._remove_access_point(nm_network) self._remove_access_point(nm_device, nm_network)
def _add_network_device(self, nm_device): def _add_network_device(self, nm_device):
for network in nm_device.get_networks(): for nm_network in nm_device.get_networks():
self._add_access_point(network) self._add_access_point(nm_device, nm_network)
nm_device.connect('network-appeared', nm_device.connect('network-appeared',
self._nm_network_appeared_cb) self._nm_network_appeared_cb)
nm_device.connect('network-disappeared', nm_device.connect('network-disappeared',
self._nm_network_disappeared_cb) self._nm_network_disappeared_cb)
def _add_access_point(self, nm_network): def _add_access_point(self, nm_device, nm_network):
model = AccessPointModel(nm_network) model = AccessPointModel(nm_device, nm_network)
self._access_points[nm_network.get_op()] = model self._access_points[nm_network.get_op()] = model
self.emit('access-point-added', model) self.emit('access-point-added', model)

View File

@ -22,13 +22,25 @@ import gobject
from sugar.graphics.spreadbox import SpreadBox from sugar.graphics.spreadbox import SpreadBox
from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.snowflakebox import SnowflakeBox
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from hardware import hardwaremanager
from view.BuddyIcon import BuddyIcon from view.BuddyIcon import BuddyIcon
class AccessPointView(CanvasIcon): class AccessPointView(CanvasIcon):
def __init__(self, model): def __init__(self, model):
CanvasIcon.__init__(self, tooltip=model.get_name()) CanvasIcon.__init__(self, tooltip=model.get_name())
self._model = model
self.connect('activated', self._activate_cb)
self._update_icon() self._update_icon()
def _activate_cb(self, icon):
network_manager = hardwaremanager.get_network_manager()
device = self._model.get_nm_device()
network = self._model.get_nm_network()
network_manager.set_active_device(device, network)
def _update_icon(self): def _update_icon(self):
self.props.icon_name = 'theme:stock-net-wireless-00' self.props.icon_name = 'theme:stock-net-wireless-00'