Attached is a patch which adds a 'reset network configuration' button to
the network tab of the sugar control panel. Clicking this button simply
rotates the config file out of the way, saving it as
~/.sugar/default/nm/networks.cfg.bak.NNN (NNN is the number of
previously backed-up configs +1).
This is just a short-term fix (hack) to resolve the problem of not
having any gui-level method to manipulate the nm network configarion.
Eben has noted that we would like to enable config panel level
manipulation of the networks.cfg stanzas; but this requires a bit more
code than this immediate fix.
Erik
diff --git a/src/controlpanel/model/network.py b/src/controlpanel/model/network.py
index d24c986..135aac1 100644
--- a/src/controlpanel/model/network.py
+++ b/src/controlpanel/model/network.py
@@ -20,6 +20,9 @@ from gettext import gettext as _
from sugar import profile
+import os
+import re
+
NM_SERVICE_NAME = 'org.freedesktop.NetworkManager'
NM_SERVICE_PATH = '/org/freedesktop/NetworkManager'
NM_SERVICE_IFACE = 'org.freedesktop.NetworkManager'
@@ -83,3 +86,22 @@ def set_radio(state):
raise ValueError(_("Error in specified radio argument use on/off."))
return 0
+
+
+def clear_networks_config_file():
+ """Rotate the networks configuration file into networks.cfg.bak.NNNN"""
+ network_cfg = '/home/olpc/.sugar/default/nm/networks.cfg'
+ # find the config files
+ network_cfgs = [file
+ for file in os.listdir('/home/olpc/.sugar/default/nm')
+ if re.match('networks.cfg.bak.', file)
+ ]
+ # establish the largest config file number
+ if network_cfgs:
+ n = 1 + max(map(lambda x: int(x.replace('networks.cfg.bak.', '')),
+ network_cfgs))
+ else:
+ n = 1
+ # move the existing config file out of the way
+ if os.path.exists(network_cfg):
+ os.rename(network_cfg, '%s.bak.%i' % (network_cfg, n))
diff --git a/src/controlpanel/view/network.py b/src/controlpanel/view/network.py
index af64a1a..a59c54c 100644
--- a/src/controlpanel/view/network.py
+++ b/src/controlpanel/view/network.py
@@ -38,6 +38,7 @@ class Network(SectionView):
self._radio_valid = True
self._jabber_change_handler = None
self._radio_change_handler = None
+ self._network_configuation_reset_handler = None
self.set_border_width(style.DEFAULT_SPACING * 2)
self.set_spacing(style.DEFAULT_SPACING)
@@ -57,6 +58,7 @@ class Network(SectionView):
box_wireless = gtk.VBox()
box_wireless.set_border_width(style.DEFAULT_SPACING * 2)
box_wireless.set_spacing(style.DEFAULT_SPACING)
+
box_radio = gtk.HBox(spacing=style.DEFAULT_SPACING)
label_radio = gtk.Label(_('Radio:'))
label_radio.set_alignment(1, 0.5)
@@ -65,6 +67,7 @@ class Network(SectionView):
box_radio.pack_start(label_radio, expand=False)
group.add_widget(label_radio)
label_radio.show()
+
self._button = gtk.CheckButton()
self._button.set_alignment(0, 0)
box_radio.pack_start(self._button, expand=False)
@@ -72,6 +75,22 @@ class Network(SectionView):
box_wireless.pack_start(box_radio, expand=False)
box_radio.show()
+ box_reset_config = gtk.HBox(spacing=style.DEFAULT_SPACING)
+ label_reset_config = gtk.Label(_('Clear preferred networks:'))
+ label_reset_config.set_alignment(1, 0.5)
+ label_reset_config.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_SELECTION_GREY.get_gdk_color())
+ box_reset_config.pack_start(label_reset_config, expand=False)
+ group.add_widget(label_reset_config)
+ label_reset_config.show()
+
+ self._reset_config_button = gtk.Button(stock=gtk.STOCK_CLEAR)
+ self._reset_config_button.set_alignment(0, 0)
+ box_reset_config.pack_start(self._reset_config_button, expand=False)
+ self._reset_config_button.show()
+ box_wireless.pack_end(box_reset_config, expand=False)
+ box_reset_config.show()
+
self._radio_alert = InlineAlert()
label_radio_error = gtk.Label()
group.add_widget(label_radio_error)
@@ -153,6 +172,9 @@ class Network(SectionView):
'toggled', self.__radio_toggled_cb)
self._jabber_change_handler = self._entry.connect( \
'changed', self.__jabber_changed_cb)
+ self._network_configuation_reset_handler = \
+ self._reset_config_button.connect( \
+ 'clicked', self.__network_configuation_reset_cb)
def undo(self):
self._button.disconnect(self._radio_change_handler)
@@ -207,3 +229,6 @@ class Network(SectionView):
self._jabber_alert.show()
return False
+
+ def __network_configuation_reset_cb(self, widget):
+ self._model.clear_networks_config_file()
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar