Search
lxdream.org :: lxdream/src/config.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/config.h
changeset 1072:d82e04e6d497
prev1041:5fcc39857c5c
next1144:00dd49743974
author nkeynes
date Wed Sep 08 08:43:15 2010 +1000 (13 years ago)
permissions -rw-r--r--
last change Actually report the error when the command-line disc or bin couldn't be loaded
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 "lxdream.h"
    25 #include "gettext.h"
    27 #ifdef __cplusplus
    28 extern "C" {
    29 #endif
    31 #define CONFIG_MAX_KEYS 24
    33 #define CONFIG_TYPE_NONE 0
    34 #define CONFIG_TYPE_FILE 1
    35 #define CONFIG_TYPE_PATH 2
    36 #define CONFIG_TYPE_KEY 3
    37 #define CONFIG_TYPE_FILELIST 4
    38 #define CONFIG_TYPE_INTEGER 5
    40 #define DEFAULT_CONFIG_FILENAME "lxdreamrc"
    42 typedef struct lxdream_config_entry {
    43     const gchar *key;
    44     const gchar *label; // i18n 
    45     int type;
    46     const gchar *default_value;
    47     uint32_t tag;
    48     gchar *value;
    49 } *lxdream_config_entry_t;
    51 struct lxdream_config_group;
    53 /**
    54  * Callback invoked for key presses (key-up/key-down).
    55  */
    56 typedef void (*key_binding_t)( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );
    58 /**
    59  * Callback invoked immediately before updating a configuration item.
    60  * @return FALSE to abort the change (ie invalid value), or TRUE to proceed normally. 
    61  */
    62 typedef gboolean (*config_change_callback_t)( void *data, struct lxdream_config_group *group, unsigned item,
    63                                    const gchar *oldval, const gchar *newval );
    65 typedef struct lxdream_config_group {
    66     const gchar *key;
    67     config_change_callback_t on_change;
    68     key_binding_t key_binding;
    69     void *data;
    70     struct lxdream_config_entry params[CONFIG_MAX_KEYS];
    71 } *lxdream_config_group_t;
    73 #define CONFIG_BIOS_PATH 0
    74 #define CONFIG_FLASH_PATH 1
    75 #define CONFIG_DEFAULT_PATH 2
    76 #define CONFIG_SAVE_PATH 3
    77 #define CONFIG_VMU_PATH 4
    78 #define CONFIG_BOOTSTRAP 5
    79 #define CONFIG_GDROM 6
    80 #define CONFIG_RECENT 7
    81 #define CONFIG_VMU 8
    82 #define CONFIG_QUICK_STATE 9
    83 #define CONFIG_KEY_MAX CONFIG_QUICK_STATE
    85 #define CONFIG_GROUP_GLOBAL 0
    86 #define CONFIG_GROUP_HOTKEYS 2
    87 #define CONFIG_GROUP_SERIAL 3
    90 /* Global config values */
    91 const gchar *lxdream_get_global_config_value( int key );
    92 struct lxdream_config_group * lxdream_get_config_group( int group );
    93 void lxdream_set_global_config_value( int key, const gchar *value );
    95 void lxdream_register_config_group( const gchar *key, lxdream_config_group_t group ); 
    96 gboolean lxdream_set_config_value( lxdream_config_group_t group, int key, const gchar *value );
    97 void lxdream_copy_config_group( lxdream_config_group_t dest, lxdream_config_group_t src );
    98 void lxdream_clone_config_group( lxdream_config_group_t dest, lxdream_config_group_t src );
   100 /**
   101  * Return a fully expanded path value for a key - this performs substitutions
   102  * for ~ and simple shell variables ($VAR and ${VAR})
   103  * 
   104  * The returned string is newly allocated and must be freed by the caller
   105  */
   106 gchar *lxdream_get_global_config_path_value( int key );
   108 /**
   109  * Set a path value for a key, escaping if necessary to protect against 
   110  * shell-substitution on the round trip.
   111  * 
   112  * @return the resultant config value.
   113  */
   114 const gchar *lxdream_set_global_config_path_value( int key, const gchar *value );
   116 /**
   117  * Construct a list of strings for the given config key - The caller is 
   118  * responsible for freeing the list and its values.
   119  */
   120 GList *lxdream_get_global_config_list_value( int key );
   122 /**
   123  * Set a config key based on a list of strings. 
   124  */
   125 void lxdream_set_global_config_list_value( int key, const GList *list );
   126 /**
   127  * Search the standard locations for the configuration file:
   128  *   $HOME/.lxdreamrc
   129  *   $CWD/lxdreamrc
   130  *   $SYSCONF_DIR/lxdreamrc
   131  * @return TRUE if the file was found, otherwise FALSE.
   132  */
   133 gboolean lxdream_find_config( );
   135 /**
   136  * Set the configuration file filename to the supplied string.
   137  * The string is copied internally (ie can be released by the
   138  * caller).
   139  */
   140 void lxdream_set_config_filename( const gchar *filename );
   142 /**
   143  * Load the configuration from the previously determined filename.
   144  */
   145 gboolean lxdream_load_config( );
   147 /**
   148  * Update the configuration
   149  */
   150 gboolean lxdream_save_config( );
   152 /**
   153  * Make the user configuration directories if they don't already exist.
   154  */ 
   155 void lxdream_make_config_dir( );
   157 #ifdef __cplusplus
   158 }
   159 #endif
   161 #endif /* !lxdream_config_H */
.