InformationSoftwareDevelopmentTutorials Valid XHTML 1.0!SF logo

Choices system

Information pages: Title page - Overview - Introduction - Help installing - Guide - News - Screenshots - Comments - FAQ - Choices system - App dirs - Contact

This document details the choices system, as used in the ROX desktop. Comments are welcome. Programmers writing programs which have nothing to do with the ROX Desktop are still encouraged to consider using this system.

02-Jun-2000: The default value for the CHOICESPATH variable has changed. Please update your programs...

06-Jan-2004: Freedesktop.org are developing a similar system: the Desktop base directory spec. It works in much the same way as the choices system described below, and we may well adopt it at some point. To avoid name conflicts, subdirectories should probably be created with a domain name you control (eg ~/.config/rox.sourceforge.net/...).

Overview

Traditionally, Unix programs have stored user choices inside a file starting with '.' inside the user's home directory. This new system attempts to provide a better way - here are its main features:

Details

The choices system is controlled by a single environment variable, CHOICESPATH. Usuaully this will not be set, in which case the default value of ${HOME}/Choices:/usr/local/share/Choices:/usr/share/Choices will always be assumed (where ${HOME} is replaced by the user's home directory).

User's view

Distribution-wide choices go in the directory /usr/share/Choices. These will be set up by the people who made your distribution and you never need to change these. Installing new packages may put new defaults in here. System-wide choices that override these go in /usr/local/share/Choices. Whoever manages your system controls what goes here. Your personal choices, which override distribution-wide and system-wide choices, go in /home/fred/Choices (replace /home/fred with your home directory).

If you want your choices hidden, set CHOICESPATH so that your Choices directory starts with a dot, eg: /home/fred/.choices:/usr/local/share/Choices:/usr/share/Choices.

If you don't want any choices to be saved then put a colon at the start, eg: :/home/fred/.choices:/usr/local/share/Choices:/usr/share/Choices.

Loading choices

The environment variable is a list of directories, separated by colons. Each of these directories contains sub-directories - one for each program which has saved choices. When a program wishes to load a configuration file it checks each directory in the path in turn (left to right) for a directory with the program's name containing the required file.

So, if a program called ROX-Filer wants to load a file called options then, with the default value of CHOICESPATH for the user fred, it will check for the following files, in order:

  1. /home/fred/Choices/ROX-Filer/options
  2. /usr/local/share/Choices/ROX-Filer/options
  3. /usr/share/Choices/ROX-Filer/options

It will use the first one it finds. A program may, at its option, choose to merge the values in all of these files provided that options set in the earlier files always override options set in the later ones. Any options not set should use built-in default values.

CHOICESPATH may start with a colon - simply ignore the colon. If CHOICESPATH is set, but to an empty string, then there are no choices to load. Do not complain to the user in either case.

It is not an error if some of the directories in CHOICESPATH do not exist or if they do not contain a sub-directory with your program's name - simply ignore these directories.

I recommend that if you cannot find any configuration files when you load that you do NOT automatically create some (or prompt the user). If you can generate some default values now, you can do it next time you load too. In particular, you should NEVER create or offer to create config files if the user has disabled saving of choices (see User's view).

Saving choices

When you wish to save some options / state data you should:

  1. Extract the first directory from CHOICESPATH.
  2. Ensure that the directory exists, and contains a sub-directory with your program's name (create new directories if necessary).
  3. Save the file(s) in the sub-directory.

If CHOICESPATH is set, but starts with a colon or is an empty string then choices cannot be saved. Automatic saving of state should simply be skipped. If the user specifically asked the program to save then display an error message.

Example:
Imagine that the user has quit your program, MegaEdit, and you want to save the current files, colours, etc:

  1. If CHOICESPATH starts with a colon or is empty then you silently skip the saving stage.
  2. Otherwise:
    1. Get the first directory (eg /home/fred/Choices).
    2. Make sure it exists (create it if necessary).
    3. Make sure /home/fred/Choices/MegaEdit exists (create it if necessary).
    4. Saves the file(s) as /home/fred/Choices/MegaEdit/colours, etc.
The choices directory should be created with all permissions allowed (rwxrwxrwx), subject to the umask of course. Subdirectories will usually be the same, but if the data saved is sensitive then more restricted permissions may be used.
ROX project admin and website maintainer : Thomas Leonard [ GPG key ]
Please send questions about the ROX applications to the mailing lists, not directly to me.
Emails sent directly to me will likely be either ignored or forwarded to the list.