comparison src/amidi-plug/pcfg/i_pcfg.c @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/amidi-plug/pcfg/i_pcfg.c@13389e613d67
children
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1 /*
2 *
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2006
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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 */
20
21
22 #include "i_pcfg.h"
23
24
25 pcfg_t * i_pcfg_new( void )
26 {
27 pcfg_t * configfile = g_key_file_new();
28 return configfile;
29 }
30
31
32 pcfg_t * i_pcfg_new_from_file( gchar * pathfilename )
33 {
34 pcfg_t * configfile = g_key_file_new();
35 if ( g_key_file_load_from_file( configfile , pathfilename , G_KEY_FILE_NONE , NULL ) == FALSE )
36 {
37 g_key_file_free( configfile );
38 configfile = NULL;
39 }
40 return configfile;
41 }
42
43
44 void i_pcfg_free( pcfg_t * configfile )
45 {
46 g_key_file_free( configfile );
47 return;
48 }
49
50
51 gboolean i_pcfg_write_to_file( pcfg_t * configfile , gchar * pathfilename )
52 {
53 GError * error = NULL;
54 gchar *configfile_string = g_key_file_to_data( configfile , NULL , &error );
55 if ( error != NULL )
56 {
57 g_clear_error( &error );
58 return FALSE;
59 }
60 else
61 {
62 if ( g_file_set_contents( pathfilename , configfile_string , -1 , NULL ) == FALSE )
63 {
64 g_free( configfile_string );
65 return FALSE;
66 }
67 else
68 {
69 g_free( configfile_string );
70 return TRUE;
71 }
72 }
73 }
74
75
76 gboolean i_pcfg_read_string( pcfg_t * configfile ,
77 const gchar * group ,
78 const gchar * key ,
79 gchar ** value ,
80 gchar * default_value )
81 {
82 GError * error = NULL;
83 *value = g_key_file_get_string( configfile , group , key , &error );
84 if ( error != NULL )
85 {
86 if ( default_value != NULL )
87 *value = g_strdup( default_value );
88 g_clear_error( &error );
89 return FALSE;
90 }
91 return TRUE;
92 }
93
94
95 gboolean i_pcfg_read_integer( pcfg_t * configfile ,
96 const gchar * group ,
97 const gchar * key ,
98 gint * value ,
99 gint default_value )
100 {
101 GError * error = NULL;
102 *value = g_key_file_get_integer( configfile , group , key , &error );
103 if ( error != NULL )
104 {
105 *value = default_value;
106 g_clear_error( &error );
107 return FALSE;
108 }
109 return TRUE;
110 }
111
112
113 gboolean i_pcfg_read_boolean( pcfg_t * configfile ,
114 const gchar * group ,
115 const gchar * key ,
116 gboolean * value ,
117 gboolean default_value )
118 {
119 GError * error = NULL;
120 *value = g_key_file_get_boolean( configfile , group , key , &error );
121 if ( error != NULL )
122 {
123 *value = default_value;
124 g_clear_error( &error );
125 return FALSE;
126 }
127 return TRUE;
128 }
129
130
131 gboolean i_pcfg_write_string( pcfg_t * configfile ,
132 const gchar * group ,
133 const gchar * key ,
134 gchar * value )
135 {
136 g_key_file_set_string( configfile , group , key , value );
137 return TRUE;
138 }
139
140
141 gboolean i_pcfg_write_integer( pcfg_t * configfile ,
142 const gchar * group ,
143 const gchar * key ,
144 gint value )
145 {
146 g_key_file_set_integer( configfile , group , key , value );
147 return TRUE;
148 }
149
150
151 gboolean i_pcfg_write_boolean( pcfg_t * configfile ,
152 const gchar * group ,
153 const gchar * key ,
154 gboolean value )
155 {
156 g_key_file_set_boolean( configfile , group , key , value );
157 return TRUE;
158 }