Mercurial > audlegacy
annotate audacious/util.c @ 1621:fae6e0cfcc77 trunk
[svn] - Reapply r2161
author | nhjm449 |
---|---|
date | Tue, 05 Sep 2006 19:57:18 -0700 |
parents | 9becbe564217 |
children | 6e477dd65024 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 20 */ |
21 | |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
22 #define WEIRD_UTF_16_PLAYLIST_ENCODING |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
23 |
0 | 24 #ifdef HAVE_CONFIG_H |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #define NEED_GLADE | |
29 #include "util.h" | |
30 | |
31 #include <glib.h> | |
32 #include <glib/gi18n.h> | |
33 #include <glade/glade.h> | |
34 #include <gtk/gtk.h> | |
35 #include <gdk/gdk.h> | |
36 #include <stdio.h> | |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 #include <ctype.h> | |
40 | |
41 #include <gdk/gdkx.h> | |
42 #include <gdk/gdkkeysyms.h> | |
43 #include <X11/Xlib.h> | |
287
2d919c756941
[svn] - attach -Iaudacious to libaudcore build crap.
nenolod
parents:
284
diff
changeset
|
44 //#include <sys/ipc.h> |
0 | 45 #include <unistd.h> |
46 #include <errno.h> | |
47 | |
48 #ifdef HAVE_FTS_H | |
49 # include <fts.h> | |
50 #endif | |
51 | |
52 #include "glade.h" | |
53 #include "input.h" | |
54 #include "main.h" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
383
diff
changeset
|
55 #include "playback.h" |
0 | 56 #include "playlist.h" |
383 | 57 #include "ui_playlist.h" |
0 | 58 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
59 #ifdef USE_CHARDET |
1106 | 60 #include "../libguess/libguess.h" |
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
61 #include "../librcd/librcd.h" |
1106 | 62 #ifdef HAVE_UDET |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
63 #include <libudet_c.h> |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
64 #endif |
1106 | 65 #endif |
0 | 66 |
67 static GQuark quark_popup_data; | |
68 | |
69 | |
70 /* | |
71 * escape_shell_chars() | |
72 * | |
73 * Escapes characters that are special to the shell inside double quotes. | |
74 */ | |
75 | |
76 gchar * | |
77 escape_shell_chars(const gchar * string) | |
78 { | |
79 const gchar *special = "$`\"\\"; /* Characters to escape */ | |
80 const gchar *in = string; | |
81 gchar *out, *escaped; | |
82 gint num = 0; | |
83 | |
84 while (*in != '\0') | |
85 if (strchr(special, *in++)) | |
86 num++; | |
87 | |
88 escaped = g_malloc(strlen(string) + num + 1); | |
89 | |
90 in = string; | |
91 out = escaped; | |
92 | |
93 while (*in != '\0') { | |
94 if (strchr(special, *in)) | |
95 *out++ = '\\'; | |
96 *out++ = *in++; | |
97 } | |
98 *out = '\0'; | |
99 | |
100 return escaped; | |
101 } | |
102 | |
103 | |
104 /* | |
105 * find <file> in directory <dirname> or subdirectories. return | |
106 * pointer to complete filename which has to be freed by calling | |
107 * "g_free()" after use. Returns NULL if file could not be found. | |
108 */ | |
109 | |
110 typedef struct { | |
111 const gchar *to_match; | |
112 gchar *match; | |
113 gboolean found; | |
114 } FindFileContext; | |
115 | |
116 static gboolean | |
117 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
118 { | |
119 FindFileContext *context = data; | |
120 | |
121 if (strlen(path) > FILENAME_MAX) { | |
122 g_warning("Ignoring path: name too long (%s)", path); | |
123 return TRUE; | |
124 } | |
125 | |
126 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
127 if (!strcasecmp(basename, context->to_match)) { | |
128 context->match = g_strdup(path); | |
129 context->found = TRUE; | |
130 return TRUE; | |
131 } | |
132 } | |
133 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
134 dir_foreach(path, find_file_func, context, NULL); | |
135 if (context->found) | |
136 return TRUE; | |
137 } | |
138 | |
139 return FALSE; | |
140 } | |
141 | |
142 gchar * | |
143 find_file_recursively(const gchar * path, const gchar * filename) | |
144 { | |
145 FindFileContext context; | |
146 | |
147 context.to_match = filename; | |
148 context.match = NULL; | |
149 context.found = FALSE; | |
150 | |
151 dir_foreach(path, find_file_func, &context, NULL); | |
152 return context.match; | |
153 } | |
154 | |
155 | |
156 typedef enum { | |
157 ARCHIVE_UNKNOWN = 0, | |
158 ARCHIVE_DIR, | |
159 ARCHIVE_TAR, | |
160 ARCHIVE_TGZ, | |
161 ARCHIVE_ZIP, | |
162 ARCHIVE_TBZ2 | |
163 } ArchiveType; | |
164 | |
165 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
166 | |
167 typedef struct { | |
168 ArchiveType type; | |
169 const gchar *ext; | |
170 } ArchiveExtensionType; | |
171 | |
172 static ArchiveExtensionType archive_extensions[] = { | |
173 {ARCHIVE_TAR, ".tar"}, | |
174 {ARCHIVE_ZIP, ".wsz"}, | |
175 {ARCHIVE_ZIP, ".zip"}, | |
176 {ARCHIVE_TGZ, ".tar.gz"}, | |
177 {ARCHIVE_TGZ, ".tgz"}, | |
178 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
179 {ARCHIVE_TBZ2, ".bz2"}, | |
180 {ARCHIVE_UNKNOWN, NULL} | |
181 }; | |
182 | |
183 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
184 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
185 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
186 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
187 | |
188 static ArchiveExtractFunc archive_extract_funcs[] = { | |
189 NULL, | |
190 NULL, | |
191 archive_extract_tar, | |
192 archive_extract_tgz, | |
193 archive_extract_zip, | |
194 archive_extract_tbz2 | |
195 }; | |
196 | |
197 | |
198 /* FIXME: these functions can be generalised into a function using a | |
199 * command lookup table */ | |
200 | |
201 static const gchar * | |
202 get_tar_command(void) | |
203 { | |
204 static const gchar *command = NULL; | |
205 | |
206 if (!command) { | |
207 if (!(command = getenv("TARCMD"))) | |
208 command = "tar"; | |
209 } | |
210 | |
211 return command; | |
212 } | |
213 | |
214 static const gchar * | |
215 get_unzip_command(void) | |
216 { | |
217 static const gchar *command = NULL; | |
218 | |
219 if (!command) { | |
220 if (!(command = getenv("UNZIPCMD"))) | |
221 command = "unzip"; | |
222 } | |
223 | |
224 return command; | |
225 } | |
226 | |
227 | |
228 static gchar * | |
229 archive_extract_tar(const gchar * archive, const gchar * dest) | |
230 { | |
231 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
232 get_tar_command(), archive, dest); | |
233 } | |
234 | |
235 static gchar * | |
236 archive_extract_zip(const gchar * archive, const gchar * dest) | |
237 { | |
238 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
239 get_unzip_command(), archive, dest); | |
240 } | |
241 | |
242 static gchar * | |
243 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
244 { | |
245 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
246 get_tar_command(), archive, dest); | |
247 } | |
248 | |
249 static gchar * | |
250 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
251 { | |
252 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
253 archive, get_tar_command(), dest); | |
254 } | |
255 | |
256 | |
257 ArchiveType | |
258 archive_get_type(const gchar * filename) | |
259 { | |
260 gint i = 0; | |
261 | |
262 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
263 return ARCHIVE_DIR; | |
264 | |
265 while (archive_extensions[i].ext) { | |
266 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
267 return archive_extensions[i].type; | |
268 } | |
269 i++; | |
270 } | |
271 | |
272 return ARCHIVE_UNKNOWN; | |
273 } | |
274 | |
275 gboolean | |
276 file_is_archive(const gchar * filename) | |
277 { | |
278 return (archive_get_type(filename) > ARCHIVE_DIR); | |
279 } | |
280 | |
281 gchar * | |
282 archive_basename(const gchar * str) | |
283 { | |
284 gint i = 0; | |
285 | |
286 while (archive_extensions[i].ext) { | |
287 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
288 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
289 if (end) { | |
290 return g_strndup(str, end - str); | |
291 } | |
292 break; | |
293 } | |
294 i++; | |
295 } | |
296 | |
297 return NULL; | |
298 } | |
299 | |
300 /* | |
301 decompress_archive | |
302 | |
303 Decompresses the archive "filename" to a temporary directory, | |
304 returns the path to the temp dir, or NULL if failed, | |
305 watch out tho, doesn't actually check if the system command succeeds :-| | |
306 */ | |
307 | |
308 gchar * | |
309 archive_decompress(const gchar * filename) | |
310 { | |
311 gchar *tmpdir, *cmd, *escaped_filename; | |
312 ArchiveType type; | |
313 | |
314 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
315 return NULL; | |
316 | |
317 tmpdir = g_build_filename(g_get_tmp_dir(), "bmp.XXXXXXXX", NULL); | |
318 if (!mkdtemp(tmpdir)) { | |
319 g_free(tmpdir); | |
320 g_message("Unable to load skin: Failed to create temporary " | |
321 "directory: %s", g_strerror(errno)); | |
322 return NULL; | |
323 } | |
324 | |
325 escaped_filename = escape_shell_chars(filename); | |
326 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
327 g_free(escaped_filename); | |
328 | |
329 if (!cmd) { | |
330 g_message("extraction function is NULL!"); | |
331 g_free(tmpdir); | |
332 return NULL; | |
333 } | |
334 | |
335 system(cmd); | |
336 g_free(cmd); | |
337 | |
338 return tmpdir; | |
339 } | |
340 | |
341 | |
342 #ifdef HAVE_FTS_H | |
343 | |
344 void | |
345 del_directory(const gchar * dirname) | |
346 { | |
347 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
348 FTS *fts; | |
349 FTSENT *p; | |
350 | |
351 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
352 while ((p = fts_read(fts))) { | |
353 switch (p->fts_info) { | |
354 case FTS_D: | |
355 break; | |
356 case FTS_DNR: | |
357 case FTS_ERR: | |
358 break; | |
359 case FTS_DP: | |
360 rmdir(p->fts_accpath); | |
361 break; | |
362 default: | |
363 unlink(p->fts_accpath); | |
364 break; | |
365 } | |
366 } | |
367 fts_close(fts); | |
368 } | |
369 | |
370 #else /* !HAVE_FTS */ | |
371 | |
372 gboolean | |
373 del_directory_func(const gchar * path, const gchar * basename, | |
374 gpointer params) | |
375 { | |
376 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
377 return FALSE; | |
378 | |
379 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
380 dir_foreach(path, del_directory_func, NULL, NULL); | |
381 rmdir(path); | |
382 return FALSE; | |
383 } | |
384 | |
385 unlink(path); | |
386 | |
387 return FALSE; | |
388 } | |
389 | |
390 void | |
391 del_directory(const gchar * path) | |
392 { | |
393 dir_foreach(path, del_directory_func, NULL, NULL); | |
394 rmdir(path); | |
395 } | |
396 | |
397 #endif /* ifdef HAVE_FTS */ | |
398 | |
399 gchar * | |
400 read_ini_string(const gchar * filename, const gchar * section, | |
401 const gchar * key) | |
402 { | |
1166
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
403 static gchar *buffer = NULL; |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
404 static gchar *open_buffer = NULL; |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
405 gchar *ret_buffer = NULL; |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
406 gint found_section = 0, len = 0; |
1193
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
407 static gsize filesize = 0; |
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
408 gsize off = 0; |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
409 gchar *outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
410 unsigned char x[] = { 0xff, 0xfe, 0x00 }; |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
411 guint counter; |
0 | 412 |
413 if (!filename) | |
414 return NULL; | |
415 | |
1166
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
416 /* |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
417 * We optimise for the condition that we may be reading from the |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
418 * same ini-file multiple times. This is fairly common; it happens |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
419 * on .pls playlist loads. To do otherwise would take entirely too |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
420 * long, as fstat() can be very slow when done 21,000 times too many. |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
421 * |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
422 * Therefore, we optimise by keeping the last ini file in memory. |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
423 * Yes, this is a memory leak, but it is not too bad, hopefully. |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
424 * - nenolod |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
425 */ |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
426 if (open_buffer == NULL || strcasecmp(filename, open_buffer)) |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
427 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
428 if (buffer != NULL) |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
429 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
430 g_free(buffer); |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
431 buffer = NULL; |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
432 } |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
433 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
434 if (open_buffer != NULL) |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
435 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
436 g_free(open_buffer); |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
437 open_buffer = NULL; |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
438 } |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
439 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
440 if (!g_file_get_contents(filename, &buffer, &filesize, NULL)) |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
441 return NULL; |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
442 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
443 open_buffer = g_strdup(filename); |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
444 } |
0 | 445 |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
446 /* |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
447 * Convert UTF-16 into something useful. Original implementation |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
448 * by incomp@#audacious. Cleanups \nenolod |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
449 */ |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
450 if (!memcmp(&buffer[0],&x,2)) { |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
451 outbuf = g_malloc (filesize); /* it's safe to waste memory. */ |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
452 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
453 for (counter = 2; counter < filesize; counter += 2) |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
454 if (!memcmp(&buffer[counter+1], &x[2], 1)) |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
455 outbuf[(counter-2)/2] = buffer[counter]; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
456 else |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
457 return NULL; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
458 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
459 outbuf[(counter-2)/2] = '\0'; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
460 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
461 if ((filesize - 2) / 2 == (counter - 2) / 2) { |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
462 g_free(buffer); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
463 buffer = outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
464 } else { |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
465 g_free(outbuf); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
466 return NULL; /* XXX wrong encoding */ |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
467 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
468 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
469 |
0 | 470 while (!ret_buffer && off < filesize) { |
471 while (off < filesize && | |
472 (buffer[off] == '\r' || buffer[off] == '\n' || | |
473 buffer[off] == ' ' || buffer[off] == '\t')) | |
474 off++; | |
475 if (off >= filesize) | |
476 break; | |
477 if (buffer[off] == '[') { | |
478 gint slen = strlen(section); | |
479 off++; | |
480 found_section = 0; | |
481 if (off + slen + 1 < filesize && | |
482 !strncasecmp(section, &buffer[off], slen)) { | |
483 off += slen; | |
484 if (buffer[off] == ']') { | |
485 off++; | |
486 found_section = 1; | |
487 } | |
488 } | |
489 } | |
490 else if (found_section && off + strlen(key) < filesize && | |
491 !strncasecmp(key, &buffer[off], strlen(key))) { | |
492 off += strlen(key); | |
493 while (off < filesize && | |
494 (buffer[off] == ' ' || buffer[off] == '\t')) | |
495 off++; | |
496 if (off >= filesize) | |
497 break; | |
498 if (buffer[off] == '=') { | |
499 off++; | |
500 while (off < filesize && | |
501 (buffer[off] == ' ' || buffer[off] == '\t')) | |
502 off++; | |
503 if (off >= filesize) | |
504 break; | |
505 len = 0; | |
506 while (off + len < filesize && | |
507 buffer[off + len] != '\r' && | |
508 buffer[off + len] != '\n' && buffer[off + len] != ';') | |
509 len++; | |
510 ret_buffer = g_strndup(&buffer[off], len); | |
511 off += len; | |
512 } | |
513 } | |
514 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n') | |
515 off++; | |
516 } | |
517 | |
518 return ret_buffer; | |
519 } | |
520 | |
521 GArray * | |
522 string_to_garray(const gchar * str) | |
523 { | |
524 GArray *array; | |
525 gint temp; | |
526 const gchar *ptr = str; | |
527 gchar *endptr; | |
528 | |
529 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
530 for (;;) { | |
531 temp = strtol(ptr, &endptr, 10); | |
532 if (ptr == endptr) | |
533 break; | |
534 g_array_append_val(array, temp); | |
535 ptr = endptr; | |
536 while (!isdigit(*ptr) && (*ptr) != '\0') | |
537 ptr++; | |
538 if (*ptr == '\0') | |
539 break; | |
540 } | |
541 return (array); | |
542 } | |
543 | |
544 GArray * | |
545 read_ini_array(const gchar * filename, const gchar * section, | |
546 const gchar * key) | |
547 { | |
548 gchar *temp; | |
549 GArray *a; | |
550 | |
551 if ((temp = read_ini_string(filename, section, key)) == NULL) { | |
552 g_free(temp); | |
553 return NULL; | |
554 } | |
555 a = string_to_garray(temp); | |
556 g_free(temp); | |
557 return a; | |
558 } | |
559 | |
560 void | |
561 glist_movedown(GList * list) | |
562 { | |
563 gpointer temp; | |
564 | |
565 if (g_list_next(list)) { | |
566 temp = list->data; | |
567 list->data = list->next->data; | |
568 list->next->data = temp; | |
569 } | |
570 } | |
571 | |
572 void | |
573 glist_moveup(GList * list) | |
574 { | |
575 gpointer temp; | |
576 | |
577 if (g_list_previous(list)) { | |
578 temp = list->data; | |
579 list->data = list->prev->data; | |
580 list->prev->data = temp; | |
581 } | |
582 } | |
583 | |
584 | |
585 void | |
586 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
587 gboolean * push_in, gpointer data) | |
588 { | |
589 GtkRequisition requisition; | |
590 gint screen_width; | |
591 gint screen_height; | |
592 MenuPos *pos = data; | |
593 | |
594 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
595 | |
596 screen_width = gdk_screen_width(); | |
597 screen_height = gdk_screen_height(); | |
598 | |
599 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
600 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
601 } | |
602 | |
603 static void | |
604 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory) | |
605 { | |
606 gtk_signal_disconnect_by_func(object, | |
607 GTK_SIGNAL_FUNC | |
608 (util_menu_delete_popup_data), ifactory); | |
609 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data); | |
610 } | |
611 | |
612 | |
613 /* | |
614 * util_item_factory_popup[_with_data]() is a replacement for | |
615 * gtk_item_factory_popup[_with_data](). | |
616 * | |
617 * The difference is that the menu is always popped up whithin the | |
618 * screen. This means it does not neccesarily pop up at (x,y). | |
619 */ | |
620 | |
621 void | |
622 util_item_factory_popup_with_data(GtkItemFactory * ifactory, | |
623 gpointer data, | |
624 GtkDestroyNotify destroy, guint x, | |
625 guint y, guint mouse_button, guint32 time) | |
626 { | |
627 static GQuark quark_user_menu_pos = 0; | |
628 MenuPos *pos; | |
629 | |
630 if (!quark_user_menu_pos) | |
631 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos"); | |
632 | |
633 if (!quark_popup_data) | |
634 quark_popup_data = | |
635 g_quark_from_static_string("GtkItemFactory-popup-data"); | |
636 | |
637 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos); | |
638 if (!pos) { | |
639 pos = g_new0(MenuPos, 1); | |
640 | |
641 g_object_set_qdata_full(G_OBJECT(ifactory->widget), | |
642 quark_user_menu_pos, pos, g_free); | |
643 } | |
644 pos->x = x; | |
645 pos->y = y; | |
646 | |
647 | |
648 if (data != NULL) { | |
649 g_object_set_qdata_full(G_OBJECT(ifactory), | |
650 quark_popup_data, data, destroy); | |
651 g_signal_connect(G_OBJECT(ifactory->widget), | |
652 "selection-done", | |
653 G_CALLBACK(util_menu_delete_popup_data), ifactory); | |
654 } | |
655 | |
656 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL, | |
657 (GtkMenuPositionFunc) util_menu_position, | |
658 pos, mouse_button, time); | |
659 } | |
660 | |
661 void | |
662 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y, | |
663 guint mouse_button, guint32 time) | |
664 { | |
665 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y, | |
666 mouse_button, time); | |
667 } | |
668 | |
669 | |
670 #define URL_HISTORY_MAX_SIZE 30 | |
671 | |
672 static void | |
673 util_add_url_callback(GtkWidget * widget, | |
674 GtkEntry * entry) | |
675 { | |
676 const gchar *text; | |
677 | |
678 text = gtk_entry_get_text(entry); | |
679 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp)) | |
680 return; | |
681 | |
682 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text)); | |
683 | |
684 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) { | |
685 GList *node = g_list_last(cfg.url_history); | |
686 g_free(node->data); | |
687 cfg.url_history = g_list_delete_link(cfg.url_history, node); | |
688 } | |
689 } | |
690 | |
691 GtkWidget * | |
86 | 692 util_add_url_dialog_new(const gchar * caption, GCallback ok_func, |
693 GCallback enqueue_func) | |
0 | 694 { |
86 | 695 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry; |
0 | 696 GList *url; |
697 | |
698 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
699 gtk_window_set_title(GTK_WINDOW(win), caption); | |
700 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG); | |
701 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER); | |
702 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1); | |
703 gtk_container_set_border_width(GTK_CONTAINER(win), 12); | |
704 | |
705 vbox = gtk_vbox_new(FALSE, 10); | |
706 gtk_container_add(GTK_CONTAINER(win), vbox); | |
707 | |
708 combo = gtk_combo_box_entry_new_text(); | |
709 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); | |
710 | |
711 entry = gtk_bin_get_child(GTK_BIN(combo)); | |
712 gtk_window_set_focus(GTK_WINDOW(win), entry); | |
713 gtk_entry_set_text(GTK_ENTRY(entry), ""); | |
714 | |
715 for (url = cfg.url_history; url; url = g_list_next(url)) | |
716 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data); | |
717 | |
718 g_signal_connect(entry, "activate", | |
719 G_CALLBACK(util_add_url_callback), | |
720 entry); | |
721 g_signal_connect(entry, "activate", | |
86 | 722 G_CALLBACK(ok_func), |
0 | 723 entry); |
724 g_signal_connect_swapped(entry, "activate", | |
725 G_CALLBACK(gtk_widget_destroy), | |
726 win); | |
727 | |
728 bbox = gtk_hbutton_box_new(); | |
729 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
730 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
731 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
732 | |
86 | 733 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN); |
734 g_signal_connect(ok, "clicked", | |
735 G_CALLBACK(util_add_url_callback), entry); | |
736 g_signal_connect(ok, "clicked", | |
737 G_CALLBACK(ok_func), entry); | |
738 g_signal_connect_swapped(ok, "clicked", | |
739 G_CALLBACK(gtk_widget_destroy), | |
740 win); | |
741 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0); | |
742 | |
0 | 743 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD); |
744 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0); | |
745 | |
746 g_signal_connect(enqueue, "clicked", | |
747 G_CALLBACK(util_add_url_callback), | |
748 entry); | |
749 g_signal_connect(enqueue, "clicked", | |
750 G_CALLBACK(enqueue_func), | |
751 entry); | |
752 g_signal_connect_swapped(enqueue, "clicked", | |
753 G_CALLBACK(gtk_widget_destroy), | |
754 win); | |
755 | |
756 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
757 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); | |
758 | |
759 g_signal_connect_swapped(cancel, "clicked", | |
760 G_CALLBACK(gtk_widget_destroy), | |
761 win); | |
762 | |
763 gtk_widget_show_all(vbox); | |
764 | |
765 return win; | |
766 } | |
767 | |
768 static void | |
769 filebrowser_add_files(GtkFileChooser * browser, | |
770 GSList * files) | |
771 { | |
772 GSList *cur; | |
773 gchar *ptr; | |
774 guint ctr = 0; | |
775 | |
776 if (GTK_IS_WIDGET(mainwin_jtf)) | |
777 gtk_widget_set_sensitive(mainwin_jtf, FALSE); | |
778 | |
779 for (cur = files; cur; cur = g_slist_next(cur)) { | |
780 | |
781 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) { | |
782 playlist_add_dir((const gchar *) cur->data); | |
783 } else { | |
784 playlist_add((const gchar *) cur->data); | |
785 } | |
786 | |
787 if (++ctr == 20) { | |
788 playlistwin_update_list(); | |
789 ctr = 0; | |
790 while (gtk_events_pending() ) gtk_main_iteration(); | |
791 } | |
792 } | |
793 | |
794 playlistwin_update_list(); | |
795 | |
796 if (GTK_IS_WIDGET(mainwin_jtf)) | |
797 gtk_widget_set_sensitive(mainwin_jtf, TRUE); | |
798 | |
799 #ifdef HAVE_GNOME_VFS | |
800 ptr = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(browser)); | |
801 #else | |
802 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
803 #endif | |
804 | |
805 g_free(cfg.filesel_path); | |
806 cfg.filesel_path = ptr; | |
807 } | |
808 | |
809 static void | |
810 filebrowser_add(GtkFileChooser * browser) | |
811 { | |
812 GSList *files; | |
813 | |
814 #ifdef HAVE_GNOME_VFS | |
815 files = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(browser)); | |
816 #else | |
817 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
818 #endif | |
819 | |
820 if (!files) { | |
821 return; | |
822 } | |
823 | |
824 filebrowser_add_files(browser, files); | |
825 g_slist_foreach(files, (GFunc) g_free, NULL); | |
826 g_slist_free(files); | |
827 } | |
828 | |
829 static void | |
830 filebrowser_play(GtkFileChooser * browser) | |
831 { | |
832 GSList *files; | |
833 | |
834 #ifdef HAVE_GNOME_VFS | |
835 files = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(browser)); | |
836 #else | |
837 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
838 #endif | |
839 | |
840 if (!files) return; | |
841 | |
842 playlist_clear(); | |
843 | |
844 filebrowser_add_files(browser, files); | |
845 g_slist_foreach(files, (GFunc) g_free, NULL); | |
846 g_slist_free(files); | |
847 | |
848 bmp_playback_initiate(); | |
849 } | |
850 | |
851 | |
852 static void | |
853 _filebrowser_add(GtkWidget *widget, | |
854 gpointer data) | |
855 { | |
856 filebrowser_add(data); | |
857 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data)); | |
858 } | |
859 | |
860 static void | |
861 _filebrowser_play(GtkWidget *widget, gpointer data) | |
862 { | |
863 filebrowser_play(data); | |
864 gtk_file_chooser_unselect_all(data); | |
865 } | |
866 | |
867 #if 0 | |
868 static void | |
869 filebrowser_on_response(GtkFileChooser * browser, | |
870 gint response, | |
871 gpointer data) | |
872 { | |
873 gtk_widget_hide(GTK_WIDGET(browser)); | |
874 switch (response) { | |
875 case GTK_RESPONSE_OK: | |
876 break; | |
877 case GTK_RESPONSE_ACCEPT: | |
878 break; | |
879 case GTK_RESPONSE_CLOSE: | |
880 break; | |
881 } | |
882 gtk_widget_destroy(GTK_WIDGET(browser)); | |
883 | |
884 } | |
885 | |
886 #endif | |
887 | |
888 static void | |
889 _filebrowser_check_hide_add(GtkWidget * widget, | |
890 gpointer data) | |
891 { | |
892 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
893 } | |
894 | |
895 static void | |
896 _filebrowser_check_hide_open(GtkWidget * widget, | |
897 gpointer data) | |
898 { | |
899 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
900 } | |
901 | |
902 | |
903 | |
904 static gboolean | |
905 filebrowser_on_keypress(GtkWidget * browser, | |
906 GdkEventKey * event, | |
907 gpointer data) | |
908 { | |
909 if (event->keyval == GDK_Escape) { | |
910 /* FIXME: this crashes BMP for some reason */ | |
911 /* g_signal_emit_by_name(browser, "delete-event"); */ | |
912 gtk_widget_hide(browser); | |
913 return TRUE; | |
914 } | |
915 | |
916 return FALSE; | |
917 } | |
918 | |
919 static void | |
920 _filebrowser_do_hide_add(GtkWidget *widget, | |
921 gpointer data) | |
922 { | |
923 if (cfg.close_dialog_add) | |
924 gtk_widget_hide(data); | |
925 } | |
926 | |
927 static void | |
928 _filebrowser_do_hide_open(GtkWidget *widget, | |
929 gpointer data) | |
930 { | |
931 if (cfg.close_dialog_open) | |
932 gtk_widget_hide(data); | |
933 } | |
934 | |
935 void | |
936 util_run_filebrowser(gboolean play_button) | |
937 { | |
938 static GladeXML *xml = NULL; | |
939 static GtkWidget *dialog = NULL; | |
940 static GtkWidget *chooser = NULL; | |
941 | |
942 static GtkWidget *button_add; | |
943 static GtkWidget *button_select_all, *button_deselect_all; | |
944 static GtkWidget *toggle; | |
945 | |
946 static gulong handlerid, handlerid_check, handlerid_do; | |
947 static gulong handlerid_activate, handlerid_do_activate; | |
948 | |
949 if (!xml) { | |
950 /* FIXME: Creating a file chooser dialog manually using | |
951 libglade because there's no way to stop | |
952 GtkFileChooserDialog from resizing the buttons to the same | |
953 size. The long toggle button title causes the buttons to | |
954 turn unnecessarily elongated and fugly. */ | |
955 | |
956 GtkWidget *alignment; | |
957 | |
958 xml = glade_xml_new_or_die(_("Add/Open Files dialog"), | |
959 DATA_DIR "/glade/addfiles.glade", | |
960 NULL, NULL); | |
961 glade_xml_signal_autoconnect(xml); | |
962 | |
963 dialog = glade_xml_get_widget(xml, "add_files_dialog"); | |
964 | |
965 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does | |
966 not support GtkFileChooserWidget */ | |
967 | |
968 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
969 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
970 | |
971 #ifdef HAVE_GNOME_VFS | |
972 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(chooser), FALSE); | |
973 #endif | |
974 | |
975 if (cfg.filesel_path) | |
976 #ifdef HAVE_GNOME_VFS | |
977 gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(chooser), | |
978 cfg.filesel_path); | |
979 #else | |
980 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
981 cfg.filesel_path); | |
982 #endif | |
983 | |
984 alignment = glade_xml_get_widget(xml, "alignment2"); | |
985 gtk_container_add(GTK_CONTAINER(alignment), chooser); | |
986 | |
987 toggle = glade_xml_get_widget(xml, "close_on_action"); | |
988 button_select_all = glade_xml_get_widget(xml, "select_all"); | |
989 button_deselect_all = glade_xml_get_widget(xml, "deselect_all"); | |
990 button_add = glade_xml_get_widget(xml, "action"); | |
991 | |
992 g_signal_connect_swapped(button_select_all, "clicked", | |
993 G_CALLBACK(gtk_file_chooser_select_all), | |
994 chooser); | |
995 g_signal_connect_swapped(button_deselect_all, "clicked", | |
996 G_CALLBACK(gtk_file_chooser_unselect_all), | |
997 chooser); | |
998 | |
999 g_signal_connect(dialog, "key_press_event", | |
1000 G_CALLBACK(filebrowser_on_keypress), | |
1001 NULL); | |
1002 | |
1003 gtk_widget_show_all(dialog); | |
1004 } /* !xml */ | |
1005 else { | |
1006 g_signal_handler_disconnect(button_add, handlerid); | |
1007 g_signal_handler_disconnect(toggle, handlerid_check); | |
1008 g_signal_handler_disconnect(chooser, handlerid_activate); | |
1009 g_signal_handler_disconnect(button_add, handlerid_do); | |
1010 g_signal_handler_disconnect(chooser, handlerid_do_activate); | |
893
6afdd0d7e1e1
[svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents:
879
diff
changeset
|
1011 if (cfg.refresh_file_list) { |
6afdd0d7e1e1
[svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents:
879
diff
changeset
|
1012 // *sigh* force a refresh |
6afdd0d7e1e1
[svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents:
879
diff
changeset
|
1013 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser))); |
6afdd0d7e1e1
[svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents:
879
diff
changeset
|
1014 } |
0 | 1015 } |
1016 | |
1017 if (play_button) { | |
1018 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files")); | |
1019 | |
1020 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN); | |
1021 | |
1022 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open")); | |
1023 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open); | |
1024 | |
1025 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play), chooser); | |
1026 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL); | |
1027 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog); | |
1028 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play), chooser); | |
1029 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog); | |
1030 } | |
1031 else { | |
1032 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files")); | |
1033 | |
1034 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD); | |
1035 | |
1036 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add")); | |
1037 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add); | |
1038 | |
1039 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add), chooser); | |
1040 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL); | |
1041 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog); | |
1042 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add), chooser); | |
1043 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog); | |
1044 } | |
1045 | |
1046 gtk_window_present(GTK_WINDOW(dialog)); | |
1047 } | |
1048 | |
1049 GdkFont * | |
1050 util_font_load(const gchar * name) | |
1051 { | |
1052 GdkFont *font; | |
1053 PangoFontDescription *desc; | |
1054 | |
1055 desc = pango_font_description_from_string(name); | |
1056 font = gdk_font_from_description(desc); | |
1057 | |
1058 return font; | |
1059 } | |
1060 | |
1061 #ifdef ENABLE_NLS | |
1062 gchar * | |
1063 bmp_menu_translate(const gchar * path, gpointer func_data) | |
1064 { | |
1065 gchar *translation = gettext(path); | |
1066 | |
1067 if (!translation || *translation != '/') { | |
1068 g_warning("Bad translation for menupath: %s", path); | |
1069 translation = (gchar *) path; | |
1070 } | |
1071 | |
1072 return translation; | |
1073 } | |
1074 #endif | |
1075 | |
1076 void | |
1077 util_set_cursor(GtkWidget * window) | |
1078 { | |
1079 static GdkCursor *cursor = NULL; | |
1080 | |
1081 if (!window) { | |
1082 if (cursor) { | |
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
625
diff
changeset
|
1083 gdk_cursor_unref(cursor); |
0 | 1084 cursor = NULL; |
1085 } | |
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
625
diff
changeset
|
1086 |
0 | 1087 return; |
1088 } | |
1089 | |
1090 if (!cursor) | |
1091 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
1092 | |
1093 gdk_window_set_cursor(window->window, cursor); | |
1094 } | |
1095 | |
1096 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter | |
1097 * Mattis et al */ | |
1098 gboolean | |
1099 text_get_extents(const gchar * fontname, | |
1100 const gchar * text, | |
1101 gint * width, gint * height, gint * ascent, gint * descent) | |
1102 { | |
1103 PangoFontDescription *font_desc; | |
1104 PangoLayout *layout; | |
1105 PangoRectangle rect; | |
1106 | |
1107 g_return_val_if_fail(fontname != NULL, FALSE); | |
1108 g_return_val_if_fail(text != NULL, FALSE); | |
1109 | |
1110 /* FIXME: resolution */ | |
1111 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
1112 | |
1113 font_desc = pango_font_description_from_string(fontname); | |
1114 pango_layout_set_font_description(layout, font_desc); | |
1115 pango_font_description_free(font_desc); | |
1116 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
1117 | |
1118 if (width) | |
1119 *width = rect.width; | |
1120 if (height) | |
1121 *height = rect.height; | |
1122 | |
1123 if (ascent || descent) { | |
1124 PangoLayoutIter *iter; | |
1125 PangoLayoutLine *line; | |
1126 | |
1127 iter = pango_layout_get_iter(layout); | |
1128 line = pango_layout_iter_get_line(iter); | |
1129 pango_layout_iter_free(iter); | |
1130 | |
1131 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
1132 | |
1133 if (ascent) | |
1134 *ascent = PANGO_ASCENT(rect); | |
1135 if (descent) | |
1136 *descent = -PANGO_DESCENT(rect); | |
1137 } | |
1138 | |
1139 g_object_unref(layout); | |
1140 | |
1141 return TRUE; | |
1142 } | |
1143 | |
1144 /* counts number of digits in a gint */ | |
1145 guint | |
1146 gint_count_digits(gint n) | |
1147 { | |
1148 guint count = 0; | |
1149 | |
1150 n = ABS(n); | |
1151 do { | |
1152 count++; | |
1153 n /= 10; | |
1154 } while (n > 0); | |
1155 | |
1156 return count; | |
1157 } | |
1158 | |
1159 static gchar * | |
1160 str_twenty_to_space(gchar * str) | |
1161 { | |
1162 gchar *match, *match_end; | |
1163 | |
1164 g_return_val_if_fail(str != NULL, NULL); | |
1165 | |
1166 while ((match = strstr(str, "%20"))) { | |
1167 match_end = match + 3; | |
1168 *match++ = ' '; | |
1169 while (*match_end) | |
1170 *match++ = *match_end++; | |
1171 *match = 0; | |
1172 } | |
1173 | |
1174 return str; | |
1175 } | |
1176 | |
1177 static gchar * | |
1178 str_replace_char(gchar * str, gchar old, gchar new) | |
1179 { | |
1180 gchar *match; | |
1181 | |
1182 g_return_val_if_fail(str != NULL, NULL); | |
1183 | |
1184 match = str; | |
1185 while ((match = strchr(match, old))) | |
1186 *match = new; | |
1187 | |
1188 return str; | |
1189 } | |
1190 | |
1191 gchar * | |
1192 str_append(gchar * str, const gchar * add_str) | |
1193 { | |
1194 return str_replace(str, g_strconcat(str, add_str, NULL)); | |
1195 } | |
1196 | |
1197 gchar * | |
1198 str_replace(gchar * str, gchar * new_str) | |
1199 { | |
1200 g_free(str); | |
1201 return new_str; | |
1202 } | |
1203 | |
1204 void | |
1205 str_replace_in(gchar ** str, gchar * new_str) | |
1206 { | |
1207 *str = str_replace(*str, new_str); | |
1208 } | |
1209 | |
1210 | |
1211 gboolean | |
1212 str_has_prefix_nocase(const gchar * str, const gchar * prefix) | |
1213 { | |
1214 return (strncasecmp(str, prefix, strlen(prefix)) == 0); | |
1215 } | |
1216 | |
1217 gboolean | |
1218 str_has_suffix_nocase(const gchar * str, const gchar * suffix) | |
1219 { | |
1220 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0); | |
1221 } | |
1222 | |
1223 gboolean | |
1224 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes) | |
1225 { | |
1226 gchar *const *suffix; | |
1227 | |
1228 g_return_val_if_fail(str != NULL, FALSE); | |
1229 g_return_val_if_fail(suffixes != NULL, FALSE); | |
1230 | |
1231 for (suffix = suffixes; *suffix; suffix++) | |
1232 if (str_has_suffix_nocase(str, *suffix)) | |
1233 return TRUE; | |
1234 | |
1235 return FALSE; | |
1236 } | |
1237 | |
1238 gchar * | |
1239 str_to_utf8_fallback(const gchar * str) | |
1240 { | |
1241 gchar *out_str, *convert_str, *chr; | |
1242 | |
1243 /* NULL in NULL out */ | |
1244 if (!str) | |
1245 return NULL; | |
1246 | |
1247 convert_str = g_strdup(str); | |
1248 for (chr = convert_str; *chr; chr++) { | |
1249 if (*chr & 0x80) | |
1250 *chr = '?'; | |
1251 } | |
1252 | |
1253 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL); | |
1254 g_free(convert_str); | |
1255 | |
1256 return out_str; | |
1257 } | |
1258 | |
1259 gchar * | |
1260 filename_to_utf8(const gchar * filename) | |
1261 { | |
1262 gchar *out_str; | |
1263 | |
1264 /* NULL in NULL out */ | |
1265 if (!filename) | |
1266 return NULL; | |
1267 | |
1268 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL))) | |
1269 return out_str; | |
1270 | |
1271 return str_to_utf8_fallback(filename); | |
1272 } | |
1273 | |
1274 gchar * | |
1275 str_to_utf8(const gchar * str) | |
1276 { | |
1277 gchar *out_str; | |
1278 | |
1279 /* NULL in NULL out */ | |
1280 if (!str) | |
1281 return NULL; | |
1282 | |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1283 /* Note: Currently, playlist calls this function repeatedly, even |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1284 * if the string is already converted into utf-8. |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1285 * chardet_to_utf8() would convert a valid utf-8 string into a |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1286 * different utf-8 string, if fallback encodings were supplied and |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1287 * the given string could be treated as a string in one of fallback |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1288 * encodings. To avoid this, the order of evaluation has been |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1289 * changed. (It might cause a drawback?) |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1290 */ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1291 /* already UTF-8? */ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1292 if (g_utf8_validate(str, -1, NULL)) |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1293 return g_strdup(str); |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1294 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1295 /* chardet encoding detector */ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1296 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL))) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1297 return out_str; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1298 |
0 | 1299 /* assume encoding associated with locale */ |
1300 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) | |
1301 return out_str; | |
1302 | |
1303 /* all else fails, we mask off character codes >= 128, | |
1304 replace with '?' */ | |
1305 return str_to_utf8_fallback(str); | |
1306 } | |
1307 | |
1308 | |
1309 const gchar * | |
1310 str_skip_chars(const gchar * str, const gchar * chars) | |
1311 { | |
1312 while (strchr(chars, *str)) | |
1313 str++; | |
1314 return str; | |
1315 } | |
1316 | |
1317 gchar * | |
1318 convert_title_text(gchar * title) | |
1319 { | |
1320 g_return_val_if_fail(title != NULL, NULL); | |
1321 | |
1322 if (cfg.convert_underscore) | |
1323 str_replace_char(title, '_', ' '); | |
1324 | |
1325 if (cfg.convert_twenty) | |
1326 str_twenty_to_space(title); | |
1327 | |
1328 return title; | |
1329 } | |
1330 | |
1331 | |
1332 gboolean | |
1333 dir_foreach(const gchar * path, DirForeachFunc function, | |
1334 gpointer user_data, GError ** error) | |
1335 { | |
1336 GError *error_out = NULL; | |
1337 GDir *dir; | |
1338 const gchar *entry; | |
1339 gchar *entry_fullpath; | |
1340 | |
1341 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
1342 g_propagate_error(error, error_out); | |
1343 return FALSE; | |
1344 } | |
1345 | |
1346 while ((entry = g_dir_read_name(dir))) { | |
1347 entry_fullpath = g_build_filename(path, entry, NULL); | |
1348 | |
1349 if ((*function) (entry_fullpath, entry, user_data)) { | |
1350 g_free(entry_fullpath); | |
1351 break; | |
1352 } | |
1353 | |
1354 g_free(entry_fullpath); | |
1355 } | |
1356 | |
1357 g_dir_close(dir); | |
1358 | |
1359 return TRUE; | |
1360 } | |
1361 | |
1362 GtkWidget * | |
1363 make_filebrowser(const gchar * title, | |
1364 gboolean save) | |
1365 { | |
1366 GtkWidget *dialog; | |
1367 GtkWidget *button; | |
1368 GtkWidget *button_close; | |
1369 | |
1370 g_return_val_if_fail(title != NULL, NULL); | |
1371 | |
1372 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
376 | 1373 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); |
0 | 1374 if (save) |
1375 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), | |
1376 GTK_FILE_CHOOSER_ACTION_SAVE); | |
1377 | |
1378 if (!save) | |
1379 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
1380 | |
1381 g_signal_connect(dialog, "destroy", | |
1382 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
1383 | |
1384 #ifdef HAVE_GNOME_VFS | |
1385 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE); | |
1386 #endif | |
1387 | |
1388 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
1389 GTK_RESPONSE_REJECT); | |
1390 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
1391 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT); | |
1392 g_signal_connect_swapped(button_close, "clicked", | |
1393 G_CALLBACK(gtk_widget_destroy), dialog); | |
1394 | |
1395 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
1396 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
1397 GTK_RESPONSE_ACCEPT); | |
1398 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
1399 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1400 gtk_window_set_default(GTK_WINDOW(dialog), button); | |
1401 | |
1402 gtk_widget_show(dialog); | |
1403 | |
1404 return dialog; | |
1405 } | |
1406 | |
1407 | |
1408 GtkItemFactory * | |
1409 create_menu(GtkItemFactoryEntry *entries, | |
1410 guint n_entries, | |
1411 GtkAccelGroup *accel) | |
1412 { | |
1413 GtkItemFactory *menu; | |
1414 | |
1415 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel); | |
1416 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL, | |
1417 NULL); | |
1418 gtk_item_factory_create_items(menu, n_entries, entries, NULL); | |
1419 | |
1420 return menu; | |
1421 } | |
1422 | |
1423 | |
1424 void | |
1425 make_submenu(GtkItemFactory *menu, | |
1426 const gchar *item_path, | |
1427 GtkItemFactory *submenu) | |
1428 { | |
1429 GtkWidget *item, *menu_; | |
1430 | |
1431 item = gtk_item_factory_get_widget(menu, item_path); | |
1432 menu_ = gtk_item_factory_get_widget(submenu, ""); | |
1433 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_); | |
1434 } | |
1435 | |
1436 | |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1437 gchar *chardet_to_utf8(const gchar *str, gssize len, |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1438 gsize *arg_bytes_read, gsize *arg_bytes_write, GError **arg_error) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1439 { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1440 #ifdef USE_CHARDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1441 char *det = NULL, *encoding = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1442 #endif |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1443 gchar *ret = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1444 gsize *bytes_read, *bytes_write; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1445 GError **error; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1446 gsize my_bytes_read, my_bytes_write; |
0 | 1447 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1448 bytes_read = arg_bytes_read ? arg_bytes_read : &my_bytes_read; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1449 bytes_write = arg_bytes_write ? arg_bytes_write : &my_bytes_write; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1450 error = arg_error ? arg_error : NULL; |
0 | 1451 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1452 #ifdef USE_CHARDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1453 if(cfg.chardet_detector) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1454 det = cfg.chardet_detector; |
0 | 1455 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1456 if(det){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1457 if(!strncasecmp("japanese", det, sizeof("japanese"))) { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1458 encoding = (char *)guess_jp(str, strlen(str)); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1459 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1460 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1461 } else if(!strncasecmp("taiwanese", det, sizeof("taiwanese"))) { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1462 encoding = (char *)guess_tw(str, strlen(str)); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1463 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1464 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1465 } else if(!strncasecmp("chinese", det, sizeof("chinese"))) { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1466 encoding = (char *)guess_cn(str, strlen(str)); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1467 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1468 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1469 } else if(!strncasecmp("korean", det, sizeof("korean"))) { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1470 encoding = (char *)guess_kr(str, strlen(str)); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1471 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1472 goto fallback; |
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1473 } else if(!strncasecmp("russian", det, sizeof("russian"))) { |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1474 rcd_russian_charset res = rcdGetRussianCharset(str, strlen(str)); |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1475 switch(res) { |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1476 case RUSSIAN_CHARSET_WIN: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1477 encoding = "CP1251"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1478 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1479 case RUSSIAN_CHARSET_ALT: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1480 encoding = "CP866"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1481 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1482 case RUSSIAN_CHARSET_KOI: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1483 encoding = "KOI8-R"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1484 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1485 case RUSSIAN_CHARSET_UTF8: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1486 encoding = "UTF-8"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1487 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1488 } |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1489 if (!encoding) |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1490 goto fallback; |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1491 #ifdef HAVE_UDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1492 } else if (!strncasecmp("universal", det, sizeof("universal"))) { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1493 encoding = (char *)detectCharset((char *)str, strlen(str)); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1494 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1495 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1496 #endif |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1497 } else /* none, invalid */ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1498 goto fallback; |
0 | 1499 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1500 ret = g_convert(str, len, "UTF-8", encoding, bytes_read, bytes_write, error); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1501 } |
0 | 1502 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1503 fallback: |
1123
170f9b68dd03
[svn] The fallback label is not used unless detection is defined. Move endif down to reflect that.
chainsaw
parents:
1106
diff
changeset
|
1504 #endif |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1505 if(!ret && cfg.chardet_fallback){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1506 gchar **encs=NULL, **enc=NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1507 encs = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1508 |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1509 if(encs){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1510 enc = encs; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1511 for(enc=encs; *enc ; enc++){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1512 ret = g_convert(str, len, "UTF-8", *enc, bytes_read, bytes_write, error); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1513 if(len == *bytes_read){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1514 break; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1515 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1516 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1517 g_strfreev(encs); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1518 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1519 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1520 |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1521 #ifdef USE_CHARDET |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1522 /* many tag libraries return 2byte latin1 utf8 character as |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1523 converted 8bit iso-8859-1 character, if they are asked to return |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1524 latin1 string. |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1525 */ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1526 if(!ret){ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1527 ret = g_convert(str, len, "UTF-8", "ISO-8859-1", bytes_read, bytes_write, error); |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1528 } |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1529 #endif |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1530 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1531 if(ret){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1532 if(g_utf8_validate(ret, -1, NULL)) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1533 return ret; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1534 else { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1535 g_free(ret); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1536 ret = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1537 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1538 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1539 |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1540 return NULL; /* if I have no idea, return NULL. */ |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1541 } |