[dots] Move gconf load/save to config_builder class. Use default values



commit d4987447643b3aa2e1674aebafe5611c2a6eb397
Author: Fernando Herrera <fherrera onirica com>
Date:   Thu Dec 2 01:31:15 2010 +0100

    Move gconf load/save to config_builder class. Use default values
    
    Defaults values are used in the gconf schemas are not found. This
    happens typically doing ./configure --prefix=/usr because schemas
    should be installed on /etc

 dots/app_window.py     |   30 +------------------
 dots/config_builder.py |   72 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 28 deletions(-)
---
diff --git a/dots/app_window.py b/dots/app_window.py
index f49ab26..807ef86 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -59,37 +59,11 @@ class AppWindow(object):
 	self.loadConfig()
 
     def loadConfig(self):
-	self.config_builder['xml']['semanticFiles'] = self.client.get_string ("/apps/dots/semanticFiles")
-	if self.client.get_bool ("/apps/dots/internetAccess"):
-		self.config_builder['xml']['internetAccess'] = 'yes'
-	else:
-		self.config_builder['xml']['internetAccess'] = 'no'
-	self.config_builder['translation']['literaryTextTable'] = self.client.get_string ("/apps/dots/literaryTextTable")
-	self.config_builder['outputFormat']['cellsPerLine'] = self.client.get_int ("/apps/dots/cellsPerLine")
-	if self.client.get_bool ("/apps/dots/braillePages"):
-		self.config_builder['outputFormat']['braillePages'] = 'yes'
-	else:
-		self.config_builder['outputFormat']['braillePages'] = 'no'
-	self.config_builder['outputFormat']['formatFor'] = self.client.get_string ("/apps/dots/formatFor")
-	self.config_builder['outputFormat']['LinesPerPage'] = self.client.get_int ("/apps/dots/LinesPerPage")
-	self.config_builder['outputFormat']['braillePageNumberAt'] =  self.client.get_string ("/apps/dots/braillePageNumberAt")
+	self.config_builder.load_from_gconf(self.client)
 	self._populateTablesMenu()
 
     def saveConfig(self):
-	self.client.set_string ("/apps/dots/semanticFiles", self.config_builder['xml']['semanticFiles'])
-	if self.config_builder['xml']['internetAccess'] == 'yes':
-		self.client.set_bool ("/apps/dots/internetAccess", True)
-	else:
-		self.client.set_bool ("/apps/dots/internetAccess", False)
-	self.client.set_string ("/apps/dots/literaryTextTable", self.config_builder['translation']['literaryTextTable'])
-	self.client.set_int ("/apps/dots/cellsPerLine", self.config_builder['outputFormat']['cellsPerLine'])
-	if self.config_builder['outputFormat']['braillePages'] == 'yes':
-		self.client.set_bool ("/apps/dots/braillePages", True)
-	else:
-		self.client.set_bool ("/apps/dots/braillePages", False)
-	self.client.set_string ("/apps/dots/formatFor", self.config_builder['outputFormat']['formatFor'])
-	self.client.set_int ("/apps/dots/LinesPerPage", self.config_builder['outputFormat']['LinesPerPage'])
-	self.client.set_string ("/apps/dots/braillePageNumberAt", self.config_builder['outputFormat']['braillePageNumberAt'])
+	self.config_builder.save_to_gconf(self.client)
 
     def _OnTranslationFormatActivate(self, item):
 	dialog = self.conf_xml.get_object('format_dialog')
diff --git a/dots/config_builder.py b/dots/config_builder.py
index f031ec3..c3281af 100644
--- a/dots/config_builder.py
+++ b/dots/config_builder.py
@@ -1,6 +1,7 @@
 # Dots - A braille translation program.
 #
 # Copyright (C) 2009 Eitan Isaacson
+# Copyright (C) 2010 Fernando Herrera
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -15,6 +16,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+DEFAULT_SEMANTICS = "*,nemeth.sem"
+DEFAULT_TABLE = "Es-Es-g1.utb"
+DEFAULT_CELLS = 40
+DEFAULT_LINES = 25
+DEFAULT_FORMAT = "textDevice"
+DEFAULT_PAGEPOS = "bottom"
+
 class ConfigBuilder(dict):
     def __init__(self):
         self['xml'] = _ConfigSection()
@@ -29,6 +37,70 @@ class ConfigBuilder(dict):
                 s += '\t%s %s\n' % (k ,v)
         return s
 
+    def load_from_gconf(self, client):
+	value = client.get_string ("/apps/dots/semanticFiles")
+	if value is not None:
+        	self['xml']['semanticFiles'] = value
+	else:
+		self['xml']['semanticFiles'] = DEFAULT_SEMANTICS
+
+        if client.get_bool ("/apps/dots/internetAccess"):
+                self['xml']['internetAccess'] = 'yes'
+        else:
+                self['xml']['internetAccess'] = 'no'
+
+	value = client.get_string ("/apps/dots/literaryTextTable")
+	if value is not None:
+        	self['translation']['literaryTextTable'] = value
+	else:
+		self['translation']['literaryTextTable'] = DEFAULT_TABLE
+
+	value = client.get_int ("/apps/dots/cellsPerLine")
+	if value > 0:
+        	self['outputFormat']['cellsPerLine'] = value
+	else:
+        	self['outputFormat']['cellsPerLine'] = DEFAULT_CELLS
+
+        if client.get_bool ("/apps/dots/braillePages"):
+                self['outputFormat']['braillePages'] = 'yes'
+        else:
+                self['outputFormat']['braillePages'] = 'no'
+
+	value = client.get_string ("/apps/dots/formatFor")
+	if value is not None:
+        	self['outputFormat']['formatFor'] = value
+	else:
+        	self['outputFormat']['formatFor'] = DEFAULT_FORMAT
+
+	value = client.get_int ("/apps/dots/LinesPerPage")
+	if value > 0:
+        	self['outputFormat']['LinesPerPage'] = value
+	else:
+        	self['outputFormat']['LinesPerPage'] = DEFAULT_LINES
+
+	value = client.get_string ("/apps/dots/braillePageNumberAt")
+	if value is not None:
+        	self['outputFormat']['braillePageNumberAt'] = value
+	else:
+        	self['outputFormat']['braillePageNumberAt'] = DEFAULT_PAGEPOS
+
+
+    def save_to_gconf(self, client):
+        client.set_string ("/apps/dots/semanticFiles", self['xml']['semanticFiles'])
+        if self['xml']['internetAccess'] == 'yes':
+                client.set_bool ("/apps/dots/internetAccess", True)
+        else:
+                client.set_bool ("/apps/dots/internetAccess", False)
+        client.set_string ("/apps/dots/literaryTextTable", self['translation']['literaryTextTable'])
+        client.set_int ("/apps/dots/cellsPerLine", self['outputFormat']['cellsPerLine'])
+        if self['outputFormat']['braillePages'] == 'yes':
+                client.set_bool ("/apps/dots/braillePages", True)
+        else:
+                client.set_bool ("/apps/dots/braillePages", False)
+        client.set_string ("/apps/dots/formatFor", self['outputFormat']['formatFor'])
+        client.set_int ("/apps/dots/LinesPerPage", self['outputFormat']['LinesPerPage'])
+        client.set_string ("/apps/dots/braillePageNumberAt", self['outputFormat']['braillePageNumberAt'])
+
 class _ConfigSection(dict):
     pass
 



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