elbaschid avatar elbaschid committed c2e3bdc

subclassed revelation Config to support gconf schema defaults

Comments (0)

Files changed (1)

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.