Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 10:44:47 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 10:44:47 (GMT)
commit247cd39d53cff1fc6ee526b95f54681f7d0ab797 (patch)
tree41c094d199f7e79d30e09dc80814965b47e74ed6 /src
parent520a7223f32e198bf8b633f524d52a04ac8e40ad (diff)
parent83a507cf6b306099adf49258e1b7c16781328415 (diff)
Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/desktop/meshbox.py179
-rw-r--r--src/jarabe/model/Makefile.am1
-rw-r--r--src/jarabe/model/neighborhood.py36
-rw-r--r--src/jarabe/model/network.py28
4 files changed, 162 insertions, 82 deletions
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 83d0ba6..7567cf9 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -40,6 +40,7 @@ from jarabe.view.pulsingicon import CanvasPulsingIcon
from jarabe.desktop.snowflakelayout import SnowflakeLayout
from jarabe.desktop.spreadlayout import SpreadLayout
from jarabe.model import bundleregistry
+from jarabe.model import network
_NM_SERVICE = 'org.freedesktop.NetworkManager'
_NM_IFACE = 'org.freedesktop.NetworkManager'
@@ -48,19 +49,6 @@ _NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
-_DEVICE_TYPE_802_11_WIRELESS = 2
-
-_DEVICE_STATE_UNKNOWN = 0
-_DEVICE_STATE_UNMANAGED = 1
-_DEVICE_STATE_UNAVAILABLE = 2
-_DEVICE_STATE_DISCONNECTED = 3
-_DEVICE_STATE_PREPARE = 4
-_DEVICE_STATE_CONFIG = 5
-_DEVICE_STATE_NEED_AUTH = 6
-_DEVICE_STATE_IP_CONFIG = 7
-_DEVICE_STATE_ACTIVATED = 8
-_DEVICE_STATE_FAILED = 9
-
_ICON_NAME = 'network-wireless'
class AccessPointView(CanvasPulsingIcon):
@@ -75,8 +63,9 @@ class AccessPointView(CanvasPulsingIcon):
self._greyed_out = False
self._name = ''
self._strength = 0
- self._caps = 0
- self._state = None
+ self._flags = 0
+ self._device_state = None
+ self._active = True
self.connect('activated', self._activate_cb)
@@ -92,37 +81,74 @@ class AccessPointView(CanvasPulsingIcon):
reply_handler=self.__get_all_props_reply_cb,
error_handler=self.__get_all_props_error_cb)
- self._bus.add_signal_receiver(self.__properties_changed_cb,
+ self._bus.add_signal_receiver(self.__ap_properties_changed_cb,
signal_name='PropertiesChanged',
- path=device.object_path,
+ path=model.object_path,
dbus_interface=_NM_ACCESSPOINT_IFACE)
self._device.Get(_NM_DEVICE_IFACE, 'State',
reply_handler=self.__get_device_state_reply_cb,
error_handler=self.__get_device_state_error_cb)
+ self._device.Get(_NM_WIRELESS_IFACE, 'ActiveAccessPoint',
+ reply_handler=self.__get_active_ap_reply_cb,
+ error_handler=self.__get_active_ap_error_cb)
- self._bus.add_signal_receiver(self.__state_changed_cb,
+ self._bus.add_signal_receiver(self.__device_state_changed_cb,
signal_name='StateChanged',
path=device.object_path,
dbus_interface=_NM_DEVICE_IFACE)
+ self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
+ signal_name='PropertiesChanged',
+ path=device.object_path,
+ dbus_interface=_NM_WIRELESS_IFACE)
+
+ def _create_palette(self):
+ icon_name = get_icon_state(_ICON_NAME, self._strength)
+ palette_icon = Icon(icon_name=icon_name,
+ icon_size=style.STANDARD_ICON_SIZE,
+ badge_name=self.props.badge_name)
+ palette_icon.props.xo_color = XoColor('%s,%s' % self._compute_color())
+
+ p = palette.Palette(primary_text=self._name,
+ icon=palette_icon)
+
+ self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
+ self._connect_item.connect('activate', self._activate_cb)
+ p.menu.append(self._connect_item)
- def __state_changed_cb(self, state):
- self._state = state
+ self._disconnect_item = MenuItem(_('Disconnect'), 'media-eject')
+ self._disconnect_item.connect('activate',
+ self._disconnect_activate_cb)
+ p.menu.append(self._disconnect_item)
+
+ return p
+
+ def __device_state_changed_cb(self, state):
+ self._device_state = state
self._update()
- def __properties_changed_cb(self, properties):
+ def __ap_properties_changed_cb(self, properties):
self._update_properties(properties)
+ def __wireless_properties_changed_cb(self, properties):
+ if 'ActiveAccessPoint' in props:
+ ap = props['ActiveAccessPoint']
+ self._active = (ap == self._model.object_path)
+ self._update_state()
+
def _update_properties(self, props):
- self._name = props['Ssid']
- self._strength = props['Strength']
- self._caps = props['Flags']
+ if 'Ssid' in props:
+ self._name = props['Ssid']
+ if 'Strength' in props:
+ self._strength = props['Strength']
+ if 'Flags' in props:
+ self._flags = props['Flags']
self._update()
def _compute_color(self):
sh = sha.new()
- data = self._name + hex(self._caps)
+ data = self._name + hex(self._flags)
sh.update(data)
h = hash(sh.digest())
idx = h % len(xocolor.colors)
@@ -130,8 +156,15 @@ class AccessPointView(CanvasPulsingIcon):
# stroke, fill
return (xocolor.colors[idx][0], xocolor.colors[idx][1])
+ def __get_active_ap_reply_cb(self, ap):
+ self._active = (ap == self._model.object_path)
+ self._update_state()
+
+ def __get_active_ap_error_cb(self, err):
+ logging.debug('Error getting the active access point: %s', err)
+
def __get_device_state_reply_cb(self, state):
- self._state = state
+ self._device_state = state
self._update()
def __get_device_state_error_cb(self, err):
@@ -144,78 +177,51 @@ class AccessPointView(CanvasPulsingIcon):
logging.debug('Error getting the access point properties: %s', err)
def _update(self):
- #self.props.badge_name = "emblem-favorite"
- #self.props.badge_name = "emblem-locked"
-
- self._update_icon()
- self._update_name()
- self._update_state()
-
- def _create_palette(self):
- icon_name = get_icon_state(_ICON_NAME, self._strength)
- palette_icon = Icon(icon_name=icon_name,
- icon_size=style.STANDARD_ICON_SIZE,
- badge_name=self.props.badge_name)
- palette_icon.props.xo_color = XoColor('%s,%s' % self._compute_color())
-
- p = palette.Palette(primary_text=self._name,
- icon=palette_icon)
-
- self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
- self._connect_item.connect('activate', self._activate_cb)
- p.menu.append(self._connect_item)
-
- self._disconnect_item = MenuItem(_('Disconnect'), 'media-eject')
- self._disconnect_item.connect('activate',
- self._disconnect_activate_cb)
- p.menu.append(self._disconnect_item)
-
- return p
+ if self._flags == network.AP_FLAGS_802_11_PRIVACY:
+ self.props.badge_name = "emblem-locked"
+ else:
+ self.props.badge_name = None
- def _disconnect_activate_cb(self, item):
- pass
+ self._palette.props.primary_text = self._name
- def _activate_cb(self, icon):
- pass
+ self._update_state()
- def _update_name(self):
- self._palette.props.primary_text = self._name
+ def _update_state(self):
+ if self._active:
+ state = self._device_state
+ else:
+ state = network.DEVICE_STATE_UNKNOWN
- def _update_icon(self):
- # keep this code in sync with view/devices/network/wireless.py
- strength = self._strength
- if self._state == _DEVICE_STATE_ACTIVATED:
+ if state == network.DEVICE_STATE_ACTIVATED:
icon_name = '%s-connected' % _ICON_NAME
else:
icon_name = _ICON_NAME
- icon_name = get_icon_state(icon_name, strength)
+
+ icon_name = get_icon_state(icon_name, self._strength)
if icon_name:
self.props.icon_name = icon_name
icon = self._palette.props.icon
icon.props.icon_name = icon_name
- def _update_state(self):
- if self._state is _DEVICE_STATE_PREPARE or \
- self._state is _DEVICE_STATE_CONFIG or \
- self._state is _DEVICE_STATE_NEED_AUTH or \
- self._state is _DEVICE_STATE_IP_CONFIG:
+ 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:
if self._disconnect_item:
self._disconnect_item.show()
self._connect_item.hide()
self._palette.props.secondary_text = _('Connecting...')
self.props.pulsing = True
- elif self._state == _DEVICE_STATE_ACTIVATED:
+ elif state == network.DEVICE_STATE_ACTIVATED:
if self._disconnect_item:
self._disconnect_item.show()
self._connect_item.hide()
- # TODO: show the channel number
self._palette.props.secondary_text = _('Connected')
self.props.pulsing = False
else:
if self._disconnect_item:
self._disconnect_item.hide()
self._connect_item.show()
- # TODO: show the channel number
self._palette.props.secondary_text = None
self.props.pulsing = False
@@ -225,20 +231,39 @@ class AccessPointView(CanvasPulsingIcon):
else:
self.props.base_color = XoColor('%s,%s' % self._compute_color())
+ def _disconnect_activate_cb(self, item):
+ pass
+
+ def _activate_cb(self, icon):
+ info = { "connection": { "type": "802-11-wireless" } ,
+ "802-11-wireless": { "ssid": self._name }
+ }
+ conn = network.add_connection(info)
+
+ obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
+ netmgr = dbus.Interface(obj, _NM_IFACE)
+ netmgr.ActivateConnection('org.freedesktop.NetworkManagerSettings',
+ conn.path, self._device.object_path,
+ self._model.object_path)
+
def set_filter(self, query):
self._greyed_out = self._name.lower().find(query) == -1
self._update_state()
def disconnect(self):
- self._bus.remove_signal_receiver(self.__properties_changed_cb,
+ self._bus.remove_signal_receiver(self.__ap_properties_changed_cb,
signal_name='PropertiesChanged',
- path=self._device.object_path,
+ path=self._model.object_path,
dbus_interface=_NM_ACCESSPOINT_IFACE)
- self._bus.remove_signal_receiver(self.__state_changed_cb,
+
+ self._bus.remove_signal_receiver(self.__device_state_changed_cb,
signal_name='StateChanged',
path=self._device.object_path,
dbus_interface=_NM_DEVICE_IFACE)
-
+ self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
+ signal_name='PropertiesChanged',
+ path=self._device.object_path,
+ dbus_interface=_NM_WIRELESS_IFACE)
class ActivityView(hippo.CanvasBox):
def __init__(self, model):
@@ -495,7 +520,7 @@ class NetworkManagerObserver(object):
props = dbus.Interface(device, 'org.freedesktop.DBus.Properties')
device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
- if device_type == _DEVICE_TYPE_802_11_WIRELESS:
+ if device_type == network.DEVICE_TYPE_802_11_WIRELESS:
self._devices[device_o] = DeviceObserver(self._box, device)
def _get_device_path_error_cb(self, err):
diff --git a/src/jarabe/model/Makefile.am b/src/jarabe/model/Makefile.am
index d968602..9ab6779 100644
--- a/src/jarabe/model/Makefile.am
+++ b/src/jarabe/model/Makefile.am
@@ -7,6 +7,7 @@ sugar_PYTHON = \
invites.py \
owner.py \
neighborhood.py \
+ network.py \
shell.py \
screen.py \
session.py \
diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
index b8dd5c3..79b2d1e 100644
--- a/src/jarabe/model/neighborhood.py
+++ b/src/jarabe/model/neighborhood.py
@@ -15,6 +15,8 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gobject
+import gconf
+import logging
from sugar.graphics.xocolor import XoColor
from sugar.presence import presenceservice
@@ -22,6 +24,13 @@ from sugar import activity
from jarabe.model.buddy import BuddyModel
from jarabe.model import bundleregistry
+from jarabe.util.telepathy import connection_watcher
+
+from dbus import PROPERTIES_IFACE
+import telepathy
+from telepathy.interfaces import CONNECTION_INTERFACE_REQUESTS
+
+CONN_INTERFACE_GADGET = 'org.laptop.Telepathy.Gadget'
class ActivityModel:
def __init__(self, act, bundle):
@@ -78,6 +87,33 @@ class Neighborhood(gobject.GObject):
self._pservice.get_activities_async(
reply_handler=self._get_activities_cb)
+ self._conn_watcher = connection_watcher.ConnectionWatcher()
+ self._conn_watcher.connect('connection-added', self._conn_addded_cb)
+
+ for conn in self._conn_watcher.get_connections():
+ self._conn_addded_cb(self._conn_watcher, conn)
+
+ def _conn_addded_cb(self, watcher, conn):
+ if CONN_INTERFACE_GADGET not in conn:
+ return
+
+ conn[CONN_INTERFACE_GADGET].connect_to_signal('GadgetDiscovered',
+ lambda: self._gadget_discovered(conn))
+
+ gadget_discovered = conn[PROPERTIES_IFACE].Get(CONN_INTERFACE_GADGET,
+ 'GadgetAvailable')
+ if gadget_discovered:
+ self._gadget_discovered(conn)
+
+ def _gadget_discovered(self, conn):
+ # FIXME: watch change of the gconf key
+ client = gconf.client_get_default()
+ publish = client.get_bool('/desktop/sugar/collaboration/publish_gadget')
+ logging.debug("Gadget discovered on connection %s."
+ " Publish our status: %r" %
+ (conn.service_name.split('.')[-1], publish))
+ conn[CONN_INTERFACE_GADGET].Publish(publish)
+
def _get_buddies_cb(self, buddy_list):
for buddy in buddy_list:
self._buddy_appeared_cb(self._pservice, buddy)
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index dcfc71e..77521cb 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -18,6 +18,22 @@ import dbus
from sugar import dispatch
+DEVICE_TYPE_802_11_WIRELESS = 2
+
+DEVICE_STATE_UNKNOWN = 0
+DEVICE_STATE_UNMANAGED = 1
+DEVICE_STATE_UNAVAILABLE = 2
+DEVICE_STATE_DISCONNECTED = 3
+DEVICE_STATE_PREPARE = 4
+DEVICE_STATE_CONFIG = 5
+DEVICE_STATE_NEED_AUTH = 6
+DEVICE_STATE_IP_CONFIG = 7
+DEVICE_STATE_ACTIVATED = 8
+DEVICE_STATE_FAILED = 9
+
+AP_FLAGS_802_11_NONE = 0
+AP_FLAGS_802_11_PRIVACY = 1
+
NM_SETTINGS_PATH = '/org/freedesktop/NetworkManagerSettings'
NM_SETTINGS_IFACE = 'org.freedesktop.NetworkManagerSettings'
NM_CONNECTION_IFACE = 'org.freedesktop.NetworkManagerSettings.Connection'
@@ -42,17 +58,17 @@ class NMSettings(dbus.service.Object):
pass
def add_connection(self, conn):
- self.connections.append(conn.object_path)
- self.NewConnection(conn.object_path)
+ self.connections.append(conn.path)
+ self.NewConnection(conn.path)
class NMSettingsConnection(dbus.service.Object):
_counter = 0
def __init__(self, settings, secrets):
- path = NM_SETTINGS_PATH + '/' + self._counter
+ self.path = NM_SETTINGS_PATH + '/' + str(self._counter)
self._counter += 1
- dbus.service.Object.__init__(self, dbus.SystemBus(), path)
+ dbus.service.Object.__init__(self, dbus.SystemBus(), self.path)
self.secrets_request = dispatch.Signal()
@@ -77,8 +93,10 @@ def add_connection(settings, secrets=None):
if _nm_settings is None:
_nm_settings = NMSettings()
- conn = NMSettingsConnection()
+ conn = NMSettingsConnection(settings, secrets)
_nm_settings.add_connection(conn)
+ return conn
+
def load_connections():
pass