Mercurial > audlegacy
annotate audacious/util.c @ 2210:165a62fdb49e trunk
[svn] - improve the presentation of the URL entry dialog
author | nenolod |
---|---|
date | Mon, 25 Dec 2006 08:44:29 -0800 |
parents | 7d40f0a290b9 |
children | 649e3418aac2 |
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 * find <file> in directory <dirname> or subdirectories. return | |
70 * pointer to complete filename which has to be freed by calling | |
71 * "g_free()" after use. Returns NULL if file could not be found. | |
72 */ | |
73 | |
74 typedef struct { | |
75 const gchar *to_match; | |
76 gchar *match; | |
77 gboolean found; | |
78 } FindFileContext; | |
79 | |
80 static gboolean | |
81 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
82 { | |
83 FindFileContext *context = data; | |
84 | |
85 if (strlen(path) > FILENAME_MAX) { | |
86 g_warning("Ignoring path: name too long (%s)", path); | |
87 return TRUE; | |
88 } | |
89 | |
90 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
91 if (!strcasecmp(basename, context->to_match)) { | |
92 context->match = g_strdup(path); | |
93 context->found = TRUE; | |
94 return TRUE; | |
95 } | |
96 } | |
97 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
98 dir_foreach(path, find_file_func, context, NULL); | |
99 if (context->found) | |
100 return TRUE; | |
101 } | |
102 | |
103 return FALSE; | |
104 } | |
105 | |
106 gchar * | |
107 find_file_recursively(const gchar * path, const gchar * filename) | |
108 { | |
109 FindFileContext context; | |
110 | |
111 context.to_match = filename; | |
112 context.match = NULL; | |
113 context.found = FALSE; | |
114 | |
115 dir_foreach(path, find_file_func, &context, NULL); | |
116 return context.match; | |
117 } | |
118 | |
119 | |
120 typedef enum { | |
121 ARCHIVE_UNKNOWN = 0, | |
122 ARCHIVE_DIR, | |
123 ARCHIVE_TAR, | |
124 ARCHIVE_TGZ, | |
125 ARCHIVE_ZIP, | |
126 ARCHIVE_TBZ2 | |
127 } ArchiveType; | |
128 | |
129 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
130 | |
131 typedef struct { | |
132 ArchiveType type; | |
133 const gchar *ext; | |
134 } ArchiveExtensionType; | |
135 | |
136 static ArchiveExtensionType archive_extensions[] = { | |
137 {ARCHIVE_TAR, ".tar"}, | |
138 {ARCHIVE_ZIP, ".wsz"}, | |
139 {ARCHIVE_ZIP, ".zip"}, | |
140 {ARCHIVE_TGZ, ".tar.gz"}, | |
141 {ARCHIVE_TGZ, ".tgz"}, | |
142 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
143 {ARCHIVE_TBZ2, ".bz2"}, | |
144 {ARCHIVE_UNKNOWN, NULL} | |
145 }; | |
146 | |
147 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
148 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
149 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
150 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
151 | |
152 static ArchiveExtractFunc archive_extract_funcs[] = { | |
153 NULL, | |
154 NULL, | |
155 archive_extract_tar, | |
156 archive_extract_tgz, | |
157 archive_extract_zip, | |
158 archive_extract_tbz2 | |
159 }; | |
160 | |
161 | |
162 /* FIXME: these functions can be generalised into a function using a | |
163 * command lookup table */ | |
164 | |
165 static const gchar * | |
166 get_tar_command(void) | |
167 { | |
168 static const gchar *command = NULL; | |
169 | |
170 if (!command) { | |
171 if (!(command = getenv("TARCMD"))) | |
172 command = "tar"; | |
173 } | |
174 | |
175 return command; | |
176 } | |
177 | |
178 static const gchar * | |
179 get_unzip_command(void) | |
180 { | |
181 static const gchar *command = NULL; | |
182 | |
183 if (!command) { | |
184 if (!(command = getenv("UNZIPCMD"))) | |
185 command = "unzip"; | |
186 } | |
187 | |
188 return command; | |
189 } | |
190 | |
191 | |
192 static gchar * | |
193 archive_extract_tar(const gchar * archive, const gchar * dest) | |
194 { | |
195 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
196 get_tar_command(), archive, dest); | |
197 } | |
198 | |
199 static gchar * | |
200 archive_extract_zip(const gchar * archive, const gchar * dest) | |
201 { | |
202 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
203 get_unzip_command(), archive, dest); | |
204 } | |
205 | |
206 static gchar * | |
207 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
208 { | |
209 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
210 get_tar_command(), archive, dest); | |
211 } | |
212 | |
213 static gchar * | |
214 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
215 { | |
216 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
217 archive, get_tar_command(), dest); | |
218 } | |
219 | |
220 | |
221 ArchiveType | |
222 archive_get_type(const gchar * filename) | |
223 { | |
224 gint i = 0; | |
225 | |
226 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
227 return ARCHIVE_DIR; | |
228 | |
229 while (archive_extensions[i].ext) { | |
230 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
231 return archive_extensions[i].type; | |
232 } | |
233 i++; | |
234 } | |
235 | |
236 return ARCHIVE_UNKNOWN; | |
237 } | |
238 | |
239 gboolean | |
240 file_is_archive(const gchar * filename) | |
241 { | |
242 return (archive_get_type(filename) > ARCHIVE_DIR); | |
243 } | |
244 | |
245 gchar * | |
246 archive_basename(const gchar * str) | |
247 { | |
248 gint i = 0; | |
249 | |
250 while (archive_extensions[i].ext) { | |
251 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
252 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
253 if (end) { | |
254 return g_strndup(str, end - str); | |
255 } | |
256 break; | |
257 } | |
258 i++; | |
259 } | |
260 | |
261 return NULL; | |
262 } | |
263 | |
264 /* | |
265 decompress_archive | |
266 | |
267 Decompresses the archive "filename" to a temporary directory, | |
268 returns the path to the temp dir, or NULL if failed, | |
269 watch out tho, doesn't actually check if the system command succeeds :-| | |
270 */ | |
271 | |
272 gchar * | |
273 archive_decompress(const gchar * filename) | |
274 { | |
275 gchar *tmpdir, *cmd, *escaped_filename; | |
276 ArchiveType type; | |
1890 | 277 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
0 | 278 |
279 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
280 return NULL; | |
281 | |
1890 | 282 #ifdef HAVE_MKDTEMP |
283 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); | |
0 | 284 if (!mkdtemp(tmpdir)) { |
285 g_free(tmpdir); | |
286 g_message("Unable to load skin: Failed to create temporary " | |
287 "directory: %s", g_strerror(errno)); | |
288 return NULL; | |
289 } | |
1890 | 290 #else |
1891 | 291 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand()); |
1890 | 292 make_directory(tmpdir, mode755); |
293 #endif | |
0 | 294 |
295 escaped_filename = escape_shell_chars(filename); | |
296 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
297 g_free(escaped_filename); | |
298 | |
299 if (!cmd) { | |
300 g_message("extraction function is NULL!"); | |
301 g_free(tmpdir); | |
302 return NULL; | |
303 } | |
304 | |
305 system(cmd); | |
306 g_free(cmd); | |
307 | |
308 return tmpdir; | |
309 } | |
310 | |
311 | |
312 #ifdef HAVE_FTS_H | |
313 | |
314 void | |
315 del_directory(const gchar * dirname) | |
316 { | |
317 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
318 FTS *fts; | |
319 FTSENT *p; | |
320 | |
321 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
322 while ((p = fts_read(fts))) { | |
323 switch (p->fts_info) { | |
324 case FTS_D: | |
325 break; | |
326 case FTS_DNR: | |
327 case FTS_ERR: | |
328 break; | |
329 case FTS_DP: | |
330 rmdir(p->fts_accpath); | |
331 break; | |
332 default: | |
333 unlink(p->fts_accpath); | |
334 break; | |
335 } | |
336 } | |
337 fts_close(fts); | |
338 } | |
339 | |
340 #else /* !HAVE_FTS */ | |
341 | |
342 gboolean | |
343 del_directory_func(const gchar * path, const gchar * basename, | |
344 gpointer params) | |
345 { | |
346 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
347 return FALSE; | |
348 | |
349 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
350 dir_foreach(path, del_directory_func, NULL, NULL); | |
351 rmdir(path); | |
352 return FALSE; | |
353 } | |
354 | |
355 unlink(path); | |
356 | |
357 return FALSE; | |
358 } | |
359 | |
360 void | |
361 del_directory(const gchar * path) | |
362 { | |
363 dir_foreach(path, del_directory_func, NULL, NULL); | |
364 rmdir(path); | |
365 } | |
366 | |
367 #endif /* ifdef HAVE_FTS */ | |
368 | |
369 gchar * | |
370 read_ini_string(const gchar * filename, const gchar * section, | |
371 const gchar * key) | |
372 { | |
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
|
373 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
|
374 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
|
375 gchar *ret_buffer = NULL; |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
376 gint found_section = 0, len = 0; |
1193
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
377 static gsize filesize = 0; |
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
378 gsize off = 0; |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
379 gchar *outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
380 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
|
381 guint counter; |
0 | 382 |
383 if (!filename) | |
384 return NULL; | |
385 | |
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
|
386 /* |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
387 * 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
|
388 * 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
|
389 * 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
|
390 * 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
|
391 * |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
392 * 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
|
393 * 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
|
394 * - 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
|
395 */ |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
396 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
|
397 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
398 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
|
399 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
400 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
|
401 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
|
402 } |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
403 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
404 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
|
405 { |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
406 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
|
407 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
|
408 } |
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 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
410 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
|
411 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
|
412 |
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
413 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
|
414 } |
0 | 415 |
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
416 /* |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
417 * 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
|
418 * 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
|
419 */ |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
420 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
|
421 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
|
422 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 else |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
427 return NULL; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
428 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
429 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
|
430 |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
431 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
|
432 g_free(buffer); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
433 buffer = outbuf; |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
434 } else { |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
435 g_free(outbuf); |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
436 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
|
437 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
438 } |
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
439 |
0 | 440 while (!ret_buffer && off < filesize) { |
441 while (off < filesize && | |
442 (buffer[off] == '\r' || buffer[off] == '\n' || | |
443 buffer[off] == ' ' || buffer[off] == '\t')) | |
444 off++; | |
445 if (off >= filesize) | |
446 break; | |
447 if (buffer[off] == '[') { | |
448 gint slen = strlen(section); | |
449 off++; | |
450 found_section = 0; | |
451 if (off + slen + 1 < filesize && | |
452 !strncasecmp(section, &buffer[off], slen)) { | |
453 off += slen; | |
454 if (buffer[off] == ']') { | |
455 off++; | |
456 found_section = 1; | |
457 } | |
458 } | |
459 } | |
460 else if (found_section && off + strlen(key) < filesize && | |
461 !strncasecmp(key, &buffer[off], strlen(key))) { | |
462 off += strlen(key); | |
463 while (off < filesize && | |
464 (buffer[off] == ' ' || buffer[off] == '\t')) | |
465 off++; | |
466 if (off >= filesize) | |
467 break; | |
468 if (buffer[off] == '=') { | |
469 off++; | |
470 while (off < filesize && | |
471 (buffer[off] == ' ' || buffer[off] == '\t')) | |
472 off++; | |
473 if (off >= filesize) | |
474 break; | |
475 len = 0; | |
476 while (off + len < filesize && | |
477 buffer[off + len] != '\r' && | |
478 buffer[off + len] != '\n' && buffer[off + len] != ';') | |
479 len++; | |
480 ret_buffer = g_strndup(&buffer[off], len); | |
481 off += len; | |
482 } | |
483 } | |
484 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n') | |
485 off++; | |
486 } | |
487 | |
488 return ret_buffer; | |
489 } | |
490 | |
491 GArray * | |
492 string_to_garray(const gchar * str) | |
493 { | |
494 GArray *array; | |
495 gint temp; | |
496 const gchar *ptr = str; | |
497 gchar *endptr; | |
498 | |
499 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
500 for (;;) { | |
501 temp = strtol(ptr, &endptr, 10); | |
502 if (ptr == endptr) | |
503 break; | |
504 g_array_append_val(array, temp); | |
505 ptr = endptr; | |
1717
837983bac90f
[svn] Fixed a lot of warnings that only showed up on *BSD.
js
parents:
1653
diff
changeset
|
506 while (!isdigit((int) *ptr) && (*ptr) != '\0') |
0 | 507 ptr++; |
508 if (*ptr == '\0') | |
509 break; | |
510 } | |
511 return (array); | |
512 } | |
513 | |
514 GArray * | |
515 read_ini_array(const gchar * filename, const gchar * section, | |
516 const gchar * key) | |
517 { | |
518 gchar *temp; | |
519 GArray *a; | |
520 | |
521 if ((temp = read_ini_string(filename, section, key)) == NULL) { | |
522 g_free(temp); | |
523 return NULL; | |
524 } | |
525 a = string_to_garray(temp); | |
526 g_free(temp); | |
527 return a; | |
528 } | |
529 | |
530 void | |
531 glist_movedown(GList * list) | |
532 { | |
533 gpointer temp; | |
534 | |
535 if (g_list_next(list)) { | |
536 temp = list->data; | |
537 list->data = list->next->data; | |
538 list->next->data = temp; | |
539 } | |
540 } | |
541 | |
542 void | |
543 glist_moveup(GList * list) | |
544 { | |
545 gpointer temp; | |
546 | |
547 if (g_list_previous(list)) { | |
548 temp = list->data; | |
549 list->data = list->prev->data; | |
550 list->prev->data = temp; | |
551 } | |
552 } | |
553 | |
554 | |
555 void | |
556 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
557 gboolean * push_in, gpointer data) | |
558 { | |
559 GtkRequisition requisition; | |
560 gint screen_width; | |
561 gint screen_height; | |
562 MenuPos *pos = data; | |
563 | |
564 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
565 | |
566 screen_width = gdk_screen_width(); | |
567 screen_height = gdk_screen_height(); | |
568 | |
569 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
570 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
571 } | |
572 | |
573 static void | |
574 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory) | |
575 { | |
576 gtk_signal_disconnect_by_func(object, | |
577 GTK_SIGNAL_FUNC | |
578 (util_menu_delete_popup_data), ifactory); | |
579 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data); | |
580 } | |
581 | |
582 | |
583 /* | |
584 * util_item_factory_popup[_with_data]() is a replacement for | |
585 * gtk_item_factory_popup[_with_data](). | |
586 * | |
587 * The difference is that the menu is always popped up whithin the | |
588 * screen. This means it does not neccesarily pop up at (x,y). | |
589 */ | |
590 | |
591 void | |
592 util_item_factory_popup_with_data(GtkItemFactory * ifactory, | |
593 gpointer data, | |
594 GtkDestroyNotify destroy, guint x, | |
595 guint y, guint mouse_button, guint32 time) | |
596 { | |
597 static GQuark quark_user_menu_pos = 0; | |
598 MenuPos *pos; | |
599 | |
600 if (!quark_user_menu_pos) | |
601 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos"); | |
602 | |
603 if (!quark_popup_data) | |
604 quark_popup_data = | |
605 g_quark_from_static_string("GtkItemFactory-popup-data"); | |
606 | |
607 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos); | |
608 if (!pos) { | |
609 pos = g_new0(MenuPos, 1); | |
610 | |
611 g_object_set_qdata_full(G_OBJECT(ifactory->widget), | |
612 quark_user_menu_pos, pos, g_free); | |
613 } | |
614 pos->x = x; | |
615 pos->y = y; | |
616 | |
617 | |
618 if (data != NULL) { | |
619 g_object_set_qdata_full(G_OBJECT(ifactory), | |
620 quark_popup_data, data, destroy); | |
621 g_signal_connect(G_OBJECT(ifactory->widget), | |
622 "selection-done", | |
623 G_CALLBACK(util_menu_delete_popup_data), ifactory); | |
624 } | |
625 | |
626 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL, | |
627 (GtkMenuPositionFunc) util_menu_position, | |
628 pos, mouse_button, time); | |
629 } | |
630 | |
631 void | |
632 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y, | |
633 guint mouse_button, guint32 time) | |
634 { | |
635 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y, | |
636 mouse_button, time); | |
637 } | |
638 | |
639 | |
640 #define URL_HISTORY_MAX_SIZE 30 | |
641 | |
642 static void | |
643 util_add_url_callback(GtkWidget * widget, | |
644 GtkEntry * entry) | |
645 { | |
646 const gchar *text; | |
647 | |
648 text = gtk_entry_get_text(entry); | |
649 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp)) | |
650 return; | |
651 | |
652 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text)); | |
653 | |
654 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) { | |
655 GList *node = g_list_last(cfg.url_history); | |
656 g_free(node->data); | |
657 cfg.url_history = g_list_delete_link(cfg.url_history, node); | |
658 } | |
659 } | |
660 | |
661 GtkWidget * | |
86 | 662 util_add_url_dialog_new(const gchar * caption, GCallback ok_func, |
663 GCallback enqueue_func) | |
0 | 664 { |
2210
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
665 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry, |
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
666 *label; |
0 | 667 GList *url; |
668 | |
669 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
2210
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
670 gtk_window_set_title(GTK_WINDOW(win), "Add/Open URL Dialog"); |
0 | 671 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG); |
672 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER); | |
673 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1); | |
674 gtk_container_set_border_width(GTK_CONTAINER(win), 12); | |
675 | |
676 vbox = gtk_vbox_new(FALSE, 10); | |
677 gtk_container_add(GTK_CONTAINER(win), vbox); | |
678 | |
2210
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
679 label = gtk_label_new(caption); |
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
680 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
681 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
165a62fdb49e
[svn] - improve the presentation of the URL entry dialog
nenolod
parents:
2184
diff
changeset
|
682 |
0 | 683 combo = gtk_combo_box_entry_new_text(); |
684 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); | |
685 | |
686 entry = gtk_bin_get_child(GTK_BIN(combo)); | |
687 gtk_window_set_focus(GTK_WINDOW(win), entry); | |
688 gtk_entry_set_text(GTK_ENTRY(entry), ""); | |
689 | |
690 for (url = cfg.url_history; url; url = g_list_next(url)) | |
691 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data); | |
692 | |
693 g_signal_connect(entry, "activate", | |
694 G_CALLBACK(util_add_url_callback), | |
695 entry); | |
696 g_signal_connect(entry, "activate", | |
86 | 697 G_CALLBACK(ok_func), |
0 | 698 entry); |
699 g_signal_connect_swapped(entry, "activate", | |
700 G_CALLBACK(gtk_widget_destroy), | |
701 win); | |
702 | |
703 bbox = gtk_hbutton_box_new(); | |
704 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
705 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
706 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
707 | |
86 | 708 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN); |
709 g_signal_connect(ok, "clicked", | |
710 G_CALLBACK(util_add_url_callback), entry); | |
711 g_signal_connect(ok, "clicked", | |
712 G_CALLBACK(ok_func), entry); | |
713 g_signal_connect_swapped(ok, "clicked", | |
714 G_CALLBACK(gtk_widget_destroy), | |
715 win); | |
716 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0); | |
717 | |
0 | 718 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD); |
719 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0); | |
720 | |
721 g_signal_connect(enqueue, "clicked", | |
722 G_CALLBACK(util_add_url_callback), | |
723 entry); | |
724 g_signal_connect(enqueue, "clicked", | |
725 G_CALLBACK(enqueue_func), | |
726 entry); | |
727 g_signal_connect_swapped(enqueue, "clicked", | |
728 G_CALLBACK(gtk_widget_destroy), | |
729 win); | |
730 | |
731 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
732 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); | |
733 | |
734 g_signal_connect_swapped(cancel, "clicked", | |
735 G_CALLBACK(gtk_widget_destroy), | |
736 win); | |
737 | |
738 gtk_widget_show_all(vbox); | |
739 | |
740 return win; | |
741 } | |
742 | |
743 static void | |
744 filebrowser_add_files(GtkFileChooser * browser, | |
745 GSList * files) | |
746 { | |
747 GSList *cur; | |
748 gchar *ptr; | |
749 guint ctr = 0; | |
2087 | 750 Playlist *playlist = playlist_get_active(); |
0 | 751 |
752 if (GTK_IS_WIDGET(mainwin_jtf)) | |
753 gtk_widget_set_sensitive(mainwin_jtf, FALSE); | |
754 | |
755 for (cur = files; cur; cur = g_slist_next(cur)) { | |
756 | |
757 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) { | |
2087 | 758 playlist_add_dir(playlist, (const gchar *) cur->data); |
0 | 759 } else { |
2087 | 760 playlist_add(playlist, (const gchar *) cur->data); |
0 | 761 } |
762 | |
763 if (++ctr == 20) { | |
2140
299651a8f107
[svn] - made playlistwin_update_list depend on passed Playlist* instead of blindly using playlist_get_active(); this solves many locking issues with multiple playlists, but SHOULD be reviewed in every place playlistwin_update_list is used; added a playlist_new_from_selected() call too
giacomo
parents:
2105
diff
changeset
|
764 playlistwin_update_list(playlist); |
0 | 765 ctr = 0; |
766 while (gtk_events_pending() ) gtk_main_iteration(); | |
767 } | |
768 } | |
769 | |
2140
299651a8f107
[svn] - made playlistwin_update_list depend on passed Playlist* instead of blindly using playlist_get_active(); this solves many locking issues with multiple playlists, but SHOULD be reviewed in every place playlistwin_update_list is used; added a playlist_new_from_selected() call too
giacomo
parents:
2105
diff
changeset
|
770 playlistwin_update_list(playlist); |
0 | 771 |
772 if (GTK_IS_WIDGET(mainwin_jtf)) | |
773 gtk_widget_set_sensitive(mainwin_jtf, TRUE); | |
774 | |
775 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
776 | |
777 g_free(cfg.filesel_path); | |
778 cfg.filesel_path = ptr; | |
779 } | |
780 | |
781 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
782 filebrowser_add(GtkFileChooser *browser) |
0 | 783 { |
784 GSList *files; | |
785 | |
786 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
787 | |
788 if (!files) { | |
789 return; | |
790 } | |
791 | |
792 filebrowser_add_files(browser, files); | |
793 g_slist_foreach(files, (GFunc) g_free, NULL); | |
794 g_slist_free(files); | |
795 } | |
796 | |
797 static void | |
798 filebrowser_play(GtkFileChooser * browser) | |
799 { | |
800 GSList *files; | |
801 | |
802 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
803 | |
804 if (!files) return; | |
805 | |
2087 | 806 playlist_clear(playlist_get_active()); |
0 | 807 |
808 filebrowser_add_files(browser, files); | |
809 g_slist_foreach(files, (GFunc) g_free, NULL); | |
810 g_slist_free(files); | |
811 | |
812 bmp_playback_initiate(); | |
813 } | |
814 | |
815 | |
816 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
817 _filebrowser_add_gtk2(GtkWidget *widget, |
0 | 818 gpointer data) |
819 { | |
820 filebrowser_add(data); | |
821 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data)); | |
822 } | |
823 | |
824 static void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
825 _filebrowser_play_gtk2(GtkWidget *widget, gpointer data) |
0 | 826 { |
827 filebrowser_play(data); | |
828 gtk_file_chooser_unselect_all(data); | |
829 } | |
830 | |
831 #if 0 | |
832 static void | |
833 filebrowser_on_response(GtkFileChooser * browser, | |
834 gint response, | |
835 gpointer data) | |
836 { | |
837 gtk_widget_hide(GTK_WIDGET(browser)); | |
838 switch (response) { | |
839 case GTK_RESPONSE_OK: | |
840 break; | |
841 case GTK_RESPONSE_ACCEPT: | |
842 break; | |
843 case GTK_RESPONSE_CLOSE: | |
844 break; | |
845 } | |
846 gtk_widget_destroy(GTK_WIDGET(browser)); | |
847 | |
848 } | |
849 | |
850 #endif | |
851 | |
852 static void | |
853 _filebrowser_check_hide_add(GtkWidget * widget, | |
854 gpointer data) | |
855 { | |
856 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
857 } | |
858 | |
859 static void | |
860 _filebrowser_check_hide_open(GtkWidget * widget, | |
861 gpointer data) | |
862 { | |
863 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
864 } | |
865 | |
866 | |
867 | |
868 static gboolean | |
869 filebrowser_on_keypress(GtkWidget * browser, | |
870 GdkEventKey * event, | |
871 gpointer data) | |
872 { | |
873 if (event->keyval == GDK_Escape) { | |
874 /* FIXME: this crashes BMP for some reason */ | |
875 /* g_signal_emit_by_name(browser, "delete-event"); */ | |
876 gtk_widget_hide(browser); | |
877 return TRUE; | |
878 } | |
879 | |
880 return FALSE; | |
881 } | |
882 | |
883 static void | |
884 _filebrowser_do_hide_add(GtkWidget *widget, | |
885 gpointer data) | |
886 { | |
887 if (cfg.close_dialog_add) | |
888 gtk_widget_hide(data); | |
889 } | |
890 | |
891 static void | |
892 _filebrowser_do_hide_open(GtkWidget *widget, | |
893 gpointer data) | |
894 { | |
895 if (cfg.close_dialog_open) | |
896 gtk_widget_hide(data); | |
897 } | |
898 | |
899 void | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
900 util_run_filebrowser_gtk2style(gboolean play_button) |
0 | 901 { |
902 static GladeXML *xml = NULL; | |
903 static GtkWidget *dialog = NULL; | |
904 static GtkWidget *chooser = NULL; | |
905 | |
906 static GtkWidget *button_add; | |
907 static GtkWidget *button_select_all, *button_deselect_all; | |
908 static GtkWidget *toggle; | |
909 | |
910 static gulong handlerid, handlerid_check, handlerid_do; | |
911 static gulong handlerid_activate, handlerid_do_activate; | |
912 | |
913 if (!xml) { | |
914 /* FIXME: Creating a file chooser dialog manually using | |
915 libglade because there's no way to stop | |
916 GtkFileChooserDialog from resizing the buttons to the same | |
917 size. The long toggle button title causes the buttons to | |
918 turn unnecessarily elongated and fugly. */ | |
919 | |
920 GtkWidget *alignment; | |
921 | |
922 xml = glade_xml_new_or_die(_("Add/Open Files dialog"), | |
923 DATA_DIR "/glade/addfiles.glade", | |
924 NULL, NULL); | |
925 glade_xml_signal_autoconnect(xml); | |
926 | |
927 dialog = glade_xml_get_widget(xml, "add_files_dialog"); | |
928 | |
929 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does | |
930 not support GtkFileChooserWidget */ | |
931 | |
932 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
933 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
934 | |
935 if (cfg.filesel_path) | |
936 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
937 cfg.filesel_path); | |
938 | |
939 alignment = glade_xml_get_widget(xml, "alignment2"); | |
940 gtk_container_add(GTK_CONTAINER(alignment), chooser); | |
941 | |
942 toggle = glade_xml_get_widget(xml, "close_on_action"); | |
943 button_select_all = glade_xml_get_widget(xml, "select_all"); | |
944 button_deselect_all = glade_xml_get_widget(xml, "deselect_all"); | |
945 button_add = glade_xml_get_widget(xml, "action"); | |
946 | |
947 g_signal_connect_swapped(button_select_all, "clicked", | |
948 G_CALLBACK(gtk_file_chooser_select_all), | |
949 chooser); | |
950 g_signal_connect_swapped(button_deselect_all, "clicked", | |
951 G_CALLBACK(gtk_file_chooser_unselect_all), | |
952 chooser); | |
953 | |
954 g_signal_connect(dialog, "key_press_event", | |
955 G_CALLBACK(filebrowser_on_keypress), | |
956 NULL); | |
957 | |
958 gtk_widget_show_all(dialog); | |
959 } /* !xml */ | |
960 else { | |
961 g_signal_handler_disconnect(button_add, handlerid); | |
962 g_signal_handler_disconnect(toggle, handlerid_check); | |
963 g_signal_handler_disconnect(chooser, handlerid_activate); | |
964 g_signal_handler_disconnect(button_add, handlerid_do); | |
965 g_signal_handler_disconnect(chooser, handlerid_do_activate); | |
1752
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
966 |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
967 if (cfg.refresh_file_list) |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
968 { |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
969 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
|
970 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
|
971 |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
972 g_free(tmp); |
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
973 } |
0 | 974 } |
975 | |
976 if (play_button) { | |
977 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files")); | |
978 | |
979 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN); | |
980 | |
981 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open")); | |
982 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open); | |
983 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
984 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
0 | 985 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL); |
986 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
|
987 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
0 | 988 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog); |
989 } | |
990 else { | |
991 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files")); | |
992 | |
993 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD); | |
994 | |
995 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add")); | |
996 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add); | |
997 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
998 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
0 | 999 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL); |
1000 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
|
1001 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
0 | 1002 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog); |
1003 } | |
1004 | |
1005 gtk_window_present(GTK_WINDOW(dialog)); | |
1006 } | |
1007 | |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1008 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1009 * Derived from Beep Media Player 0.9.6.1. |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1010 * Which is (C) 2003 - 2006 Milosz Derezynski &c |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1011 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1012 * Although I changed it quite a bit. -nenolod |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1013 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1014 static void filebrowser_changed_classic(GtkFileSelection * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1015 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1016 GList *list; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1017 GList *node; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1018 char *filename = (char *) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1019 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1020 GtkListStore *store; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1021 GtkTreeIter iter; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1022 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1023 if ((list = input_scan_dir(filename)) != NULL) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1024 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1025 * 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
|
1026 * input-plugin. This is used by the CDDA plugin |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1027 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1028 store = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1029 GTK_LIST_STORE(gtk_tree_view_get_model |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1030 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1031 gtk_list_store_clear(store); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1032 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1033 node = list; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1034 while (node) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1035 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1036 gtk_list_store_append(store, &iter); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1037 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
|
1038 g_free(node->data); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1039 node = g_list_next(node); |
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 g_list_free(list); |
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 } |
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 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
|
1046 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1047 filebrowser_changed_classic(GTK_FILE_SELECTION(data)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1048 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1049 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1050 gboolean util_filebrowser_is_dir_classic(GtkFileSelection * filesel) |
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 char *text; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1053 struct stat buf; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1054 gboolean retv = FALSE; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1055 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1056 text = g_strdup(gtk_file_selection_get_filename(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1057 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1058 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
|
1059 /* Selected directory */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1060 int len = strlen(text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1061 if (len > 3 && !strcmp(text + len - 4, "/../")) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1062 if (len == 4) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1063 /* At the root already */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1064 *(text + len - 3) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1065 else { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1066 char *ptr; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1067 *(text + len - 4) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1068 ptr = strrchr(text, '/'); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1069 *(ptr + 1) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1070 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1071 } else if (len > 2 && !strcmp(text + len - 3, "/./")) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1072 *(text + len - 2) = '\0'; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1073 gtk_file_selection_set_filename(filesel, text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1074 retv = TRUE; |
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 g_free(text); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1077 return retv; |
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 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1080 static void filebrowser_add_files_classic(gchar ** files, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1081 GtkFileSelection * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1082 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1083 int ctr = 0; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1084 char *ptr; |
2087 | 1085 Playlist *playlist = playlist_get_active(); |
1905
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 (GTK_IS_WIDGET(mainwin_jtf)) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1088 gtk_widget_set_sensitive(mainwin_jtf, FALSE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1089 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1090 while (files[ctr] != NULL) { |
2087 | 1091 playlist_add(playlist, files[ctr++]); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1092 } |
2140
299651a8f107
[svn] - made playlistwin_update_list depend on passed Playlist* instead of blindly using playlist_get_active(); this solves many locking issues with multiple playlists, but SHOULD be reviewed in every place playlistwin_update_list is used; added a playlist_new_from_selected() call too
giacomo
parents:
2105
diff
changeset
|
1093 playlistwin_update_list(playlist); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1094 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1095 if (GTK_IS_WIDGET(mainwin_jtf)) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1096 gtk_widget_set_sensitive(mainwin_jtf, TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1097 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1098 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
|
1099 &ptr); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1100 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1101 /* 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
|
1102 cfg.filesel_path = g_strconcat(ptr, "/", NULL); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1103 } |
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 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1106 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1107 gchar **files; |
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 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
|
1110 return; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1111 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
|
1112 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1113 gtk_widget_destroy(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1114 } |
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 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1117 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1118 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1119 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1120 if (util_filebrowser_is_dir_classic |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1121 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel)))) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1122 return; |
2087 | 1123 playlist_clear(playlist_get_active()); |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1124 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
|
1125 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1126 gtk_widget_destroy(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1127 bmp_playback_initiate(); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1128 } |
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 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
|
1131 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1132 gchar **files; |
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 GtkFileSelection *filesel = GTK_FILE_SELECTION(data); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1135 files = gtk_file_selection_get_selections(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1136 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1137 filebrowser_add_files_classic(files, filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1138 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
|
1139 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1140 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1141 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1142 } |
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 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
|
1145 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1146 gchar **files; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1147 GtkFileSelection *filesel; |
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 filesel = data; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1150 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
|
1151 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1152 files = gtk_file_selection_get_selections(filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1153 filebrowser_add_files_classic(files, filesel); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1154 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
|
1155 (GTK_TREE_VIEW(filesel->file_list))); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1156 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
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 void |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1160 util_run_filebrowser_classic(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1161 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1162 static GtkWidget *dialog; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1163 GtkWidget *button_add_selected, *button_add_all, *button_close, |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1164 *button_add; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1165 char *title; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1166 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1167 if (dialog != NULL) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1168 gtk_window_present(GTK_WINDOW(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1169 return; |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1170 } |
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 if (play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1173 title = _("Play files"); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1174 else |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1175 title = _("Load files"); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1176 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1177 dialog = gtk_file_selection_new(title); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1178 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1179 gtk_file_selection_set_select_multiple |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1180 (GTK_FILE_SELECTION(dialog), TRUE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1181 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1182 if (cfg.filesel_path) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1183 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1184 cfg.filesel_path); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1185 |
1907
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1186 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
|
1187 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
|
1188 |
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1189 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1190 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1191 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1192 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1193 * 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
|
1194 * plus kinda easy to use |
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 button_add_selected = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1197 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1198 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1199 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
|
1200 g_signal_connect(G_OBJECT(button_add_selected), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1201 G_CALLBACK(filebrowser_add_selected_files_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1202 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1203 button_add_all = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1204 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1205 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1206 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
|
1207 g_signal_connect(G_OBJECT(button_add_all), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1208 G_CALLBACK(filebrowser_add_all_files_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1209 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1210 if (play_button) { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1211 button_add = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1212 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
|
1213 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1214 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
|
1215 g_signal_connect(G_OBJECT(button_add), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1216 G_CALLBACK(filebrowser_play_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1217 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
|
1218 "clicked", G_CALLBACK(filebrowser_play_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1219 } else { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1220 button_add = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1221 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
|
1222 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1223 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
|
1224 g_signal_connect(G_OBJECT(button_add), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1225 G_CALLBACK(filebrowser_ok_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1226 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
|
1227 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1228 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1229 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1230 button_close = |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1231 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
|
1232 GTK_RESPONSE_NONE); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1233 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
|
1234 g_signal_connect_swapped(G_OBJECT(button_close), "clicked", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1235 G_CALLBACK(gtk_widget_destroy), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1236 G_OBJECT(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1237 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1238 gtk_widget_set_size_request(dialog, 600, 450); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1239 gtk_widget_realize(dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1240 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1241 g_signal_connect(G_OBJECT |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1242 (GTK_FILE_SELECTION(dialog)->history_pulldown), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1243 "changed", G_CALLBACK(filebrowser_entry_changed_classic), |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1244 dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1245 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1246 g_signal_connect(G_OBJECT(dialog), "destroy", |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1247 G_CALLBACK(gtk_widget_destroyed), &dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1248 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1249 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog)); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1250 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1251 gtk_widget_show(dialog); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1252 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1253 |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1254 /* |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1255 * util_run_filebrowser(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1256 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1257 * Inputs: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1258 * - whether or not a play button should be used |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1259 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1260 * Outputs: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1261 * - none |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1262 * |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1263 * Side Effects: |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1264 * - either a GTK1 or a GTK2 fileselector is launched |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1265 */ |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1266 void |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1267 util_run_filebrowser(gboolean play_button) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1268 { |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1269 if (!cfg.use_xmms_style_fileselector) |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1270 util_run_filebrowser_gtk2style(play_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1271 else |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1272 util_run_filebrowser_classic(play_button); |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1273 } |
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1274 |
0 | 1275 GdkFont * |
1276 util_font_load(const gchar * name) | |
1277 { | |
1278 GdkFont *font; | |
1279 PangoFontDescription *desc; | |
1280 | |
1281 desc = pango_font_description_from_string(name); | |
1282 font = gdk_font_from_description(desc); | |
1283 | |
1284 return font; | |
1285 } | |
1286 | |
1287 #ifdef ENABLE_NLS | |
1288 gchar * | |
1289 bmp_menu_translate(const gchar * path, gpointer func_data) | |
1290 { | |
1291 gchar *translation = gettext(path); | |
1292 | |
1293 if (!translation || *translation != '/') { | |
1294 g_warning("Bad translation for menupath: %s", path); | |
1295 translation = (gchar *) path; | |
1296 } | |
1297 | |
1298 return translation; | |
1299 } | |
1300 #endif | |
1301 | |
1302 void | |
1303 util_set_cursor(GtkWidget * window) | |
1304 { | |
1305 static GdkCursor *cursor = NULL; | |
1306 | |
1307 if (!window) { | |
1308 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
|
1309 gdk_cursor_unref(cursor); |
0 | 1310 cursor = NULL; |
1311 } | |
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
|
1312 |
0 | 1313 return; |
1314 } | |
1315 | |
1316 if (!cursor) | |
1317 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
1318 | |
1319 gdk_window_set_cursor(window->window, cursor); | |
1320 } | |
1321 | |
1653 | 1322 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter |
1323 * Mattis et al */ | |
1324 gboolean | |
1325 text_get_extents(const gchar * fontname, | |
1326 const gchar * text, | |
1327 gint * width, gint * height, gint * ascent, gint * descent) | |
1328 { | |
1329 PangoFontDescription *font_desc; | |
1330 PangoLayout *layout; | |
1331 PangoRectangle rect; | |
1332 | |
1333 g_return_val_if_fail(fontname != NULL, FALSE); | |
1334 g_return_val_if_fail(text != NULL, FALSE); | |
1335 | |
1336 /* FIXME: resolution */ | |
1337 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
1338 | |
1339 font_desc = pango_font_description_from_string(fontname); | |
1340 pango_layout_set_font_description(layout, font_desc); | |
1341 pango_font_description_free(font_desc); | |
1342 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
1343 | |
1344 if (width) | |
1345 *width = rect.width; | |
1346 if (height) | |
1347 *height = rect.height; | |
1348 | |
1349 if (ascent || descent) { | |
1350 PangoLayoutIter *iter; | |
1351 PangoLayoutLine *line; | |
1352 | |
1353 iter = pango_layout_get_iter(layout); | |
1354 line = pango_layout_iter_get_line(iter); | |
1355 pango_layout_iter_free(iter); | |
1356 | |
1357 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
1358 | |
1359 if (ascent) | |
1360 *ascent = PANGO_ASCENT(rect); | |
1361 if (descent) | |
1362 *descent = -PANGO_DESCENT(rect); | |
1363 } | |
1364 | |
1365 g_object_unref(layout); | |
1366 | |
1367 return TRUE; | |
1368 } | |
1369 | |
0 | 1370 /* counts number of digits in a gint */ |
1371 guint | |
1372 gint_count_digits(gint n) | |
1373 { | |
1374 guint count = 0; | |
1375 | |
1376 n = ABS(n); | |
1377 do { | |
1378 count++; | |
1379 n /= 10; | |
1380 } while (n > 0); | |
1381 | |
1382 return count; | |
1383 } | |
1384 | |
1385 gboolean | |
1386 dir_foreach(const gchar * path, DirForeachFunc function, | |
1387 gpointer user_data, GError ** error) | |
1388 { | |
1389 GError *error_out = NULL; | |
1390 GDir *dir; | |
1391 const gchar *entry; | |
1392 gchar *entry_fullpath; | |
1393 | |
1394 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
1395 g_propagate_error(error, error_out); | |
1396 return FALSE; | |
1397 } | |
1398 | |
1399 while ((entry = g_dir_read_name(dir))) { | |
1400 entry_fullpath = g_build_filename(path, entry, NULL); | |
1401 | |
1402 if ((*function) (entry_fullpath, entry, user_data)) { | |
1403 g_free(entry_fullpath); | |
1404 break; | |
1405 } | |
1406 | |
1407 g_free(entry_fullpath); | |
1408 } | |
1409 | |
1410 g_dir_close(dir); | |
1411 | |
1412 return TRUE; | |
1413 } | |
1414 | |
1653 | 1415 GtkWidget * |
1416 make_filebrowser(const gchar * title, | |
1417 gboolean save) | |
1418 { | |
1419 GtkWidget *dialog; | |
1420 GtkWidget *button; | |
1421 GtkWidget *button_close; | |
1422 | |
1423 g_return_val_if_fail(title != NULL, NULL); | |
1424 | |
1425 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
1426 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); | |
1427 if (save) | |
1428 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), | |
1429 GTK_FILE_CHOOSER_ACTION_SAVE); | |
1430 | |
1431 if (!save) | |
1432 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
1433 | |
1434 g_signal_connect(dialog, "destroy", | |
1435 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
1436 | |
1437 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
1438 GTK_RESPONSE_REJECT); | |
1439 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
1440 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT); | |
1441 g_signal_connect_swapped(button_close, "clicked", | |
1442 G_CALLBACK(gtk_widget_destroy), dialog); | |
1443 | |
1444 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
1445 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
1446 GTK_RESPONSE_ACCEPT); | |
1447 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
1448 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1449 gtk_window_set_default(GTK_WINDOW(dialog), button); | |
1450 | |
1451 gtk_widget_show(dialog); | |
1452 | |
1453 return dialog; | |
1454 } | |
1455 | |
1456 | |
0 | 1457 GtkItemFactory * |
1458 create_menu(GtkItemFactoryEntry *entries, | |
1459 guint n_entries, | |
1460 GtkAccelGroup *accel) | |
1461 { | |
1462 GtkItemFactory *menu; | |
1463 | |
1464 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel); | |
1465 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL, | |
1466 NULL); | |
1467 gtk_item_factory_create_items(menu, n_entries, entries, NULL); | |
1468 | |
1469 return menu; | |
1470 } | |
1471 | |
1472 | |
1473 void | |
1474 make_submenu(GtkItemFactory *menu, | |
1475 const gchar *item_path, | |
1476 GtkItemFactory *submenu) | |
1477 { | |
1478 GtkWidget *item, *menu_; | |
1479 | |
1480 item = gtk_item_factory_get_widget(menu, item_path); | |
1481 menu_ = gtk_item_factory_get_widget(submenu, ""); | |
1482 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_); | |
1483 } | |
1484 | |
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1485 /* |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1486 * Resizes a GDK pixmap. |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1487 */ |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1488 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
|
1489 { |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1490 GdkPixmap *out; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1491 gint owidth, oheight; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1492 |
1887 | 1493 g_return_val_if_fail(src != NULL, NULL); |
1494 g_return_val_if_fail(src_gc != NULL, NULL); | |
1495 g_return_val_if_fail(in != NULL, NULL); | |
1496 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
|
1497 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1498 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
|
1499 |
1852 | 1500 if (oheight == height && owidth == width) |
1887 | 1501 return NULL; |
1852 | 1502 |
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1503 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
|
1504 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1505 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
|
1506 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1507 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
|
1508 g_object_unref(src); |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1509 |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1510 return out; |
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1511 } |
1938 | 1512 |
1513 GdkImage *create_dblsize_image(GdkImage * img) | |
1514 { | |
1515 GdkImage *dblimg; | |
1516 register guint x, y; | |
1517 | |
1518 /* | |
1519 * This needs to be optimized | |
1520 */ | |
1521 | |
1522 dblimg = | |
1972
edc01e85648d
[svn] - in particular X environment, double size caused a bad match X error.
yaz
parents:
1938
diff
changeset
|
1523 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), |
1938 | 1524 img->width << 1, img->height << 1); |
1525 if (dblimg->bpp == 1) { | |
1526 register guint8 *srcptr, *ptr, *ptr2, pix; | |
1527 | |
1528 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
1529 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
1530 ptr2 = ptr + dblimg->bpl; | |
1531 | |
1532 for (y = 0; y < img->height; y++) { | |
1533 for (x = 0; x < img->width; x++) { | |
1534 pix = *srcptr++; | |
1535 *ptr++ = pix; | |
1536 *ptr++ = pix; | |
1537 *ptr2++ = pix; | |
1538 *ptr2++ = pix; | |
1539 } | |
1540 srcptr += img->bpl - img->width; | |
1541 ptr += (dblimg->bpl << 1) - dblimg->width; | |
1542 ptr2 += (dblimg->bpl << 1) - dblimg->width; | |
1543 } | |
1544 } | |
1545 if (dblimg->bpp == 2) { | |
1546 guint16 *srcptr, *ptr, *ptr2, pix; | |
1547 | |
1548 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data; | |
1549 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
1550 ptr2 = ptr + (dblimg->bpl >> 1); | |
1551 | |
1552 for (y = 0; y < img->height; y++) { | |
1553 for (x = 0; x < img->width; x++) { | |
1554 pix = *srcptr++; | |
1555 *ptr++ = pix; | |
1556 *ptr++ = pix; | |
1557 *ptr2++ = pix; | |
1558 *ptr2++ = pix; | |
1559 } | |
1560 srcptr += (img->bpl >> 1) - img->width; | |
1561 ptr += (dblimg->bpl) - dblimg->width; | |
1562 ptr2 += (dblimg->bpl) - dblimg->width; | |
1563 } | |
1564 } | |
1565 if (dblimg->bpp == 3) { | |
1566 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3; | |
1567 | |
1568 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
1569 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
1570 ptr2 = ptr + dblimg->bpl; | |
1571 | |
1572 for (y = 0; y < img->height; y++) { | |
1573 for (x = 0; x < img->width; x++) { | |
1574 pix1 = *srcptr++; | |
1575 pix2 = *srcptr++; | |
1576 pix3 = *srcptr++; | |
1577 *ptr++ = pix1; | |
1578 *ptr++ = pix2; | |
1579 *ptr++ = pix3; | |
1580 *ptr++ = pix1; | |
1581 *ptr++ = pix2; | |
1582 *ptr++ = pix3; | |
1583 *ptr2++ = pix1; | |
1584 *ptr2++ = pix2; | |
1585 *ptr2++ = pix3; | |
1586 *ptr2++ = pix1; | |
1587 *ptr2++ = pix2; | |
1588 *ptr2++ = pix3; | |
1589 | |
1590 } | |
1591 srcptr += img->bpl - (img->width * 3); | |
1592 ptr += (dblimg->bpl << 1) - (dblimg->width * 3); | |
1593 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3); | |
1594 } | |
1595 } | |
1596 if (dblimg->bpp == 4) { | |
1597 register guint32 *srcptr, *ptr, *ptr2, pix; | |
1598 | |
1599 srcptr = (guint32 *) GDK_IMAGE_XIMAGE(img)->data; | |
1600 ptr = (guint32 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
1601 ptr2 = ptr + (dblimg->bpl >> 2); | |
1602 | |
1603 for (y = 0; y < img->height; y++) { | |
1604 for (x = 0; x < img->width; x++) { | |
1605 pix = *srcptr++; | |
1606 *ptr++ = pix; | |
1607 *ptr++ = pix; | |
1608 *ptr2++ = pix; | |
1609 *ptr2++ = pix; | |
1610 } | |
1611 srcptr += (img->bpl >> 2) - img->width; | |
1612 ptr += (dblimg->bpl >> 1) - dblimg->width; | |
1613 ptr2 += (dblimg->bpl >> 1) - dblimg->width; | |
1614 } | |
1615 } | |
1616 return dblimg; | |
1617 } | |
2074
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1618 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1619 /* 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
|
1620 gchar * |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1621 xmms_urldecode_path(const gchar * encoded_path) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1622 { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1623 const gchar *cur, *ext; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1624 gchar *path, *tmp; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1625 gint realchar; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1626 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1627 if (!encoded_path) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1628 return NULL; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1629 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1630 if (!str_has_prefix_nocase(encoded_path, "file:")) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1631 return NULL; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1632 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1633 cur = encoded_path + 5; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1634 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1635 if (str_has_prefix_nocase(cur, "//localhost")) |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1636 cur += 11; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1637 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1638 if (*cur == '/') |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1639 while (cur[1] == '/') |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1640 cur++; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1641 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1642 tmp = g_malloc0(strlen(cur) + 1); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1643 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1644 while ((ext = strchr(cur, '%')) != NULL) { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1645 strncat(tmp, cur, ext - cur); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1646 ext++; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1647 cur = ext + 2; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1648 if (!sscanf(ext, "%2x", &realchar)) { |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1649 /* Assume it is a literal '%'. Several file |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1650 * managers send unencoded file: urls on drag |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1651 * and drop. */ |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1652 realchar = '%'; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1653 cur -= 2; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1654 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1655 tmp[strlen(tmp)] = realchar; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1656 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1657 |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1658 path = g_strconcat(tmp, cur, NULL); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1659 g_free(tmp); |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1660 return path; |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1661 } |
c725daec3849
[svn] - move xmms_urldecode_path() back into main binary
nenolod
parents:
2019
diff
changeset
|
1662 |