[hamster-applet] dropping gconf schema and reusing conduit's code for preferences



commit 17635c48dbd53c82586346dfd0ca2f501660fb9d
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue Jan 12 13:31:51 2010 +0000

    dropping gconf schema and reusing conduit's code for preferences

 data/Makefile.am               |   17 ----
 data/hamster-applet.schemas.in |   86 -----------------
 hamster/KeyBinder.py           |   24 ++---
 hamster/applet.py              |   51 +++++------
 hamster/configuration.py       |  198 ++++++++++++++++++++++++++++------------
 hamster/db.py                  |   12 ++-
 hamster/hamster-applet.py      |    5 +-
 hamster/preferences.py         |   34 ++++---
 hamster/stats.py               |   13 ++-
 hamster/stats_reports.py       |    8 +--
 hamster/widgets/timechart.py   |    5 +-
 po/POTFILES.in                 |    1 -
 12 files changed, 213 insertions(+), 241 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 4596c48..cfcd775 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -7,13 +7,6 @@ serverdir = $(libdir)/bonobo/servers
 server_in_files = Hamster_Applet.server.in
 server_DATA = $(server_in_files:.server.in=.server)
 
-# ******************************************************************************
-# GConf Schemas
-# ******************************************************************************
-# GConf Preference Schemas
-schemadir = $(GCONF_SCHEMA_FILE_DIR)
-schema_in_files = hamster-applet.schemas.in
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
 
 # ******************************************************************************
 # Misc data
@@ -43,25 +36,15 @@ hamsterbindir = $(libdir)/hamster-applet
 # ******************************************************************************
 @INTLTOOL_DESKTOP_RULE@
 @INTLTOOL_SERVER_RULE@
- INTLTOOL_SCHEMAS_RULE@
 
 $(server_in_files): $(server_in_files:.server.in=.server.in.in)
 	sed -e "s|\ LIBEXECDIR\@|$(hamsterbindir)|" $< > $@
 
-if GCONF_SCHEMAS_INSTALL
-install-data-local: install-schemas
-install-schemas:
-	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
-		$(GCONFTOOL) --makefile-install-rule $(schema_DATA)
-endif
-
 DISTCLEANFILES = \
-	$(schema_DATA) \
 	$(server_DATA) \
 	$(server_in_files)
 
 EXTRA_DIST = \
-	$(schema_in_files) \
 	$(xml_in_files) \
 	Hamster_Applet.server.in.in \
 	$(resources_DATA)
diff --git a/hamster/KeyBinder.py b/hamster/KeyBinder.py
index 6545d9d..5abd4a0 100644
--- a/hamster/KeyBinder.py
+++ b/hamster/KeyBinder.py
@@ -21,27 +21,25 @@
 
 import gtk, gconf
 import keybinder
-from configuration import GconfStore, runtime
+from configuration import runtime, conf
 
 class Keybinder(object):
     def __init__(self):
-        self.config = GconfStore()
-
         self.bound = False
         self.prevbinding = None
 
-        self.key_combination = self.config.get_keybinding()
-        if self.key_combination is None:
-            # This is for uninstalled cases, the real default is in the schema
-            self.key_combination = "<Super>H"
-
-        runtime.dispatcher.add_handler("gconf_keybinding_changed", self.on_keybinding_changed)
+        self.key_combination = conf.get("keybinding")
+        runtime.dispatcher.add_handler("conf_changed", self.on_conf_changed)
 
         self.bind()
 
-    def on_keybinding_changed(self, event, new_binding = None):
+    def on_conf_changed(self, event, data):
+        key, value = data
+        if key != "keybinding":
+            return
+        
         self.prevbinding = self.key_combination
-        self.key_combination = new_binding
+        self.key_combination = value
         self.bind()
 
     def on_keybinding_activated(self):
@@ -73,10 +71,6 @@ class Keybinder(object):
             # if the requested keybinding is not bound, a KeyError will be thrown
             pass
 
-if gtk.pygtk_version < (2,8,0):
-    gobject.type_register(Keybinder)
 
 keybinder = Keybinder()
 
-def get_hamster_keybinder():
-    return keybinder
diff --git a/hamster/applet.py b/hamster/applet.py
index 3688391..91e2cc1 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -32,7 +32,7 @@ import gobject
 import dbus, dbus.service, dbus.mainloop.glib
 
 import eds
-from configuration import GconfStore, runtime, dialogs
+from configuration import conf, runtime, dialogs
 
 import stuff
 from KeyBinder import *
@@ -211,8 +211,6 @@ class HamsterApplet(object):
         self.applet.about = None
         self.open_fact_editors = []
 
-        self.config = GconfStore()
-
         self.button = PanelButton()
         self.button.connect('toggled', self.on_toggle)
         self.applet.add(self.button)
@@ -262,7 +260,8 @@ class HamsterApplet(object):
         except dbus.DBusException, e:
             logging.error("Can't init dbus: %s" % e)
 
-        self.day_start = self.config.get_day_start()
+        self.day_start = conf.get("day_start_minutes")
+        self.day_start = dt.time(self.day_start / 60, self.day_start % 60) # it comes in as minutes
 
         # Load today's data, activities and set label
         self.last_activity = None
@@ -287,19 +286,14 @@ class HamsterApplet(object):
         runtime.dispatcher.add_handler('keybinding_activated', self.on_keybinding_activated)
 
         # init idle check
-        runtime.dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
-        self.timeout_enabled = self.config.get_timeout_enabled()
-
-        runtime.dispatcher.add_handler('gconf_notify_on_idle_changed', self.on_notify_on_idle_changed)
-        self.notify_on_idle = self.config.get_notify_on_idle()
+        self.timeout_enabled = conf.get("enable_timeout")
+        self.notify_on_idle = conf.get("notify_on_idle")
 
-        runtime.dispatcher.add_handler('gconf_on_day_start_changed', self.on_day_start_changed)
 
         # init nagging timeout
         if PYNOTIFY:
             self.notify = Notifier(self.button)
-            runtime.dispatcher.add_handler('gconf_notify_interval_changed', self.on_notify_interval_changed)
-            self.on_notify_interval_changed(None, self.config.get_notify_interval())
+            self.on_conf_changed(None, ("notify_interval", conf.get("notify_interval")))
 
 
     """UI functions"""
@@ -591,27 +585,28 @@ class HamsterApplet(object):
             runtime.storage.touch_fact(self.last_activity,
                                        end_time = self.dbusIdleListener.getIdleFrom())
 
-    def on_day_start_changed(self, event, new_minutes):
-        self.day_start = self.config.get_day_start()
-        self.load_day()
-        self.update_label()
-
     """global shortcuts"""
     def on_keybinding_activated(self, event, data):
         self.__show_toggle(None, not self.button.get_active())
 
-    def on_timeout_enabled_changed(self, event, enabled):
-        self.timeout_enabled = enabled
-
-    def on_notify_on_idle_changed(self, event, enabled):
-        self.notify_on_idle = enabled
-
-    def on_notify_interval_changed(self, event, new_interval):
-        if PYNOTIFY and 0 < new_interval < 121:
-            self.notify_interval = new_interval
-        else:
-            self.notify_interval = None
 
+    def on_conf_changed(self, event, data):
+        key, value = data
+        
+        if key == "enable_timeout":
+            self.timeout_enabled = value
+        elif key == "notify_on_idle":
+            self.notify_on_idle = value
+        elif key == "notify_interval":
+            if PYNOTIFY and 0 < value < 121:
+                self.notify_interval = value
+            else:
+                self.notify_interval = None
+        elif key == "day_start_minutes":
+            self.day_start = dt.time(value / 60, value % 60)
+            self.load_day()
+            self.update_label()
+            
     def on_activity_text_changed(self, widget):
         self.get_widget("switch_activity").set_sensitive(widget.get_text() != "")
 
diff --git a/hamster/configuration.py b/hamster/configuration.py
index 2eb594e..72b9075 100644
--- a/hamster/configuration.py
+++ b/hamster/configuration.py
@@ -17,6 +17,11 @@
 # You should have received a copy of the GNU General Public License
 # along with Project Hamster.  If not, see <http://www.gnu.org/licenses/>.
 
+"""
+gconf part of this code copied from Gimmie (c) Alex Gravely via Conduit (c) John Stowers, 2006
+License: GPLv2
+"""
+
 import gconf
 import gettext
 import os
@@ -28,6 +33,9 @@ import logging
 import datetime as dt
 import gio
 
+import logging
+log = logging.getLogger("configuration")
+
 class Singleton(object):
      def __new__(cls, *args, **kwargs):
          if '__instance' not in vars(cls):
@@ -44,6 +52,7 @@ class RuntimeStore(Singleton):
     data_dir = ""
     dispatcher = None
     storage = None
+    conf = None
 
 
     def __init__(self):
@@ -57,6 +66,7 @@ class RuntimeStore(Singleton):
         self.data_dir = data_dir
         self.dispatcher = Dispatcher()
         self.storage = Storage(self.dispatcher)
+        
 
         # figure out the correct database file
         old_db_file = os.path.expanduser("~/.gnome2/hamster-applet/hamster.db")
@@ -168,74 +178,144 @@ class Dialogs(Singleton):
 
 dialogs = Dialogs()
 
-class GconfStore(Singleton):
-    """
-    Handles storing to and retrieving values from GConf
-    """
 
-    # GConf directory for deskbar in window mode and shared settings
-    GCONF_DIR = "/apps/hamster-applet/general"
 
-    # GConf key for global keybinding
-    GCONF_KEYBINDING = GCONF_DIR + "/keybinding"
-    GCONF_ENABLE_TIMEOUT = GCONF_DIR + "/enable_timeout"
-    GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"
-    GCONF_NOTIFY_INTERVAL = GCONF_DIR + "/notify_interval"
-    GCONF_NOTIFY_ON_IDLE = GCONF_DIR + "/notify_on_idle"
-    GCONF_DAY_START = GCONF_DIR + "/day_start"
 
-    __instance = None
 
+class GConfStore(Singleton):
+    """
+    Settings implementation which stores settings in GConf
+    Snatched from the conduit project (http://live.gnome.org/Conduit)
+    """
+    GCONF_DIR = "/apps/hamster-applet/"
+    VALID_KEY_TYPES = (bool, str, int, list, tuple)
+    DEFAULTS = {
+        'enable_timeout'            :   False,          # Should hamster stop tracking on idle
+        'stop_on_shutdown'          :   False,          # Should hamster stop tracking on shutdown
+        'notify_on_idle'            :   False,          # Remind also if no activity is set
+        'notify_interval'           :   27,             # Remind of current activity every X minutes
+        'day_start_minutes'         :   5 * 60 + 30,    # At what time does the day start (5:30AM)
+        'keybinding'                :   "<Super>H",     # Key binding to summon hamster
+        'overview_window_box'       :   [],             # X, Y, W, H
+        'overview_window_maximized' :   False,          # Is overview window maximized
+    }
+    
     def __init__(self):
-        super(GconfStore, self).__init__()
         self._client = gconf.client_get_default()
-        self.__connect_notifications()
-
-    def __connect_notifications(self):
-        self._client.add_dir(self.GCONF_DIR, gconf.CLIENT_PRELOAD_RECURSIVE)
-        self._client.notify_add(self.GCONF_KEYBINDING, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_keybinding_changed", z.value.get_string()))
-        self._client.notify_add(self.GCONF_ENABLE_TIMEOUT, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_timeout_enabled_changed", z.value.get_bool()))
-        self._client.notify_add(self.GCONF_STOP_ON_SHUTDOWN, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_stop_on_shutdown_changed", z.value.get_bool()))
-        self._client.notify_add(self.GCONF_NOTIFY_INTERVAL, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_interval_changed", z.value.get_int()))
-        self._client.notify_add(self.GCONF_NOTIFY_ON_IDLE, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_on_idle_changed", z.value.get_bool()))
-        self._client.notify_add(self.GCONF_DAY_START, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_on_day_start_changed", z.value.get_int()))
-
-
-    def get_keybinding(self):
-        return self._client.get_string(self.GCONF_KEYBINDING) or ""
-
-    def get_timeout_enabled(self):
-        return self._client.get_bool(self.GCONF_ENABLE_TIMEOUT) or False
-
-    def get_stop_on_shutdown(self):
-        return self._client.get_bool(self.GCONF_STOP_ON_SHUTDOWN) or False
-
-    def get_notify_interval(self):
-    	return self._client.get_int(self.GCONF_NOTIFY_INTERVAL) or 27
-
-    def get_notify_on_idle(self):
-    	return self._client.get_bool(self.GCONF_NOTIFY_ON_IDLE) or False
-
-    def get_day_start(self):
-        minutes = self._client.get_int(self.GCONF_DAY_START) or 5*60 + 30
-        return dt.time(minutes / 60, minutes % 60)
-
-    #------------------------
-    def set_keybinding(self, binding):
-        self._client.set_string(self.GCONF_KEYBINDING, binding)
+        self._client.add_dir(self.GCONF_DIR[:-1], gconf.CLIENT_PRELOAD_RECURSIVE)  
+        self._notifications = []
+
+    def _fix_key(self, key):
+        """
+        Appends the 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.GCONF_DIR):
+            return self.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)[len(self.GCONF_DIR):]
+        value = self._get_value(entry.value, self.DEFAULTS[key])
+
+        runtime.dispatcher.dispatch("conf_changed", (key, value))
+
+
+    def _get_value(self, value, default):
+        """calls appropriate gconf function by the default value"""
+        vtype = type(default)
+
+        if vtype is bool:
+            return value.get_bool()
+        elif vtype is str:
+            return value.get_string()
+        elif vtype is int:
+            return value.get_int()
+        elif vtype in (list, tuple):
+            l = []
+            for i in value.get_list():
+                l.append(i.get_string())
+            return l
+        
+        return None
+        
+    def get(self, key, default=None):
+        """
+        Returns the value of the key or the default value if the key is 
+        not yet in gconf
+        """
+        
+        #function arguments override defaults
+        if default is None:
+            default = self.DEFAULTS.get(key, None)
+        vtype = type(default)
+        
+        #we now have a valid key and type
+        if default is None:
+            log.warn("Unknown key: %s, must specify default value" % key)
+            return None
+
+        if vtype not in self.VALID_KEY_TYPES:
+            log.warn("Invalid key type: %s" % vtype)
+            return None
+
+        #for gconf refer to the full key path
+        key = self._fix_key(key)
+
+        if key not in self._notifications:
+            self._client.notify_add(key, self._key_changed)
+            self._notifications.append(key)
+        
+        value = self._client.get(key)
+        if value is None:
+            self.set(key, default)
+            return default
+
+        value = self._get_value(value, default)
+        if value is not None:
+            return value
+            
+        log.warn("Unknown gconf key: %s" % key)
+        return None
+
+    def set(self, key, value):
+        """
+        Sets the key value in gconf and connects adds a signal 
+        which is fired if the key changes
+        """
+        log.debug("Settings %s -> %s" % (key, value))
+        if key in self.DEFAULTS:
+            vtype = type(self.DEFAULTS[key])
+        else:
+            vtype = type(value)
 
-    def set_timeout_enabled(self, enabled):
-        self._client.set_bool(self.GCONF_ENABLE_TIMEOUT, enabled)
+        if vtype not in self.VALID_KEY_TYPES:
+            log.warn("Invalid key type: %s" % vtype)
+            return False
 
-    def set_stop_on_shutdown(self, enabled):
-        self._client.set_bool(self.GCONF_STOP_ON_SHUTDOWN, enabled)
+        #for gconf refer to the full key path
+        key = self._fix_key(key)
 
-    def set_notify_interval(self, interval):
-    	return self._client.set_int(self.GCONF_NOTIFY_INTERVAL, interval)
+        if vtype is bool:
+            self._client.set_bool(key, value)
+        elif vtype is str:
+            self._client.set_string(key, value)
+        elif vtype is int:
+            self._client.set_int(key, value)
+        elif vtype in (list, tuple):
+            #Save every value as a string
+            strvalues = [str(i) for i in value]
+            self._client.set_list(key, gconf.VALUE_STRING, strvalues)
 
-    def set_notify_on_idle(self, enabled):
-        self._client.set_bool(self.GCONF_NOTIFY_ON_IDLE, enabled)
+        return True
 
-    def set_day_start(self, time):
-    	return self._client.set_int(self.GCONF_DAY_START, time.hour * 60 + time.minute)
 
+conf = GConfStore()
diff --git a/hamster/db.py b/hamster/db.py
index d1edd83..cbe5d08 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -56,7 +56,7 @@ class Storage(storage.Storage):
         self.__con = None
         self.__cur = None
 
-        from configuration import runtime, GconfStore
+        from configuration import runtime
 
         db_file = runtime.database_path
         db_path, _ = os.path.split(os.path.realpath(db_file))
@@ -328,8 +328,9 @@ class Storage(storage.Storage):
         return grouped_facts
 
     def __get_last_activity(self):
-        from configuration import GconfStore
-        day_start = GconfStore().get_day_start()
+        from configuration import conf
+        day_start = conf.get("day_start_minutes")
+        day_start = dt.time(day_start / 60, day_start % 60)
 
         today = (dt.datetime.now() - dt.timedelta(hours = day_start.hour,
                                                   minutes = day_start.minute)).date()
@@ -615,8 +616,9 @@ class Storage(storage.Storage):
         query += " ORDER BY a.start_time, e.name"
         end_date = end_date or date
 
-        from configuration import GconfStore
-        day_start = GconfStore().get_day_start()
+        from configuration import conf
+        day_start = conf.get("day_start_minutes")
+        day_start = dt.time(day_start / 60, day_start % 60)
 
         split_time = day_start
         datetime_from = dt.datetime.combine(date, split_time)
diff --git a/hamster/hamster-applet.py b/hamster/hamster-applet.py
index 59194fb..ead960d 100755
--- a/hamster/hamster-applet.py
+++ b/hamster/hamster-applet.py
@@ -41,11 +41,10 @@ def applet_factory(applet, iid):
     return True
 
 def on_destroy(event):
-    from hamster.configuration import GconfStore, runtime
-    config = GconfStore()
+    from hamster.configuration import runtime, conf
 
     # handle config option to stop tracking on shutdown
-    if config.get_stop_on_shutdown():
+    if conf.get("stop_on_shutdown"):
         last_activity = runtime.storage.get_last_activity()
         if last_activity and last_activity['end_time'] is None:
             runtime.storage.touch_fact(last_activity)
diff --git a/hamster/preferences.py b/hamster/preferences.py
index d234ba1..29466f8 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -81,7 +81,7 @@ class ActivityStore(gtk.ListStore):
 formats = ["fixed", "symbolic", "minutes"]
 appearances = ["text", "icon", "both"]
 
-from configuration import runtime, GconfStore
+from configuration import runtime, conf
 import widgets
 import dispatcher, storage, stuff
 
@@ -95,7 +95,6 @@ class PreferencesEditor:
     def __init__(self, parent = None):
         self.parent = parent
         self._gui = stuff.load_ui_file("preferences.ui")
-        self.config = GconfStore()
         self.window = self.get_widget('preferences_window')
 
 
@@ -173,6 +172,7 @@ class PreferencesEditor:
         self.prev_selected_activity = None
         self.prev_selected_category = None
 
+        
         # disable notification thing if pynotify is not available
         try:
             import pynotify
@@ -182,14 +182,16 @@ class PreferencesEditor:
         self._gui.connect_signals(self)
         self.window.show_all()
 
-    def load_config(self):
-        self.get_widget("shutdown_track").set_active(self.config.get_stop_on_shutdown())
-        self.get_widget("idle_track").set_active(self.config.get_timeout_enabled())
-        self.get_widget("notify_interval").set_value(self.config.get_notify_interval())
-        self.get_widget("keybinding").set_text(self.config.get_keybinding())
-        self.get_widget("notify_on_idle").set_active(self.config.get_notify_on_idle())
+    def load_config(self, *args):
+        self.get_widget("shutdown_track").set_active(conf.get("stop_on_shutdown"))
+        self.get_widget("idle_track").set_active(conf.get("enable_timeout"))
+        self.get_widget("notify_interval").set_value(conf.get("notify_interval"))
+        self.get_widget("keybinding").set_text(conf.get("keybinding"))
+        self.get_widget("notify_on_idle").set_active(conf.get("notify_on_idle"))
 
-        self.day_start.set_time(self.config.get_day_start())
+        day_start = conf.get("day_start_minutes")
+        day_start = dt.time(day_start / 60, day_start % 60)
+        self.day_start.set_time(day_start)
 
         self.tags = [tag["name"] for tag in runtime.storage.get_tags(autocomplete=True)]
         self.get_widget("autocomplete_tags").set_text(", ".join(self.tags))
@@ -642,13 +644,13 @@ class PreferencesEditor:
             return False
 
     def on_shutdown_track_toggled(self, checkbox):
-        self.config.set_stop_on_shutdown(checkbox.get_active())
+        conf.set("stop_on_shutdown", checkbox.get_active())
 
     def on_idle_track_toggled(self, checkbox):
-        self.config.set_timeout_enabled(checkbox.get_active())
+        conf.set("enable_timeout", checkbox.get_active())
 
     def on_notify_on_idle_toggled(self, checkbox):
-        self.config.set_notify_on_idle(checkbox.get_active())
+        conf.set("notify_on_idle", checkbox.get_active())
 
     def on_notify_interval_format_value(self, slider, value):
         if value <=120:
@@ -662,18 +664,20 @@ class PreferencesEditor:
 
     def on_notify_interval_value_changed(self, scale):
         value = int(scale.get_value())
-        self.config.set_notify_interval(value)
+        conf.set("notify_interval", value)
         self.get_widget("notify_on_idle").set_sensitive(value <= 120)
 
     def on_keybinding_changed(self, textbox):
-        self.config.set_keybinding(textbox.get_text().decode('utf8', 'replace'))
+        conf.set("keybinding", textbox.get_text().decode('utf8', 'replace'))
 
     def on_day_start_changed(self, widget):
         day_start = self.day_start.get_time()
         if not day_start:
             return
+        
+        day_start = day_start.hour * 60 + day_start.minute
 
-        self.config.set_day_start(day_start)
+        conf.set("day_start_minutes", day_start)
 
     def on_preferences_window_destroy(self, window):
         self.window = None
diff --git a/hamster/stats.py b/hamster/stats.py
index 70162d7..b7cabd3 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -31,7 +31,7 @@ import pango
 
 import stuff
 from hamster.i18n import C_
-from configuration import runtime, GconfStore, dialogs
+from configuration import runtime, conf, dialogs
 import widgets, reports
 
 from stats_overview import OverviewBox
@@ -48,8 +48,8 @@ class StatsViewer(object):
 
         self.window = self.get_widget("tabs_window")
 
-        self.config = GconfStore()
-        self.day_start = self.config.get_day_start()
+        self.day_start = conf.get("day_start_minutes")
+        self.day_start = dt.time(self.day_start / 60, self.day_start % 60)
 
         self.view_date = (dt.datetime.today() - dt.timedelta(hours = self.day_start.hour,
                                                         minutes = self.day_start.minute)).date()
@@ -104,6 +104,7 @@ class StatsViewer(object):
         self._gui.connect_signals(self)
         runtime.dispatcher.add_handler('activity_updated', self.after_activity_update)
         runtime.dispatcher.add_handler('day_updated', self.after_activity_update)
+        runtime.dispatcher.add_handler('conf_changed', self.on_conf_change)
 
 
         self.window.show_all()
@@ -168,6 +169,12 @@ class StatsViewer(object):
         self.get_widget("range_title").set_text(self.title)
 
 
+    def on_conf_change(self, event, data):
+        key, value = data
+        if key == "day_start_minutes":
+            self.day_start = dt.time(value / 60, value % 60)
+            self.search()
+    
     def on_fact_selection_changed(self, tree):
         """ enables and disables action buttons depending on selected item """
         selection = tree.get_selection()
diff --git a/hamster/stats_reports.py b/hamster/stats_reports.py
index 3028d49..a4deabd 100644
--- a/hamster/stats_reports.py
+++ b/hamster/stats_reports.py
@@ -33,7 +33,7 @@ import gtk, gobject
 
 import stuff, widgets
 import charting, reports
-from configuration import runtime, GconfStore, dialogs
+from configuration import runtime, dialogs
 
 from hamster.i18n import C_
 
@@ -90,9 +90,6 @@ class ReportsBox(gtk.VBox):
 
         self._gui.connect_signals(self)
 
-        self.config = GconfStore()
-        runtime.dispatcher.add_handler('gconf_on_day_start_changed', self.on_day_start_changed)
-
         self.report_chooser = None
 
 
@@ -242,9 +239,6 @@ class ReportsBox(gtk.VBox):
         """ skip one variable (huh) """
         return self._gui.get_object(name)
 
-    def on_day_start_changed(self, event, new_minutes):
-        self.do_graph()
-
     def on_statistics_button_clicked(self, button):
         dialogs.stats.show(self)
 
diff --git a/hamster/widgets/timechart.py b/hamster/widgets/timechart.py
index 4109c9a..6f44f06 100644
--- a/hamster/widgets/timechart.py
+++ b/hamster/widgets/timechart.py
@@ -21,7 +21,7 @@ import gtk, pango
 
 from .hamster import graphics, stuff
 
-from .hamster.configuration import GconfStore
+from .hamster.configuration import conf
 
 import datetime as dt
 import calendar
@@ -40,7 +40,8 @@ class TimeChart(graphics.Area):
         graphics.Area.__init__(self)
         self.start_time, self.end_time = None, None
         self.facts = []
-        self.day_start = GconfStore().get_day_start()
+        self.day_start = conf.get("day_start_minutes")
+        self.day_start = dt.time(self.day_start / 60, self.day_start % 60)
         self.first_weekday = stuff.locale_first_weekday()
 
         self.minor_tick = None
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 27480fd..edff4f3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,7 +4,6 @@ data/Hamster_Applet.server.in.in
 data/Hamster_Applet.xml
 [type: gettext/glade]data/preferences.ui
 [type: gettext/glade]data/edit_activity.ui
-data/hamster-applet.schemas.in
 [type: gettext/glade]data/applet.ui
 [type: gettext/glade]data/stats.ui
 [type: gettext/glade]data/stats_reports.ui



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]