Mercurial > audlegacy
annotate audacious/util.c @ 2105:f18a5b617c34 trunk
[svn] - move to GPLv2-only. Based on my interpretation of the license, we are
allowed to do this, so we are.
author | nenolod |
---|---|
date | Tue, 12 Dec 2006 08:38:32 -0800 |
parents | bc47a2129067 |
children | 299651a8f107 |
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 | |
2105
f18a5b617c34
[svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents:
2087
diff
changeset
|
9 * the Free Software Foundation; under version 2 of the License. |
0 | 10 * |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
1459 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 19 */ |
20 | |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
21 #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
|
22 |
0 | 23 #ifdef HAVE_CONFIG_H |
24 # include "config.h" | |
25 #endif | |
26 | |
27 #define NEED_GLADE | |
28 #include "util.h" | |
29 | |
30 #include <glib.h> | |
31 #include <glib/gi18n.h> | |
32 #include <glade/glade.h> | |
33 #include <gtk/gtk.h> | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <ctype.h> | |
38 | |
1640 | 39 #include "platform/smartinclude.h" |
0 | 40 #include <gdk/gdkkeysyms.h> |
41 #include <X11/Xlib.h> | |
287
2d919c756941
[svn] - attach -Iaudacious to libaudcore build crap.
nenolod
parents:
284
diff
changeset
|
42 //#include <sys/ipc.h> |
0 | 43 #include <unistd.h> |
44 #include <errno.h> | |
45 | |
46 #ifdef HAVE_FTS_H | |
47 # include <fts.h> | |
48 #endif | |
49 | |
50 #include "glade.h" | |
51 #include "input.h" | |
52 #include "main.h" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
383
diff
changeset
|
53 #include "playback.h" |
0 | 54 #include "playlist.h" |
1653 | 55 #include "ui_playlist.h" |
0 | 56 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
57 #ifdef USE_CHARDET |
1106 | 58 #include "../libguess/libguess.h" |
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
59 #include "../librcd/librcd.h" |
1106 | 60 #ifdef HAVE_UDET |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
61 #include <libudet_c.h> |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
62 #endif |
1106 | 63 #endif |
0 | 64 |
65 static GQuark quark_popup_data; | |
66 | |
67 | |
68 /* | |
69 * escape_shell_chars() | |
70 * | |
71 * Escapes characters that are special to the shell inside double quotes. | |
72 */ | |
73 | |
74 gchar * | |
75 escape_shell_chars(const gchar * string) | |
76 { | |
77 const gchar *special = "$`\"\\"; /* Characters to escape */ | |
78 const gchar *in = string; | |
79 gchar *out, *escaped; | |
80 gint num = 0; | |
81 | |
82 while (*in != '\0') | |
83 if (strchr(special, *in++)) | |
84 num++; | |
85 | |
86 escaped = g_malloc(strlen(string) + num + 1); | |
87 | |
88 in = string; | |
89 out = escaped; | |
90 | |
91 while (*in != '\0') { | |
92 if (strchr(special, *in)) | |
93 *out++ = '\\'; | |
94 *out++ = *in++; | |
95 } | |
96 *out = '\0'; | |
97 | |
98 return escaped; | |
99 } | |
100 | |
101 | |
102 /* | |
103 * find <file> in directory <dirname> or subdirectories. return | |
104 * pointer to complete filename which has to be freed by calling | |
105 * "g_free()" after use. Returns NULL if file could not be found. | |
106 */ | |
107 | |
108 typedef struct { | |
109 const gchar *to_match; | |
110 gchar *match; | |
111 gboolean found; | |
112 } FindFileContext; | |
113 | |
114 static gboolean | |
115 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
116 { | |
117 FindFileContext *context = data; | |
118 | |
119 if (strlen(path) > FILENAME_MAX) { | |
120 g_warning("Ignoring path: name too long (%s)", path); | |
121 return TRUE; | |
122 } | |
123 | |
124 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
125 if (!strcasecmp(basename, context->to_match)) { | |
126 context->match = g_strdup(path); | |
127 context->found = TRUE; | |
128 return TRUE; | |
129 } | |
130 } | |
131 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
132 dir_foreach(path, find_file_func, context, NULL); | |
133 if (context->found) | |
134 return TRUE; | |
135 } | |
136 | |
137 return FALSE; | |
138 } | |
139 | |
140 gchar * | |
141 find_file_recursively(const gchar * path, const gchar * filename) | |
142 { | |
143 FindFileContext context; | |
144 | |
145 context.to_match = filename; | |
146 context.match = NULL; | |
147 context.found = FALSE; | |
148 | |
149 dir_foreach(path, find_file_func, &context, NULL); | |
150 return context.match; | |
151 } | |
152 | |
153 | |
154 typedef enum { | |
155 ARCHIVE_UNKNOWN = 0, | |
156 ARCHIVE_DIR, | |
157 ARCHIVE_TAR, | |
158 ARCHIVE_TGZ, | |
159 ARCHIVE_ZIP, | |
160 ARCHIVE_TBZ2 | |
161 } ArchiveType; | |
162 | |
163 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
164 | |
165 typedef struct { | |
166 ArchiveType type; | |
167 const gchar *ext; | |
168 } ArchiveExtensionType; | |
169 | |
170 static ArchiveExtensionType archive_extensions[] = { | |
171 {ARCHIVE_TAR, ".tar"}, | |
172 {ARCHIVE_ZIP, ".wsz"}, | |
173 {ARCHIVE_ZIP, ".zip"}, | |
174 {ARCHIVE_TGZ, ".tar.gz"}, | |
175 {ARCHIVE_TGZ, ".tgz"}, | |
176 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
177 {ARCHIVE_TBZ2, ".bz2"}, | |
178 {ARCHIVE_UNKNOWN, NULL} | |
179 }; | |
180 | |
181 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
182 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
183 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
184 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
185 | |
186 static ArchiveExtractFunc archive_extract_funcs[] = { | |
187 NULL, | |
188 NULL, | |
189 archive_extract_tar, | |
190 archive_extract_tgz, | |
191 archive_extract_zip, | |
192 archive_extract_tbz2 | |
193 }; | |
194 | |
195 | |
196 /* FIXME: these functions can be generalised into a function using a | |
197 * command lookup table */ | |
198 | |
199 static const gchar * | |
200 get_tar_command(void) | |
201 { | |
202 static const gchar *command = NULL; | |
203 | |
204 if (!command) { | |
205 if (!(command = getenv("TARCMD"))) | |
206 command = "tar"; | |
207 } | |
208 | |
209 return command; | |
210 } | |
211 | |
212 static const gchar * | |
213 get_unzip_command(void) | |
214 { | |
215 static const gchar *command = NULL; | |
216 | |
217 if (!command) { | |
218 if (!(command = getenv("UNZIPCMD"))) | |
219 command = "unzip"; | |
220 } | |
221 | |
222 return command; | |
223 } | |
224 | |
225 | |
226 static gchar * | |
227 archive_extract_tar(const gchar * archive, const gchar * dest) | |
228 { | |
229 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
230 get_tar_command(), archive, dest); | |
231 } | |
232 | |
233 static gchar * | |
234 archive_extract_zip(const gchar * archive, const gchar * dest) | |
235 { | |
236 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
237 get_unzip_command(), archive, dest); | |
238 } | |
239 | |
240 static gchar * | |
241 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
242 { | |
243 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
244 get_tar_command(), archive, dest); | |
245 } | |
246 | |
247 static gchar * | |
248 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
249 { | |
250 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
251 archive, get_tar_command(), dest); | |
252 } | |
253 | |
254 | |
255 ArchiveType | |
256 archive_get_type(const gchar * filename) | |
257 { | |
258 gint i = 0; | |
259 | |
260 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
261 return ARCHIVE_DIR; | |
262 | |
263 while (archive_extensions[i].ext) { | |
264 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
265 return archive_extensions[i].type; | |
266 } | |
267 i++; | |
268 } | |
269 | |
270 return ARCHIVE_UNKNOWN; | |
271 } | |
272 | |
273 gboolean | |
274 file_is_archive(const gchar * filename) | |
275 { | |
276 return (archive_get_type(filename) > ARCHIVE_DIR); | |
277 } | |
278 | |
279 gchar * | |
280 archive_basename(const gchar * str) | |
281 { | |
282 gint i = 0; | |
283 | |
284 while (archive_extensions[i].ext) { | |
285 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
286 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
287 if (end) { | |
288 return g_strndup(str, end - str); | |
289 } | |
290 break; | |
291 } | |
292 i++; | |
293 } | |
294 | |
295 return NULL; | |
296 } | |
297 | |
298 /* | |
299 decompress_archive | |
300 | |
301 Decompresses the archive "filename" to a temporary directory, | |
302 returns the path to the temp dir, or NULL if failed, | |
303 watch out tho, doesn't actually check if the system command succeeds :-| | |
304 */ | |
305 | |
306 gchar * | |
307 archive_decompress(const gchar * filename) | |
308 { | |
309 gchar *tmpdir, *cmd, *escaped_filename; | |
310 ArchiveType type; | |
1890 | 311 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
0 | 312 |
313 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
314 return NULL; | |
315 | |
1890 | 316 #ifdef HAVE_MKDTEMP |
317 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); | |
0 | 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 } | |
1890 | 324 #else |
1891 | 325 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand()); |
1890 | 326 make_directory(tmpdir, mode755); |
327 #endif | |
0 | 328 |
329 escaped_filename = escape_shell_chars(filename); | |
330 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
331 g_free(escaped_filename); | |
332 | |
333 if (!cmd) { | |
334 g_message("extraction function is NULL!"); | |
335 g_free(tmpdir); | |
336 return NULL; | |
337 } | |
338 | |
339 system(cmd); | |
340 g_free(cmd); | |
341 | |
342 return tmpdir; | |
343 } | |
344 | |
345 | |
346 #ifdef HAVE_FTS_H | |
347 | |
348 void | |
349 del_directory(const gchar * dirname) | |
350 { | |
351 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
352 FTS *fts; | |
353 FTSENT *p; | |
354 | |
355 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
356 while ((p = fts_read(fts))) { | |
357 switch (p->fts_info) { | |
358 case FTS_D: | |
359 break; | |
360 case FTS_DNR: | |
361 case FTS_ERR: | |
362 break; | |
363 case FTS_DP: | |
364 rmdir(p->fts_accpath); | |
365 break; | |
366 default: | |
367 unlink(p->fts_accpath); | |
368 break; | |
369 } | |
370 } | |
371 fts_close(fts); | |
372 } | |
373 | |
374 #else /* !HAVE_FTS */ | |
375 | |
376 gboolean | |
377 del_directory_func(const gchar * path, const gchar * basename, | |
378 gpointer params) | |
379 { | |
380 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
381 return FALSE; | |
382 | |
383 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
384 dir_foreach(path, del_directory_func, NULL, NULL); | |
385 rmdir(path); | |
386 return FALSE; | |
387 } | |
388 | |
389 unlink(path); | |
390 | |
391 return FALSE; | |
392 } | |
393 | |
394 void | |
395 del_directory(const gchar * path) | |
396 { | |
397 dir_foreach(path, del_directory_func, NULL, NULL); | |
398 rmdir(path); | |
399 } | |
400 | |
401 #endif /* ifdef HAVE_FTS */ | |
402 | |
403 gchar * | |
404 read_ini_string(const gchar * filename, const gchar * section, | |
405 const gchar * key) | |
406 { | |
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
|
407 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
|
408 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
|
409 gchar *ret_buffer = NULL; |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
410 gint found_section = 0, len = 0; |
1193
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
411 static gsize filesize = 0; |
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
412 gsize off = 0; |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
413 gchar *outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
414 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
|
415 guint counter; |
0 | 416 |
417 if (!filename) | |
418 return NULL; | |
419 | |
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
|
420 /* |
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 * 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
|
422 * 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
|
423 * 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
|
424 * 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
|
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 * 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
|
427 * 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
|
428 * - 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
|
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 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
|
431 { |
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 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
|
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 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
|
435 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
|
436 } |
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 |
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 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
|
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 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
|
441 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
|
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 |
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 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
|
445 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
|
446 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
447 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
|
448 } |
0 | 449 |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
450 /* |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
451 * 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
|
452 * 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
|
453 */ |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
454 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
|
455 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
|
456 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
457 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
|
458 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
|
459 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
|
460 else |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
461 return NULL; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
462 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
463 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
|
464 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
465 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
|
466 g_free(buffer); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
467 buffer = outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
468 } else { |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
469 g_free(outbuf); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
470 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
|
471 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
472 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
473 |
0 | 474 while (!ret_buffer && off < filesize) { |
475 while (off < filesize && | |
476 (buffer[off] == '\r' || buffer[off] == '\n' || | |
477 buffer[off] == ' ' || buffer[off] == '\t')) | |
478 off++; | |
479 if (off >= filesize) | |
480 break; | |
481 if (buffer[off] == '[') { | |
482 gint slen = strlen(section); | |
483 off++; | |
484 found_section = 0; | |
485 if (off + slen + 1 < filesize && | |
486 !strncasecmp(section, &buffer[off], slen)) { | |
487 off += slen; | |
488 if (buffer[off] == ']') { | |
489 off++; | |
490 found_section = 1; | |
491 } | |
492 } | |
493 } | |
494 else if (found_section && off + strlen(key) < filesize && | |
495 !strncasecmp(key, &buffer[off], strlen(key))) { | |
496 off += strlen(key); | |
497 while (off < filesize && | |
498 (buffer[off] == ' ' || buffer[off] == '\t')) | |
499 off++; | |
500 if (off >= filesize) | |
501 break; | |
502 if (buffer[off] == '=') { | |
503 off++; | |
504 while (off < filesize && | |
505 (buffer[off] == ' ' || buffer[off] == '\t')) | |
506 off++; | |
507 if (off >= filesize) | |
508 break; | |
509 len = 0; | |
510 while (off + len < filesize && | |
511 buffer[off + len] != '\r' && | |
512 buffer[off + len] != '\n' && buffer[off + len] != ';') | |
513 len++; | |
514 ret_buffer = g_strndup(&buffer[off], len); | |
515 off += len; | |
516 } | |
517 } | |
518 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n') | |
519 off++; | |
520 } | |
521 | |
522 return ret_buffer; | |
523 } | |
524 | |
525 GArray * | |
526 string_to_garray(const gchar * str) | |
527 { | |
528 GArray *array; | |
529 gint temp; | |
530 const gchar *ptr = str; | |
531 gchar *endptr; | |
532 | |
533 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
534 for (;;) { | |
535 temp = strtol(ptr, &endptr, 10); | |
536 if (ptr == endptr) | |
537 break; | |
538 g_array_append_val(array, temp); | |
539 ptr = endptr; | |
1717
837983bac90f
[svn] Fixed a lot of warnings that only showed up on *BSD.
js
parents:
1653
diff
changeset
|
540 while (!isdigit((int) *ptr) && (*ptr) != '\0') |
0 | 541 ptr++; |
542 if (*ptr == '\0') | |
543 break; | |
544 } | |
545 return (array); | |
546 } | |
547 | |
548 GArray * | |
549 read_ini_array(const gchar * filename, const gchar * section, | |
550 const gchar * key) | |
551 { | |
552 gchar *temp; | |
553 GArray *a; | |
554 | |
555 if ((temp = read_ini_string(filename, section, key)) == NULL) { | |
556 g_free(temp); | |
557 return NULL; | |
558 } | |
559 a = string_to_garray(temp); | |
560 g_free(temp); | |
561 return a; | |
562 } | |
563 | |
564 void | |
565 glist_movedown(GList * list) | |
566 { | |
567 gpointer temp; | |
568 | |
569 if (g_list_next(list)) { | |
570 temp = list->data; | |
571 list->data = list->next->data; | |
572 list->next->data = temp; | |
573 } | |
574 } | |
575 | |
576 void | |
577 glist_moveup(GList * list) | |
578 { | |
579 gpointer temp; | |
580 | |
581 if (g_list_previous(list)) { | |
582 temp = list->data; | |
583 list->data = list->prev->data; | |
584 list->prev->data = temp; | |
585 } | |
586 } | |
587 | |
588 | |
589 void | |
590 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
591 gboolean * push_in, gpointer data) | |
592 { | |
593 GtkRequisition requisition; | |
594 gint screen_width; | |
595 gint screen_height; | |
596 MenuPos *pos = data; | |
597 | |
598 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
599 | |
600 screen_width = gdk_screen_width(); | |
601 screen_height = gdk_screen_height(); | |
602 | |
603 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
604 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
605 } | |
606 | |
607 static void | |
608 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory) | |
609 { | |
610 gtk_signal_disconnect_by_func(object, | |
611 GTK_SIGNAL_FUNC | |
612 (util_menu_delete_popup_data), ifactory); | |
613 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data); | |
614 } | |
615 | |
616 | |
617 /* | |
618 * util_item_factory_popup[_with_data]() is a replacement for | |
619 * gtk_item_factory_popup[_with_data](). | |
620 * | |
621 * The difference is that the menu is always popped up whithin the | |
622 * screen. This means it does not neccesarily pop up at (x,y). | |
623 */ | |
624 | |
625 void | |
626 util_item_factory_popup_with_data(GtkItemFactory * ifactory, | |
627 gpointer data, | |
628 GtkDestroyNotify destroy, guint x, | |
629 guint y, guint mouse_button, guint32 time) | |
630 { | |
631 static GQuark quark_user_menu_pos = 0; | |
632 MenuPos *pos; | |
633 | |
634 if (!quark_user_menu_pos) | |
635 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos"); | |
636 | |
637 if (!quark_popup_data) | |
638 quark_popup_data = | |
639 g_quark_from_static_string("GtkItemFactory-popup-data"); | |
640 | |
641 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos); | |
642 if (!pos) { | |
643 pos = g_new0(MenuPos, 1); | |
644 | |
645 g_object_set_qdata_full(G_OBJECT(ifactory->widget), | |
646 quark_user_menu_pos, pos, g_free); | |
647 } | |
648 pos->x = x; | |
649 pos->y = y; | |
650 | |
651 | |
652 if (data != NULL) { | |
653 g_object_set_qdata_full(G_OBJECT(ifactory), | |
654 quark_popup_data, data, destroy); | |
655 g_signal_connect(G_OBJECT(ifactory->widget), | |
656 "selection-done", | |
657 G_CALLBACK(util_menu_delete_popup_data), ifactory); | |
658 } | |
659 | |
660 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL, | |
661 (GtkMenuPositionFunc) util_menu_position, | |
662 pos, mouse_button, time); | |
663 } | |
664 | |
665 void | |
666 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y, | |
667 guint mouse_button, guint32 time) | |
668 { | |
669 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y, | |
670 mouse_button, time); | |
671 } | |
672 | |
673 | |
674 #define URL_HISTORY_MAX_SIZE 30 | |
675 | |
676 static void | |
677 util_add_url_callback(GtkWidget * widget, | |
678 GtkEntry * entry) | |
679 { | |
680 const gchar *text; | |
681 | |
682 text = gtk_entry_get_text(entry); | |
683 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp)) | |
684 return; | |
685 | |
686 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text)); | |
687 | |
688 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) { | |
689 GList *node = g_list_last(cfg.url_history); | |
690 g_free(node->data); | |
691 cfg.url_history = g_list_delete_link(cfg.url_history, node); | |
692 } | |
693 } | |
694 | |
695 GtkWidget * | |
86 | 696 util_add_url_dialog_new(const gchar * caption, GCallback ok_func, |
697 GCallback enqueue_func) | |
0 | 698 { |
86 | 699 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry; |
0 | 700 GList *url; |
701 | |
702 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
703 gtk_window_set_title(GTK_WINDOW(win), caption); | |
704 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG); | |
705 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER); | |
706 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1); | |
707 gtk_container_set_border_width(GTK_CONTAINER(win), 12); | |
708 | |
709 vbox = gtk_vbox_new(FALSE, 10); | |
710 gtk_container_add(GTK_CONTAINER(win), vbox); | |
711 | |
712 combo = gtk_combo_box_entry_new_text(); | |
713 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); | |
714 | |
715 entry = gtk_bin_get_child(GTK_BIN(combo)); | |
716 gtk_window_set_focus(GTK_WINDOW(win), entry); | |
717 gtk_entry_set_text(GTK_ENTRY(entry), ""); | |
718 | |
719 for (url = cfg.url_history; url; url = g_list_next(url)) | |
720 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data); | |
721 | |
722 g_signal_connect(entry, "activate", | |
723 G_CALLBACK(util_add_url_callback), | |
724 entry); | |
725 g_signal_connect(entry, "activate", | |
86 | 726 G_CALLBACK(ok_func), |
0 | 727 entry); |
728 g_signal_connect_swapped(entry, "activate", | |
729 G_CALLBACK(gtk_widget_destroy), | |
730 win); | |
731 | |
732 bbox = gtk_hbutton_box_new(); | |
733 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
734 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
735 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
736 | |
86 | 737 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN); |
738 g_signal_connect(ok, "clicked", | |
739 G_CALLBACK(util_add_url_callback), entry); | |
740 g_signal_connect(ok, "clicked", | |
741 G_CALLBACK(ok_func), entry); | |
742 g_signal_connect_swapped(ok, "clicked", | |
743 G_CALLBACK(gtk_widget_destroy), | |
744 win); | |
745 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0); | |
746 | |
0 | 747 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD); |
748 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0); | |
749 | |
750 g_signal_connect(enqueue, "clicked", | |
751 G_CALLBACK(util_add_url_callback), | |
752 entry); | |
753 g_signal_connect(enqueue, "clicked", | |
754 G_CALLBACK(enqueue_func), | |
755 entry); | |
756 g_signal_connect_swapped(enqueue, "clicked", | |
757 G_CALLBACK(gtk_widget_destroy), | |
758 win); | |
759 | |
760 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
761 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); | |
762 | |
763 g_signal_connect_swapped(cancel, "clicked", | |
764 G_CALLBACK(gtk_widget_destroy), | |
765 win); | |
766 | |
767 gtk_widget_show_all(vbox); | |
768 | |
769 return win; | |
770 } | |
771 | |
772 static void | |
773 filebrowser_add_files(GtkFileChooser * browser, | |
774 GSList * files) | |
775 { | |
776 GSList *cur; | |
777 gchar *ptr; | |
778 guint ctr = 0; | |
2087 | 779 Playlist *playlist = playlist_get_active(); |
0 | 780 |
781 if (GTK_IS_WIDGET(mainwin_jtf)) | |
782 gtk_widget_set_sensitive(mainwin_jtf, FALSE); | |
783 | |
784 for (cur = files; cur; cur = g_slist_next(cur)) { | |
785 | |
786 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) { | |
2087 | 787 playlist_add_dir(playlist, (const gchar *) cur->data); |
0 | 788 } else { |
2087 | 789 playlist_add(playlist, (const gchar *) cur->data); |
0 | 790 } |
791 | |
792 if (++ctr == 20) { | |
793 playlistwin_update_list(); | |
794 ctr = 0; | |
795 while (gtk_events_pending() ) gtk_main_iteration(); | |
796 } | |
797 } | |
798 | |
799 playlistwin_update_list(); | |
800 | |
801 if (GTK_IS_WIDGET(mainwin_jtf)) | |
802 gtk_widget_set_sensitive(mainwin_jtf, TRUE); | |
803 | |
804 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
805 | |
806 g_free(cfg.filesel_path); | |
807 cfg.filesel_path = ptr; | |
808 } | |
809 | |
810 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
811 filebrowser_add(GtkFileChooser *browser) |
0 | 812 { |
813 GSList *files; | |
814 | |
815 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
816 | |
817 if (!files) { | |
818 return; | |
819 } | |
820 | |
821 filebrowser_add_files(browser, files); | |
822 g_slist_foreach(files, (GFunc) g_free, NULL); | |
823 g_slist_free(files); | |
824 } | |
825 | |
826 static void | |
827 filebrowser_play(GtkFileChooser * browser) | |
828 { | |
829 GSList *files; | |
830 | |
831 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
832 | |
833 if (!files) return; | |
834 | |
2087 | 835 playlist_clear(playlist_get_active()); |
0 | 836 |
837 filebrowser_add_files(browser, files); | |
838 g_slist_foreach(files, (GFunc) g_free, NULL); | |
839 g_slist_free(files); | |
840 | |
841 bmp_playback_initiate(); | |
842 } | |
843 | |
844 | |
845 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
846 _filebrowser_add_gtk2(GtkWidget *widget, |
0 | 847 gpointer data) |
848 { | |
849 filebrowser_add(data); | |
850 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data)); | |
851 } | |
852 | |
853 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
854 _filebrowser_play_gtk2(GtkWidget *widget, gpointer data) |
0 | 855 { |
856 filebrowser_play(data); | |
857 gtk_file_chooser_unselect_all(data); | |
858 } | |
859 | |
860 #if 0 | |
861 static void | |
862 filebrowser_on_response(GtkFileChooser * browser, | |
863 gint response, | |
864 gpointer data) | |
865 { | |
866 gtk_widget_hide(GTK_WIDGET(browser)); | |
867 switch (response) { | |
868 case GTK_RESPONSE_OK: | |
869 break; | |
870 case GTK_RESPONSE_ACCEPT: | |
871 break; | |
872 case GTK_RESPONSE_CLOSE: | |
873 break; | |
874 } | |
875 gtk_widget_destroy(GTK_WIDGET(browser)); | |
876 | |
877 } | |
878 | |
879 #endif | |
880 | |
881 static void | |
882 _filebrowser_check_hide_add(GtkWidget * widget, | |
883 gpointer data) | |
884 { | |
885 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
886 } | |
887 | |
888 static void | |
889 _filebrowser_check_hide_open(GtkWidget * widget, | |
890 gpointer data) | |
891 { | |
892 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
893 } | |
894 | |
895 | |
896 | |
897 static gboolean | |
898 filebrowser_on_keypress(GtkWidget * browser, | |
899 GdkEventKey * event, | |
900 gpointer data) | |
901 { | |
902 if (event->keyval == GDK_Escape) { | |
903 /* FIXME: this crashes BMP for some reason */ | |
904 /* g_signal_emit_by_name(browser, "delete-event"); */ | |
905 gtk_widget_hide(browser); | |
906 return TRUE; | |
907 } | |
908 | |
909 return FALSE; | |
910 } | |
911 | |
912 static void | |
913 _filebrowser_do_hide_add(GtkWidget *widget, | |
914 gpointer data) | |
915 { | |
916 if (cfg.close_dialog_add) | |
917 gtk_widget_hide(data); | |
918 } | |
919 | |
920 static void | |
921 _filebrowser_do_hide_open(GtkWidget *widget, | |
922 gpointer data) | |
923 { | |
924 if (cfg.close_dialog_open) | |
925 gtk_widget_hide(data); | |
926 } | |
927 | |
928 void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
929 util_run_filebrowser_gtk2style(gboolean play_button) |
0 | 930 { |
931 static GladeXML *xml = NULL; | |
932 static GtkWidget *dialog = NULL; | |
933 static GtkWidget *chooser = NULL; | |
934 | |
935 static GtkWidget *button_add; | |
936 static GtkWidget *button_select_all, *button_deselect_all; | |
937 static GtkWidget *toggle; | |
938 | |
939 static gulong handlerid, handlerid_check, handlerid_do; | |
940 static gulong handlerid_activate, handlerid_do_activate; | |
941 | |
942 if (!xml) { | |
943 /* FIXME: Creating a file chooser dialog manually using | |
944 libglade because there's no way to stop | |
945 GtkFileChooserDialog from resizing the buttons to the same | |
946 size. The long toggle button title causes the buttons to | |
947 turn unnecessarily elongated and fugly. */ | |
948 | |
949 GtkWidget *alignment; | |
950 | |
951 xml = glade_xml_new_or_die(_("Add/Open Files dialog"), | |
952 DATA_DIR "/glade/addfiles.glade", | |
953 NULL, NULL); | |
954 glade_xml_signal_autoconnect(xml); | |
955 | |
956 dialog = glade_xml_get_widget(xml, "add_files_dialog"); | |
957 | |
958 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does | |
959 not support GtkFileChooserWidget */ | |
960 | |
961 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
962 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
963 | |
964 if (cfg.filesel_path) | |
965 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
966 cfg.filesel_path); | |
967 | |
968 alignment = glade_xml_get_widget(xml, "alignment2"); | |
969 gtk_container_add(GTK_CONTAINER(alignment), chooser); | |
970 | |
971 toggle = glade_xml_get_widget(xml, "close_on_action"); | |
972 button_select_all = glade_xml_get_widget(xml, "select_all"); | |
973 button_deselect_all = glade_xml_get_widget(xml, "deselect_all"); | |
974 button_add = glade_xml_get_widget(xml, "action"); | |
975 | |
976 g_signal_connect_swapped(button_select_all, "clicked", | |
977 G_CALLBACK(gtk_file_chooser_select_all), | |
978 chooser); | |
979 g_signal_connect_swapped(button_deselect_all, "clicked", | |
980 G_CALLBACK(gtk_file_chooser_unselect_all), | |
981 chooser); | |
982 | |
983 g_signal_connect(dialog, "key_press_event", | |
984 G_CALLBACK(filebrowser_on_keypress), | |
985 NULL); | |
986 | |
987 gtk_widget_show_all(dialog); | |
988 } /* !xml */ | |
989 else { | |
990 g_signal_handler_disconnect(button_add, handlerid); | |
991 g_signal_handler_disconnect(toggle, handlerid_check); | |
992 g_signal_handler_disconnect(chooser, handlerid_activate); | |
993 g_signal_handler_disconnect(button_add, handlerid_do); | |
994 g_signal_handler_disconnect(chooser, handlerid_do_activate); | |
1752
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
995 |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
996 if (cfg.refresh_file_list) |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
997 { |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
998 gchar *tmp = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser)); |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
999 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), tmp); |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1000 |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1001 g_free(tmp); |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1002 } |
0 | 1003 } |
1004 | |
1005 if (play_button) { | |
1006 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files")); | |
1007 | |
1008 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN); | |
1009 | |
1010 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open")); | |
1011 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open); | |
1012 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1013 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
0 | 1014 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL); |
1015 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog); | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1016 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
0 | 1017 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog); |
1018 } | |
1019 else { | |
1020 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files")); | |
1021 | |
1022 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD); | |
1023 | |
1024 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add")); | |
1025 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add); | |
1026 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1027 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
0 | 1028 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL); |
1029 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog); | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1030 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
0 | 1031 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog); |
1032 } | |
1033 | |
1034 gtk_window_present(GTK_WINDOW(dialog)); | |
1035 } | |
1036 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1037 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1038 * Derived from Beep Media Player 0.9.6.1. |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1039 * Which is (C) 2003 - 2006 Milosz Derezynski &c |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1040 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1041 * Although I changed it quite a bit. -nenolod |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1042 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1043 static void filebrowser_changed_classic(GtkFileSelection * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1044 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1045 GList *list; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1046 GList *node; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1047 char *filename = (char *) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1048 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1049 GtkListStore *store; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1050 GtkTreeIter iter; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1051 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1052 if ((list = input_scan_dir(filename)) != NULL) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1053 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1054 * We enter a directory that has been "hijacked" by an |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1055 * input-plugin. This is used by the CDDA plugin |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1056 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1057 store = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1058 GTK_LIST_STORE(gtk_tree_view_get_model |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1059 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1060 gtk_list_store_clear(store); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1061 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1062 node = list; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1063 while (node) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1064 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1065 gtk_list_store_append(store, &iter); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1066 gtk_list_store_set(store, &iter, 0, node->data, -1); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1067 g_free(node->data); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1068 node = g_list_next(node); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1069 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1070 g_list_free(list); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1071 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1072 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1073 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1074 static void filebrowser_entry_changed_classic(GtkEditable * entry, gpointer data) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1075 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1076 filebrowser_changed_classic(GTK_FILE_SELECTION(data)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1077 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1078 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1079 gboolean util_filebrowser_is_dir_classic(GtkFileSelection * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1080 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1081 char *text; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1082 struct stat buf; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1083 gboolean retv = FALSE; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1084 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1085 text = g_strdup(gtk_file_selection_get_filename(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1086 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1087 if (stat(text, &buf) == 0 && S_ISDIR(buf.st_mode)) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1088 /* Selected directory */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1089 int len = strlen(text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1090 if (len > 3 && !strcmp(text + len - 4, "/../")) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1091 if (len == 4) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1092 /* At the root already */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1093 *(text + len - 3) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1094 else { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1095 char *ptr; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1096 *(text + len - 4) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1097 ptr = strrchr(text, '/'); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1098 *(ptr + 1) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1099 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1100 } else if (len > 2 && !strcmp(text + len - 3, "/./")) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1101 *(text + len - 2) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1102 gtk_file_selection_set_filename(filesel, text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1103 retv = TRUE; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1104 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1105 g_free(text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1106 return retv; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1107 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1108 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1109 static void filebrowser_add_files_classic(gchar ** files, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1110 GtkFileSelection * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1111 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1112 int ctr = 0; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1113 char *ptr; |
2087 | 1114 Playlist *playlist = playlist_get_active(); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1115 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1116 if (GTK_IS_WIDGET(mainwin_jtf)) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1117 gtk_widget_set_sensitive(mainwin_jtf, FALSE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1118 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1119 while (files[ctr] != NULL) { |
2087 | 1120 playlist_add(playlist, files[ctr++]); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1121 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1122 playlistwin_update_list(); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1123 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1124 if (GTK_IS_WIDGET(mainwin_jtf)) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1125 gtk_widget_set_sensitive(mainwin_jtf, TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1126 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1127 gtk_label_get(GTK_LABEL(GTK_BIN(filesel->history_pulldown)->child), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1128 &ptr); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1129 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1130 /* This will give an extra slash if the current dir is the root. */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1131 cfg.filesel_path = g_strconcat(ptr, "/", NULL); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1132 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1133 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1134 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1135 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1136 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1137 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1138 if (util_filebrowser_is_dir_classic(GTK_FILE_SELECTION(filesel))) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1139 return; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1140 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1141 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1142 gtk_widget_destroy(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1143 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1144 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1145 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1146 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1147 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1148 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1149 if (util_filebrowser_is_dir_classic |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1150 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel)))) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1151 return; |
2087 | 1152 playlist_clear(playlist_get_active()); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1153 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1154 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1155 gtk_widget_destroy(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1156 bmp_playback_initiate(); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1157 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1158 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1159 static void filebrowser_add_selected_files_classic(GtkWidget * w, gpointer data) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1160 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1161 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1162 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1163 GtkFileSelection *filesel = GTK_FILE_SELECTION(data); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1164 files = gtk_file_selection_get_selections(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1165 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1166 filebrowser_add_files_classic(files, filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1167 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1168 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1169 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1170 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1171 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1172 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1173 static void filebrowser_add_all_files_classic(GtkWidget * w, gpointer data) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1174 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1175 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1176 GtkFileSelection *filesel; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1177 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1178 filesel = data; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1179 gtk_tree_selection_select_all(gtk_tree_view_get_selection |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1180 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1181 files = gtk_file_selection_get_selections(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1182 filebrowser_add_files_classic(files, filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1183 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1184 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1185 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1186 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1187 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1188 void |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1189 util_run_filebrowser_classic(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1190 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1191 static GtkWidget *dialog; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1192 GtkWidget *button_add_selected, *button_add_all, *button_close, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1193 *button_add; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1194 char *title; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1195 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1196 if (dialog != NULL) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1197 gtk_window_present(GTK_WINDOW(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1198 return; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1199 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1200 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1201 if (play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1202 title = _("Play files"); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1203 else |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1204 title = _("Load files"); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1205 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1206 dialog = gtk_file_selection_new(title); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1207 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1208 gtk_file_selection_set_select_multiple |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1209 (GTK_FILE_SELECTION(dialog), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1210 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1211 if (cfg.filesel_path) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1212 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1213 cfg.filesel_path); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1214 |
1907
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1215 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(dialog)); |
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1216 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); |
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1217 |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1218 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1219 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1220 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1221 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1222 * The mnemonics are quite unorthodox, but that should guarantee they're unique in any locale |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1223 * plus kinda easy to use |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1224 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1225 button_add_selected = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1226 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1227 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1228 gtk_button_set_use_underline(GTK_BUTTON(button_add_selected), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1229 g_signal_connect(G_OBJECT(button_add_selected), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1230 G_CALLBACK(filebrowser_add_selected_files_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1231 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1232 button_add_all = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1233 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1234 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1235 gtk_button_set_use_underline(GTK_BUTTON(button_add_all), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1236 g_signal_connect(G_OBJECT(button_add_all), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1237 G_CALLBACK(filebrowser_add_all_files_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1238 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1239 if (play_button) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1240 button_add = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1241 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_MEDIA_PLAY, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1242 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1243 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1244 g_signal_connect(G_OBJECT(button_add), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1245 G_CALLBACK(filebrowser_play_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1246 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1247 "clicked", G_CALLBACK(filebrowser_play_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1248 } else { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1249 button_add = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1250 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ADD, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1251 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1252 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1253 g_signal_connect(G_OBJECT(button_add), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1254 G_CALLBACK(filebrowser_ok_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1255 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1256 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1257 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1258 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1259 button_close = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1260 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1261 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1262 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1263 g_signal_connect_swapped(G_OBJECT(button_close), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1264 G_CALLBACK(gtk_widget_destroy), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1265 G_OBJECT(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1266 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1267 gtk_widget_set_size_request(dialog, 600, 450); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1268 gtk_widget_realize(dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1269 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1270 g_signal_connect(G_OBJECT |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1271 (GTK_FILE_SELECTION(dialog)->history_pulldown), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1272 "changed", G_CALLBACK(filebrowser_entry_changed_classic), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1273 dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1274 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1275 g_signal_connect(G_OBJECT(dialog), "destroy", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1276 G_CALLBACK(gtk_widget_destroyed), &dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1277 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1278 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1279 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1280 gtk_widget_show(dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1281 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1282 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1283 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1284 * util_run_filebrowser(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1285 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1286 * Inputs: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1287 * - whether or not a play button should be used |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1288 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1289 * Outputs: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1290 * - none |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1291 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1292 * Side Effects: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1293 * - either a GTK1 or a GTK2 fileselector is launched |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1294 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1295 void |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1296 util_run_filebrowser(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1297 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1298 if (!cfg.use_xmms_style_fileselector) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1299 util_run_filebrowser_gtk2style(play_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1300 else |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1301 util_run_filebrowser_classic(play_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1302 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1303 |
0 | 1304 GdkFont * |
1305 util_font_load(const gchar * name) | |
1306 { | |
1307 GdkFont *font; | |
1308 PangoFontDescription *desc; | |
1309 | |
1310 desc = pango_font_description_from_string(name); | |
1311 font = gdk_font_from_description(desc); | |
1312 | |
1313 return font; | |
1314 } | |
1315 | |
1316 #ifdef ENABLE_NLS | |
1317 gchar * | |
1318 bmp_menu_translate(const gchar * path, gpointer func_data) | |
1319 { | |
1320 gchar *translation = gettext(path); | |
1321 | |
1322 if (!translation || *translation != '/') { | |
1323 g_warning("Bad translation for menupath: %s", path); | |
1324 translation = (gchar *) path; | |
1325 } | |
1326 | |
1327 return translation; | |
1328 } | |
1329 #endif | |
1330 | |
1331 void | |
1332 util_set_cursor(GtkWidget * window) | |
1333 { | |
1334 static GdkCursor *cursor = NULL; | |
1335 | |
1336 if (!window) { | |
1337 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
|
1338 gdk_cursor_unref(cursor); |
0 | 1339 cursor = NULL; |
1340 } | |
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
|
1341 |
0 | 1342 return; |
1343 } | |
1344 | |
1345 if (!cursor) | |
1346 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
1347 | |
1348 gdk_window_set_cursor(window->window, cursor); | |
1349 } | |
1350 | |
1653 | 1351 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter |
1352 * Mattis et al */ | |
1353 gboolean | |
1354 text_get_extents(const gchar * fontname, | |
1355 const gchar * text, | |
1356 gint * width, gint * height, gint * ascent, gint * descent) | |
1357 { | |
1358 PangoFontDescription *font_desc; | |
1359 PangoLayout *layout; | |
1360 PangoRectangle rect; | |
1361 | |
1362 g_return_val_if_fail(fontname != NULL, FALSE); | |
1363 g_return_val_if_fail(text != NULL, FALSE); | |
1364 | |
1365 /* FIXME: resolution */ | |
1366 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
1367 | |
1368 font_desc = pango_font_description_from_string(fontname); | |
1369 pango_layout_set_font_description(layout, font_desc); | |
1370 pango_font_description_free(font_desc); | |
1371 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
1372 | |
1373 if (width) | |
1374 *width = rect.width; | |
1375 if (height) | |
1376 *height = rect.height; | |
1377 | |
1378 if (ascent || descent) { | |
1379 PangoLayoutIter *iter; | |
1380 PangoLayoutLine *line; | |
1381 | |
1382 iter = pango_layout_get_iter(layout); | |
1383 line = pango_layout_iter_get_line(iter); | |
1384 pango_layout_iter_free(iter); | |
1385 | |
1386 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
1387 | |
1388 if (ascent) | |
1389 *ascent = PANGO_ASCENT(rect); | |
1390 if (descent) | |
1391 *descent = -PANGO_DESCENT(rect); | |
1392 } | |
1393 | |
1394 g_object_unref(layout); | |
1395 | |
1396 return TRUE; | |
1397 } | |
1398 | |
0 | 1399 /* counts number of digits in a gint */ |
1400 guint | |
1401 gint_count_digits(gint n) | |
1402 { | |
1403 guint count = 0; | |
1404 | |
1405 n = ABS(n); | |
1406 do { | |
1407 count++; | |
1408 n /= 10; | |
1409 } while (n > 0); | |
1410 | |
1411 return count; | |
1412 } | |
1413 | |
1414 static gchar * | |
1415 str_twenty_to_space(gchar * str) | |
1416 { | |
1417 gchar *match, *match_end; | |
1418 | |
1419 g_return_val_if_fail(str != NULL, NULL); | |
1420 | |
1421 while ((match = strstr(str, "%20"))) { | |
1422 match_end = match + 3; | |
1423 *match++ = ' '; | |
1424 while (*match_end) | |
1425 *match++ = *match_end++; | |
1426 *match = 0; | |
1427 } | |
1428 | |
1429 return str; | |
1430 } | |
1431 | |
1432 static gchar * | |
1433 str_replace_char(gchar * str, gchar old, gchar new) | |
1434 { | |
1435 gchar *match; | |
1436 | |
1437 g_return_val_if_fail(str != NULL, NULL); | |
1438 | |
1439 match = str; | |
1440 while ((match = strchr(match, old))) | |
1441 *match = new; | |
1442 | |
1443 return str; | |
1444 } | |
1445 | |
1446 gchar * | |
1447 str_append(gchar * str, const gchar * add_str) | |
1448 { | |
1449 return str_replace(str, g_strconcat(str, add_str, NULL)); | |
1450 } | |
1451 | |
1452 gchar * | |
1453 str_replace(gchar * str, gchar * new_str) | |
1454 { | |
1455 g_free(str); | |
1456 return new_str; | |
1457 } | |
1458 | |
1459 void | |
1460 str_replace_in(gchar ** str, gchar * new_str) | |
1461 { | |
1462 *str = str_replace(*str, new_str); | |
1463 } | |
1464 | |
1465 | |
1466 gboolean | |
1467 str_has_prefix_nocase(const gchar * str, const gchar * prefix) | |
1468 { | |
1469 return (strncasecmp(str, prefix, strlen(prefix)) == 0); | |
1470 } | |
1471 | |
1472 gboolean | |
1473 str_has_suffix_nocase(const gchar * str, const gchar * suffix) | |
1474 { | |
1475 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0); | |
1476 } | |
1477 | |
1478 gboolean | |
1479 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes) | |
1480 { | |
1481 gchar *const *suffix; | |
1482 | |
1483 g_return_val_if_fail(str != NULL, FALSE); | |
1484 g_return_val_if_fail(suffixes != NULL, FALSE); | |
1485 | |
1486 for (suffix = suffixes; *suffix; suffix++) | |
1487 if (str_has_suffix_nocase(str, *suffix)) | |
1488 return TRUE; | |
1489 | |
1490 return FALSE; | |
1491 } | |
1492 | |
1493 gchar * | |
1494 str_to_utf8_fallback(const gchar * str) | |
1495 { | |
1496 gchar *out_str, *convert_str, *chr; | |
1497 | |
1498 /* NULL in NULL out */ | |
1499 if (!str) | |
1500 return NULL; | |
1501 | |
1502 convert_str = g_strdup(str); | |
1503 for (chr = convert_str; *chr; chr++) { | |
1504 if (*chr & 0x80) | |
1505 *chr = '?'; | |
1506 } | |
1507 | |
1508 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL); | |
1509 g_free(convert_str); | |
1510 | |
1511 return out_str; | |
1512 } | |
1513 | |
1514 gchar * | |
1515 filename_to_utf8(const gchar * filename) | |
1516 { | |
1517 gchar *out_str; | |
1518 | |
1519 /* NULL in NULL out */ | |
1520 if (!filename) | |
1521 return NULL; | |
1522 | |
1523 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL))) | |
1524 return out_str; | |
1525 | |
1526 return str_to_utf8_fallback(filename); | |
1527 } | |
1528 | |
1529 gchar * | |
1530 str_to_utf8(const gchar * str) | |
1531 { | |
1532 gchar *out_str; | |
1533 | |
1534 /* NULL in NULL out */ | |
1535 if (!str) | |
1536 return NULL; | |
1537 | |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1538 /* 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
|
1539 * 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
|
1540 * 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
|
1541 * 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
|
1542 * 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
|
1543 * 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
|
1544 * 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
|
1545 */ |
2015
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1546 /* chardet encoding detector */ |
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1547 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL))) |
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1548 return out_str; |
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1549 |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1550 /* already UTF-8? */ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1551 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
|
1552 return g_strdup(str); |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1553 |
0 | 1554 /* assume encoding associated with locale */ |
1555 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) | |
1556 return out_str; | |
1557 | |
1558 /* all else fails, we mask off character codes >= 128, | |
1559 replace with '?' */ | |
1560 return str_to_utf8_fallback(str); | |
1561 } | |
1562 | |
1563 | |
1564 const gchar * | |
1565 str_skip_chars(const gchar * str, const gchar * chars) | |
1566 { | |
1567 while (strchr(chars, *str)) | |
1568 str++; | |
1569 return str; | |
1570 } | |
1571 | |
1572 gchar * | |
1573 convert_title_text(gchar * title) | |
1574 { | |
1575 g_return_val_if_fail(title != NULL, NULL); | |
1576 | |
2019
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1577 if (cfg.convert_slash) |
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1578 str_replace_char(title, '\\', '/'); |
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1579 |
0 | 1580 if (cfg.convert_underscore) |
1581 str_replace_char(title, '_', ' '); | |
1582 | |
1583 if (cfg.convert_twenty) | |
1584 str_twenty_to_space(title); | |
1585 | |
1586 return title; | |
1587 } | |
1588 | |
1589 | |
1590 gboolean | |
1591 dir_foreach(const gchar * path, DirForeachFunc function, | |
1592 gpointer user_data, GError ** error) | |
1593 { | |
1594 GError *error_out = NULL; | |
1595 GDir *dir; | |
1596 const gchar *entry; | |
1597 gchar *entry_fullpath; | |
1598 | |
1599 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
1600 g_propagate_error(error, error_out); | |
1601 return FALSE; | |
1602 } | |
1603 | |
1604 while ((entry = g_dir_read_name(dir))) { | |
1605 entry_fullpath = g_build_filename(path, entry, NULL); | |
1606 | |
1607 if ((*function) (entry_fullpath, entry, user_data)) { | |
1608 g_free(entry_fullpath); | |
1609 break; | |
1610 } | |
1611 | |
1612 g_free(entry_fullpath); | |
1613 } | |
1614 | |
1615 g_dir_close(dir); | |
1616 | |
1617 return TRUE; | |
1618 } | |
1619 | |
1653 | 1620 GtkWidget * |
1621 make_filebrowser(const gchar * title, | |
1622 gboolean save) | |
1623 { | |
1624 GtkWidget *dialog; | |
1625 GtkWidget *button; | |
1626 GtkWidget *button_close; | |
1627 | |
1628 g_return_val_if_fail(title != NULL, NULL); | |
1629 | |
1630 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
1631 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); | |
1632 if (save) | |
1633 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), | |
1634 GTK_FILE_CHOOSER_ACTION_SAVE); | |
1635 | |
1636 if (!save) | |
1637 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
1638 | |
1639 g_signal_connect(dialog, "destroy", | |
1640 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
1641 | |
1642 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
1643 GTK_RESPONSE_REJECT); | |
1644 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
1645 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT); | |
1646 g_signal_connect_swapped(button_close, "clicked", | |
1647 G_CALLBACK(gtk_widget_destroy), dialog); | |
1648 | |
1649 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
1650 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
1651 GTK_RESPONSE_ACCEPT); | |
1652 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
1653 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1654 gtk_window_set_default(GTK_WINDOW(dialog), button); | |
1655 | |
1656 gtk_widget_show(dialog); | |
1657 | |
1658 return dialog; | |
1659 } | |
1660 | |
1661 | |
0 | 1662 GtkItemFactory * |
1663 create_menu(GtkItemFactoryEntry *entries, | |
1664 guint n_entries, | |
1665 GtkAccelGroup *accel) | |
1666 { | |
1667 GtkItemFactory *menu; | |
1668 | |
1669 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel); | |
1670 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL, | |
1671 NULL); | |
1672 gtk_item_factory_create_items(menu, n_entries, entries, NULL); | |
1673 | |
1674 return menu; | |
1675 } | |
1676 | |
1677 | |
1678 void | |
1679 make_submenu(GtkItemFactory *menu, | |
1680 const gchar *item_path, | |
1681 GtkItemFactory *submenu) | |
1682 { | |
1683 GtkWidget *item, *menu_; | |
1684 | |
1685 item = gtk_item_factory_get_widget(menu, item_path); | |
1686 menu_ = gtk_item_factory_get_widget(submenu, ""); | |
1687 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_); | |
1688 } | |
1689 | |
1690 | |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1691 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
|
1692 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
|
1693 { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1694 #ifdef USE_CHARDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1695 char *det = NULL, *encoding = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1696 #endif |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1697 gchar *ret = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1698 gsize *bytes_read, *bytes_write; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1699 GError **error; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1700 gsize my_bytes_read, my_bytes_write; |
0 | 1701 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1702 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
|
1703 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
|
1704 error = arg_error ? arg_error : NULL; |
0 | 1705 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1706 #ifdef USE_CHARDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1707 if(cfg.chardet_detector) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1708 det = cfg.chardet_detector; |
0 | 1709 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1710 if(det){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1711 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
|
1712 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
|
1713 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1714 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1715 } 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
|
1716 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
|
1717 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1718 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1719 } 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
|
1720 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
|
1721 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1722 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1723 } 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
|
1724 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
|
1725 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1726 goto fallback; |
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1727 } else if(!strncasecmp("russian", det, sizeof("russian"))) { |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1728 rcd_russian_charset res = rcdGetRussianCharset(str, strlen(str)); |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1729 switch(res) { |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1730 case RUSSIAN_CHARSET_WIN: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1731 encoding = "CP1251"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1732 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1733 case RUSSIAN_CHARSET_ALT: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1734 encoding = "CP866"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1735 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1736 case RUSSIAN_CHARSET_KOI: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1737 encoding = "KOI8-R"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1738 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1739 case RUSSIAN_CHARSET_UTF8: |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1740 encoding = "UTF-8"; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1741 break; |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1742 } |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1743 if (!encoding) |
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1744 goto fallback; |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1745 #ifdef HAVE_UDET |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1746 } 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
|
1747 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
|
1748 if (!encoding) |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1749 goto fallback; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1750 #endif |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1751 } else /* none, invalid */ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1752 goto fallback; |
0 | 1753 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1754 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
|
1755 } |
0 | 1756 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1757 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
|
1758 #endif |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1759 if(!ret && cfg.chardet_fallback){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1760 gchar **encs=NULL, **enc=NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1761 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
|
1762 |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1763 if(encs){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1764 enc = encs; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1765 for(enc=encs; *enc ; enc++){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1766 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
|
1767 if(len == *bytes_read){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1768 break; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1769 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1770 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1771 g_strfreev(encs); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1772 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1773 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1774 |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1775 #ifdef USE_CHARDET |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1776 /* 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
|
1777 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
|
1778 latin1 string. |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1779 */ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1780 if(!ret){ |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1781 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
|
1782 } |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1783 #endif |
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1784 |
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1785 if(ret){ |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1786 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
|
1787 return ret; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1788 else { |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1789 g_free(ret); |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1790 ret = NULL; |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1791 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1792 } |
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1793 |
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1794 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
|
1795 } |
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1796 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1797 /* |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1798 * Resizes a GDK pixmap. |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1799 */ |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1800 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height) |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1801 { |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1802 GdkPixmap *out; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1803 gint owidth, oheight; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1804 |
1887 | 1805 g_return_val_if_fail(src != NULL, NULL); |
1806 g_return_val_if_fail(src_gc != NULL, NULL); | |
1807 g_return_val_if_fail(in != NULL, NULL); | |
1808 g_return_val_if_fail(width > 0 && height > 0, NULL); | |
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1809 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1810 gdk_drawable_get_size(in, &owidth, &oheight); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1811 |
1852 | 1812 if (oheight == height && owidth == width) |
1887 | 1813 return NULL; |
1852 | 1814 |
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1815 out = gdk_pixmap_new(src, width, height, -1); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1816 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1817 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1818 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1819 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1820 g_object_unref(src); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1821 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1822 return out; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1823 } |
1938 | 1824 |
1825 GdkImage *create_dblsize_image(GdkImage * img) | |
1826 { | |
1827 GdkImage *dblimg; | |
1828 register guint x, y; | |
1829 | |
1830 /* | |
1831 * This needs to be optimized | |
1832 */ | |
1833 | |
1834 dblimg = | |
1972
edc01e85648d
[svn] - in particular X environment, double size caused a bad match X error.
yaz
parents:
1938
diff
changeset
|
1835 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), |
1938 | 1836 img->width << 1, img->height << 1); |
1837 if (dblimg->bpp == 1) { | |
1838 register guint8 *srcptr, *ptr, *ptr2, pix; | |
1839 | |
1840 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
1841 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
1842 ptr2 = ptr + dblimg->bpl; | |
1843 | |
1844 for (y = 0; y < img->height; y++) { | |
1845 for (x = 0; x < img->width; x++) { | |
1846 pix = *srcptr++; | |
1847 *ptr++ = pix; | |
1848 *ptr++ = pix; | |
1849 *ptr2++ = pix; | |
1850 *ptr2++ = pix; | |
1851 } | |
1852 srcptr += img->bpl - img->width; | |
1853 ptr += (dblimg->bpl << 1) - dblimg->width; | |
1854 ptr2 += (dblimg->bpl << 1) - dblimg->width; | |
1855 } | |
1856 } | |
1857 if (dblimg->bpp == 2) { | |
1858 guint16 *srcptr, *ptr, *ptr2, pix; | |
1859 | |
1860 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data; | |
1861 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
1862 ptr2 = ptr + (dblimg->bpl >> 1); | |
1863 | |
1864 for (y = 0; y < img->height; y++) { | |
1865 for (x = 0; x < img->width; x++) { | |
1866 pix = *srcptr++; | |
1867 *ptr++ = pix; | |
1868 *ptr++ = pix; | |
1869 *ptr2++ = pix; | |
1870 *ptr2++ = pix; | |
1871 } | |
1872 srcptr += (img->bpl >> 1) - img->width; | |
1873 ptr += (dblimg->bpl) - dblimg->width; | |
1874 ptr2 += (dblimg->bpl) - dblimg->width; | |
1875 } | |
1876 } | |
1877 if (dblimg->bpp == 3) { | |
1878 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3; | |
1879 | |
1880 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
1881 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
1882 ptr2 = ptr + dblimg->bpl; | |
1883 | |
1884 for (y = 0; y < img->height; y++) { | |
1885 for (x = 0; x < img->width; x++) { | |
1886 pix1 = *srcptr++; | |
1887 pix2 = *srcptr++; | |
1888 pix3 = *srcptr++; | |
1889 *ptr++ = pix1; | |
1890 *ptr++ = pix2; | |
1891 *ptr++ = pix3; | |
1892 *ptr++ = pix1; | |
1893 *ptr++ = pix2; | |
1894 *ptr++ = pix3; | |
1895 *ptr2++ = pix1; | |
1896 *ptr2++ = pix2; | |
1897 *ptr2++ = pix3; | |
1898 *ptr2++ = pix1; | |
1899 *ptr2++ = pix2; | |
1900 *ptr2++ = pix3; | |
1901 | |
1902 } | |
1903 srcptr += img->bpl - (img->width * 3); | |
1904 ptr += (dblimg->bpl << 1) - (dblimg->width * 3); | |
1905 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3); | |
1906 } | |
1907 } | |
1908 if (dblimg->bpp == 4) { | |
1909 register guint32 *srcptr, *ptr, *ptr2, pix; | |
1910 | |
1911 srcptr = (guint32 *) GDK_IMAGE_XIMAGE(img)->data; | |
1912 ptr = (guint32 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
1913 ptr2 = ptr + (dblimg->bpl >> 2); | |
1914 | |
1915 for (y = 0; y < img->height; y++) { | |
1916 for (x = 0; x < img->width; x++) { | |
1917 pix = *srcptr++; | |
1918 *ptr++ = pix; | |
1919 *ptr++ = pix; | |
1920 *ptr2++ = pix; | |
1921 *ptr2++ = pix; | |
1922 } | |
1923 srcptr += (img->bpl >> 2) - img->width; | |
1924 ptr += (dblimg->bpl >> 1) - dblimg->width; | |
1925 ptr2 += (dblimg->bpl >> 1) - dblimg->width; | |
1926 } | |
1927 } | |
1928 return dblimg; | |
1929 } | |
2074
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1930 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1931 /* URL-decode a file: URL path, return NULL if it's not what we expect */ |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1932 gchar * |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1933 xmms_urldecode_path(const gchar * encoded_path) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1934 { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1935 const gchar *cur, *ext; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1936 gchar *path, *tmp; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1937 gint realchar; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1938 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1939 if (!encoded_path) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1940 return NULL; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1941 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1942 if (!str_has_prefix_nocase(encoded_path, "file:")) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1943 return NULL; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1944 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1945 cur = encoded_path + 5; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1946 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1947 if (str_has_prefix_nocase(cur, "//localhost")) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1948 cur += 11; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1949 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1950 if (*cur == '/') |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1951 while (cur[1] == '/') |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1952 cur++; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1953 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1954 tmp = g_malloc0(strlen(cur) + 1); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1955 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1956 while ((ext = strchr(cur, '%')) != NULL) { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1957 strncat(tmp, cur, ext - cur); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1958 ext++; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1959 cur = ext + 2; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1960 if (!sscanf(ext, "%2x", &realchar)) { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1961 /* Assume it is a literal '%'. Several file |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1962 * managers send unencoded file: urls on drag |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1963 * and drop. */ |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1964 realchar = '%'; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1965 cur -= 2; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1966 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1967 tmp[strlen(tmp)] = realchar; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1968 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1969 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1970 path = g_strconcat(tmp, cur, NULL); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1971 g_free(tmp); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1972 return path; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1973 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1974 |