Search
lxdream.org :: lxdream/src/config.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/config.h
changeset 1036:af7b0c5905dd
prev1034:7044e01148f0
next1038:f220d18c0615
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * User configuration support
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #ifndef lxdream_config_H
    20 #define lxdream_config_H 1
    22 #include <glib/gtypes.h>
    23 #include <glib/glist.h>
    24 #include "gettext.h"
    26 #ifdef __cplusplus
    27 extern "C" {
    28 #endif
    30 #define CONFIG_TYPE_NONE 0
    31 #define CONFIG_TYPE_FILE 1
    32 #define CONFIG_TYPE_PATH 2
    33 #define CONFIG_TYPE_KEY 3
    34 #define CONFIG_TYPE_FILELIST 4
    36 #define DEFAULT_CONFIG_FILENAME "lxdreamrc"
    38 typedef struct lxdream_config_entry {
    39     const gchar *key;
    40     const gchar *label; // i18n 
    41     const int type;
    42     const gchar *default_value;
    43     gchar *value;
    44 } *lxdream_config_entry_t;
    46 typedef struct lxdream_config_group {
    47     const gchar *key;
    48     struct lxdream_config_entry *params;
    49 } *lxdream_config_group_t;
    51 #define CONFIG_BIOS_PATH 0
    52 #define CONFIG_FLASH_PATH 1
    53 #define CONFIG_DEFAULT_PATH 2
    54 #define CONFIG_SAVE_PATH 3
    55 #define CONFIG_VMU_PATH 4
    56 #define CONFIG_BOOTSTRAP 5
    57 #define CONFIG_GDROM 6
    58 #define CONFIG_RECENT 7
    59 #define CONFIG_VMU 8
    60 #define CONFIG_KEY_MAX CONFIG_VMU
    62 extern struct lxdream_config_group lxdream_config_root[];
    64 /* Global config values */
    65 const gchar *lxdream_get_global_config_value( int key );
    66 const struct lxdream_config_entry * lxdream_get_global_config_entry( int key );
    67 void lxdream_set_global_config_value( int key, const gchar *value );
    69 void lxdream_register_config_group( const gchar *key, lxdream_config_entry_t group ); 
    70 void lxdream_set_config_value( lxdream_config_entry_t entry, const gchar *value );
    71 gboolean lxdream_set_group_value( lxdream_config_group_t group, const gchar *key, const gchar *value );
    72 void lxdream_copy_config_list( lxdream_config_entry_t dest, lxdream_config_entry_t src );
    74 /**
    75  * Return a fully expanded path value for a key - this performs substitutions
    76  * for ~ and simple shell variables ($VAR and ${VAR})
    77  * 
    78  * The returned string is newly allocated and must be freed by the caller
    79  */
    80 gchar *lxdream_get_global_config_path_value( int key );
    82 /**
    83  * Set a path value for a key, escaping if necessary to protect against 
    84  * shell-substitution on the round trip.
    85  * 
    86  * @return the resultant config value.
    87  */
    88 const gchar *lxdream_set_global_config_path_value( int key, const gchar *value );
    90 /**
    91  * Construct a list of strings for the given config key - The caller is 
    92  * responsible for freeing the list and its values.
    93  */
    94 GList *lxdream_get_global_config_list_value( int key );
    96 /**
    97  * Set a config key based on a list of strings. 
    98  */
    99 void lxdream_set_global_config_list_value( int key, const GList *list );
   100 /**
   101  * Search the standard locations for the configuration file:
   102  *   $HOME/.lxdreamrc
   103  *   $CWD/lxdreamrc
   104  *   $SYSCONF_DIR/lxdreamrc
   105  * @return TRUE if the file was found, otherwise FALSE.
   106  */
   107 gboolean lxdream_find_config( );
   109 /**
   110  * Set the configuration file filename to the supplied string.
   111  * The string is copied internally (ie can be released by the
   112  * caller).
   113  */
   114 void lxdream_set_config_filename( const gchar *filename );
   116 /**
   117  * Load the configuration from the previously determined filename.
   118  */
   119 gboolean lxdream_load_config( );
   121 /**
   122  * Update the configuration
   123  */
   124 gboolean lxdream_save_config( );
   126 /**
   127  * Escape a pathname if needed to prevent shell substitution.
   128  * @return a newly allocated string (or NULL if the input is NULL)
   129  */
   130 gchar *get_escaped_path( const gchar *name );
   132 /**
   133  * Expand a pathname according to standard shell substitution rules
   134  * (excluding command substitutions).
   135  * @return a newly allocated string (or NULL if the input is NULL)
   136  */
   137 gchar *get_expanded_path( const gchar *name );
   139 #ifdef __cplusplus
   140 }
   141 #endif
   143 #endif /* !lxdream_config_H */
.