[dots/remove-assistant: 4/38] Load and save configuration from gconf



commit 70faeb66d6de9cfab4b6a34a9399230533350db3
Author: Fernando Herrera <fherrera onirica com>
Date:   Thu Jul 8 16:48:53 2010 +0200

    Load and save configuration from gconf

 configure.ac       |    4 ++
 data/Makefile.am   |   23 +++++++++++++-
 data/dots.schemas  |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 dots/app_window.py |   49 ++++++++++++++++++++++--------
 4 files changed, 146 insertions(+), 14 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 71b4e58..7d9e13d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,10 @@ dnl == i18n ==
 dnl == intltool check ==
 #IT_PROG_INTLTOOL([0.35.0])
 
+dnl == gconf check ==
+AC_PATH_PROG(GCONFTOOL, gconftool-2)
+AM_GCONF_SOURCE_2
+
 dnl == generate makefiles ==
 AC_OUTPUT([
 Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 3ce4960..d123b7e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,25 @@
 gtkbuilderdir = $(datadir)/dots
 gtkbuilder_DATA = dots_assist.xml app_window.xml
 
-EXTRA_DIST = $(gtkbuilder_DATA)
+schemasdir = $(GCONF_SCHEMA_FILE_DIR)
+schemas_DATA = dots.schemas
+
+EXTRA_DIST = $(gtkbuilder_DATA) $(schemas_DATA)
+
+
+if GCONF_SCHEMAS_INSTALL
+install-data-local:
+	if test -z "$(DESTDIR)" ; then \
+		for p in $(schemas_DATA) ; do \
+			GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(srcdir)/$$p ; \
+		done \
+	fi
+uninstall-local:
+	for p in $(schemas_DATA) ; do \
+		GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-uninstall-rule $(srcdir)/$$p ; \
+	done
+else
+install-data-local:
+uninstall-local:
+endif
+
diff --git a/data/dots.schemas b/data/dots.schemas
new file mode 100644
index 0000000..f03eec6
--- /dev/null
+++ b/data/dots.schemas
@@ -0,0 +1,84 @@
+<gconfschemafile>
+  <schemalist>
+    <schema>
+	  <key>/schemas/apps/dots/semanticFiles</key>
+	  <applyto>/apps/dots/semanticFiles</applyto>
+	  <type>string</type>
+	  <default>*,nemeth.sem</default>
+      <locale name="C">
+        <short>Semantic files for translation</short>
+        <long>Semantic files for translation</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/internetAccess</key>
+	  <applyto>/apps/dots/internetAccess</applyto>
+	  <type>bool</type>
+	  <default>true</default>
+      <locale name="C">
+        <short>Use internet access to access XML schemas</short>
+        <long>Use internet access to access XML schemas</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/braillePages</key>
+	  <applyto>/apps/dots/braillePages</applyto>
+	  <type>bool</type>
+	  <default>true</default>
+      <locale name="C">
+        <short>Show braille page number</short>
+        <long>Show braille page number</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/formatFor</key>
+	  <applyto>/apps/dots/formatFor</applyto>
+	  <type>string</type>
+	  <default>textDevice</default>
+      <locale name="C">
+        <short>Formatting for output</short>
+        <long>Formatting for output</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/LinesPerPage</key>
+	  <applyto>/apps/dots/LinesPerPage</applyto>
+	  <type>int</type>
+	  <default>25</default>
+      <locale name="C">
+        <short>Number of lines per page</short>
+        <long>Number of lines per page</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/cellsPerLine</key>
+	  <applyto>/apps/dots/cellsPerLine</applyto>
+	  <type>int</type>
+	  <default>40</default>
+      <locale name="C">
+        <short>Number of cells per line</short>
+        <long>Number of cells per line</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/literaryTextTable</key>
+	  <applyto>/apps/dots/literaryTextTable</applyto>
+	  <type>string</type>
+	  <default>Es-Es-g1.utb</default>
+      <locale name="C">
+        <short>Translation table</short>
+        <long>Translation table</long>
+      </locale>
+    </schema>
+    <schema>
+	  <key>/schemas/apps/dots/braillePageNumberAt</key>
+	  <applyto>/apps/dots/braillePageNumberAt</applyto>
+	  <type>string</type>
+	  <default>bottom</default>
+      <locale name="C">
+        <short>Position for page number</short>
+        <long>Position for page numbres. Valid values are top and bottom</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>
diff --git a/dots/app_window.py b/dots/app_window.py
index a8a7ecf..d12e8af 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -21,6 +21,7 @@ from config_builder import ConfigBuilder
 import host_settings
 from dots_project import DotsProject
 from document_builder import document_new
+import gconf
 
 class AppWindow(object):
     def __init__(self):
@@ -32,24 +33,46 @@ class AppWindow(object):
         self.main_xml.get_object('main_alignment').add(self.main_notebook)
         self.main_xml.connect_signals(self)
         self.config_builder = ConfigBuilder()
+	self.client = gconf.client_get_default ()
+	self.client.add_dir ("/apps/dots", gconf.CLIENT_PRELOAD_NONE)
 	self.loadConfig()
 
     def loadConfig(self):
-	#FIXME Load this from gconf. Populate to UI
-	self.config_builder['xml']['semanticFiles'] = '*'
-	self.config_builder['xml']['semanticFiles'] += ',nemeth.sem'
-	self.config_builder['xml']['internetAccess'] = 'yes'
-	self.config_builder['translation']['literaryTextTable'] = "Es-Es-g1.utb"
-	self.config_builder['outputFormat']['cellsPerLine'] = 40
-	self.config_builder['outputFormat']['braillePages'] = 'yes'
-	self.config_builder['outputFormat']['formatFor'] = 'textDevice'
-	self.config_builder['outputFormat']['LinesPerPage'] = 25
-	self.config_builder['outputFormat']['braillePageNumberAt'] =  'bottom'
+	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._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'])
+
+
 
     def _addTable(self, submenu, group, table):
-	print "Adding table %s to menu %s with group %s submenu" % (table, submenu, group)
 	tableitem = gtk.RadioMenuItem(group, table[:-4])
 	tableitem.connect("activate", self._onTableActivate, table)
 	submenu.append (tableitem)
@@ -57,7 +80,6 @@ class AppWindow(object):
 	
     def _onTableOtherActivate(self, item, group):
 	
-	eitem = self._addTable(self.submenu, group, "CHOCHOCHO.txt")
 	chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
 					buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
  	response = chooser.run()
@@ -69,7 +91,7 @@ class AppWindow(object):
 
     def _onTableActivate(self, item, table):
 	print table
-	self.config_builder['translation']['literaryTextTable']
+	self.config_builder['translation']['literaryTextTable'] = table
 	
 	
 
@@ -193,6 +215,7 @@ class AppWindow(object):
         gtk.main()
 
     def _onQuit(self, window, event=None):
+	self.saveConfig()
         gtk.main_quit()
 
 if __name__ == "__main__":



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