Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/network/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/cpsection/network/model.py')
-rw-r--r--extensions/cpsection/network/model.py40
1 files changed, 30 insertions, 10 deletions
diff --git a/extensions/cpsection/network/model.py b/extensions/cpsection/network/model.py
index 2713f23..916ce8c 100644
--- a/extensions/cpsection/network/model.py
+++ b/extensions/cpsection/network/model.py
@@ -19,25 +19,33 @@ import dbus
from gettext import gettext as _
import gconf
+from jarabe.model import network
+
+
_NM_SERVICE = 'org.freedesktop.NetworkManager'
_NM_PATH = '/org/freedesktop/NetworkManager'
_NM_IFACE = 'org.freedesktop.NetworkManager'
KEYWORDS = ['network', 'jabber', 'radio', 'server']
+
class ReadError(Exception):
def __init__(self, value):
self.value = value
+
def __str__(self):
return repr(self.value)
+
def get_jabber():
client = gconf.client_get_default()
return client.get_string('/desktop/sugar/collaboration/jabber_server')
+
def print_jabber():
print get_jabber()
+
def set_jabber(server):
"""Set the jabber server
server : e.g. 'olpc.collabora.co.uk'
@@ -47,11 +55,12 @@ def set_jabber(server):
return 0
+
def get_radio():
try:
bus = dbus.SystemBus()
obj = bus.get_object(_NM_SERVICE, _NM_PATH)
- nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
+ nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
except dbus.DBusException:
raise ReadError('%s service not available' % _NM_SERVICE)
@@ -61,18 +70,20 @@ def get_radio():
else:
raise ReadError(_('State is unknown.'))
+
def print_radio():
print ('off', 'on')[get_radio()]
-
+
+
def set_radio(state):
"""Turn Radio 'on' or 'off'
state : 'on/off'
- """
+ """
if state == 'on' or state == 1:
try:
bus = dbus.SystemBus()
obj = bus.get_object(_NM_SERVICE, _NM_PATH)
- nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
+ nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
except dbus.DBusException:
raise ReadError('%s service not available' % _NM_SERVICE)
nm_props.Set(_NM_IFACE, 'WirelessEnabled', True)
@@ -80,15 +91,16 @@ def set_radio(state):
try:
bus = dbus.SystemBus()
obj = bus.get_object(_NM_SERVICE, _NM_PATH)
- nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
+ nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
except dbus.DBusException:
raise ReadError('%s service not available' % _NM_SERVICE)
nm_props.Set(_NM_IFACE, 'WirelessEnabled', False)
else:
- raise ValueError(_("Error in specified radio argument use on/off."))
+ raise ValueError(_('Error in specified radio argument use on/off.'))
return 0
+
def clear_registration():
"""Clear the registration with the schoolserver
"""
@@ -96,28 +108,36 @@ def clear_registration():
client.set_string('/desktop/sugar/backup_url', '')
return 1
+
def clear_networks():
"""Clear saved passwords and network configurations.
"""
- pass
+ network.clear_wifi_connections()
+
+
+def have_networks():
+ return network.have_wifi_connections()
+
def get_publish_information():
client = gconf.client_get_default()
publish = client.get_bool('/desktop/sugar/collaboration/publish_gadget')
return publish
-
+
+
def print_publish_information():
print get_publish_information()
+
def set_publish_information(value):
- """ If set to true, Sugar will make you searchable for
+ """ If set to true, Sugar will make you searchable for
the other users of the Jabber server.
value: 0/1
"""
try:
value = (False, True)[int(value)]
except:
- raise ValueError(_("Error in specified argument use 0/1."))
+ raise ValueError(_('Error in specified argument use 0/1.'))
client = gconf.client_get_default()
client.set_bool('/desktop/sugar/collaboration/publish_gadget', value)