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