Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-05-30 17:14:20 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-05-30 17:14:20 (GMT)
commit69fed18c81ac7104b5a867eabdba81b5dced7c49 (patch)
tree56eae346f789d83def0a5e9b9dda1ee9c699bbeb /extensions
parent7e0442205daa8589c59b931b4dbc3a925548d289 (diff)
Add code for creating ad-hoc wireless networks
Diffstat (limited to 'extensions')
-rw-r--r--extensions/deviceicon/network.py103
1 files changed, 60 insertions, 43 deletions
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 47864de..0abf25e 100644
--- a/extensions/deviceicon/network.py
+++ b/extensions/deviceicon/network.py
@@ -32,8 +32,11 @@ from sugar.graphics.palette import Palette
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.tray import TrayIcon
from sugar.graphics import xocolor
+from sugar.util import unique_id
from jarabe.model import network
+from jarabe.model.network import Settings
+from jarabe.model.network import IP4Config
from jarabe.frame.frameinvoker import FrameWidgetInvoker
from jarabe.view.pulsingicon import PulsingIcon
@@ -71,7 +74,9 @@ class WirelessPalette(Palette):
__gsignals__ = {
'deactivate-connection' : (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE, ([]))
+ gobject.TYPE_NONE, ([])),
+ 'create-connection' : (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([])),
}
def __init__(self, primary_text):
@@ -105,6 +110,11 @@ class WirelessPalette(Palette):
self._disconnect_item.connect('activate', self.__disconnect_activate_cb)
self.menu.append(self._disconnect_item)
+ self._adhoc_item = gtk.MenuItem(_('Create new wireless network'))
+ self._adhoc_item.connect('activate', self.__adhoc_activate_cb)
+ self.menu.append(self._adhoc_item)
+ self._adhoc_item.show()
+
def set_connecting(self):
self.props.secondary_text = _('Connecting...')
@@ -118,6 +128,9 @@ class WirelessPalette(Palette):
def __disconnect_activate_cb(self, menuitem):
self.emit('deactivate-connection')
+ def __adhoc_activate_cb(self, menuitem):
+ self.emit('create-connection')
+
def _set_channel(self, frequency):
try:
channel = frequency_to_channel(frequency)
@@ -215,7 +228,9 @@ class WirelessDeviceView(ToolButton):
self.set_palette_invoker(FrameWidgetInvoker(self))
self._palette = WirelessPalette(self._name)
self._palette.connect('deactivate-connection',
- self.__deactivate_connection)
+ self.__deactivate_connection_cb)
+ self._palette.connect('create-connection',
+ self.__create_connection_cb)
self.set_palette(self._palette)
self._palette.set_group_id('frame')
@@ -351,7 +366,7 @@ class WirelessDeviceView(ToolButton):
def _update_color(self):
self._icon.props.base_color = self._color
- def __deactivate_connection(self, palette, data=None):
+ def __deactivate_connection_cb(self, palette, data=None):
if self._active_ap_op is not None:
obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
netmgr = dbus.Interface(obj, _NM_IFACE)
@@ -368,6 +383,42 @@ class WirelessDeviceView(ToolButton):
netmgr.DeactivateConnection(conn_o)
break
+ def __create_connection_cb(self, palette, data=None):
+ client = gconf.client_get_default()
+ nick = client.get_string('/desktop/sugar/user/nick')
+ connection_name = _('%s\'s network') % nick
+
+ connection = network.find_connection(connection_name)
+ if connection is None:
+ settings = Settings()
+ settings.connection.id = 'Auto ' + connection_name
+ settings.connection.uuid = unique_id()
+ settings.connection.type = '802-11-wireless'
+ settings.connection.mode = 'adhoc'
+ settings.wireless.ssid = dbus.ByteArray(connection_name)
+ settings.wireless.channel = 'bg'
+ settings.wireless.mode = 'adhoc'
+
+ settings.ip4_config = IP4Config()
+ settings.ip4_config.method = 'shared'
+
+ connection = network.add_connection(connection_name, settings)
+
+ obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
+ netmgr = dbus.Interface(obj, _NM_IFACE)
+
+ netmgr.ActivateConnection(network.SETTINGS_SERVICE,
+ connection.path,
+ self._device.object_path,
+ '/',
+ reply_handler=self.__activate_reply_cb,
+ error_handler=self.__activate_error_cb)
+
+ def __activate_reply_cb(self, connection):
+ logging.debug('Network created: %s', connection)
+
+ def __activate_error_cb(self, err):
+ logging.debug('Failed to create network: %s', err)
class WiredDeviceView(TrayIcon):
@@ -389,52 +440,18 @@ class WiredDeviceView(TrayIcon):
class WirelessDeviceObserver(object):
def __init__(self, device, tray):
- self._bus = dbus.SystemBus()
self._device = device
self._device_view = None
self._tray = tray
- props = dbus.Interface(self._device, 'org.freedesktop.DBus.Properties')
- props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
- reply_handler=self.__get_device_props_reply_cb,
- error_handler=self.__get_device_props_error_cb)
-
- self._bus.add_signal_receiver(self.__state_changed_cb,
- signal_name='StateChanged',
- path=self._device.object_path,
- dbus_interface=_NM_DEVICE_IFACE)
+ self._device_view = WirelessDeviceView(self._device)
+ self._tray.add_device(self._device_view)
def disconnect(self):
- self._bus.remove_signal_receiver(self.__state_changed_cb,
- signal_name='StateChanged',
- path=self._device.object_path,
- dbus_interface=_NM_DEVICE_IFACE)
-
- def __get_device_props_reply_cb(self, properties):
- if 'State' in properties:
- self._update_state(properties['State'])
-
- def __get_device_props_error_cb(self, err):
- logging.error('Error getting the device properties: %s', err)
-
- def __state_changed_cb(self, new_state, old_state, reason):
- self._update_state(new_state)
-
- def _update_state(self, state):
- if state == network.DEVICE_STATE_PREPARE or \
- state == network.DEVICE_STATE_CONFIG or \
- state == network.DEVICE_STATE_NEED_AUTH or \
- state == network.DEVICE_STATE_IP_CONFIG or \
- state == network.DEVICE_STATE_ACTIVATED:
- if self._device_view is None:
- self._device_view = WirelessDeviceView(self._device)
- self._tray.add_device(self._device_view)
- else:
- if self._device_view is not None:
- self._device_view.disconnect()
- self._tray.remove_device(self._device_view)
- del self._device_view
- self._device_view = None
+ self._device_view.disconnect()
+ self._tray.remove_device(self._device_view)
+ del self._device_view
+ self._device_view = None
class WiredDeviceObserver(object):