[billreminder] More work done to get a working gconf handler.
- From: Og B. Maciel <ogmaciel src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [billreminder] More work done to get a working gconf handler.
- Date: Thu, 31 Dec 2009 03:20:00 +0000 (UTC)
commit 0f5f075042113a35dfabbd82e83abd05f377db37
Author: Og B. Maciel <ogmaciel gnome org>
Date: Wed Dec 30 22:17:47 2009 -0500
More work done to get a working gconf handler.
src/lib/Settings.py | 18 +++-----
src/lib/SettingsGConf.py | 101 +++++++++++++++++----------------------------
2 files changed, 45 insertions(+), 74 deletions(-)
---
diff --git a/src/lib/Settings.py b/src/lib/Settings.py
index e6a8c65..cfad7a5 100644
--- a/src/lib/Settings.py
+++ b/src/lib/Settings.py
@@ -35,13 +35,13 @@ def string_to_bool(stringy):
return True
else:
return False
-
+
def list_to_string(listy):
s = ""
if type(listy) is list:
s = ",".join(listy) #cool
return s
-
+
def string_to_list(string, listInternalVtype=str):
l = string.split(",")
internalTypeName = TYPE_TO_TYPE_NAME[listInternalVtype]
@@ -51,10 +51,8 @@ def string_to_list(string, listInternalVtype=str):
class Settings(gobject.GObject):
"""
- Class for storing conduit.GLOBALS.settings. Keys of type str, bool, int,
+ Class for storing settings. Keys of type str, bool, int,
and list of strings supported at this stage.
-
- Also stores the special proxy settings.
"""
__gsignals__ = {
'changed' : (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_DETAILED, gobject.TYPE_NONE, ()),
@@ -62,10 +60,10 @@ class Settings(gobject.GObject):
#Default values for conduit settings
DEFAULTS = {
- 'startup_delay' : 1, #How long to wait before starting the backend
+ 'startup_delay' : 60000, #How long to wait before starting the backend
'start_in_tray' : False, #Show the application start minimized
'show_startup_notification' : True,
- 'show_pay_notification', : True,
+ 'show_pay_notification' : True,
'show_before_alarm' : True,
'show_due_alarm' : True,
'show_alarm' : True,
@@ -73,7 +71,7 @@ class Settings(gobject.GObject):
'use_alert_dialog' : False,
'show_alarm_before_days' : 3,
'show_alarm_at_time' : '13:00',
- 'interval' : 60,
+ 'interval' : 60000,
'window_position_x' : 0,
'window_position_y' : 0,
'window_width' : 550,
@@ -94,7 +92,7 @@ class Settings(gobject.GObject):
except Exception, e:
SETTINGS_IMPL = 'GConf'
- implName = kwargs.get("implName", conduit.SETTINGS_IMPL)
+ implName = kwargs.get("implName", SETTINGS_IMPL)
if implName == "GConf":
import SettingsGConf as SettingsImpl
else:
@@ -131,5 +129,3 @@ class Settings(gobject.GObject):
Performs any necessary tasks to ensure settings are saved between sessions
"""
self._settings.save()
-
-
diff --git a/src/lib/SettingsGConf.py b/src/lib/SettingsGConf.py
index 1f2312f..ca72d8f 100644
--- a/src/lib/SettingsGConf.py
+++ b/src/lib/SettingsGConf.py
@@ -6,47 +6,69 @@ try:
except ImportError:
from gnome import gconf
-import conduit.platform
+class Settings(object):
+ def __init__(self, defaults, changedCb):
+ self._defaults = defaults
+ self._changedCb = changedCb
+ self._overrides = {}
+
+ def get(self, key, **kwargs):
+ return None
+
+ def set(self, key, val, **kwargs):
+ return False
+
+ def set_overrides(self, **overrides):
+ self._overrides = overrides
+
+ def proxy_enabled(self):
+ return False
+
+ def get_proxy(self):
+ return ("",0,"","")
+
+ def save(self):
+ pass
import logging
log = logging.getLogger("Settings")
-
-class SettingsImpl(conduit.platform.Settings):
+
+class SettingsImpl(Settings):
"""
Settings implementation which stores settings in GConf
"""
-
- CONDUIT_GCONF_DIR = "/apps/conduit/"
+
+ BILLREMINDER_GCONF_DIR = "/apps/billreminder/"
VALID_KEY_TYPES = (bool, str, int, list, tuple)
-
+
def __init__(self, defaults, changedCb):
- conduit.platform.Settings.__init__(self, defaults, changedCb)
+ Settings.__init__(self, defaults, changedCb)
self._client = gconf.client_get_default()
- self._client.add_dir(self.CONDUIT_GCONF_DIR[:-1], gconf.CLIENT_PRELOAD_RECURSIVE)
+ self._client.add_dir(self.BILLREMINDER_GCONF_DIR[:-1], gconf.CLIENT_PRELOAD_RECURSIVE)
self._notifications = []
def _fix_key(self, key):
"""
- Appends the CONDUIT_GCONF_PREFIX to the key if needed
-
+ Appends the BILLREMINDER_GCONF_PREFIX to the key if needed
+
@param key: The key to check
@type key: C{string}
@returns: The fixed key
@rtype: C{string}
"""
- if not key.startswith(self.CONDUIT_GCONF_DIR):
- return self.CONDUIT_GCONF_DIR + key
+ if not key.startswith(self.BILLREMINDER_GCONF_DIR):
+ return self.BILLREMINDER_GCONF_DIR + key
else:
return key
-
+
def _key_changed(self, client, cnxn_id, entry, data=None):
"""
Callback when a gconf key changes
"""
key = self._fix_key(entry.key)
self._changedCb(key)
-
+
def get(self, key, default=None):
"""
Returns the value of the key or the default value if the key is
@@ -80,7 +102,7 @@ class SettingsImpl(conduit.platform.Settings):
if key not in self._notifications:
self._client.notify_add(key, self._key_changed)
self._notifications.append(key)
-
+
value = self._client.get(key)
if not value:
self.set(key, default)
@@ -97,7 +119,7 @@ class SettingsImpl(conduit.platform.Settings):
for i in value.get_list():
l.append(i.get_string())
return l
-
+
log.warn("Unknown gconf key: %s" % key)
return None
@@ -136,50 +158,3 @@ class SettingsImpl(conduit.platform.Settings):
self._client.set_list(key, gconf.VALUE_STRING, strvalues)
return True
-
- def proxy_enabled(self):
- """
- @returns: True if the user has specified a http proxy via
- the http_proxy environment variable, or in gconf
- """
- return os.environ.has_key("http_proxy") or \
- self._client.get_bool("/system/http_proxy/use_http_proxy")
-
- def get_proxy(self):
- """
- Returns the details of the configured http proxy.
- The http_proxy environment variable overrides the GNOME setting
- @returns: host,port,user,password
- """
- if self.proxy_enabled():
- #env vars have preference
- if os.environ.has_key("http_proxy"):
- #re taken from python boto
- pattern = re.compile(
- '(?:http://)?' \
- '(?:(?P<user>\w+):(?P<pass>.*)@)?' \
- '(?P<host>[\w\-\.]+)' \
- '(?::(?P<port>\d+))?'
- )
- match = pattern.match(os.environ['http_proxy'])
- if match:
- return (match.group('host'),
- int(match.group('port')),
- match.group('user'),
- match.group('pass'))
- #now try gconf
- if self._client.get_bool("/system/http_proxy/use_authentication"):
- return (self._client.get_string("/system/http_proxy/host"),
- self._client.get_int("/system/http_proxy/port"),
- self._client.get_string("/system/http_proxy/authentication_user"),
- self._client.get_string("/system/http_proxy/authentication_password"))
- else:
- return (self._client.get_string("/system/http_proxy/host"),
- self._client.get_int("/system/http_proxy/port"),
- "",
- "")
-
- return ("",0,"","")
-
-
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]