## gnome-program

gnome-program — Initialize and retrieve information about a GNOME application.

## Synopsis

    #include <libgnome/libgnome.h>

    enum        GnomeFileDomain;
    struct      GnomeProgram;
    struct      GnomeModuleInfo;
    struct      GnomeModuleRequirement;
    void        (*GnomeModuleInitHook)          (const GnomeModuleInfo *mod_info);
    void        (*GnomeModuleClassInitHook)     (GnomeProgramClass *klass,
                                                 const GnomeModuleInfo *mod_info);
    void        (*GnomeModuleHook)              (GnomeProgram *program,
                                                 GnomeModuleInfo *mod_info);
    GnomeProgram* gnome_program_init            (const char *app_id,
                                                 const char *app_version,
                                                 const GnomeModuleInfo *module_info,
                                                 int argc,
                                                 char **argv,
                                                 const char *first_property_name,
                                                 ...);
    GnomeProgram* gnome_program_initv           (GType type,
                                                 const char *app_id,
                                                 const char *app_version,
                                                 const GnomeModuleInfo *module_info,
                                                 int argc,
                                                 char **argv,
                                                 const char *first_property_name,
                                                 va_list args);

    GnomeProgram* gnome_program_get             (void);
    const char* gnome_program_get_human_readable_name
                                                (GnomeProgram *program);
    const char* gnome_program_get_app_id        (GnomeProgram *program);
    const char* gnome_program_get_app_version   (GnomeProgram *program);
    gchar*      gnome_program_locate_file       (GnomeProgram *program,
                                                 GnomeFileDomain domain,
                                                 const gchar *file_name,
                                                 gboolean only_if_exists,
                                                 GSList **ret_locations);

    void        gnome_program_module_register   (const GnomeModuleInfo *module_info);
    gboolean    gnome_program_module_registered (const GnomeModuleInfo *module_info);
    const GnomeModuleInfo* gnome_program_module_load
                                                (const char *mod_name);
    guint       gnome_program_install_property  (GnomeProgramClass *pclass,
                                                 GObjectGetPropertyFunc get_fn,
                                                 GObjectSetPropertyFunc set_fn,
                                                 GParamSpec *pspec);
    poptContext gnome_program_preinit           (GnomeProgram *program,
                                                 const char *app_id,
                                                 const char *app_version,
                                                 int argc,
                                                 char **argv);
    void        gnome_program_parse_args        (GnomeProgram *program);
    void        gnome_program_postinit          (GnomeProgram *program);

    #define     GNOME_PARAM_POPT_TABLE
    #define     GNOME_PARAM_POPT_FLAGS
    #define     GNOME_PARAM_POPT_CONTEXT
    #define     GNOME_PARAM_CREATE_DIRECTORIES
    #define     GNOME_PARAM_ENABLE_SOUND
    #define     GNOME_PARAM_ESPEAKER
    #define     GNOME_PARAM_APP_ID
    #define     GNOME_PARAM_APP_VERSION
    #define     GNOME_PARAM_GNOME_PREFIX
    #define     GNOME_PARAM_GNOME_SYSCONFDIR
    #define     GNOME_PARAM_GNOME_DATADIR
    #define     GNOME_PARAM_GNOME_LIBDIR
    #define     GNOME_PARAM_APP_PREFIX
    #define     GNOME_PARAM_APP_SYSCONFDIR
    #define     GNOME_PARAM_APP_DATADIR
    #define     GNOME_PARAM_APP_LIBDIR
    #define     GNOME_PARAM_HUMAN_READABLE_NAME
    #define     GNOME_PARAM_GNOME_PATH
    #define     GNOME_PARAM_NONE
    #define     GNOME_PROGRAM_STANDARD_PROPERTIES

## Description

## Details

### enum GnomeFileDomain

    typedef enum {
        GNOME_FILE_DOMAIN_UNKNOWN = 0,

        /* Gnome installed files */
        GNOME_FILE_DOMAIN_LIBDIR,
        GNOME_FILE_DOMAIN_DATADIR,
        GNOME_FILE_DOMAIN_SOUND,
        GNOME_FILE_DOMAIN_PIXMAP,
        GNOME_FILE_DOMAIN_CONFIG,
        GNOME_FILE_DOMAIN_HELP,

        /* Application files */
        GNOME_FILE_DOMAIN_APP_LIBDIR,
        GNOME_FILE_DOMAIN_APP_DATADIR,
        GNOME_FILE_DOMAIN_APP_SOUND,
        GNOME_FILE_DOMAIN_APP_PIXMAP,
        GNOME_FILE_DOMAIN_APP_CONFIG,
        GNOME_FILE_DOMAIN_APP_HELP
    } GnomeFileDomain;

Many of the files that a GNOME application needs to access will be installed in standard locations. For example, GNOME help files will be in one location, while help files specific to the current application might be in another location.

The different types of files are given in this enum. User applications make use of the `GNOME_FILE_DOMAIN_APP_*` types, which specify locations relative to GNOME_PARAM_APP_DATADIR.

`GNOME_FILE_DOMAIN_UNKNOWN` | An unknown file domain (should never be used).
`GNOME_FILE_DOMAIN_LIBDIR` | Libraries in the main GNOME installation.
`GNOME_FILE_DOMAIN_DATADIR` | Data files in the main GNOME installation.
`GNOME_FILE_DOMAIN_SOUND` | Sound files in the main GNOME installation.
`GNOME_FILE_DOMAIN_PIXMAP` | Pixmap files in the main GNOME installation.
`GNOME_FILE_DOMAIN_CONFIG` | Config files in the main GNOME installation.
`GNOME_FILE_DOMAIN_HELP` | Help files in the main GNOME installation.
`GNOME_FILE_DOMAIN_APP_LIBDIR` | Application specific libraries.
`GNOME_FILE_DOMAIN_APP_DATADIR` | Application specific data files.
`GNOME_FILE_DOMAIN_APP_SOUND` | Application specific sound files.
`GNOME_FILE_DOMAIN_APP_PIXMAP` | Application specific pixmap files.
`GNOME_FILE_DOMAIN_APP_CONFIG` | Application specific config files.
`GNOME_FILE_DOMAIN_APP_HELP` | Application specific help files.

### struct GnomeProgram

    struct GnomeProgram {

        GObject object;

        GnomeProgramPrivate *_priv;
    };

A structure containing information about the current application. Initialised during a call to `gnome_program_init()`.

GObject `object` | A GObject containing the parameters and their values which were set dring initialisation.
GnomeProgramPrivate *`_priv` | Private data about the program instance.

### struct GnomeModuleInfo

    struct GnomeModuleInfo {

        const char *name;
        const char *version;
        const char *description;
        GnomeModuleRequirement *requirements; /* last element has NULL version */

        GnomeModuleHook instance_init;
        GnomeModuleHook pre_args_parse, post_args_parse;

        struct poptOption *options;

        GnomeModuleInitHook init_pass;

        GnomeModuleClassInitHook class_init;

        const char *opt_prefix;
        gpointer    expansion1;
    };

A structure containing information about a module. This contains descriptive information about the module, as well as how to initialise it and what its dependencies are (chained via the `requirements` parameter).

const char *`name` | The module name.
const char *`version` | The module's version string.
const char *`description` | A string describing the module (can be `NULL`).
GnomeModuleRequirement *`requirements` | A pointer to an array of modules that are required by this module. The last module in the array should have its required_version field set to `NULL`.
GnomeModuleHook `instance_init` | A function to call to initialise an instance of this module (can be `NULL`).
GnomeModuleHook `pre_args_parse` | A function to call before parsing the arguments for this module (can be `NULL`).
GnomeModuleHook `post_args_parse` | A function to call after parsing the arguments for this module (can be `NULL`).
struct poptOption *`options` | A poptOption structure giving any special arguments for this module (can be `NULL`).
GnomeModuleInitHook `init_pass` | A function which is run before the `init_instance` function to allow the module to register other modules as needed. The module cannot assume its required modules are initialized (although they might be).
GnomeModuleClassInitHook `class_init` | A function to call to initialise this module prior to creating any instances (can be `NULL`).
const char *`opt_prefix` | Unused.
gpointer `expansion1` | Unused.

### struct GnomeModuleRequirement

    struct GnomeModuleRequirement {

        const char *required_version;
        const GnomeModuleInfo *module_info;
    };

A structure which allows a module to specify the minimum required versions of modules it depends upon.

const char *`required_version` | The version required by the parent module.
const GnomeModuleInfo *`module_info` | A GnomeModuleInfo structure detailing the required module.

### GnomeModuleInitHook ()

    void        (*GnomeModuleInitHook)          (const GnomeModuleInfo *mod_info);

A function that will be called to allow a module to do any pre-initialisation it might need to do prior to having arguments parsed by the controlling parent module (the parent will do the argument parsing for all modules in the hierarchy).

`mod_info` : | The current module.

### GnomeModuleClassInitHook ()

    void        (*GnomeModuleClassInitHook)     (GnomeProgramClass *klass,
                                                 const GnomeModuleInfo *mod_info);

A function called to perform any class specific setup that is required by each module.

`klass` : | The class of the parent module (which could be this module's class). This will usually be GnomeProgramClass.
`mod_info` : | The current module.

### GnomeModuleHook ()

    void        (*GnomeModuleHook)              (GnomeProgram *program,
                                                 GnomeModuleInfo *mod_info);

A function that is called to perform some intialisation in a module (which could be either the main init function or the pre or post argument parsing phase).

`program` : | The GnomeProgram instance which is being initialised.
`mod_info` : | The current module's GnomeModuleInfo structure.

### gnome_program_init ()

    GnomeProgram* gnome_program_init            (const char *app_id,
                                                 const char *app_version,
                                                 const GnomeModuleInfo *module_info,
                                                 int argc,
                                                 char **argv,
                                                 const char *first_property_name,
                                                 ...);

Initialises the current GNOME libraries for use by the application.

Every GNOME application will need to call this function (or `gnome_program_initv()`) early in its lifetime to initialize the various GNOME libraries in a consistent fashion. This function is very flexible in allowing the user to specify which modules should be initialised and any special paramter values that should be passed to these modules (along with processing commandline options).

It loads the specified `module_info`, which is normally LIBGNOME_MODULE or LIBGNOMEUI_MODULE and pulls in all the dependencies. Programs that are not running in setuid or setgid mode will also load modules specified in the `--load-modules` and also in the `GNOME_MODULES` environment variable.

After setting up the module loading, this function then calls (in order) `gnome_program_preinit()`, `gnome_program_parse_args()` and `gnome_program_postinit()`.

The following example shows how one might initialise a typical program using a popt table that is defined elsewhere (in other words, this is how to remove the use of the deprecated `gnome_init_with_popt_table()` from code).

Example 1. Initializing a GNOME application

    int main(int argc, char **argv) {
    	GnomeProgram *my_app;

    	/* We assume PACKAGE and VERSION are set the program name and version
    	 * number respectively. Also, assume the 'options' is a global array of
    	 * poptOptions.
    	 */
    	my_app = gnome_program_init(PACKAGE, VERSION, LIBGNOMEUI_MODULE,
    	                            argc, argv, GNOME_PARAM_POPT_TABLE, options,
    				    GNOME_PARAM_NONE);
    	/* Now process any extra args, etc ... */
    }

`app_id` : | Application ID string.
`app_version` : | Application version string.
`module_info` : | The module to init with this program.
`argc` : | The number of commmand line arguments contained in `argv`.
`argv` : | A string array of command line arguments.
`first_property_name` : | The first item in a `NULL`-terminated list of attribute name and value pairs (so this will be an attribute name or `NULL`).
`...` : | The continuation of a `NULL`-terminated list of attribute name/value pairs.
Returns : | A GnomeProgram instance representing the current application.

### gnome_program_initv ()

    GnomeProgram* gnome_program_initv           (GType type,
                                                 const char *app_id,
                                                 const char *app_version,
                                                 const GnomeModuleInfo *module_info,
                                                 int argc,
                                                 char **argv,
                                                 const char *first_property_name,
                                                 va_list args);

Provides a non-varargs form of `gnome_program_init()`. Users will rarely need to call this function directly.

`type` : | The type of application to be initialized (usually GNOME_TYPE_PROGRAM).
`app_id` : | Application ID string.
`app_version` : | Application version string.
`module_info` : | The modules to init with the application.
`argc` : | The number of command line arguments contained in `argv`.
`argv` : | A string array of command line arguments.
`first_property_name` : | The first item in a `NULL`-terminated list of attribute name/value.
`args` : | The remaining elements in the `NULL` terminated list (of which `first_property_name` is the first element).
Returns : | A GnomeProgram instance representing the current application.

### gnome_program_get ()

    GnomeProgram* gnome_program_get             (void);

Retrieves an object that stored information about the application's state. Other functions assume this will always return a GnomeProgram object which (if not `NULL`) has already been initialized.

Returns : | The application's GnomeProgram instance, or `NULL` if it does not exist.

### gnome_program_get_human_readable_name ()

    const char* gnome_program_get_human_readable_name
                                                (GnomeProgram *program);

This function returns a pointer to a static string that the application has provided as a human readable name. The app should provide the name with the GNOME_PARAM_HUMAN_READABLE_NAME init argument. Returns `NULL` if no name was set.

`program` : | The application object
Returns : | Application human-readable name string.

### gnome_program_get_app_id ()

    const char* gnome_program_get_app_id        (GnomeProgram *program);

This function returns a pointer to a static string that the application has provided as an identifier. This is not meant as a human-readable identifier so much as a unique identifier for programs and libraries.

`program` : | The program object
Returns : | Application ID string.

### gnome_program_get_app_version ()

    const char* gnome_program_get_app_version   (GnomeProgram *program);

This function returns a pointer to a static string that the application has provided as a version number. This is not meant as a human-readable identifier so much as a unique identifier for programs and libraries.

`program` : | The application object
Returns : | Application version string.

### gnome_program_locate_file ()

    gchar*      gnome_program_locate_file       (GnomeProgram *program,
                                                 GnomeFileDomain domain,
                                                 const gchar *file_name,
                                                 gboolean only_if_exists,
                                                 GSList **ret_locations);

This function finds a full path to the `file_name` located in the specified "domain". A domain is a name for a collection of related files. For example, common domains are "libdir", "pixmap", and "config".

If `ret_locations` is `NULL`, only one pathname is returned. Otherwise, alternative paths are returned in `ret_locations`.

User applications should store files in the GNOME_FILE_DOMAIN_APP_* domains. However you MUST set the correct attributes for GnomeProgram for the APP specific prefixes (during the initialization part of the application).

The `ret_locations` list and its contents should be freed by the caller, as should the returned string.

`program` : | A valid GnomeProgram object or `NULL` (in which case the current application is used).
`domain` : | A GnomeFileDomain.
`file_name` : | A file name or path inside the 'domain' to find.
`only_if_exists` : | Only return a full pathname if the specified file actually exists
`ret_locations` : | If this is not `NULL`, a list of all the possible locations of the file will be returned.
Returns : | The full path to the file (if it exists or only_if_exists is `FALSE`) or `NULL`.

### gnome_program_module_register ()

    void        gnome_program_module_register   (const GnomeModuleInfo *module_info);

This function is used to register a module to be initialized by the GNOME library framework. The memory pointed to by `module_info` must be valid during the whole application initialization process, and the module described by `module_info` must only use the `module_info` pointer to register itself.

`module_info` : | A pointer to a GnomeModuleInfo structure describing the module to be initialized

### gnome_program_module_registered ()

    gboolean    gnome_program_module_registered (const GnomeModuleInfo *module_info);

This method checks to see whether a specific module has been initialized in the specified program.

`module_info` : | A pointer to a GnomeModuleInfo structure describing the module to be queried
Returns : | A value indicating whether the specified module has been registered/initialized in the current program

### gnome_program_module_load ()

    const GnomeModuleInfo* gnome_program_module_load
                                                (const char *mod_name);

Loads a shared library that contains a GnomeModuleInfo dynamic_module_info structure.

`mod_name` : | module name
Returns : | The GnomeModuleInfo structure that was loaded, or `NULL` if the module could not be loaded.

### gnome_program_install_property ()

    guint       gnome_program_install_property  (GnomeProgramClass *pclass,
                                                 GObjectGetPropertyFunc get_fn,
                                                 GObjectSetPropertyFunc set_fn,
                                                 GParamSpec *pspec);

Install a collection of available properties, their default values and the functions to set and retrieve these properties.

Normal applications will never need to call this function, it is mostly for use by other platform library authors.

`pclass` : | A GnomeProgramClass.
`get_fn` : | A function to get property values.
`set_fn` : | A function to set property values.
`pspec` : | A collection of properties.
Returns : | The number of properties installed.

### gnome_program_preinit ()

    poptContext gnome_program_preinit           (GnomeProgram *program,
                                                 const char *app_id,
                                                 const char *app_version,
                                                 int argc,
                                                 char **argv);

This function performs the portion of application initialization that needs to be done prior to command line argument parsing. The poptContext returned can be used for `getopt()`-style option processing.

`program` : | Application object
`app_id` : | application ID string
`app_version` : | application version string
`argc` : | The number of commmand line arguments contained in 'argv'
`argv` : | A string array of command line arguments
Returns : | A poptContext representing the argument parsing state.

### gnome_program_parse_args ()

    void        gnome_program_parse_args        (GnomeProgram *program);

Parses the command line arguments for the application

`program` : | Application object

### gnome_program_postinit ()

    void        gnome_program_postinit          (GnomeProgram *program);

Called after `gnome_program_parse_args()`, this function takes care of post-parse initialization and cleanup

`program` : | Application object

### GNOME_PARAM_POPT_TABLE

    #define GNOME_PARAM_POPT_TABLE          "popt-table"

This parameter contains the table of options to be passed to popt (write on init only).

### GNOME_PARAM_POPT_FLAGS

    #define GNOME_PARAM_POPT_FLAGS          "popt-flags"

This parameter contains the flags to use for popt (write on init only).

### GNOME_PARAM_POPT_CONTEXT

    #define GNOME_PARAM_POPT_CONTEXT        "popt-context"

This parameter contains the context pointer that GnomeProgram is using for popt parsing (readable).

### GNOME_PARAM_CREATE_DIRECTORIES

    #define GNOME_PARAM_CREATE_DIRECTORIES  "create-directories"

This parameter contains `TRUE` if the standard GNOME directories should be created on startup.

### GNOME_PARAM_ENABLE_SOUND

    #define GNOME_PARAM_ENABLE_SOUND        "enable-sound"

This parameter determines whether or not to enable sound on startup.

### GNOME_PARAM_ESPEAKER

    #define GNOME_PARAM_ESPEAKER            "espeaker"

This parameter describes how to connect to esd.

### GNOME_PARAM_APP_ID

    #define GNOME_PARAM_APP_ID              "app-id"

This parameter contains the ID string to use for the application (readable).

### GNOME_PARAM_APP_VERSION

    #define GNOME_PARAM_APP_VERSION         "app-version"

This parameter contains the application version (readable).

### GNOME_PARAM_GNOME_PREFIX

    #define GNOME_PARAM_GNOME_PREFIX        "gnome-prefix"

This parameter contains the prefix where the main GNOME system is installed (readable, writable on init only).

### GNOME_PARAM_GNOME_SYSCONFDIR

    #define GNOME_PARAM_GNOME_SYSCONFDIR    "gnome-sysconfdir"

This parameter contains the prefix where the GNOME configuration files are installed (readable, writable on init only).

### GNOME_PARAM_GNOME_DATADIR

    #define GNOME_PARAM_GNOME_DATADIR       "gnome-datadir"

This parameter contains the prefix where the GNOME data files are installed (readable, writable on init only).

### GNOME_PARAM_GNOME_LIBDIR

    #define GNOME_PARAM_GNOME_LIBDIR        "gnome-libdir"

This parameter contains the prefix where the GNOME library files are installed (readable, writable on init only).

### GNOME_PARAM_APP_PREFIX

    #define GNOME_PARAM_APP_PREFIX          "app-prefix"

This parameter contains the prefix where this application was installed (read / write).

### GNOME_PARAM_APP_SYSCONFDIR

    #define GNOME_PARAM_APP_SYSCONFDIR      "app-sysconfdir"

This parameter contains the prefix where this application's configuration files are installed (read / write).

### GNOME_PARAM_APP_DATADIR

    #define GNOME_PARAM_APP_DATADIR         "app-datadir"

This parameter contains the prefix where this application's data files are installed (read / write).

### GNOME_PARAM_APP_LIBDIR

    #define GNOME_PARAM_APP_LIBDIR          "app-libdir"

This parameter contains the prefix where this application's library files are installed (read / write).

### GNOME_PARAM_HUMAN_READABLE_NAME

    #define GNOME_PARAM_HUMAN_READABLE_NAME "human-readable-name"

This parameter contains the human readable name of the application (readable).

### GNOME_PARAM_GNOME_PATH

    #define GNOME_PARAM_GNOME_PATH          "gnome-path"

This parameter contains the path in which to look for installed files (taken from the GNOME2_PATH environment variable).

### GNOME_PARAM_NONE

    #define GNOME_PARAM_NONE                NULL

Used to terminate a list of parameters and their values.

### GNOME_PROGRAM_STANDARD_PROPERTIES

    #define     GNOME_PROGRAM_STANDARD_PROPERTIES

When PREFIX, SYSCONFDIR, DATADIR and LIBDIR are defined during the build process, this macro can be used to assign these values to GNOME_PARAM_APP_PREFIX, GNOME_PARAM_APP_SYSCONFDIR, GNOME_PARAM_APP_DATADIR and GNOME_PARAM_APP_LIBDIR respectively so that the GNOME libraries automatically know where to fetch application specific data from.

Every respectable GNOME application should set these variables and use GNOME_PROGRAM_STANDARD_PROPERTIES in the call to `gnome_program_init()`.