Commits

elbaschid  committed c2e3bdc

subclassed revelation Config to support gconf schema defaults

  • Participants
  • Parent commits 012abe3

Comments (0)

Files changed (1)

File revelation_indicator

 
 import os
 import sys
+import gconf
 import argparse
 
 import logging
 from revelation import config, data, datahandler, dialog, entry, io, ui, util
 
 
+class Config(config.Config):
+
+    def __init__(self, basedir):
+        super(Config, self).__init__(basedir)
+
+
+    def get(self, key):
+        value = self.client.get(self.__resolve_keypath(key))
+
+        if value is None:
+            raise ConfigError
+
+        if value.type == gconf.VALUE_SCHEMA:
+            logger.debug('found schema for %s. will use default value', key)
+            value = value.get_schema().get_default_value()
+
+        if value.type == gconf.VALUE_STRING:
+            return str(value.get_string())
+
+        elif value.type == gconf.VALUE_INT:
+            return value.get_int()
+
+        elif value.type == gconf.VALUE_BOOL:
+            return value.get_bool()
+
+
 class RevelationIndicator(object):
 
     def __init__(self, options=None):
             sys.exit(1)
 
     def __init_config(self, filename=''):
-        self.config = config.Config("/schemas/apps/revelation-applet/prefs")
+        self.config = Config("/schemas/apps/revelation-indicator/prefs")
         
-        # set up defaults
-        # TODO this shouldn't really be necessary, the schema should
-        # be used for defaults - is this even possible with the current
-        # applet api?
-        defaults = {
-            "autolock": True,
-            "autolock_timeout": 10,
-            "chain_username": False,
-            "file": '',
-            "menuaction": "show",
-            "show_passwords": False,
-        }
-
-        for key, value in defaults.items():
-            try:
-                if self.config.get(key) is None:
-                    self.config.set_force(key, value)
-
-            except config.ConfigError:
-                self.config.set_force(key, value)
-
         ##FIXME: use a better way to set the filename
         if filename:
             self.config.set_force('file', filename)