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