Ticket #1673: 0001-fix-discard-history-1673-for-uruguay-consensus.patch

File 0001-fix-discard-history-1673-for-uruguay-consensus.patch, 7.3 KB (added by quozl, 10 years ago)
  • extensions/cpsection/network/model.py

    From 954dc489c4a75991ccb385efdee41ce3e1777a33 Mon Sep 17 00:00:00 2001
    From: James Cameron <quozl@laptop.org>
    Date: Wed, 25 Aug 2010 15:49:27 +1000
    Subject: [PATCH] fix discard history #1673
    
    User interface changes:
    
    - enable the discard network history button in the network control
      panel, which also now forces a disconnect, and will be insensitive
      if there are no networks to be discarded, (rather than the button
      doing nothing),
    
    Design changes:
    
    - expose trusted access point list count for network control panel,
    
    - changes to the autoconnect connection flag are now cascaded to
      NetworkManager using the Updated signal,
    
    - discarding network history is now cascaded to NetworkManager using
      the Removed signal,
    
    - factoring of connections.cfg path and empty file creation,
    
    Tested extensively on Sugar 0.84.
    Not tested on Sugar 0.88.
    
    References:
    
        http://dev.laptop.org/ticket/9977 (fixes a workaround)
        http://bugs.sugarlabs.org/ticket/1673
    ---
     extensions/cpsection/network/model.py |    6 +++-
     extensions/cpsection/network/view.py  |    8 ++++-
     src/jarabe/model/network.py           |   58 +++++++++++++++++++++++++++------
     3 files changed, 60 insertions(+), 12 deletions(-)
    
    diff --git a/extensions/cpsection/network/model.py b/extensions/cpsection/network/model.py
    index e1c3dab..eed0b03 100644
    a b  
    1717
    1818import dbus
    1919from gettext import gettext as _
     20from jarabe.model import network
    2021import gconf
    2122
    2223_NM_SERVICE = 'org.freedesktop.NetworkManager'
    def clear_registration(): 
    116117def clear_networks():
    117118    """Clear saved passwords and network configurations.
    118119    """
    119     pass
     120    network.clear_wifi_connections()
     121
     122def count_networks():
     123    return network.count_wifi_connections()
    120124
    121125def get_publish_information():
    122126    client = gconf.client_get_default()
  • extensions/cpsection/network/view.py

    diff --git a/extensions/cpsection/network/view.py b/extensions/cpsection/network/view.py
    index 588daeb..b0f1336 100644
    a b class Network(SectionView): 
    104104        self._clear_history_button = gtk.Button()
    105105        self._clear_history_button.set_label(_('Discard network history'))
    106106        box_clear_history.pack_start(self._clear_history_button, expand=False)
     107        if self._model.count_networks() == 0:
     108            self._clear_history_button.set_sensitive(False)
    107109        self._clear_history_button.show()
    108110        box_wireless.pack_start(box_clear_history, expand=False)
    109111        box_clear_history.show()
    class Network(SectionView): 
    217219            self._radio_alert.props.msg = detail
    218220            self._radio_valid = False
    219221        else:
    220             self._radio_valid = True           
     222            self._radio_valid = True
     223            if self._model.count_networks() != 0:
     224                self._clear_history_button.set_sensitive(True)
    221225
    222226        self._validate()
    223227        return False
    class Network(SectionView): 
    248252
    249253    def __network_configuration_reset_cb(self, widget):
    250254        self._model.clear_networks()
     255        if self._model.count_networks() == 0:
     256            self._clear_history_button.set_sensitive(False)
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 66d86d8..2c0afe3 100644
    a b class NMSettings(dbus.service.Object): 
    508508        self.secrets_request.send(self, connection=sender,
    509509                                  response=kwargs['response'])
    510510
     511    def clear_wifi_connections(self):
     512        for uuid in self.connections.keys():
     513            conn = self.connections[uuid]
     514            if conn.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
     515                conn.Removed()
     516                self.connections.pop(uuid)
     517
    511518class SecretsResponse(object):
    512519    ''' Intermediate object to report the secrets from the dialog
    513520    back to the connection object and which will inform NM
    class NMSettingsConnection(dbus.service.Object): 
    536543        self._settings = settings
    537544        self._secrets = secrets
    538545
     546    @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE,
     547                         signature='')
     548    def Removed(self):
     549        pass
     550
     551    @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE,
     552                         signature='a{sa{sv}}')
     553    def Updated(self, settings):
     554        pass
     555
    539556    def set_connected(self):
    540557        if self._settings.connection.type == NM_CONNECTION_TYPE_GSM:
    541558            self._settings.connection.timestamp = int(time.time())
    class NMSettingsConnection(dbus.service.Object): 
    544561                self._settings.connection.autoconnect = True
    545562                self._settings.connection.timestamp = int(time.time())
    546563                if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
     564                    self.Updated(self._settings.get_dict())
    547565                    self.save()
    548566
     567    def set_disconnected(self):
     568        if self._settings.connection.type != NM_CONNECTION_TYPE_GSM and \
     569               self._settings.connection.autoconnect:
     570            self._settings.connection.autoconnect = False
     571            self._settings.connection.timestamp = None
     572            self.Updated(self._settings.get_dict())
     573            self.save()
     574
    549575    def set_secrets(self, secrets):
    550576        self._secrets = secrets
    551577        if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
    class NMSettingsConnection(dbus.service.Object): 
    555581        return self._settings
    556582
    557583    def save(self):
    558         profile_path = env.get_profile_path()
    559         config_path = os.path.join(profile_path, 'nm', 'connections.cfg')
     584        config_path = get_wifi_connections_path()
    560585
    561586        config = ConfigParser.ConfigParser()
    562587        try:
    def add_connection(uuid, settings, secrets=None): 
    777802    _nm_settings.add_connection(uuid, conn)
    778803    return conn
    779804
    780 def load_wifi_connections():
     805def get_wifi_connections_path():
    781806    profile_path = env.get_profile_path()
    782     config_path = os.path.join(profile_path, 'nm', 'connections.cfg')
     807    return os.path.join(profile_path, 'nm', 'connections.cfg')
    783808
    784     config = ConfigParser.ConfigParser()
     809def create_wifi_connections(config_path):
     810    if not os.path.exists(os.path.dirname(config_path)):
     811        os.makedirs(os.path.dirname(config_path), 0755)
     812    f = open(config_path, 'w')
     813    f.close()
     814
     815def load_wifi_connections():
     816    config_path = get_wifi_connections_path()
    785817
    786818    if not os.path.exists(config_path):
    787         if not os.path.exists(os.path.dirname(config_path)):
    788             os.makedirs(os.path.dirname(config_path), 0755)
    789         f = open(config_path, 'w')
    790         config.write(f)
    791         f.close()
     819        create_wifi_connections(config_path)
    792820
     821    config = ConfigParser.ConfigParser()
    793822    try:
    794823        if not config.read(config_path):
    795824            logging.error('Error reading the nm config file')
    def find_gsm_connection(): 
    895924
    896925    logging.debug('There is no gsm connection in the NMSettings.')
    897926    return None
     927
     928def count_wifi_connections():
     929    return len(get_settings().connections)
     930
     931def clear_wifi_connections():
     932    _nm_settings.clear_wifi_connections()
     933
     934    config_path = get_wifi_connections_path()
     935    create_wifi_connections(config_path)