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