Editing Documentation/Maemo 5 Developer Guide/Using Generic Platform Components/Application Preferences-Gconf

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 39 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 42: Line 42:
What is missing from the above list is storing binary data (for a good reason). The type system is also fairly limited. This is on purpose, so that complex configurations (like the Apache HTTP daemon uses, or Samba) are not attempted using GConf.
What is missing from the above list is storing binary data (for a good reason). The type system is also fairly limited. This is on purpose, so that complex configurations (like the Apache HTTP daemon uses, or Samba) are not attempted using GConf.
-
There is a diagnostic and administration tool called <code>gconftool-2</code> that is also available in the SDK. It can be used to set and unset keys, as well as display their current contents.
+
There is a diagnostic and administration tool called gconftool-2 that is also available in the SDK. It can be used to set and unset keys, as well as display their current contents.
Some examples of using gconftool-2 (on the SDK):
Some examples of using gconftool-2 (on the SDK):
Line 439: Line 439:
</source>
</source>
-
Since the graphical appearance of the program does not change (except that the <code>ColorButton</code> will display the correct initial color), a look will be taken at the stdout display of the program.
+
Since the graphical appearance of the program does not change (except that the ColorButton will display the correct initial color), a look will be taken at the stdout display of the program.
 +
 
 +
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
 +
buildToolbar: loading color pref.
 +
confLoadCurrentColor: invoked
 +
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 +
  confGetInt: key /apps/Maemo/hildon_hello/red not found
 +
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 +
  confGetInt: key /apps/Maemo/hildon_hello/green not found
 +
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 +
  confGetInt: key /apps/Maemo/hildon_hello/blue not found
 +
  loaded color same as default
 +
main: calling gtk_main
 +
cbActionMainToolbarToggle invoked
 +
cbActionColorChanged invoked
 +
  color changed, storing into preferences..
 +
confStoreColor: invoked
 +
  done.
 +
main: returned from gtk_main and exiting with success
-
<pre>
 
-
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
 
-
buildToolbar: loading color pref.
 
-
confLoadCurrentColor: invoked
 
-
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 
-
confGetInt: key /apps/Maemo/hildon_hello/red not found
 
-
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 
-
confGetInt: key /apps/Maemo/hildon_hello/green not found
 
-
hildon_helloworld-9[19840]: GLIB WARNING ** default -
 
-
confGetInt: key /apps/Maemo/hildon_hello/blue not found
 
-
loaded color same as default
 
-
main: calling gtk_main
 
-
cbActionMainToolbarToggle invoked
 
-
cbActionColorChanged invoked
 
-
color changed, storing into preferences..
 
-
confStoreColor: invoked
 
-
done.
 
-
main: returned from gtk_main and exiting with success
 
-
</pre>
 
When running the program for the first time, warnings about the missing keys can be expected (since the values were not present in GConf).
When running the program for the first time, warnings about the missing keys can be expected (since the values were not present in GConf).
Line 465: Line 464:
Run the program again and exit:
Run the program again and exit:
-
<pre>
+
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
-
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
+
buildToolbar: loading color pref.
-
buildToolbar: loading color pref.
+
confLoadCurrentColor: invoked
-
confLoadCurrentColor: invoked
+
  got red = 65535, after clamping = 65535
-
got red = 65535, after clamping = 65535
+
  got green = 65535, after clamping = 65535
-
got green = 65535, after clamping = 65535
+
  got blue = 0, after clamping = 0
-
got blue = 0, after clamping = 0
+
  color not same as default one
-
color not same as default one
+
main: calling gtk_main
-
main: calling gtk_main
+
main: returned from gtk_main and exiting with success
-
main: returned from gtk_main and exiting with success
+
 
-
</pre>
+
The next step is to remove one key (red), and run the program again (this is to test and verify that the logic works):
The next step is to remove one key (red), and run the program again (this is to test and verify that the logic works):
-
 
+
-
<pre>
+
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh gconftool-2  \
-
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh gconftool-2  \
+
  --unset /apps/Maemo/hildon_hello/red
-
--unset /apps/Maemo/hildon_hello/red
+
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh gconftool-2  \
-
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh gconftool-2  \
+
  -R /apps/Maemo/hildon_hello
-
-R /apps/Maemo/hildon_hello
+
  green = 65535
-
green = 65535
+
  blue = 0
-
blue = 0
+
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
-
[sbox-DIABLO_X86: ~/appdev] &gt; run-standalone.sh ./hildon_helloworld-9
+
buildToolbar: loading color pref.
-
buildToolbar: loading color pref.
+
confLoadCurrentColor: invoked
-
confLoadCurrentColor: invoked
+
hildon_helloworld-9[19924]: GLIB WARNING ** default -
-
hildon_helloworld-9[19924]: GLIB WARNING ** default -
+
  confGetInt: key /apps/Maemo/hildon_hello/red not found
-
confGetInt: key /apps/Maemo/hildon_hello/red not found
+
  got green = 65535, after clamping = 65535
-
got green = 65535, after clamping = 65535
+
  got blue = 0, after clamping = 0
-
got blue = 0, after clamping = 0
+
  color not same as default one
-
color not same as default one
+
main: calling gtk_main
-
main: calling gtk_main
+
main: returned from gtk_main and exiting with success
-
main: returned from gtk_main and exiting with success
+
-
</pre>
+
==  Asynchronous GConf ==
==  Asynchronous GConf ==
Line 506: Line 502:
When the configuration needs for the service are simple, and reacting to configuration changes in "realtime" is desired, it is advisable to use GConf. Also, people tend to use GConf when they are too lazy to write their own configuration file parsers (although there is a simple one in GLib), or too lazy to write the GUI part to change the settings. This example program will simulate the first case, and react to changes in a subset of GConf configuration name space when the changes happen.
When the configuration needs for the service are simple, and reacting to configuration changes in "realtime" is desired, it is advisable to use GConf. Also, people tend to use GConf when they are too lazy to write their own configuration file parsers (although there is a simple one in GLib), or too lazy to write the GUI part to change the settings. This example program will simulate the first case, and react to changes in a subset of GConf configuration name space when the changes happen.
-
The application will be interested in two string values; one to set the device to use for communication (connection), and the other to set the communication parameters for the device (connectionparams). Since this example will be concentrating on just the change notifications, the program logic is simplified by omitting the proper set-up code in the program. This means that it is necessary to set up some values to the GConf keys prior to running the program. For this, <code>gconftool-2</code> will be used, and a target has been prepared in the '''Makefile''' just for this (see section [[Documentation/Maemo 5 Developer Guide/GNU Build System#GNU Make and Makefiles|GNU Make and Makefiles]] if necessary): gconf-listener/Makefile
+
The application will be interested in two string values; one to set the device to use for communication (connection), and the other to set the communication parameters for the device (connectionparams). Since this example will be concentrating on just the change notifications, the program logic is simplified by omitting the proper set-up code in the program. This means that it is necessary to set up some values to the GConf keys prior to running the program. For this, gconftool-2 will be used, and a target has been prepared in the '''Makefile''' just for this (see section [[Documentation/Maemo_5_Developer_Guide/GNU_Build_System#GNU_Make_and_Makefiles GNU Make and Makefiles]] if necessary): gconf-listener/Makefile
<source lang="make">
<source lang="make">
Line 532: Line 528:
</source>
</source>
-
The next step is to prepare the keyspace by running the <code>primekeys</code> target, and to verify that it succeeds by running the <code>dumpkeys</code> target:
+
The next step is to prepare the keyspace by running the primekeys target, and to verify that it succeeds by running the dumpkeys target:
<pre>
<pre>
Line 611: Line 607:
</source>
</source>
-
The <code>dispStringKey</code> utility is rather simple as well, building on the GConf material that was covered in the [[#Using GConf to read and write preferences|previous section]]: gconf-listener/gconf-key-watch.c
+
The dispStringKey utility is rather simple as well, building on the GConf material that was covered in the previous section [localhost#sec:using_gconf_to_read_write_pref 9.3.2]<nowiki>: </nowiki>gconf-listener/gconf-key-watch.c
<source lang="c">
<source lang="c">
Line 814: Line 810:
The complications in the above code rise from the fact that GConf communicates values using a <code>GValue</code> structure, which can carry values of any simple type. Since GConf (or the user for that matter) cannot be completely trusted to return the correct type for the value, it is necessary to be extra careful, and not assume that it will always be a string. GConf also supports "default" values, which are communicated to the application using <code>NULL</code>s, so it is also necessary to guard against that. Especially since the application does not provide a schema for the configuration space that would contain the default values.
The complications in the above code rise from the fact that GConf communicates values using a <code>GValue</code> structure, which can carry values of any simple type. Since GConf (or the user for that matter) cannot be completely trusted to return the correct type for the value, it is necessary to be extra careful, and not assume that it will always be a string. GConf also supports "default" values, which are communicated to the application using <code>NULL</code>s, so it is also necessary to guard against that. Especially since the application does not provide a schema for the configuration space that would contain the default values.
-
The next step is to build and test the program. The program will be started on the background, so that <code>gconftool-2</code> can be used to see how the program reacts to changing parameters:
+
The next step is to build and test the program. The program will be started on the background, so that gconftool-2 can be used to see how the program reacts to changing parameters:
<pre>
<pre>
Line 848: Line 844:
One option would also be resetting the value back to a valid value, whenever the program detects an invalid value set attempt. This will lead to a lot of problems, if the value is set programmatically from another program that will obey the same rule, so it is not advisable. Quitting the program on invalid values is also an option that should not be used, since the restricted environment does not provide many ways to inform the user that the program has quit.
One option would also be resetting the value back to a valid value, whenever the program detects an invalid value set attempt. This will lead to a lot of problems, if the value is set programmatically from another program that will obey the same rule, so it is not advisable. Quitting the program on invalid values is also an option that should not be used, since the restricted environment does not provide many ways to inform the user that the program has quit.
-
An additional possible problem is having multiple keys that are all "related" to a single setting or action. It is necessary to decide, how to deal with changes across multiple GConf keys that are related, yet changed separately. The two key example code demonstrates the inherent problem: should the server re-initialize the (theoretic) connection, when the connection key is changed, or when the connectionparams key is changed? If the connection is re-initialized when either of the keys is changed, then the connection will be re-initialized twice when both are changed "simultaneously" (user presses "Apply" on a settings dialog, or gconftool-2 is run and sets both keys). It is easy to see how this might be an even larger problem, if instead of two keys, there were five per connection. GConf and the <code>GConfClient</code> <code>GObject</code> wrapper that has been used here do not support "configuration set transactions", which would allow setting and processing multiple related keys using an atomic model. The example program ignores this issue completely.
+
An additional possible problem is having multiple keys that are all "related" to a single setting or action. It is necessary to decide, how to deal with changes across multiple GConf keys that are related, yet changed separately. The two key example code demonstrates the inherent problem: should the server re-initialize the (theoretic) connection, when the connection key is changed, or when the connectionparams key is changed? If the connection is re-initialized when either of the keys is changed, then the connection will be re-initialized twice when both are changed "simultaneously" (user presses "Apply" on a settings dialog, or gconftool-2 is run and sets both keys). It is easy to see how this might be an even larger problem, if instead of two keys, there were five per connection. GConf and the GConfClient GObject wrapper that has been used here do not support "configuration set transactions", which would allow setting and processing multiple related keys using an atomic model. The example program ignores this issue completely.
The next step is to test how the program (which is still running) reacts to other problematic situations:
The next step is to test how the program (which is still running) reacts to other problematic situations:

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)