1 /* Gnome Music Player Client (GMPC) 2 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org> 3 * Project homepage: http://gmpclient.org/ 4 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 #include <glib.h> 20 21 #ifndef __CONFIG_1_H__ 22 #define __CONFIG_1_H__ 23 24 /** 25 * \defgroup Config1 Config 26 * \brief GMPC config system. 27 */ 28 /* @{@ */ 29 #define CFG_INT_NOT_DEFINED -65536 30 31 32 typedef struct _config_obj config_obj; 33 34 35 typedef struct conf_mult_obj 36 { 37 char *key; 38 char *value; 39 struct conf_mult_obj *next; 40 struct conf_mult_obj *prev; 41 } conf_mult_obj; 42 43 /** 44 * @param url The path to the config file to open. 45 * 46 * Open the config file. 47 * 48 * @returns A #config_obj if opened succesful #NULL on failure. 49 */ 50 config_obj *cfg_open(const gchar * url); 51 52 /** 53 * @param cfgo The #config_obj to close 54 * 55 * Free's the #config_obj and if needed saves it. 56 */ 57 void cfg_close(config_obj * cfgo); 58 59 60 /** 61 * @param cfg The #config_obj. 62 * @param class The config subclass. 63 * @param key The key to get. 64 * 65 * Get a single config value as a string. 66 * 67 * F.e. #cfg_get_single_value_as_string(cfg, "aap", "mies"); 68 * Will get the value of key mies in class aap. 69 * 70 * 71 * @returns NULL when the value is not availible, an allocated string if 72 * found. (needs to be free'ed) 73 */ 74 char *cfg_get_single_value_as_string(config_obj * cfg, const char *class, 75 const char *key); 76 /** 77 * @param cfg The #config_obj. 78 * @param class The config subclass. 79 * @param key The key to get. 80 * @param value The new value for class:key. 81 * 82 * Set single value. 83 */ 84 void cfg_set_single_value_as_string(config_obj * cfg, const char *class, 85 const char *key, const char *value); 86 /** 87 * @param cfg The #config_obj. 88 * @param class The config subclass. 89 * @param key The key to get. 90 * @param def The value to return if class:key is not found. 91 * 92 * Get single string value. 93 * 94 * @returns The value off class:key converted to a string or def is not found. 95 */ 96 char *cfg_get_single_value_as_string_with_default(config_obj * cfg, 97 const char *class, 98 const char *key, 99 const char *def); 100 /** 101 * @param cfg The #config_obj. 102 * @param class The config subclass. 103 * @param key The key to get. 104 * 105 * Get a single config value as a int. 106 * 107 * 108 * @returns CFG_INT_NOT_DEFINED when the value is not availible. 109 */ 110 int cfg_get_single_value_as_int(config_obj * cfg, const char *class, 111 const char *key); 112 /** 113 * @param cfg The #config_obj. 114 * @param class The config subclass. 115 * @param key The key to get. 116 * @param value The new value for class:key. 117 * 118 * Set single value. 119 */ 120 void cfg_set_single_value_as_int(config_obj * cfg, const char *class, 121 const char *key, int value); 122 /** 123 * @param cfg The #config_obj. 124 * @param class The config subclass. 125 * @param key The key to get. 126 * @param def The value to return if class:key is not found. 127 * 128 * Get single int value. 129 * @returns The value off class:key converted to a int or def is not found. 130 */ 131 int cfg_get_single_value_as_int_with_default(config_obj * cfg, 132 const char *class, const char *key, 133 int def); 134 135 /** 136 * @param cfg The #config_obj. 137 * @param class The config subclass. 138 * @param key The key to get. 139 * 140 * Get a single config value as a float. 141 * 142 * 143 * @returns CFG_INT_NOT_DEFINED when the value is not availible. 144 */ 145 float cfg_get_single_value_as_float(config_obj * cfg, const char *class, 146 const char *key); 147 /** 148 * @param cfg The #config_obj. 149 * @param class The config subclass. 150 * @param key The key to get. 151 * @param value The new value for class:key. 152 * 153 * Set single value. 154 */ 155 void cfg_set_single_value_as_float(config_obj * cfg, const char *class, 156 const char *key, float value); 157 /** 158 * @param cfg The #config_obj. 159 * @param class The config subclass. 160 * @param key The key to get. 161 * @param def The value to return if class:key is not found. 162 * 163 * Get single float value. 164 * @returns The value off class:key converted to a float or def is not found. 165 */ 166 float cfg_get_single_value_as_float_with_default(config_obj * cfg, 167 const char *class, 168 const char *key, float def); 169 170 /** 171 * @param cfg The #config_obj. 172 * @param class The config subclass. 173 * @param key The key to remove. 174 * 175 * Removes a single value. 176 */ 177 void cfg_del_single_value(config_obj * cfg, const char *class, const char *key); 178 179 /** 180 * @param cfg The #config_obj 181 * 182 * Get a list of all the classes. 183 * 184 * @returns a linked list (type #conf_mult_obj) of all the classes. 185 */ 186 conf_mult_obj *cfg_get_class_list(config_obj * data); 187 188 /** 189 * @param cfg The #config_obj 190 * @param class The class to get the keys from. 191 * 192 * Get a list of all the keys in class class. 193 * 194 * @returns a linked list (type #conf_mult_obj) of all the keys. 195 */ 196 conf_mult_obj *cfg_get_key_list(config_obj * data, const char *class); 197 198 /** 199 * @param data The #conf_mult_obj to free 200 * 201 * Free's the #conf_mult_obj. 202 */ 203 void cfg_free_multiple(conf_mult_obj * data); 204 205 /** 206 * @param cfg the #config_obj. 207 * 208 * Remove class from the config file, including all sub-items. 209 */ 210 void cfg_remove_class(config_obj * cfg, const char *class); 211 212 #define cfg_free_string(a) g_free(a);a=NULL; 213 /* @{@ */ 214 #endif 215