Mercurial > audlegacy
annotate src/audacious/util.c @ 4596:a77d02342ee1
change visualization timeout; export calc_stereo_pcm, calc_mono_pcm and calc_mono_freq to PAPI
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Sat, 31 May 2008 14:17:15 +0200 |
parents | 332d2992e04c |
children | a7392e85d4c6 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
4259
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
2 * Copyright (C) 2005-2008 Audacious development team |
2313 | 3 * |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3103
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
2313 | 13 * |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3103
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3122
diff
changeset
|
21 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3122
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3122
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
2313 | 24 */ |
25 | |
4127 | 26 /*#define AUD_DEBUG*/ |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
27 |
2313 | 28 #ifdef HAVE_CONFIG_H |
29 # include "config.h" | |
30 #endif | |
31 | |
32 #include "util.h" | |
33 | |
34 #include <glib.h> | |
35 #include <glib/gi18n.h> | |
36 #include <gtk/gtk.h> | |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 #include <ctype.h> | |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
40 #include <math.h> |
2313 | 41 |
42 #include "platform/smartinclude.h" | |
43 #include <errno.h> | |
44 | |
45 #ifdef HAVE_FTS_H | |
3033 | 46 # include <sys/types.h> |
47 # include <sys/stat.h> | |
2313 | 48 # include <fts.h> |
49 #endif | |
50 | |
51 #include "input.h" | |
52 #include "playback.h" | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2365
diff
changeset
|
53 #include "strings.h" |
4347 | 54 |
4259
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
55 #include "libSAD.h" |
2313 | 56 |
57 #ifdef USE_CHARDET | |
4474
6e323e395886
Fix some random #includes.
Matti Hamalainen <ccr@tnsp.org>
parents:
4454
diff
changeset
|
58 # include "../libguess/libguess.h" |
6e323e395886
Fix some random #includes.
Matti Hamalainen <ccr@tnsp.org>
parents:
4454
diff
changeset
|
59 # ifdef HAVE_UDET |
6e323e395886
Fix some random #includes.
Matti Hamalainen <ccr@tnsp.org>
parents:
4454
diff
changeset
|
60 # include <libudet_c.h> |
6e323e395886
Fix some random #includes.
Matti Hamalainen <ccr@tnsp.org>
parents:
4454
diff
changeset
|
61 # endif |
2313 | 62 #endif |
63 | |
64 /* | |
65 * find <file> in directory <dirname> or subdirectories. return | |
66 * pointer to complete filename which has to be freed by calling | |
67 * "g_free()" after use. Returns NULL if file could not be found. | |
68 */ | |
69 | |
70 typedef struct { | |
71 const gchar *to_match; | |
72 gchar *match; | |
73 gboolean found; | |
74 } FindFileContext; | |
75 | |
4259
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
76 static const struct { |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
77 AFormat afmt; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
78 SAD_sample_format sadfmt; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
79 } format_table[] = { |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
80 {FMT_U8, SAD_SAMPLE_U8}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
81 {FMT_S8, SAD_SAMPLE_S8}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
82 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
83 {FMT_S16_LE, SAD_SAMPLE_S16_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
84 {FMT_S16_BE, SAD_SAMPLE_S16_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
85 {FMT_S16_NE, SAD_SAMPLE_S16}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
86 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
87 {FMT_U16_LE, SAD_SAMPLE_U16_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
88 {FMT_U16_BE, SAD_SAMPLE_U16_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
89 {FMT_U16_NE, SAD_SAMPLE_U16}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
90 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
91 {FMT_S24_LE, SAD_SAMPLE_S24_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
92 {FMT_S24_BE, SAD_SAMPLE_S24_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
93 {FMT_S24_NE, SAD_SAMPLE_S24}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
94 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
95 {FMT_U24_LE, SAD_SAMPLE_U24_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
96 {FMT_U24_BE, SAD_SAMPLE_U24_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
97 {FMT_U24_NE, SAD_SAMPLE_U24}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
98 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
99 {FMT_S32_LE, SAD_SAMPLE_S32_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
100 {FMT_S32_BE, SAD_SAMPLE_S32_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
101 {FMT_S32_NE, SAD_SAMPLE_S32}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
102 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
103 {FMT_U32_LE, SAD_SAMPLE_U32_LE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
104 {FMT_U32_BE, SAD_SAMPLE_U32_BE}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
105 {FMT_U32_NE, SAD_SAMPLE_U32}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
106 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
107 {FMT_FLOAT, SAD_SAMPLE_FLOAT}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
108 {FMT_FIXED32, SAD_SAMPLE_FIXED32}, |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
109 }; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
110 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
111 SAD_sample_format |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
112 sadfmt_from_afmt(AFormat fmt) |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
113 { |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
114 int i; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
115 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) { |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
116 if (format_table[i].afmt == fmt) return format_table[i].sadfmt; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
117 } |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
118 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
119 return -1; |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
120 } |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
121 |
92642f860860
- added template for src_flow
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4223
diff
changeset
|
122 |
2313 | 123 static gboolean |
124 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
125 { | |
126 FindFileContext *context = data; | |
127 | |
128 if (strlen(path) > FILENAME_MAX) { | |
4124
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
129 AUDDBG("Ignoring path: name too long (%s)\n", path); |
2313 | 130 return TRUE; |
131 } | |
132 | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
133 if (vfs_file_test(path, G_FILE_TEST_IS_REGULAR)) { |
2313 | 134 if (!strcasecmp(basename, context->to_match)) { |
135 context->match = g_strdup(path); | |
136 context->found = TRUE; | |
137 return TRUE; | |
138 } | |
139 } | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
140 else if (vfs_file_test(path, G_FILE_TEST_IS_DIR)) { |
2313 | 141 dir_foreach(path, find_file_func, context, NULL); |
142 if (context->found) | |
143 return TRUE; | |
144 } | |
145 | |
146 return FALSE; | |
147 } | |
148 | |
149 gchar * | |
150 find_file_recursively(const gchar * path, const gchar * filename) | |
151 { | |
152 FindFileContext context; | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
153 gchar *out = NULL; |
2313 | 154 |
155 context.to_match = filename; | |
156 context.match = NULL; | |
157 context.found = FALSE; | |
158 | |
159 dir_foreach(path, find_file_func, &context, NULL); | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
160 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
161 if (context.match) |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
162 { |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
163 out = g_filename_to_uri(context.match, NULL, NULL); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
164 g_free(context.match); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
165 } |
2988
43a075cb5c81
find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents:
2977
diff
changeset
|
166 |
43a075cb5c81
find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents:
2977
diff
changeset
|
167 return out; |
2313 | 168 } |
169 | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
170 gchar * |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
171 find_path_recursively(const gchar * path, const gchar * filename) |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
172 { |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
173 FindFileContext context; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
174 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
175 context.to_match = filename; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
176 context.match = NULL; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
177 context.found = FALSE; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
178 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
179 dir_foreach(path, find_file_func, &context, NULL); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
180 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
181 return context.match; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
182 } |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
183 |
2313 | 184 |
185 typedef enum { | |
186 ARCHIVE_UNKNOWN = 0, | |
187 ARCHIVE_DIR, | |
188 ARCHIVE_TAR, | |
189 ARCHIVE_TGZ, | |
190 ARCHIVE_ZIP, | |
191 ARCHIVE_TBZ2 | |
192 } ArchiveType; | |
193 | |
194 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
195 | |
196 typedef struct { | |
197 ArchiveType type; | |
198 const gchar *ext; | |
199 } ArchiveExtensionType; | |
200 | |
201 static ArchiveExtensionType archive_extensions[] = { | |
202 {ARCHIVE_TAR, ".tar"}, | |
203 {ARCHIVE_ZIP, ".wsz"}, | |
204 {ARCHIVE_ZIP, ".zip"}, | |
205 {ARCHIVE_TGZ, ".tar.gz"}, | |
206 {ARCHIVE_TGZ, ".tgz"}, | |
207 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
208 {ARCHIVE_TBZ2, ".bz2"}, | |
209 {ARCHIVE_UNKNOWN, NULL} | |
210 }; | |
211 | |
212 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
213 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
214 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
215 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
216 | |
217 static ArchiveExtractFunc archive_extract_funcs[] = { | |
218 NULL, | |
219 NULL, | |
220 archive_extract_tar, | |
221 archive_extract_tgz, | |
222 archive_extract_zip, | |
223 archive_extract_tbz2 | |
224 }; | |
225 | |
226 | |
227 /* FIXME: these functions can be generalised into a function using a | |
228 * command lookup table */ | |
229 | |
230 static const gchar * | |
231 get_tar_command(void) | |
232 { | |
233 static const gchar *command = NULL; | |
234 | |
235 if (!command) { | |
236 if (!(command = getenv("TARCMD"))) | |
237 command = "tar"; | |
238 } | |
239 | |
240 return command; | |
241 } | |
242 | |
243 static const gchar * | |
244 get_unzip_command(void) | |
245 { | |
246 static const gchar *command = NULL; | |
247 | |
248 if (!command) { | |
249 if (!(command = getenv("UNZIPCMD"))) | |
250 command = "unzip"; | |
251 } | |
252 | |
253 return command; | |
254 } | |
255 | |
256 | |
257 static gchar * | |
258 archive_extract_tar(const gchar * archive, const gchar * dest) | |
259 { | |
260 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
261 get_tar_command(), archive, dest); | |
262 } | |
263 | |
264 static gchar * | |
265 archive_extract_zip(const gchar * archive, const gchar * dest) | |
266 { | |
267 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
268 get_unzip_command(), archive, dest); | |
269 } | |
270 | |
271 static gchar * | |
272 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
273 { | |
274 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
275 get_tar_command(), archive, dest); | |
276 } | |
277 | |
278 static gchar * | |
279 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
280 { | |
281 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
282 archive, get_tar_command(), dest); | |
283 } | |
284 | |
285 | |
286 ArchiveType | |
287 archive_get_type(const gchar * filename) | |
288 { | |
289 gint i = 0; | |
290 | |
291 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
292 return ARCHIVE_DIR; | |
293 | |
294 while (archive_extensions[i].ext) { | |
295 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
296 return archive_extensions[i].type; | |
297 } | |
298 i++; | |
299 } | |
300 | |
301 return ARCHIVE_UNKNOWN; | |
302 } | |
303 | |
304 gboolean | |
305 file_is_archive(const gchar * filename) | |
306 { | |
307 return (archive_get_type(filename) > ARCHIVE_DIR); | |
308 } | |
309 | |
310 gchar * | |
311 archive_basename(const gchar * str) | |
312 { | |
313 gint i = 0; | |
314 | |
315 while (archive_extensions[i].ext) { | |
316 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
317 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
318 if (end) { | |
319 return g_strndup(str, end - str); | |
320 } | |
321 break; | |
322 } | |
323 i++; | |
324 } | |
325 | |
326 return NULL; | |
327 } | |
328 | |
329 /* | |
330 decompress_archive | |
331 | |
332 Decompresses the archive "filename" to a temporary directory, | |
333 returns the path to the temp dir, or NULL if failed, | |
334 watch out tho, doesn't actually check if the system command succeeds :-| | |
335 */ | |
336 | |
337 gchar * | |
338 archive_decompress(const gchar * filename) | |
339 { | |
340 gchar *tmpdir, *cmd, *escaped_filename; | |
341 ArchiveType type; | |
2328 | 342 #ifndef HAVE_MKDTEMP |
2313 | 343 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
2328 | 344 #endif |
2313 | 345 |
346 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
347 return NULL; | |
348 | |
349 #ifdef HAVE_MKDTEMP | |
350 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); | |
351 if (!mkdtemp(tmpdir)) { | |
352 g_free(tmpdir); | |
4124
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
353 AUDDBG("Unable to load skin: Failed to create temporary " |
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
354 "directory: %s\n", g_strerror(errno)); |
2313 | 355 return NULL; |
356 } | |
357 #else | |
3637 | 358 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), (long) rand()); |
2313 | 359 make_directory(tmpdir, mode755); |
360 #endif | |
361 | |
362 escaped_filename = escape_shell_chars(filename); | |
363 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
364 g_free(escaped_filename); | |
365 | |
366 if (!cmd) { | |
4124
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
367 AUDDBG("extraction function is NULL!\n"); |
2313 | 368 g_free(tmpdir); |
369 return NULL; | |
370 } | |
371 | |
4124
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
372 AUDDBG("Attempt to execute \"%s\"\n", cmd); |
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
373 |
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
374 if(system(cmd) != 0) |
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
375 { |
4124
d217b71e5836
more strict error handling. make use of AUDDBG
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4097
diff
changeset
|
376 AUDDBG("could not execute cmd %s\n",cmd); |
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
377 g_free(cmd); |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
378 return NULL; |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
379 } |
2313 | 380 g_free(cmd); |
381 | |
382 return tmpdir; | |
383 } | |
384 | |
385 | |
386 #ifdef HAVE_FTS_H | |
387 | |
388 void | |
389 del_directory(const gchar * dirname) | |
390 { | |
391 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
392 FTS *fts; | |
393 FTSENT *p; | |
394 | |
395 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
396 while ((p = fts_read(fts))) { | |
397 switch (p->fts_info) { | |
398 case FTS_D: | |
399 break; | |
400 case FTS_DNR: | |
401 case FTS_ERR: | |
402 break; | |
403 case FTS_DP: | |
404 rmdir(p->fts_accpath); | |
405 break; | |
406 default: | |
407 unlink(p->fts_accpath); | |
408 break; | |
409 } | |
410 } | |
411 fts_close(fts); | |
412 } | |
413 | |
414 #else /* !HAVE_FTS */ | |
415 | |
416 gboolean | |
417 del_directory_func(const gchar * path, const gchar * basename, | |
418 gpointer params) | |
419 { | |
420 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
421 return FALSE; | |
422 | |
423 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
424 dir_foreach(path, del_directory_func, NULL, NULL); | |
425 rmdir(path); | |
426 return FALSE; | |
427 } | |
428 | |
429 unlink(path); | |
430 | |
431 return FALSE; | |
432 } | |
433 | |
434 void | |
435 del_directory(const gchar * path) | |
436 { | |
437 dir_foreach(path, del_directory_func, NULL, NULL); | |
438 rmdir(path); | |
439 } | |
440 | |
441 #endif /* ifdef HAVE_FTS */ | |
442 | |
2529 | 443 static void |
444 strip_string(GString *string) | |
445 { | |
446 while (string->len > 0 && string->str[0] == ' ') | |
447 g_string_erase(string, 0, 1); | |
448 | |
449 while (string->len > 0 && string->str[string->len - 1] == ' ') | |
450 g_string_erase(string, string->len - 1, 1); | |
451 } | |
452 | |
453 static void | |
454 strip_lower_string(GString *string) | |
455 { | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
456 gchar *lower; |
2529 | 457 strip_string(string); |
2609 | 458 |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
459 lower = g_ascii_strdown(string->str, -1); |
2529 | 460 g_free(string->str); |
461 string->str = lower; | |
462 } | |
463 | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
464 static void |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
465 close_ini_file_free_value(gpointer value) |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
466 { |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
467 g_free((gchar*)value); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
468 } |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
469 |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
470 static void |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
471 close_ini_file_free_section(gpointer section) |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
472 { |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
473 g_hash_table_destroy((GHashTable*)section); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
474 } |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
475 |
2529 | 476 INIFile * |
477 open_ini_file(const gchar *filename) | |
2313 | 478 { |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
479 GHashTable *ini_file = NULL; |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
480 GHashTable *section = NULL; |
2529 | 481 GString *section_name, *key_name, *value; |
482 gpointer section_hash, key_hash; | |
483 gchar *buffer = NULL; | |
2313 | 484 gsize off = 0; |
2529 | 485 gsize filesize = 0; |
486 | |
2313 | 487 unsigned char x[] = { 0xff, 0xfe, 0x00 }; |
2529 | 488 |
489 g_return_val_if_fail(filename, NULL); | |
490 vfs_file_get_contents(filename, &buffer, &filesize); | |
491 if (buffer == NULL) | |
2313 | 492 return NULL; |
493 | |
494 /* | |
495 * Convert UTF-16 into something useful. Original implementation | |
496 * by incomp@#audacious. Cleanups \nenolod | |
2529 | 497 * FIXME: can't we use a GLib function for that? -- 01mf02 |
2313 | 498 */ |
2607
65543c999c7e
[svn] Check filesize before doing memcmp (potential sigsegv).
hansmi
parents:
2556
diff
changeset
|
499 if (filesize > 2 && !memcmp(&buffer[0],&x,2)) |
2529 | 500 { |
501 gchar *outbuf = g_malloc (filesize); /* it's safe to waste memory. */ | |
502 guint counter; | |
2313 | 503 |
504 for (counter = 2; counter < filesize; counter += 2) | |
2529 | 505 { |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
506 if (!memcmp(&buffer[counter+1], &x[2], 1)) { |
2313 | 507 outbuf[(counter-2)/2] = buffer[counter]; |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
508 } else { |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
509 g_free(buffer); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
510 g_free(outbuf); |
2529 | 511 return NULL; |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
512 } |
2529 | 513 } |
2313 | 514 |
515 outbuf[(counter-2)/2] = '\0'; | |
516 | |
2529 | 517 if ((filesize - 2) / 2 == (counter - 2) / 2) |
518 { | |
2313 | 519 g_free(buffer); |
520 buffer = outbuf; | |
2529 | 521 } |
522 else | |
523 { | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
524 g_free(buffer); |
2313 | 525 g_free(outbuf); |
2529 | 526 return NULL; /* XXX wrong encoding */ |
2313 | 527 } |
528 } | |
529 | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
530 section_name = g_string_new(""); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
531 key_name = g_string_new(NULL); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
532 value = g_string_new(NULL); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
533 |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
534 ini_file = g_hash_table_new_full(NULL, NULL, NULL, |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
535 close_ini_file_free_section); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
536 section = g_hash_table_new_full(NULL, NULL, NULL, |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
537 close_ini_file_free_value); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
538 /* make a nameless section which should store all entries that are not |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
539 * embedded in a section */ |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
540 section_hash = GINT_TO_POINTER(g_string_hash(section_name)); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
541 g_hash_table_insert(ini_file, section_hash, section); |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
542 |
2529 | 543 while (off < filesize) |
544 { | |
545 /* ignore the following characters */ | |
546 if (buffer[off] == '\r' || buffer[off] == '\n' || | |
547 buffer[off] == ' ' || buffer[off] == '\t') | |
548 { | |
549 if (buffer[off] == '\n') | |
550 { | |
551 g_string_free(key_name, TRUE); | |
4095
7e57ace6385a
Fix memory leak in open_ini_file() function. (Bugzilla #17)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4073
diff
changeset
|
552 g_string_free(value, TRUE); |
2529 | 553 key_name = g_string_new(NULL); |
554 value = g_string_new(NULL); | |
555 } | |
556 | |
557 off++; | |
558 continue; | |
559 } | |
560 | |
561 /* if we encounter a possible section statement */ | |
562 if (buffer[off] == '[') | |
563 { | |
564 g_string_free(section_name, TRUE); | |
565 section_name = g_string_new(NULL); | |
2313 | 566 off++; |
2529 | 567 |
568 if (off >= filesize) | |
569 goto return_sequence; | |
570 | |
571 while (buffer[off] != ']') | |
572 { | |
573 /* if the section statement has not been closed before a | |
574 * linebreak */ | |
575 if (buffer[off] == '\n') | |
576 break; | |
577 | |
578 g_string_append_c(section_name, buffer[off]); | |
579 off++; | |
580 if (off >= filesize) | |
581 goto return_sequence; | |
582 } | |
583 if (buffer[off] == '\n') | |
584 continue; | |
585 if (buffer[off] == ']') | |
586 { | |
587 off++; | |
588 if (off >= filesize) | |
589 goto return_sequence; | |
590 | |
591 strip_lower_string(section_name); | |
592 section_hash = GINT_TO_POINTER(g_string_hash(section_name)); | |
593 | |
594 /* if this section already exists, we don't make a new one, | |
595 * but reuse the old one */ | |
596 if (g_hash_table_lookup(ini_file, section_hash) != NULL) | |
597 section = g_hash_table_lookup(ini_file, section_hash); | |
598 else | |
599 { | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
600 section = g_hash_table_new_full(NULL, NULL, NULL, |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
601 close_ini_file_free_value); |
2529 | 602 g_hash_table_insert(ini_file, section_hash, section); |
2313 | 603 } |
2529 | 604 |
605 continue; | |
2313 | 606 } |
607 } | |
2529 | 608 |
609 if (buffer[off] == '=') | |
610 { | |
611 off++; | |
2313 | 612 if (off >= filesize) |
2529 | 613 goto return_sequence; |
614 | |
2556 | 615 while (buffer[off] != '\n' && buffer[off] != '\r') |
2529 | 616 { |
617 g_string_append_c(value, buffer[off]); | |
2313 | 618 off++; |
619 if (off >= filesize) | |
620 break; | |
621 } | |
2529 | 622 |
623 strip_lower_string(key_name); | |
624 key_hash = GINT_TO_POINTER(g_string_hash(key_name)); | |
625 strip_string(value); | |
626 | |
627 if (key_name->len > 0 && value->len > 0) | |
2609 | 628 g_hash_table_insert(section, key_hash, g_strdup(value->str)); |
2313 | 629 } |
2529 | 630 else |
631 { | |
632 g_string_append_c(key_name, buffer[off]); | |
2313 | 633 off++; |
2529 | 634 if (off >= filesize) |
635 goto return_sequence; | |
636 } | |
2313 | 637 } |
638 | |
2529 | 639 return_sequence: |
640 g_string_free(section_name, TRUE); | |
641 g_string_free(key_name, TRUE); | |
642 g_string_free(value, TRUE); | |
643 g_free(buffer); | |
644 return ini_file; | |
645 } | |
646 | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
647 /** |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
648 * Frees the memory allocated for inifile. |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
649 */ |
2529 | 650 void |
651 close_ini_file(INIFile *inifile) | |
652 { | |
653 g_return_if_fail(inifile); | |
654 g_hash_table_destroy(inifile); | |
655 } | |
656 | |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
657 /** |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
658 * Returns a string that corresponds to correct section and key in inifile. |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
659 * |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
660 * Returns NULL if value was not found in inifile. Otherwise returns a copy |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
661 * of string pointed by "section" and "key". Returned string should be freed |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
662 * after use. |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
663 */ |
2529 | 664 gchar * |
665 read_ini_string(INIFile *inifile, const gchar *section, const gchar *key) | |
666 { | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
667 GString *section_string; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
668 GString *key_string; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
669 gchar *value = NULL; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
670 gpointer section_hash, key_hash; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
671 GHashTable *section_table; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
672 |
2529 | 673 g_return_val_if_fail(inifile, NULL); |
674 | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
675 section_string = g_string_new(section); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
676 key_string = g_string_new(key); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
677 value = NULL; |
2529 | 678 |
679 strip_lower_string(section_string); | |
680 strip_lower_string(key_string); | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
681 section_hash = GINT_TO_POINTER(g_string_hash(section_string)); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
682 key_hash = GINT_TO_POINTER(g_string_hash(key_string)); |
4097
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
683 section_table = g_hash_table_lookup(inifile, section_hash); |
2529 | 684 |
4097
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
685 if (section_table) { |
4157
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
686 value = g_strdup(g_hash_table_lookup(section_table, |
e474286a4c23
Close_ini_file() frees all memory allocated in open_ini_file() (Bugzilla #40)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4127
diff
changeset
|
687 GINT_TO_POINTER(key_hash))); |
4097
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
688 } |
2529 | 689 |
4097
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
690 g_string_free(section_string, TRUE); |
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
691 g_string_free(key_string, TRUE); |
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
692 |
96194518173c
Fix memory leak in read_ini_string() (Bugzilla #24)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
4095
diff
changeset
|
693 g_return_val_if_fail(value, NULL); |
2529 | 694 return value; |
2313 | 695 } |
696 | |
697 GArray * | |
2529 | 698 read_ini_array(INIFile *inifile, const gchar *section, const gchar *key) |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
699 { |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
700 gchar *temp; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
701 GArray *a; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
702 |
2529 | 703 g_return_val_if_fail((temp = read_ini_string(inifile, section, key)), NULL); |
704 | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
705 a = string_to_garray(temp); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
706 g_free(temp); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
707 return a; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
708 } |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
709 |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
710 GArray * |
2313 | 711 string_to_garray(const gchar * str) |
712 { | |
713 GArray *array; | |
714 gint temp; | |
715 const gchar *ptr = str; | |
716 gchar *endptr; | |
717 | |
718 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
719 for (;;) { | |
720 temp = strtol(ptr, &endptr, 10); | |
721 if (ptr == endptr) | |
722 break; | |
723 g_array_append_val(array, temp); | |
724 ptr = endptr; | |
725 while (!isdigit((int) *ptr) && (*ptr) != '\0') | |
726 ptr++; | |
727 if (*ptr == '\0') | |
728 break; | |
729 } | |
730 return (array); | |
731 } | |
732 | |
733 void | |
734 glist_movedown(GList * list) | |
735 { | |
736 gpointer temp; | |
737 | |
738 if (g_list_next(list)) { | |
739 temp = list->data; | |
740 list->data = list->next->data; | |
741 list->next->data = temp; | |
742 } | |
743 } | |
744 | |
745 void | |
746 glist_moveup(GList * list) | |
747 { | |
748 gpointer temp; | |
749 | |
750 if (g_list_previous(list)) { | |
751 temp = list->data; | |
752 list->data = list->prev->data; | |
753 list->prev->data = temp; | |
754 } | |
755 } | |
756 | |
757 GdkFont * | |
758 util_font_load(const gchar * name) | |
759 { | |
760 GdkFont *font; | |
761 PangoFontDescription *desc; | |
762 | |
763 desc = pango_font_description_from_string(name); | |
764 font = gdk_font_from_description(desc); | |
765 | |
766 return font; | |
767 } | |
768 | |
769 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter | |
770 * Mattis et al */ | |
771 gboolean | |
772 text_get_extents(const gchar * fontname, | |
773 const gchar * text, | |
774 gint * width, gint * height, gint * ascent, gint * descent) | |
775 { | |
776 PangoFontDescription *font_desc; | |
777 PangoLayout *layout; | |
778 PangoRectangle rect; | |
779 | |
780 g_return_val_if_fail(fontname != NULL, FALSE); | |
781 g_return_val_if_fail(text != NULL, FALSE); | |
782 | |
783 /* FIXME: resolution */ | |
784 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
785 | |
786 font_desc = pango_font_description_from_string(fontname); | |
787 pango_layout_set_font_description(layout, font_desc); | |
788 pango_font_description_free(font_desc); | |
789 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
790 | |
791 if (width) | |
792 *width = rect.width; | |
793 if (height) | |
794 *height = rect.height; | |
795 | |
796 if (ascent || descent) { | |
797 PangoLayoutIter *iter; | |
798 PangoLayoutLine *line; | |
799 | |
800 iter = pango_layout_get_iter(layout); | |
801 line = pango_layout_iter_get_line(iter); | |
802 pango_layout_iter_free(iter); | |
803 | |
804 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
805 | |
806 if (ascent) | |
807 *ascent = PANGO_ASCENT(rect); | |
808 if (descent) | |
809 *descent = -PANGO_DESCENT(rect); | |
810 } | |
811 | |
812 g_object_unref(layout); | |
813 | |
814 return TRUE; | |
815 } | |
816 | |
817 /* counts number of digits in a gint */ | |
818 guint | |
819 gint_count_digits(gint n) | |
820 { | |
821 guint count = 0; | |
822 | |
823 n = ABS(n); | |
824 do { | |
825 count++; | |
826 n /= 10; | |
827 } while (n > 0); | |
828 | |
829 return count; | |
830 } | |
831 | |
832 gboolean | |
833 dir_foreach(const gchar * path, DirForeachFunc function, | |
834 gpointer user_data, GError ** error) | |
835 { | |
836 GError *error_out = NULL; | |
837 GDir *dir; | |
838 const gchar *entry; | |
839 gchar *entry_fullpath; | |
840 | |
841 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
842 g_propagate_error(error, error_out); | |
843 return FALSE; | |
844 } | |
845 | |
846 while ((entry = g_dir_read_name(dir))) { | |
847 entry_fullpath = g_build_filename(path, entry, NULL); | |
848 | |
849 if ((*function) (entry_fullpath, entry, user_data)) { | |
850 g_free(entry_fullpath); | |
851 break; | |
852 } | |
853 | |
854 g_free(entry_fullpath); | |
855 } | |
856 | |
857 g_dir_close(dir); | |
858 | |
859 return TRUE; | |
860 } | |
861 | |
862 GtkWidget * | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
863 make_filebrowser(const gchar *title, gboolean save) |
2313 | 864 { |
865 GtkWidget *dialog; | |
866 GtkWidget *button; | |
867 | |
868 g_return_val_if_fail(title != NULL, NULL); | |
869 | |
870 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
871 save ? |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
872 GTK_FILE_CHOOSER_ACTION_SAVE : |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
873 GTK_FILE_CHOOSER_ACTION_OPEN, |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
874 NULL, NULL); |
2313 | 875 |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
876 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
877 GTK_RESPONSE_REJECT); |
2313 | 878 |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
879 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
880 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
2313 | 881 |
882 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
883 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
884 GTK_RESPONSE_ACCEPT); | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
885 |
2313 | 886 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
887 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); |
2635 | 888 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ |
2313 | 889 |
890 return dialog; | |
891 } | |
892 | |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
893 /** |
4522
8f36cce36fef
Doxycomment change: xmms_show_message -> util_info_dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
4513
diff
changeset
|
894 * util_info_dialog: |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
895 * @title: The title of the message to show. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
896 * @text: The text of the message to show. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
897 * @button_text: The text of the button which will close the messagebox. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
898 * @modal: Whether or not the messagebox should be modal. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
899 * @button_action: Code to execute on when the messagebox is closed, or %NULL. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
900 * @action_data: Optional opaque data to pass to @button_action. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
901 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
902 * Displays a message box. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
903 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
904 * Return value: A GTK widget handle for the message box. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
905 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
906 GtkWidget * |
3731
0e5da33a32b7
fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents:
3730
diff
changeset
|
907 util_info_dialog(const gchar * title, const gchar * text, |
0e5da33a32b7
fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents:
3730
diff
changeset
|
908 const gchar * button_text, gboolean modal, |
0e5da33a32b7
fun util dialog shit -> vtable
William Pitcock <nenolod@atheme.org>
parents:
3730
diff
changeset
|
909 GCallback button_action, gpointer action_data) |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
910 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
911 GtkWidget *dialog; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
912 GtkWidget *dialog_vbox, *dialog_hbox, *dialog_bbox; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
913 GtkWidget *dialog_bbox_b1; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
914 GtkWidget *dialog_textlabel; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
915 GtkWidget *dialog_icon; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
916 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
917 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
918 gtk_window_set_type_hint( GTK_WINDOW(dialog) , GDK_WINDOW_TYPE_HINT_DIALOG ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
919 gtk_window_set_modal( GTK_WINDOW(dialog) , modal ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
920 gtk_window_set_title( GTK_WINDOW(dialog) , title ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
921 gtk_container_set_border_width( GTK_CONTAINER(dialog) , 10 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
922 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
923 dialog_vbox = gtk_vbox_new( FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
924 dialog_hbox = gtk_hbox_new( FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
925 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
926 /* icon */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
927 dialog_icon = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO , GTK_ICON_SIZE_DIALOG ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
928 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_icon , FALSE , FALSE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
929 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
930 /* label */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
931 dialog_textlabel = gtk_label_new( text ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
932 /* gtk_label_set_selectable( GTK_LABEL(dialog_textlabel) , TRUE ); */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
933 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_textlabel , TRUE , TRUE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
934 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
935 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_hbox , FALSE , FALSE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
936 gtk_box_pack_start( GTK_BOX(dialog_vbox) , gtk_hseparator_new() , FALSE , FALSE , 4 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
937 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
938 dialog_bbox = gtk_hbutton_box_new(); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
939 gtk_button_box_set_layout( GTK_BUTTON_BOX(dialog_bbox) , GTK_BUTTONBOX_END ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
940 dialog_bbox_b1 = gtk_button_new_with_label( button_text ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
941 g_signal_connect_swapped( G_OBJECT(dialog_bbox_b1) , "clicked" , |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
942 G_CALLBACK(gtk_widget_destroy) , dialog ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
943 if ( button_action ) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
944 g_signal_connect( G_OBJECT(dialog_bbox_b1) , "clicked" , |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
945 button_action , action_data ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
946 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
947 gtk_container_add( GTK_CONTAINER(dialog_bbox) , dialog_bbox_b1 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
948 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_bbox , FALSE , FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
949 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
950 gtk_container_add( GTK_CONTAINER(dialog) , dialog_vbox ); |
3120
3262bf0b8831
Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents:
3103
diff
changeset
|
951 |
3262bf0b8831
Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents:
3103
diff
changeset
|
952 GTK_WIDGET_SET_FLAGS( dialog_bbox_b1 , GTK_CAN_DEFAULT); |
3262bf0b8831
Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents:
3103
diff
changeset
|
953 gtk_widget_grab_default( dialog_bbox_b1 ); |
3262bf0b8831
Moving gtk_widget_grab_default() below gtk_container_add() to avoid this
Christian Birchinger <joker@netswarm.net>
parents:
3103
diff
changeset
|
954 |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
955 gtk_widget_show_all(dialog); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
956 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
957 return dialog; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
958 } |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
959 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
960 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
961 /** |
3757
d24d28e76588
export util_get_localdir().
William Pitcock <nenolod@atheme.org>
parents:
3731
diff
changeset
|
962 * util_get_localdir: |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
963 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
964 * Returns a string with the full path of Audacious local datadir (where config files are placed). |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
965 * It's useful in order to put in the right place custom config files for audacious plugins. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
966 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
967 * Return value: a string with full path of Audacious local datadir (should be freed after use) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
968 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
969 gchar* |
3757
d24d28e76588
export util_get_localdir().
William Pitcock <nenolod@atheme.org>
parents:
3731
diff
changeset
|
970 util_get_localdir(void) |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
971 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
972 gchar *datadir; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
973 gchar *tmp; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
974 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
975 if ( (tmp = getenv("XDG_CONFIG_HOME")) == NULL ) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
976 datadir = g_build_filename( g_get_home_dir() , ".config" , "audacious" , NULL ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
977 else |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
978 datadir = g_build_filename( tmp , "audacious" , NULL ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
979 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
980 return datadir; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
981 } |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
982 |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
983 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
984 gchar * |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
985 construct_uri(gchar *string, const gchar *playlist_name) // uri, path and anything else |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
986 { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
987 gchar *filename = g_strdup(string); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
988 gchar *tmp, *path; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
989 gchar *uri = NULL; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
990 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
991 /* try to translate dos path */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
992 convert_dos_path(filename); /* in place replacement */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
993 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
994 // make full path uri here |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
995 // case 1: filename is raw full path or uri |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
996 if (filename[0] == '/' || strstr(filename, "://")) { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
997 uri = g_filename_to_uri(filename, NULL, NULL); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
998 if(!uri) { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
999 uri = g_strdup(filename); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1000 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1001 g_free(filename); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1002 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1003 // case 2: filename is not raw full path nor uri, playlist path is full path |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1004 // make full path by replacing last part of playlist path with filename. (using g_build_filename) |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1005 else if (playlist_name[0] == '/' || strstr(playlist_name, "://")) { |
4451
539f3cb7b1e8
Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents:
4352
diff
changeset
|
1006 path = g_filename_from_uri(playlist_name, NULL, NULL); |
539f3cb7b1e8
Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents:
4352
diff
changeset
|
1007 if (!path) { |
539f3cb7b1e8
Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents:
4352
diff
changeset
|
1008 path = g_strdup(playlist_name); |
539f3cb7b1e8
Fix relative paths in construct_uri() function. (Bugzilla #246)
Paul Marks <paul@pmarks.net>
parents:
4352
diff
changeset
|
1009 } |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1010 tmp = strrchr(path, '/'); *tmp = '\0'; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1011 tmp = g_build_filename(path, filename, NULL); |
4073 | 1012 g_free(path); g_free(filename); |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1013 uri = g_filename_to_uri(tmp, NULL, NULL); |
4073 | 1014 g_free(tmp); |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1015 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1016 // case 3: filename is not raw full path nor uri, playlist path is not full path |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1017 // just abort. |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1018 else { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1019 g_free(filename); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1020 return NULL; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1021 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1022 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1023 AUDDBG("uri=%s\n", uri); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1024 return uri; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3993
diff
changeset
|
1025 } |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1026 |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1027 /* |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1028 * minimize number of realloc's: |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1029 * - set N to nearest power of 2 not less then N |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1030 * - double it |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1031 * |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1032 * -- asphyx |
4278 | 1033 * |
1034 * XXX: what's so smart about this?? seems wasteful and silly. --nenolod | |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1035 */ |
4278 | 1036 gpointer |
1037 smart_realloc(gpointer ptr, gsize *size) | |
1038 { | |
4556
332d2992e04c
Use gsize and g_realloc in smart_realloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
4522
diff
changeset
|
1039 *size = (gsize)pow(2, ceil(log(*size) / log(2)) + 1); |
332d2992e04c
Use gsize and g_realloc in smart_realloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
4522
diff
changeset
|
1040 return g_realloc(ptr, *size); |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1041 } |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4259
diff
changeset
|
1042 |
4352
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1043 void |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1044 make_directory(const gchar * path, mode_t mode) |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1045 { |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1046 if (g_mkdir_with_parents(path, mode) == 0) |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1047 return; |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1048 |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1049 g_printerr(_("Could not create directory (%s): %s\n"), path, |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1050 g_strerror(errno)); |
ac1f6d211223
Split BmpConfig from main.c and main.h; move around some other stuff too
mf0102 <0102@gmx.at>
parents:
4347
diff
changeset
|
1051 } |