e4d7c0f3f82ad2d7d978096016c9d3d925ddcec8
[wifi-assistant] / package / src / wifi_assistant / settings / application_settings.py
1 #!/usr/bin/python2.5
2 from gnome import gconf
3
4 class ApplicationSettings():
5     
6     def __init__(self, gconf_client, gconf_root_dir):
7         self._gc = gconf_client
8         self._gconfRootDir = gconf_root_dir
9         self._gconfPopupKey = gconf_root_dir + '/daemon'
10         self._listeners = {}
11     
12     # ---- public API __________________________________________________________
13         
14     def registerUsePopupListener(self, callback):
15         """Registers a listener/callback to changes on Use Daemon setting"""
16         
17         if len(self._listeners) == 0:
18             self._gc.add_dir(self._gconfRootDir, gconf.CLIENT_PRELOAD_NONE)
19         ref_id = self._gc.notify_add(self._gconfPopupKey, callback)
20         self._listeners[callback] = ref_id
21         
22     
23     def unregisterUsePopupListener(self, callback):
24         """Unregisters the listener/callback"""
25         
26         if (self._listeners.has_key(callback)):
27             ref_id = self._listeners.pop(callback)
28             self._gc.notify_remove(ref_id)
29             
30             if len(self._listeners) == 0:
31                 self._gc.remove_dir(self._gconfRootDir)
32     
33             
34     def getUsePopup(self):
35         """Tells whether to use the daemon or not."""
36         
37         value = self._gc.get_without_default(self._gconfPopupKey)
38         if value is None:
39             self.setUsePopup(True)
40             return True
41         return value.get_bool() is not False
42
43
44     def setUsePopup(self, mode):
45         """mode is either True or False."""
46         
47         self._gc.set_bool(self._gconfPopupKey, mode)