Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/modemconfiguration/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/cpsection/modemconfiguration/model.py')
-rwxr-xr-xextensions/cpsection/modemconfiguration/model.py107
1 files changed, 63 insertions, 44 deletions
diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py
index 1e83c44..969b5d9 100755
--- a/extensions/cpsection/modemconfiguration/model.py
+++ b/extensions/cpsection/modemconfiguration/model.py
@@ -14,68 +14,87 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
-import gconf
+import logging
-from jarabe.model.network import GSM_USERNAME_PATH, GSM_PASSWORD_PATH, \
- GSM_NUMBER_PATH, GSM_APN_PATH, GSM_PIN_PATH, \
- GSM_PUK_PATH
+import dbus
+import gtk
+from jarabe.model import network
-def get_username():
- client = gconf.client_get_default()
- return client.get_string(GSM_USERNAME_PATH) or ''
+def get_connection():
+ return network.find_gsm_connection()
-def get_password():
- client = gconf.client_get_default()
- return client.get_string(GSM_PASSWORD_PATH) or ''
+def get_modem_settings():
+ modem_settings = {}
+ connection = get_connection()
+ if not connection:
+ return modem_settings
-def get_number():
- client = gconf.client_get_default()
- return client.get_string(GSM_NUMBER_PATH) or ''
+ settings = connection.get_settings('gsm')
+ for setting in ('username', 'number', 'apn'):
+ modem_settings[setting] = settings.get(setting, '')
+ # use mutable container for nested function control variable
+ secrets_call_done = [False]
-def get_apn():
- client = gconf.client_get_default()
- return client.get_string(GSM_APN_PATH) or ''
+ def _secrets_cb(secrets):
+ secrets_call_done[0] = True
+ if not secrets or not 'gsm' in secrets:
+ return
+ gsm_secrets = secrets['gsm']
+ modem_settings['password'] = gsm_secrets.get('password', '')
+ modem_settings['pin'] = gsm_secrets.get('pin', '')
-def get_pin():
- client = gconf.client_get_default()
- return client.get_string(GSM_PIN_PATH) or ''
+ def _secrets_err_cb(err):
+ secrets_call_done[0] = True
+ if isinstance(err, dbus.exceptions.DBusException) and \
+ err.get_dbus_name() == network.NM_AGENT_MANAGER_ERR_NO_SECRETS:
+ logging.debug('No GSM secrets present')
+ else:
+ logging.error('Error retrieving GSM secrets: %s', err)
+ # must be called asynchronously as this re-enters the GTK main loop
+ connection.get_secrets('gsm', _secrets_cb, _secrets_err_cb)
-def get_puk():
- client = gconf.client_get_default()
- return client.get_string(GSM_PUK_PATH) or ''
+ # wait til asynchronous execution completes
+ while not secrets_call_done[0]:
+ gtk.main_iteration()
+ return modem_settings
-def set_username(username):
- client = gconf.client_get_default()
- client.set_string(GSM_USERNAME_PATH, username)
+def _set_or_clear(_dict, key, value):
+ """Update a dictionary value for a specific key. If value is None or
+ zero-length, but the key is present in the dictionary, delete that
+ dictionary entry."""
+ if value:
+ _dict[key] = value
+ return
-def set_password(password):
- client = gconf.client_get_default()
- client.set_string(GSM_PASSWORD_PATH, password)
+ if key in _dict:
+ del _dict[key]
-def set_number(number):
- client = gconf.client_get_default()
- client.set_string(GSM_NUMBER_PATH, number)
+def set_modem_settings(modem_settings):
+ username = modem_settings.get('username', '')
+ password = modem_settings.get('password', '')
+ number = modem_settings.get('number', '')
+ apn = modem_settings.get('apn', '')
+ pin = modem_settings.get('pin', '')
+ connection = get_connection()
+ if not connection:
+ network.create_gsm_connection(username, password, number, apn, pin)
+ return
-def set_apn(apn):
- client = gconf.client_get_default()
- client.set_string(GSM_APN_PATH, apn)
-
-
-def set_pin(pin):
- client = gconf.client_get_default()
- client.set_string(GSM_PIN_PATH, pin)
-
-
-def set_puk(puk):
- client = gconf.client_get_default()
- client.set_string(GSM_PUK_PATH, puk)
+ settings = connection.get_settings()
+ gsm_settings = settings['gsm']
+ _set_or_clear(gsm_settings, 'username', username)
+ _set_or_clear(gsm_settings, 'password', password)
+ _set_or_clear(gsm_settings, 'number', number)
+ _set_or_clear(gsm_settings, 'apn', apn)
+ _set_or_clear(gsm_settings, 'pin', pin)
+ connection.update_settings(settings)