annotate libaudacious/configdb_xmlfile.c @ 1062:b727849e2128 trunk

[svn] - Add the ability to easily save to playlist.m3u from the list menu. (For those who hate having to restart Audacious in order to save the playlist).
author nhjm449
date Mon, 15 May 2006 20:55:19 -0700
parents 6af6627e14f5
children f12d7e208b43
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 struct _ConfigDb
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 {
463
6af6627e14f5 [svn] Fork off the rcfile backend for conversion into an XML file-based preferences option using GMarkup. This does not work
nenolod
parents: 0
diff changeset
27 BmpXmlDocument *file;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 gboolean dirty;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
463
6af6627e14f5 [svn] Fork off the rcfile backend for conversion into an XML file-based preferences option using GMarkup. This does not work
nenolod
parents: 0
diff changeset
32 #define XMLFILE_DEFAULT_SECTION
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 ConfigDb *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 bmp_cfg_db_open()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 ConfigDb *db;
463
6af6627e14f5 [svn] Fork off the rcfile backend for conversion into an XML file-based preferences option using GMarkup. This does not work
nenolod
parents: 0
diff changeset
38 GError *err = NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 db = g_new(ConfigDb, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 db->filename = g_build_filename(g_get_home_dir(), BMP_RCPATH,
463
6af6627e14f5 [svn] Fork off the rcfile backend for conversion into an XML file-based preferences option using GMarkup. This does not work
nenolod
parents: 0
diff changeset
42 "preferences.xml", NULL);
6af6627e14f5 [svn] Fork off the rcfile backend for conversion into an XML file-based preferences option using GMarkup. This does not work
nenolod
parents: 0
diff changeset
43 bmp_xml_document_load(&db->file, db->filename, &err);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 if (!db->file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 db->file = bmp_rcfile_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 db->dirty = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 return db;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 bmp_cfg_db_close(ConfigDb * db)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 if (db->dirty)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 bmp_rcfile_write(db->file, db->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 bmp_rcfile_free(db->file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 g_free(db->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 bmp_cfg_db_get_string(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 gchar ** value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 return bmp_rcfile_read_string(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 bmp_cfg_db_get_int(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 const gchar * section, const gchar * key, gint * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 return bmp_rcfile_read_int(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 bmp_cfg_db_get_bool(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 gboolean * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 return bmp_rcfile_read_bool(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 bmp_cfg_db_get_float(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 gfloat * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 return bmp_rcfile_read_float(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 bmp_cfg_db_get_double(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 gdouble * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 return bmp_rcfile_read_double(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 bmp_cfg_db_set_string(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 bmp_rcfile_write_string(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 bmp_cfg_db_set_int(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 gint value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 bmp_rcfile_write_int(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 bmp_cfg_db_set_bool(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 gboolean value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 bmp_rcfile_write_boolean(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 bmp_cfg_db_set_float(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 gfloat value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 bmp_rcfile_write_float(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 bmp_cfg_db_set_double(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 gdouble value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 bmp_rcfile_write_double(db->file, section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 bmp_cfg_db_unset_key(ConfigDb * db,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 db->dirty = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 g_return_if_fail(db != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 if (!section)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 section = RCFILE_DEFAULT_SECTION_NAME;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 bmp_rcfile_remove_key(db->file, section, key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 }