0
|
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
|
1459
|
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
0
|
14 */
|
|
15
|
|
16 #ifdef HAVE_CONFIG_H
|
|
17 # include "config.h"
|
|
18 #endif
|
|
19
|
|
20 #include "configdb.h"
|
|
21
|
|
22 #include <string.h>
|
|
23 #include "rcfile.h"
|
|
24
|
|
25
|
|
26 #define RCFILE_DEFAULT_SECTION_NAME "audacious"
|
|
27
|
|
28
|
|
29 struct _ConfigDb
|
|
30 {
|
|
31 RcFile *file;
|
|
32 gchar *filename;
|
|
33 gboolean dirty;
|
|
34 };
|
|
35
|
|
36
|
|
37 ConfigDb *
|
|
38 bmp_cfg_db_open()
|
|
39 {
|
|
40 ConfigDb *db;
|
|
41
|
|
42 db = g_new(ConfigDb, 1);
|
|
43 db->filename = g_build_filename(g_get_home_dir(), BMP_RCPATH,
|
|
44 "config", NULL);
|
|
45 db->file = bmp_rcfile_open(db->filename);
|
|
46 if (!db->file)
|
|
47 db->file = bmp_rcfile_new();
|
|
48
|
|
49 db->dirty = FALSE;
|
|
50
|
|
51 return db;
|
|
52 }
|
|
53
|
|
54 void
|
|
55 bmp_cfg_db_close(ConfigDb * db)
|
|
56 {
|
|
57 if (db->dirty)
|
|
58 bmp_rcfile_write(db->file, db->filename);
|
|
59 bmp_rcfile_free(db->file);
|
|
60 g_free(db->filename);
|
|
61 }
|
|
62
|
|
63 gboolean
|
|
64 bmp_cfg_db_get_string(ConfigDb * db,
|
|
65 const gchar * section,
|
|
66 const gchar * key,
|
|
67 gchar ** value)
|
|
68 {
|
|
69 if (!section)
|
|
70 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
71
|
|
72 return bmp_rcfile_read_string(db->file, section, key, value);
|
|
73 }
|
|
74
|
|
75 gboolean
|
|
76 bmp_cfg_db_get_int(ConfigDb * db,
|
|
77 const gchar * section, const gchar * key, gint * value)
|
|
78 {
|
|
79 if (!section)
|
|
80 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
81
|
|
82 return bmp_rcfile_read_int(db->file, section, key, value);
|
|
83 }
|
|
84
|
|
85 gboolean
|
|
86 bmp_cfg_db_get_bool(ConfigDb * db,
|
|
87 const gchar * section,
|
|
88 const gchar * key,
|
|
89 gboolean * value)
|
|
90 {
|
|
91 if (!section)
|
|
92 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
93
|
|
94 return bmp_rcfile_read_bool(db->file, section, key, value);
|
|
95 }
|
|
96
|
|
97 gboolean
|
|
98 bmp_cfg_db_get_float(ConfigDb * db,
|
|
99 const gchar * section,
|
|
100 const gchar * key,
|
|
101 gfloat * value)
|
|
102 {
|
|
103 if (!section)
|
|
104 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
105
|
|
106 return bmp_rcfile_read_float(db->file, section, key, value);
|
|
107 }
|
|
108
|
|
109 gboolean
|
|
110 bmp_cfg_db_get_double(ConfigDb * db,
|
|
111 const gchar * section,
|
|
112 const gchar * key,
|
|
113 gdouble * value)
|
|
114 {
|
|
115 if (!section)
|
|
116 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
117
|
|
118 return bmp_rcfile_read_double(db->file, section, key, value);
|
|
119 }
|
|
120
|
|
121 void
|
|
122 bmp_cfg_db_set_string(ConfigDb * db,
|
|
123 const gchar * section,
|
|
124 const gchar * key,
|
|
125 gchar * value)
|
|
126 {
|
|
127 db->dirty = TRUE;
|
|
128
|
|
129 if (!section)
|
|
130 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
131
|
|
132 bmp_rcfile_write_string(db->file, section, key, value);
|
|
133 }
|
|
134
|
|
135 void
|
|
136 bmp_cfg_db_set_int(ConfigDb * db,
|
|
137 const gchar * section,
|
|
138 const gchar * key,
|
|
139 gint value)
|
|
140 {
|
|
141 db->dirty = TRUE;
|
|
142
|
|
143 if (!section)
|
|
144 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
145
|
|
146 bmp_rcfile_write_int(db->file, section, key, value);
|
|
147 }
|
|
148
|
|
149 void
|
|
150 bmp_cfg_db_set_bool(ConfigDb * db,
|
|
151 const gchar * section,
|
|
152 const gchar * key,
|
|
153 gboolean value)
|
|
154 {
|
|
155 db->dirty = TRUE;
|
|
156
|
|
157 if (!section)
|
|
158 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
159
|
|
160 bmp_rcfile_write_boolean(db->file, section, key, value);
|
|
161 }
|
|
162
|
|
163 void
|
|
164 bmp_cfg_db_set_float(ConfigDb * db,
|
|
165 const gchar * section,
|
|
166 const gchar * key,
|
|
167 gfloat value)
|
|
168 {
|
|
169 db->dirty = TRUE;
|
|
170
|
|
171 if (!section)
|
|
172 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
173
|
|
174 bmp_rcfile_write_float(db->file, section, key, value);
|
|
175 }
|
|
176
|
|
177 void
|
|
178 bmp_cfg_db_set_double(ConfigDb * db,
|
|
179 const gchar * section,
|
|
180 const gchar * key,
|
|
181 gdouble value)
|
|
182 {
|
|
183 db->dirty = TRUE;
|
|
184
|
|
185 if (!section)
|
|
186 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
187
|
|
188 bmp_rcfile_write_double(db->file, section, key, value);
|
|
189 }
|
|
190
|
|
191 void
|
|
192 bmp_cfg_db_unset_key(ConfigDb * db,
|
|
193 const gchar * section,
|
|
194 const gchar * key)
|
|
195 {
|
|
196 db->dirty = TRUE;
|
|
197
|
|
198 g_return_if_fail(db != NULL);
|
|
199 g_return_if_fail(key != NULL);
|
|
200
|
|
201 if (!section)
|
|
202 section = RCFILE_DEFAULT_SECTION_NAME;
|
|
203
|
|
204 bmp_rcfile_remove_key(db->file, section, key);
|
|
205 }
|