[kupfer] settings: Use a timer to save settings when modified



commit c12b432bceafd542fcac04a13896aff82d9b7717
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Aug 22 17:05:55 2009 +0200

    settings: Use a timer to save settings when modified
    
    We use a scheduler.Timer object to save config if it is modified; this
    way we don't lose config if Kupfer exits abnormally (since Kupfer may
    run for very long time) or does not catch log out signals.

 kupfer/settings.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/settings.py b/kupfer/settings.py
index ea1dfcd..78d1854 100644
--- a/kupfer/settings.py
+++ b/kupfer/settings.py
@@ -36,6 +36,11 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		# connect to save settings
 		sch = scheduler.GetScheduler()
 		sch.connect("finish", self._save_config)
+		self._save_timer = scheduler.Timer()
+
+	def _update_config_save_timer(self):
+		self._save_timer.set(60, self._save_config)
+
 	def _read_config(self, read_config=True):
 		"""
 		Read cascading config files
@@ -105,6 +110,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		return confmap
 
 	def _save_config(self, scheduler=None):
+		self.output_debug("Saving config")
 		config_path = config.save_config_file(self.config_filename)
 		if not config_path:
 			self.output_info("Unable to save settings, can't find config dir")
@@ -165,6 +171,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 			value_type = type(oldvalue)
 			self._config[section][key] = value_type(value)
 			self.emit("value-changed", section, key, value)
+			self._update_config_save_timer()
 			return True
 		self.output_info("Settings key", section, key, "is invalid")
 		return False
@@ -182,6 +189,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		if section not in self._config:
 			self._config[section] = {}
 		self._config[section][key] = str(value)
+		self._update_config_save_timer()
 		return False
 
 	def get_plugin_enabled(self, plugin_id):



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