Mercurial > audlegacy
annotate src/libaudacious/configdb_rcfile.c @ 2367:d5522d3cd68f trunk
[svn] fix a stupid bug of mine
author | mf0102 |
---|---|
date | Fri, 19 Jan 2007 15:05:01 -0800 |
parents | 0b98ad8c8b17 |
children |
rev | line source |
---|---|
2313 | 1 /* This program is free software; you can redistribute it and/or modify |
2 * it under the terms of the GNU General Public License as published by | |
3 * the Free Software Foundation; either version 2 of the License, or | |
4 * (at your option) any later version. | |
5 * | |
6 * This program is distributed in the hope that it will be useful, | |
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 * GNU General Public License for more details. | |
10 * | |
11 * You should have received a copy of the GNU General Public License | |
12 * along with this program; if not, write to the Free Software | |
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
14 */ | |
15 | |
16 #ifdef HAVE_CONFIG_H | |
17 # include "config.h" | |
18 #endif | |
19 | |
20 #include "configdb.h" | |
21 | |
2314
d5d95a459a19
[svn] - fix: E:configdb_rcfile.c(45) [bmp_cfg_db_open]:Autoconversion of integer to pointer is not allowed in C99
nenolod
parents:
2313
diff
changeset
|
22 #include <stdlib.h> |
2313 | 23 #include <string.h> |
24 #include "rcfile.h" | |
25 | |
26 | |
27 #define RCFILE_DEFAULT_SECTION_NAME "audacious" | |
28 | |
29 | |
30 struct _ConfigDb | |
31 { | |
32 RcFile *file; | |
33 gchar *filename; | |
34 gboolean dirty; | |
35 }; | |
36 | |
37 | |
38 ConfigDb * | |
39 bmp_cfg_db_open() | |
40 { | |
41 ConfigDb *db; | |
42 char *tmp; | |
43 | |
44 db = g_new(ConfigDb, 1); | |
45 | |
46 if ((tmp = getenv("XDG_CONFIG_HOME")) == NULL) | |
47 db->filename = g_build_filename(g_get_home_dir(), ".config", | |
48 "audacious", "config", NULL); | |
49 else | |
50 db->filename = g_build_filename(tmp, "audacious", "config", NULL); | |
51 | |
52 db->file = bmp_rcfile_open(db->filename); | |
53 | |
2325
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
54 #ifdef DOTAUDACIOUS_COMPAT |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
55 if (!db->file) { |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
56 tmp = g_build_filename(g_get_home_dir(), BMP_RCPATH, "config", NULL); |
2326
094cac62c904
[svn] Fixed: configdb_rcfile.c:57: warning: suggest parentheses around assignment used as truth value
js
parents:
2325
diff
changeset
|
57 if ((db->file = bmp_rcfile_open(tmp))) { |
2325
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
58 g_free(db->filename); |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
59 db->filename = tmp; |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
60 } |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
61 } |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
62 #endif |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
63 |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
64 if (!db->file) { |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
65 #ifdef DOTAUDACIOUS_COMPAT |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
66 g_free(tmp); |
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
67 #endif |
2313 | 68 db->file = bmp_rcfile_new(); |
2325
63c9a2724e73
[svn] - revert r3646 because it is not a user-friendly method of transitioning.
nenolod
parents:
2318
diff
changeset
|
69 } |
2313 | 70 |
71 db->dirty = FALSE; | |
72 | |
73 return db; | |
74 } | |
75 | |
76 void | |
77 bmp_cfg_db_close(ConfigDb * db) | |
78 { | |
79 if (db->dirty) | |
80 bmp_rcfile_write(db->file, db->filename); | |
81 bmp_rcfile_free(db->file); | |
82 g_free(db->filename); | |
83 } | |
84 | |
85 gboolean | |
86 bmp_cfg_db_get_string(ConfigDb * db, | |
87 const gchar * section, | |
88 const gchar * key, | |
89 gchar ** value) | |
90 { | |
91 if (!section) | |
92 section = RCFILE_DEFAULT_SECTION_NAME; | |
93 | |
94 return bmp_rcfile_read_string(db->file, section, key, value); | |
95 } | |
96 | |
97 gboolean | |
98 bmp_cfg_db_get_int(ConfigDb * db, | |
99 const gchar * section, const gchar * key, gint * value) | |
100 { | |
101 if (!section) | |
102 section = RCFILE_DEFAULT_SECTION_NAME; | |
103 | |
104 return bmp_rcfile_read_int(db->file, section, key, value); | |
105 } | |
106 | |
107 gboolean | |
108 bmp_cfg_db_get_bool(ConfigDb * db, | |
109 const gchar * section, | |
110 const gchar * key, | |
111 gboolean * value) | |
112 { | |
113 if (!section) | |
114 section = RCFILE_DEFAULT_SECTION_NAME; | |
115 | |
116 return bmp_rcfile_read_bool(db->file, section, key, value); | |
117 } | |
118 | |
119 gboolean | |
120 bmp_cfg_db_get_float(ConfigDb * db, | |
121 const gchar * section, | |
122 const gchar * key, | |
123 gfloat * value) | |
124 { | |
125 if (!section) | |
126 section = RCFILE_DEFAULT_SECTION_NAME; | |
127 | |
128 return bmp_rcfile_read_float(db->file, section, key, value); | |
129 } | |
130 | |
131 gboolean | |
132 bmp_cfg_db_get_double(ConfigDb * db, | |
133 const gchar * section, | |
134 const gchar * key, | |
135 gdouble * value) | |
136 { | |
137 if (!section) | |
138 section = RCFILE_DEFAULT_SECTION_NAME; | |
139 | |
140 return bmp_rcfile_read_double(db->file, section, key, value); | |
141 } | |
142 | |
143 void | |
144 bmp_cfg_db_set_string(ConfigDb * db, | |
145 const gchar * section, | |
146 const gchar * key, | |
2346
0b98ad8c8b17
[svn] removed xmms_create_dirbrowser, small config db fixes
mf0102
parents:
2326
diff
changeset
|
147 const gchar * value) |
2313 | 148 { |
149 db->dirty = TRUE; | |
150 | |
151 if (!section) | |
152 section = RCFILE_DEFAULT_SECTION_NAME; | |
153 | |
154 bmp_rcfile_write_string(db->file, section, key, value); | |
155 } | |
156 | |
157 void | |
158 bmp_cfg_db_set_int(ConfigDb * db, | |
159 const gchar * section, | |
160 const gchar * key, | |
161 gint value) | |
162 { | |
163 db->dirty = TRUE; | |
164 | |
165 if (!section) | |
166 section = RCFILE_DEFAULT_SECTION_NAME; | |
167 | |
168 bmp_rcfile_write_int(db->file, section, key, value); | |
169 } | |
170 | |
171 void | |
172 bmp_cfg_db_set_bool(ConfigDb * db, | |
173 const gchar * section, | |
174 const gchar * key, | |
175 gboolean value) | |
176 { | |
177 db->dirty = TRUE; | |
178 | |
179 if (!section) | |
180 section = RCFILE_DEFAULT_SECTION_NAME; | |
181 | |
182 bmp_rcfile_write_boolean(db->file, section, key, value); | |
183 } | |
184 | |
185 void | |
186 bmp_cfg_db_set_float(ConfigDb * db, | |
187 const gchar * section, | |
188 const gchar * key, | |
189 gfloat value) | |
190 { | |
191 db->dirty = TRUE; | |
192 | |
193 if (!section) | |
194 section = RCFILE_DEFAULT_SECTION_NAME; | |
195 | |
196 bmp_rcfile_write_float(db->file, section, key, value); | |
197 } | |
198 | |
199 void | |
200 bmp_cfg_db_set_double(ConfigDb * db, | |
201 const gchar * section, | |
202 const gchar * key, | |
203 gdouble value) | |
204 { | |
205 db->dirty = TRUE; | |
206 | |
207 if (!section) | |
208 section = RCFILE_DEFAULT_SECTION_NAME; | |
209 | |
210 bmp_rcfile_write_double(db->file, section, key, value); | |
211 } | |
212 | |
213 void | |
214 bmp_cfg_db_unset_key(ConfigDb * db, | |
215 const gchar * section, | |
216 const gchar * key) | |
217 { | |
218 db->dirty = TRUE; | |
219 | |
220 g_return_if_fail(db != NULL); | |
221 g_return_if_fail(key != NULL); | |
222 | |
223 if (!section) | |
224 section = RCFILE_DEFAULT_SECTION_NAME; | |
225 | |
226 bmp_rcfile_remove_key(db->file, section, key); | |
227 } |