annotate libaudacious/configdb_rcfile.c @ 1625:79891e2fd8a5 trunk

[svn] - use $(SHARED_SUFFIX) - use $(PICFLAGS) - use $(PICLDFLAGS)
author nenolod
date Wed, 06 Sep 2006 13:21:40 -0700
parents 705d4c089fce
children a19f86d81427
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #include "configdb.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include "rcfile.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #define RCFILE_DEFAULT_SECTION_NAME "audacious"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 struct _ConfigDb
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 RcFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 gboolean dirty;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 ConfigDb *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 bmp_cfg_db_open()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 ConfigDb *db;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 db = g_new(ConfigDb, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 db->filename = g_build_filename(g_get_home_dir(), BMP_RCPATH,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 "config", NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 db->file = bmp_rcfile_open(db->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 if (!db->file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 db->file = bmp_rcfile_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 db->dirty = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 return db;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 bmp_cfg_db_close(ConfigDb * db)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 if (db->dirty)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 bmp_rcfile_write(db->file, db->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 bmp_rcfile_free(db->file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 g_free(db->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 bmp_cfg_db_get_string(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 gchar ** value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 return bmp_rcfile_read_string(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 bmp_cfg_db_get_int(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 const gchar * section, const gchar * key, gint * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 return bmp_rcfile_read_int(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 bmp_cfg_db_get_bool(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 gboolean * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 return bmp_rcfile_read_bool(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 bmp_cfg_db_get_float(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 gfloat * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 return bmp_rcfile_read_float(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 bmp_cfg_db_get_double(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 gdouble * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 return bmp_rcfile_read_double(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 bmp_cfg_db_set_string(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 bmp_rcfile_write_string(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 bmp_cfg_db_set_int(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 gint value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 bmp_rcfile_write_int(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 bmp_cfg_db_set_bool(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 gboolean value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 bmp_rcfile_write_boolean(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 bmp_cfg_db_set_float(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 gfloat value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 bmp_rcfile_write_float(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 bmp_cfg_db_set_double(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 gdouble value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 bmp_rcfile_write_double(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 bmp_cfg_db_unset_key(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 g_return_if_fail(db != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 bmp_rcfile_remove_key(db->file, section, key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 }