2313
|
1 /* Audacious - Cross-platform multimedia player
|
|
2 * Copyright (C) 2005-2007 Audacious development team
|
|
3 *
|
|
4 * Based on BMP:
|
|
5 * Copyright (C) 2003-2004 BMP development team.
|
|
6 *
|
|
7 * Based on XMMS:
|
|
8 * Copyright (C) 1998-2003 XMMS development team.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; under version 2 of the License.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
22 */
|
|
23
|
|
24 #define WEIRD_UTF_16_PLAYLIST_ENCODING
|
|
25
|
|
26 #ifdef HAVE_CONFIG_H
|
|
27 # include "config.h"
|
|
28 #endif
|
|
29
|
|
30 #define NEED_GLADE
|
|
31 #include "util.h"
|
|
32
|
|
33 #include <glib.h>
|
|
34 #include <glib/gi18n.h>
|
|
35 #include <glade/glade.h>
|
|
36 #include <gtk/gtk.h>
|
|
37 #include <stdio.h>
|
|
38 #include <stdlib.h>
|
|
39 #include <string.h>
|
|
40 #include <ctype.h>
|
|
41
|
|
42 #include "platform/smartinclude.h"
|
|
43 #include <gdk/gdkkeysyms.h>
|
|
44 #include <X11/Xlib.h>
|
|
45 //#include <sys/ipc.h>
|
|
46 #include <unistd.h>
|
|
47 #include <errno.h>
|
|
48
|
|
49 #ifdef HAVE_FTS_H
|
|
50 # include <fts.h>
|
|
51 #endif
|
|
52
|
|
53 #include "glade.h"
|
|
54 #include "input.h"
|
|
55 #include "main.h"
|
|
56 #include "playback.h"
|
|
57 #include "playlist.h"
|
|
58 #include "ui_playlist.h"
|
|
59
|
|
60 #ifdef USE_CHARDET
|
|
61 #include "../libguess/libguess.h"
|
|
62 #include "../librcd/librcd.h"
|
|
63 #ifdef HAVE_UDET
|
|
64 #include <libudet_c.h>
|
|
65 #endif
|
|
66 #endif
|
|
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;
|
2328
|
277 #ifndef HAVE_MKDTEMP
|
2313
|
278 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
2328
|
279 #endif
|
2313
|
280
|
|
281 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
|
|
282 return NULL;
|
|
283
|
|
284 #ifdef HAVE_MKDTEMP
|
|
285 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL);
|
|
286 if (!mkdtemp(tmpdir)) {
|
|
287 g_free(tmpdir);
|
|
288 g_message("Unable to load skin: Failed to create temporary "
|
|
289 "directory: %s", g_strerror(errno));
|
|
290 return NULL;
|
|
291 }
|
|
292 #else
|
|
293 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand());
|
|
294 make_directory(tmpdir, mode755);
|
|
295 #endif
|
|
296
|
|
297 escaped_filename = escape_shell_chars(filename);
|
|
298 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
|
|
299 g_free(escaped_filename);
|
|
300
|
|
301 if (!cmd) {
|
|
302 g_message("extraction function is NULL!");
|
|
303 g_free(tmpdir);
|
|
304 return NULL;
|
|
305 }
|
|
306
|
|
307 system(cmd);
|
|
308 g_free(cmd);
|
|
309
|
|
310 return tmpdir;
|
|
311 }
|
|
312
|
|
313
|
|
314 #ifdef HAVE_FTS_H
|
|
315
|
|
316 void
|
|
317 del_directory(const gchar * dirname)
|
|
318 {
|
|
319 gchar *const argv[2] = { (gchar *) dirname, NULL };
|
|
320 FTS *fts;
|
|
321 FTSENT *p;
|
|
322
|
|
323 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
|
|
324 while ((p = fts_read(fts))) {
|
|
325 switch (p->fts_info) {
|
|
326 case FTS_D:
|
|
327 break;
|
|
328 case FTS_DNR:
|
|
329 case FTS_ERR:
|
|
330 break;
|
|
331 case FTS_DP:
|
|
332 rmdir(p->fts_accpath);
|
|
333 break;
|
|
334 default:
|
|
335 unlink(p->fts_accpath);
|
|
336 break;
|
|
337 }
|
|
338 }
|
|
339 fts_close(fts);
|
|
340 }
|
|
341
|
|
342 #else /* !HAVE_FTS */
|
|
343
|
|
344 gboolean
|
|
345 del_directory_func(const gchar * path, const gchar * basename,
|
|
346 gpointer params)
|
|
347 {
|
|
348 if (!strcmp(basename, ".") || !strcmp(path, ".."))
|
|
349 return FALSE;
|
|
350
|
|
351 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
|
|
352 dir_foreach(path, del_directory_func, NULL, NULL);
|
|
353 rmdir(path);
|
|
354 return FALSE;
|
|
355 }
|
|
356
|
|
357 unlink(path);
|
|
358
|
|
359 return FALSE;
|
|
360 }
|
|
361
|
|
362 void
|
|
363 del_directory(const gchar * path)
|
|
364 {
|
|
365 dir_foreach(path, del_directory_func, NULL, NULL);
|
|
366 rmdir(path);
|
|
367 }
|
|
368
|
|
369 #endif /* ifdef HAVE_FTS */
|
|
370
|
|
371 gchar *
|
|
372 read_ini_string(const gchar * filename, const gchar * section,
|
|
373 const gchar * key)
|
|
374 {
|
|
375 static gchar *buffer = NULL;
|
|
376 static gchar *open_buffer = NULL;
|
|
377 gchar *ret_buffer = NULL;
|
|
378 gint found_section = 0, len = 0;
|
|
379 static gsize filesize = 0;
|
|
380 gsize off = 0;
|
|
381 gchar *outbuf;
|
|
382 unsigned char x[] = { 0xff, 0xfe, 0x00 };
|
|
383 guint counter;
|
|
384
|
|
385 if (!filename)
|
|
386 return NULL;
|
|
387
|
|
388 /*
|
|
389 * We optimise for the condition that we may be reading from the
|
|
390 * same ini-file multiple times. This is fairly common; it happens
|
|
391 * on .pls playlist loads. To do otherwise would take entirely too
|
|
392 * long, as fstat() can be very slow when done 21,000 times too many.
|
|
393 *
|
|
394 * Therefore, we optimise by keeping the last ini file in memory.
|
|
395 * Yes, this is a memory leak, but it is not too bad, hopefully.
|
|
396 * - nenolod
|
|
397 */
|
|
398 if (open_buffer == NULL || strcasecmp(filename, open_buffer))
|
|
399 {
|
|
400 if (buffer != NULL)
|
|
401 {
|
|
402 g_free(buffer);
|
|
403 buffer = NULL;
|
|
404 }
|
|
405
|
|
406 if (open_buffer != NULL)
|
|
407 {
|
|
408 g_free(open_buffer);
|
|
409 open_buffer = NULL;
|
|
410 }
|
|
411
|
|
412 if (!g_file_get_contents(filename, &buffer, &filesize, NULL))
|
|
413 return NULL;
|
|
414
|
|
415 open_buffer = g_strdup(filename);
|
|
416 }
|
|
417
|
|
418 /*
|
|
419 * Convert UTF-16 into something useful. Original implementation
|
|
420 * by incomp@#audacious. Cleanups \nenolod
|
|
421 */
|
|
422 if (!memcmp(&buffer[0],&x,2)) {
|
|
423 outbuf = g_malloc (filesize); /* it's safe to waste memory. */
|
|
424
|
|
425 for (counter = 2; counter < filesize; counter += 2)
|
|
426 if (!memcmp(&buffer[counter+1], &x[2], 1))
|
|
427 outbuf[(counter-2)/2] = buffer[counter];
|
|
428 else
|
|
429 return NULL;
|
|
430
|
|
431 outbuf[(counter-2)/2] = '\0';
|
|
432
|
|
433 if ((filesize - 2) / 2 == (counter - 2) / 2) {
|
|
434 g_free(buffer);
|
|
435 buffer = outbuf;
|
|
436 } else {
|
|
437 g_free(outbuf);
|
|
438 return NULL; /* XXX wrong encoding */
|
|
439 }
|
|
440 }
|
|
441
|
|
442 while (!ret_buffer && off < filesize) {
|
|
443 while (off < filesize &&
|
|
444 (buffer[off] == '\r' || buffer[off] == '\n' ||
|
|
445 buffer[off] == ' ' || buffer[off] == '\t'))
|
|
446 off++;
|
|
447 if (off >= filesize)
|
|
448 break;
|
|
449 if (buffer[off] == '[') {
|
|
450 gint slen = strlen(section);
|
|
451 off++;
|
|
452 found_section = 0;
|
|
453 if (off + slen + 1 < filesize &&
|
|
454 !strncasecmp(section, &buffer[off], slen)) {
|
|
455 off += slen;
|
|
456 if (buffer[off] == ']') {
|
|
457 off++;
|
|
458 found_section = 1;
|
|
459 }
|
|
460 }
|
|
461 }
|
|
462 else if (found_section && off + strlen(key) < filesize &&
|
|
463 !strncasecmp(key, &buffer[off], strlen(key))) {
|
|
464 off += strlen(key);
|
|
465 while (off < filesize &&
|
|
466 (buffer[off] == ' ' || buffer[off] == '\t'))
|
|
467 off++;
|
|
468 if (off >= filesize)
|
|
469 break;
|
|
470 if (buffer[off] == '=') {
|
|
471 off++;
|
|
472 while (off < filesize &&
|
|
473 (buffer[off] == ' ' || buffer[off] == '\t'))
|
|
474 off++;
|
|
475 if (off >= filesize)
|
|
476 break;
|
|
477 len = 0;
|
|
478 while (off + len < filesize &&
|
|
479 buffer[off + len] != '\r' &&
|
|
480 buffer[off + len] != '\n' && buffer[off + len] != ';')
|
|
481 len++;
|
|
482 ret_buffer = g_strndup(&buffer[off], len);
|
|
483 off += len;
|
|
484 }
|
|
485 }
|
|
486 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n')
|
|
487 off++;
|
|
488 }
|
|
489
|
|
490 return ret_buffer;
|
|
491 }
|
|
492
|
|
493 GArray *
|
|
494 string_to_garray(const gchar * str)
|
|
495 {
|
|
496 GArray *array;
|
|
497 gint temp;
|
|
498 const gchar *ptr = str;
|
|
499 gchar *endptr;
|
|
500
|
|
501 array = g_array_new(FALSE, TRUE, sizeof(gint));
|
|
502 for (;;) {
|
|
503 temp = strtol(ptr, &endptr, 10);
|
|
504 if (ptr == endptr)
|
|
505 break;
|
|
506 g_array_append_val(array, temp);
|
|
507 ptr = endptr;
|
|
508 while (!isdigit((int) *ptr) && (*ptr) != '\0')
|
|
509 ptr++;
|
|
510 if (*ptr == '\0')
|
|
511 break;
|
|
512 }
|
|
513 return (array);
|
|
514 }
|
|
515
|
|
516 GArray *
|
|
517 read_ini_array(const gchar * filename, const gchar * section,
|
|
518 const gchar * key)
|
|
519 {
|
|
520 gchar *temp;
|
|
521 GArray *a;
|
|
522
|
|
523 if ((temp = read_ini_string(filename, section, key)) == NULL) {
|
|
524 g_free(temp);
|
|
525 return NULL;
|
|
526 }
|
|
527 a = string_to_garray(temp);
|
|
528 g_free(temp);
|
|
529 return a;
|
|
530 }
|
|
531
|
|
532 void
|
|
533 glist_movedown(GList * list)
|
|
534 {
|
|
535 gpointer temp;
|
|
536
|
|
537 if (g_list_next(list)) {
|
|
538 temp = list->data;
|
|
539 list->data = list->next->data;
|
|
540 list->next->data = temp;
|
|
541 }
|
|
542 }
|
|
543
|
|
544 void
|
|
545 glist_moveup(GList * list)
|
|
546 {
|
|
547 gpointer temp;
|
|
548
|
|
549 if (g_list_previous(list)) {
|
|
550 temp = list->data;
|
|
551 list->data = list->prev->data;
|
|
552 list->prev->data = temp;
|
|
553 }
|
|
554 }
|
|
555
|
|
556
|
|
557 void
|
|
558 util_menu_position(GtkMenu * menu, gint * x, gint * y,
|
|
559 gboolean * push_in, gpointer data)
|
|
560 {
|
|
561 GtkRequisition requisition;
|
|
562 gint screen_width;
|
|
563 gint screen_height;
|
|
564 MenuPos *pos = data;
|
|
565
|
|
566 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
|
|
567
|
|
568 screen_width = gdk_screen_width();
|
|
569 screen_height = gdk_screen_height();
|
|
570
|
|
571 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width));
|
|
572 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height));
|
|
573 }
|
|
574
|
|
575 #define URL_HISTORY_MAX_SIZE 30
|
|
576
|
|
577 static void
|
|
578 util_add_url_callback(GtkWidget * widget,
|
|
579 GtkEntry * entry)
|
|
580 {
|
|
581 const gchar *text;
|
|
582
|
|
583 text = gtk_entry_get_text(entry);
|
|
584 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp))
|
|
585 return;
|
|
586
|
|
587 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text));
|
|
588
|
|
589 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) {
|
|
590 GList *node = g_list_last(cfg.url_history);
|
|
591 g_free(node->data);
|
|
592 cfg.url_history = g_list_delete_link(cfg.url_history, node);
|
|
593 }
|
|
594 }
|
|
595
|
|
596 GtkWidget *
|
|
597 util_add_url_dialog_new(const gchar * caption, GCallback ok_func,
|
|
598 GCallback enqueue_func)
|
|
599 {
|
|
600 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry,
|
|
601 *label;
|
|
602 GList *url;
|
|
603
|
|
604 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
605 gtk_window_set_title(GTK_WINDOW(win), _("Add/Open URL Dialog"));
|
|
606 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
607 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
|
|
608 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1);
|
|
609 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
|
|
610
|
|
611 vbox = gtk_vbox_new(FALSE, 10);
|
|
612 gtk_container_add(GTK_CONTAINER(win), vbox);
|
|
613
|
|
614 label = gtk_label_new(caption);
|
|
615 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
616 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
|
|
617
|
|
618 combo = gtk_combo_box_entry_new_text();
|
|
619 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
|
|
620
|
|
621 entry = gtk_bin_get_child(GTK_BIN(combo));
|
|
622 gtk_window_set_focus(GTK_WINDOW(win), entry);
|
|
623 gtk_entry_set_text(GTK_ENTRY(entry), "");
|
|
624
|
|
625 for (url = cfg.url_history; url; url = g_list_next(url))
|
|
626 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data);
|
|
627
|
|
628 g_signal_connect(entry, "activate",
|
|
629 G_CALLBACK(util_add_url_callback),
|
|
630 entry);
|
|
631 g_signal_connect(entry, "activate",
|
|
632 G_CALLBACK(ok_func),
|
|
633 entry);
|
|
634 g_signal_connect_swapped(entry, "activate",
|
|
635 G_CALLBACK(gtk_widget_destroy),
|
|
636 win);
|
|
637
|
|
638 bbox = gtk_hbutton_box_new();
|
|
639 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
640 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
|
|
641 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
642
|
|
643 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN);
|
|
644 g_signal_connect(ok, "clicked",
|
|
645 G_CALLBACK(util_add_url_callback), entry);
|
|
646 g_signal_connect(ok, "clicked",
|
|
647 G_CALLBACK(ok_func), entry);
|
|
648 g_signal_connect_swapped(ok, "clicked",
|
|
649 G_CALLBACK(gtk_widget_destroy),
|
|
650 win);
|
|
651 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0);
|
|
652
|
|
653 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD);
|
|
654 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0);
|
|
655
|
|
656 g_signal_connect(enqueue, "clicked",
|
|
657 G_CALLBACK(util_add_url_callback),
|
|
658 entry);
|
|
659 g_signal_connect(enqueue, "clicked",
|
|
660 G_CALLBACK(enqueue_func),
|
|
661 entry);
|
|
662 g_signal_connect_swapped(enqueue, "clicked",
|
|
663 G_CALLBACK(gtk_widget_destroy),
|
|
664 win);
|
|
665
|
|
666 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
|
|
667 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
|
|
668
|
|
669 g_signal_connect_swapped(cancel, "clicked",
|
|
670 G_CALLBACK(gtk_widget_destroy),
|
|
671 win);
|
|
672
|
|
673 gtk_widget_show_all(vbox);
|
|
674
|
|
675 return win;
|
|
676 }
|
|
677
|
|
678 static void
|
|
679 filebrowser_add_files(GtkFileChooser * browser,
|
|
680 GSList * files)
|
|
681 {
|
|
682 GSList *cur;
|
|
683 gchar *ptr;
|
|
684 guint ctr = 0;
|
|
685 Playlist *playlist = playlist_get_active();
|
|
686
|
|
687 if (GTK_IS_WIDGET(mainwin_jtf))
|
|
688 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
|
|
689
|
|
690 for (cur = files; cur; cur = g_slist_next(cur)) {
|
|
691
|
|
692 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) {
|
|
693 playlist_add_dir(playlist, (const gchar *) cur->data);
|
|
694 } else {
|
|
695 playlist_add(playlist, (const gchar *) cur->data);
|
|
696 }
|
|
697
|
|
698 if (++ctr == 20) {
|
|
699 playlistwin_update_list(playlist);
|
|
700 ctr = 0;
|
|
701 while (gtk_events_pending() ) gtk_main_iteration();
|
|
702 }
|
|
703 }
|
|
704
|
|
705 playlistwin_update_list(playlist);
|
|
706
|
|
707 if (GTK_IS_WIDGET(mainwin_jtf))
|
|
708 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
|
|
709
|
|
710 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser));
|
|
711
|
|
712 g_free(cfg.filesel_path);
|
|
713 cfg.filesel_path = ptr;
|
|
714 }
|
|
715
|
|
716 static void
|
|
717 filebrowser_add(GtkFileChooser *browser)
|
|
718 {
|
|
719 GSList *files;
|
|
720
|
|
721 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
|
|
722
|
|
723 if (!files) {
|
|
724 return;
|
|
725 }
|
|
726
|
|
727 filebrowser_add_files(browser, files);
|
|
728 g_slist_foreach(files, (GFunc) g_free, NULL);
|
|
729 g_slist_free(files);
|
|
730 }
|
|
731
|
|
732 static void
|
|
733 filebrowser_play(GtkFileChooser * browser)
|
|
734 {
|
|
735 GSList *files;
|
|
736
|
|
737 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
|
|
738
|
|
739 if (!files) return;
|
|
740
|
|
741 playlist_clear(playlist_get_active());
|
|
742
|
|
743 filebrowser_add_files(browser, files);
|
|
744 g_slist_foreach(files, (GFunc) g_free, NULL);
|
|
745 g_slist_free(files);
|
|
746
|
|
747 playback_initiate();
|
|
748 }
|
|
749
|
|
750
|
|
751 static void
|
|
752 _filebrowser_add_gtk2(GtkWidget *widget,
|
|
753 gpointer data)
|
|
754 {
|
|
755 filebrowser_add(data);
|
|
756 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data));
|
|
757 }
|
|
758
|
|
759 static void
|
|
760 _filebrowser_play_gtk2(GtkWidget *widget, gpointer data)
|
|
761 {
|
|
762 filebrowser_play(data);
|
|
763 gtk_file_chooser_unselect_all(data);
|
|
764 }
|
|
765
|
|
766 #if 0
|
|
767 static void
|
|
768 filebrowser_on_response(GtkFileChooser * browser,
|
|
769 gint response,
|
|
770 gpointer data)
|
|
771 {
|
|
772 gtk_widget_hide(GTK_WIDGET(browser));
|
|
773 switch (response) {
|
|
774 case GTK_RESPONSE_OK:
|
|
775 break;
|
|
776 case GTK_RESPONSE_ACCEPT:
|
|
777 break;
|
|
778 case GTK_RESPONSE_CLOSE:
|
|
779 break;
|
|
780 }
|
|
781 gtk_widget_destroy(GTK_WIDGET(browser));
|
|
782
|
|
783 }
|
|
784
|
|
785 #endif
|
|
786
|
|
787 static void
|
|
788 _filebrowser_check_hide_add(GtkWidget * widget,
|
|
789 gpointer data)
|
|
790 {
|
|
791 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
|
792 }
|
|
793
|
|
794 static void
|
|
795 _filebrowser_check_hide_open(GtkWidget * widget,
|
|
796 gpointer data)
|
|
797 {
|
|
798 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
|
799 }
|
|
800
|
|
801
|
|
802
|
|
803 static gboolean
|
|
804 filebrowser_on_keypress(GtkWidget * browser,
|
|
805 GdkEventKey * event,
|
|
806 gpointer data)
|
|
807 {
|
|
808 if (event->keyval == GDK_Escape) {
|
|
809 /* FIXME: this crashes BMP for some reason */
|
|
810 /* g_signal_emit_by_name(browser, "delete-event"); */
|
|
811 gtk_widget_hide(browser);
|
|
812 return TRUE;
|
|
813 }
|
|
814
|
|
815 return FALSE;
|
|
816 }
|
|
817
|
|
818 static void
|
|
819 _filebrowser_do_hide_add(GtkWidget *widget,
|
|
820 gpointer data)
|
|
821 {
|
|
822 if (cfg.close_dialog_add)
|
|
823 gtk_widget_hide(data);
|
|
824 }
|
|
825
|
|
826 static void
|
|
827 _filebrowser_do_hide_open(GtkWidget *widget,
|
|
828 gpointer data)
|
|
829 {
|
|
830 if (cfg.close_dialog_open)
|
|
831 gtk_widget_hide(data);
|
|
832 }
|
|
833
|
|
834 void
|
|
835 util_run_filebrowser_gtk2style(gboolean play_button)
|
|
836 {
|
|
837 static GladeXML *xml = NULL;
|
|
838 static GtkWidget *dialog = NULL;
|
|
839 static GtkWidget *chooser = NULL;
|
|
840
|
|
841 static GtkWidget *button_add;
|
|
842 static GtkWidget *button_select_all, *button_deselect_all;
|
|
843 static GtkWidget *toggle;
|
|
844
|
|
845 static gulong handlerid, handlerid_check, handlerid_do;
|
|
846 static gulong handlerid_activate, handlerid_do_activate;
|
|
847
|
|
848 if (!xml) {
|
|
849 /* FIXME: Creating a file chooser dialog manually using
|
|
850 libglade because there's no way to stop
|
|
851 GtkFileChooserDialog from resizing the buttons to the same
|
|
852 size. The long toggle button title causes the buttons to
|
|
853 turn unnecessarily elongated and fugly. */
|
|
854
|
|
855 GtkWidget *alignment;
|
|
856
|
|
857 xml = glade_xml_new_or_die(_("Add/Open Files dialog"),
|
|
858 DATA_DIR "/glade/addfiles.glade",
|
|
859 NULL, NULL);
|
|
860 glade_xml_signal_autoconnect(xml);
|
|
861
|
|
862 dialog = glade_xml_get_widget(xml, "add_files_dialog");
|
|
863
|
|
864 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does
|
|
865 not support GtkFileChooserWidget */
|
|
866
|
|
867 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
|
|
868 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE);
|
|
869
|
|
870 if (cfg.filesel_path)
|
|
871 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
|
|
872 cfg.filesel_path);
|
|
873
|
|
874 alignment = glade_xml_get_widget(xml, "alignment2");
|
|
875 gtk_container_add(GTK_CONTAINER(alignment), chooser);
|
|
876
|
|
877 toggle = glade_xml_get_widget(xml, "close_on_action");
|
|
878 button_select_all = glade_xml_get_widget(xml, "select_all");
|
|
879 button_deselect_all = glade_xml_get_widget(xml, "deselect_all");
|
|
880 button_add = glade_xml_get_widget(xml, "action");
|
|
881
|
|
882 g_signal_connect_swapped(button_select_all, "clicked",
|
|
883 G_CALLBACK(gtk_file_chooser_select_all),
|
|
884 chooser);
|
|
885 g_signal_connect_swapped(button_deselect_all, "clicked",
|
|
886 G_CALLBACK(gtk_file_chooser_unselect_all),
|
|
887 chooser);
|
|
888
|
|
889 g_signal_connect(dialog, "key_press_event",
|
|
890 G_CALLBACK(filebrowser_on_keypress),
|
|
891 NULL);
|
|
892
|
|
893 gtk_widget_show_all(dialog);
|
|
894 } /* !xml */
|
|
895 else {
|
|
896 g_signal_handler_disconnect(button_add, handlerid);
|
|
897 g_signal_handler_disconnect(toggle, handlerid_check);
|
|
898 g_signal_handler_disconnect(chooser, handlerid_activate);
|
|
899 g_signal_handler_disconnect(button_add, handlerid_do);
|
|
900 g_signal_handler_disconnect(chooser, handlerid_do_activate);
|
|
901
|
|
902 if (cfg.refresh_file_list)
|
|
903 {
|
|
904 gchar *tmp = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser));
|
|
905 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), tmp);
|
|
906
|
|
907 g_free(tmp);
|
|
908 }
|
|
909 }
|
|
910
|
|
911 if (play_button) {
|
|
912 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files"));
|
|
913
|
|
914 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN);
|
|
915
|
|
916 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open"));
|
|
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open);
|
|
918
|
|
919 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play_gtk2), chooser);
|
|
920 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL);
|
|
921 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog);
|
|
922 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play_gtk2), chooser);
|
|
923 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog);
|
|
924 }
|
|
925 else {
|
|
926 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files"));
|
|
927
|
|
928 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD);
|
|
929
|
|
930 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add"));
|
|
931 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add);
|
|
932
|
|
933 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add_gtk2), chooser);
|
|
934 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL);
|
|
935 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog);
|
|
936 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add_gtk2), chooser);
|
|
937 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog);
|
|
938 }
|
|
939
|
|
940 gtk_window_present(GTK_WINDOW(dialog));
|
|
941 }
|
|
942
|
|
943 /*
|
|
944 * Derived from Beep Media Player 0.9.6.1.
|
|
945 * Which is (C) 2003 - 2006 Milosz Derezynski &c
|
|
946 *
|
|
947 * Although I changed it quite a bit. -nenolod
|
|
948 */
|
|
949 static void filebrowser_changed_classic(GtkFileSelection * filesel)
|
|
950 {
|
|
951 GList *list;
|
|
952 GList *node;
|
|
953 char *filename = (char *)
|
|
954 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel));
|
|
955 GtkListStore *store;
|
|
956 GtkTreeIter iter;
|
|
957
|
|
958 if ((list = input_scan_dir(filename)) != NULL) {
|
|
959 /*
|
|
960 * We enter a directory that has been "hijacked" by an
|
|
961 * input-plugin. This is used by the CDDA plugin
|
|
962 */
|
|
963 store =
|
|
964 GTK_LIST_STORE(gtk_tree_view_get_model
|
|
965 (GTK_TREE_VIEW(filesel->file_list)));
|
|
966 gtk_list_store_clear(store);
|
|
967
|
|
968 node = list;
|
|
969 while (node) {
|
|
970
|
|
971 gtk_list_store_append(store, &iter);
|
|
972 gtk_list_store_set(store, &iter, 0, node->data, -1);
|
|
973 g_free(node->data);
|
|
974 node = g_list_next(node);
|
|
975 }
|
|
976 g_list_free(list);
|
|
977 }
|
|
978 }
|
|
979
|
|
980 static void filebrowser_entry_changed_classic(GtkEditable * entry, gpointer data)
|
|
981 {
|
|
982 filebrowser_changed_classic(GTK_FILE_SELECTION(data));
|
|
983 }
|
|
984
|
|
985 gboolean util_filebrowser_is_dir_classic(GtkFileSelection * filesel)
|
|
986 {
|
|
987 char *text;
|
|
988 struct stat buf;
|
|
989 gboolean retv = FALSE;
|
|
990
|
|
991 text = g_strdup(gtk_file_selection_get_filename(filesel));
|
|
992
|
|
993 if (stat(text, &buf) == 0 && S_ISDIR(buf.st_mode)) {
|
|
994 /* Selected directory */
|
|
995 int len = strlen(text);
|
|
996 if (len > 3 && !strcmp(text + len - 4, "/../")) {
|
|
997 if (len == 4)
|
|
998 /* At the root already */
|
|
999 *(text + len - 3) = '\0';
|
|
1000 else {
|
|
1001 char *ptr;
|
|
1002 *(text + len - 4) = '\0';
|
|
1003 ptr = strrchr(text, '/');
|
|
1004 *(ptr + 1) = '\0';
|
|
1005 }
|
|
1006 } else if (len > 2 && !strcmp(text + len - 3, "/./"))
|
|
1007 *(text + len - 2) = '\0';
|
|
1008 gtk_file_selection_set_filename(filesel, text);
|
|
1009 retv = TRUE;
|
|
1010 }
|
|
1011 g_free(text);
|
|
1012 return retv;
|
|
1013 }
|
|
1014
|
|
1015 static void filebrowser_add_files_classic(gchar ** files,
|
|
1016 GtkFileSelection * filesel)
|
|
1017 {
|
|
1018 int ctr = 0;
|
|
1019 char *ptr;
|
|
1020 Playlist *playlist = playlist_get_active();
|
|
1021
|
|
1022 if (GTK_IS_WIDGET(mainwin_jtf))
|
|
1023 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
|
|
1024
|
|
1025 while (files[ctr] != NULL) {
|
|
1026 playlist_add(playlist, files[ctr++]);
|
|
1027 }
|
|
1028 playlistwin_update_list(playlist);
|
|
1029
|
|
1030 if (GTK_IS_WIDGET(mainwin_jtf))
|
|
1031 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
|
|
1032
|
|
1033 gtk_label_get(GTK_LABEL(GTK_BIN(filesel->history_pulldown)->child),
|
|
1034 &ptr);
|
|
1035
|
|
1036 /* This will give an extra slash if the current dir is the root. */
|
|
1037 cfg.filesel_path = g_strconcat(ptr, "/", NULL);
|
|
1038 }
|
|
1039
|
|
1040 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel)
|
|
1041 {
|
|
1042 gchar **files;
|
|
1043
|
|
1044 if (util_filebrowser_is_dir_classic(GTK_FILE_SELECTION(filesel)))
|
|
1045 return;
|
|
1046 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel));
|
|
1047 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel));
|
|
1048 gtk_widget_destroy(filesel);
|
|
1049 }
|
|
1050
|
|
1051 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel)
|
|
1052 {
|
|
1053 gchar **files;
|
|
1054
|
|
1055 if (util_filebrowser_is_dir_classic
|
|
1056 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel))))
|
|
1057 return;
|
|
1058 playlist_clear(playlist_get_active());
|
|
1059 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel));
|
|
1060 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel));
|
|
1061 gtk_widget_destroy(filesel);
|
|
1062 playback_initiate();
|
|
1063 }
|
|
1064
|
|
1065 static void filebrowser_add_selected_files_classic(GtkWidget * w, gpointer data)
|
|
1066 {
|
|
1067 gchar **files;
|
|
1068
|
|
1069 GtkFileSelection *filesel = GTK_FILE_SELECTION(data);
|
|
1070 files = gtk_file_selection_get_selections(filesel);
|
|
1071
|
|
1072 filebrowser_add_files_classic(files, filesel);
|
|
1073 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
|
|
1074 (GTK_TREE_VIEW(filesel->file_list)));
|
|
1075
|
|
1076 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), "");
|
|
1077 }
|
|
1078
|
|
1079 static void filebrowser_add_all_files_classic(GtkWidget * w, gpointer data)
|
|
1080 {
|
|
1081 gchar **files;
|
|
1082 GtkFileSelection *filesel;
|
|
1083
|
|
1084 filesel = data;
|
|
1085 gtk_tree_selection_select_all(gtk_tree_view_get_selection
|
|
1086 (GTK_TREE_VIEW(filesel->file_list)));
|
|
1087 files = gtk_file_selection_get_selections(filesel);
|
|
1088 filebrowser_add_files_classic(files, filesel);
|
|
1089 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
|
|
1090 (GTK_TREE_VIEW(filesel->file_list)));
|
|
1091 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), "");
|
|
1092 }
|
|
1093
|
|
1094 void
|
|
1095 util_run_filebrowser_classic(gboolean play_button)
|
|
1096 {
|
|
1097 static GtkWidget *dialog;
|
|
1098 GtkWidget *button_add_selected, *button_add_all, *button_close,
|
|
1099 *button_add;
|
|
1100 char *title;
|
|
1101
|
|
1102 if (dialog != NULL) {
|
|
1103 gtk_window_present(GTK_WINDOW(dialog));
|
|
1104 return;
|
|
1105 }
|
|
1106
|
|
1107 if (play_button)
|
|
1108 title = _("Play files");
|
|
1109 else
|
|
1110 title = _("Load files");
|
|
1111
|
|
1112 dialog = gtk_file_selection_new(title);
|
|
1113
|
|
1114 gtk_file_selection_set_select_multiple
|
|
1115 (GTK_FILE_SELECTION(dialog), TRUE);
|
|
1116
|
|
1117 if (cfg.filesel_path)
|
|
1118 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog),
|
|
1119 cfg.filesel_path);
|
|
1120
|
|
1121 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(dialog));
|
|
1122 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
|
|
1123
|
|
1124 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button);
|
|
1125 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button);
|
|
1126
|
|
1127 /*
|
|
1128 * The mnemonics are quite unorthodox, but that should guarantee they're unique in any locale
|
|
1129 * plus kinda easy to use
|
|
1130 */
|
|
1131 button_add_selected =
|
|
1132 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected",
|
|
1133 GTK_RESPONSE_NONE);
|
|
1134 gtk_button_set_use_underline(GTK_BUTTON(button_add_selected), TRUE);
|
|
1135 g_signal_connect(G_OBJECT(button_add_selected), "clicked",
|
|
1136 G_CALLBACK(filebrowser_add_selected_files_classic), dialog);
|
|
1137
|
|
1138 button_add_all =
|
|
1139 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all",
|
|
1140 GTK_RESPONSE_NONE);
|
|
1141 gtk_button_set_use_underline(GTK_BUTTON(button_add_all), TRUE);
|
|
1142 g_signal_connect(G_OBJECT(button_add_all), "clicked",
|
|
1143 G_CALLBACK(filebrowser_add_all_files_classic), dialog);
|
|
1144
|
|
1145 if (play_button) {
|
|
1146 button_add =
|
|
1147 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_MEDIA_PLAY,
|
|
1148 GTK_RESPONSE_NONE);
|
|
1149 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE);
|
|
1150 g_signal_connect(G_OBJECT(button_add), "clicked",
|
|
1151 G_CALLBACK(filebrowser_play_classic), dialog);
|
|
1152 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
|
|
1153 "clicked", G_CALLBACK(filebrowser_play_classic), dialog);
|
|
1154 } else {
|
|
1155 button_add =
|
|
1156 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ADD,
|
|
1157 GTK_RESPONSE_NONE);
|
|
1158 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE);
|
|
1159 g_signal_connect(G_OBJECT(button_add), "clicked",
|
|
1160 G_CALLBACK(filebrowser_ok_classic), dialog);
|
|
1161 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
|
|
1162 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog);
|
|
1163 }
|
|
1164
|
|
1165 button_close =
|
|
1166 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE,
|
|
1167 GTK_RESPONSE_NONE);
|
|
1168 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
|
|
1169 g_signal_connect_swapped(G_OBJECT(button_close), "clicked",
|
|
1170 G_CALLBACK(gtk_widget_destroy),
|
|
1171 G_OBJECT(dialog));
|
|
1172
|
|
1173 gtk_widget_set_size_request(dialog, 600, 450);
|
|
1174 gtk_widget_realize(dialog);
|
|
1175
|
|
1176 g_signal_connect(G_OBJECT
|
|
1177 (GTK_FILE_SELECTION(dialog)->history_pulldown),
|
|
1178 "changed", G_CALLBACK(filebrowser_entry_changed_classic),
|
|
1179 dialog);
|
|
1180
|
|
1181 g_signal_connect(G_OBJECT(dialog), "destroy",
|
|
1182 G_CALLBACK(gtk_widget_destroyed), &dialog);
|
|
1183
|
|
1184 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog));
|
|
1185
|
|
1186 gtk_widget_show(dialog);
|
|
1187 }
|
|
1188
|
|
1189 /*
|
|
1190 * util_run_filebrowser(gboolean play_button)
|
|
1191 *
|
|
1192 * Inputs:
|
|
1193 * - whether or not a play button should be used
|
|
1194 *
|
|
1195 * Outputs:
|
|
1196 * - none
|
|
1197 *
|
|
1198 * Side Effects:
|
|
1199 * - either a GTK1 or a GTK2 fileselector is launched
|
|
1200 */
|
|
1201 void
|
|
1202 util_run_filebrowser(gboolean play_button)
|
|
1203 {
|
|
1204 if (!cfg.use_xmms_style_fileselector)
|
|
1205 util_run_filebrowser_gtk2style(play_button);
|
|
1206 else
|
|
1207 util_run_filebrowser_classic(play_button);
|
|
1208 }
|
|
1209
|
|
1210 GdkFont *
|
|
1211 util_font_load(const gchar * name)
|
|
1212 {
|
|
1213 GdkFont *font;
|
|
1214 PangoFontDescription *desc;
|
|
1215
|
|
1216 desc = pango_font_description_from_string(name);
|
|
1217 font = gdk_font_from_description(desc);
|
|
1218
|
|
1219 return font;
|
|
1220 }
|
|
1221
|
|
1222 #ifdef ENABLE_NLS
|
|
1223 gchar *
|
|
1224 bmp_menu_translate(const gchar * path, gpointer func_data)
|
|
1225 {
|
|
1226 gchar *translation = gettext(path);
|
|
1227
|
|
1228 if (!translation || *translation != '/') {
|
|
1229 g_warning("Bad translation for menupath: %s", path);
|
|
1230 translation = (gchar *) path;
|
|
1231 }
|
|
1232
|
|
1233 return translation;
|
|
1234 }
|
|
1235 #endif
|
|
1236
|
|
1237 void
|
|
1238 util_set_cursor(GtkWidget * window)
|
|
1239 {
|
|
1240 static GdkCursor *cursor = NULL;
|
|
1241
|
|
1242 if (!window) {
|
|
1243 if (cursor) {
|
|
1244 gdk_cursor_unref(cursor);
|
|
1245 cursor = NULL;
|
|
1246 }
|
|
1247
|
|
1248 return;
|
|
1249 }
|
|
1250
|
|
1251 if (!cursor)
|
|
1252 cursor = gdk_cursor_new(GDK_LEFT_PTR);
|
|
1253
|
|
1254 gdk_window_set_cursor(window->window, cursor);
|
|
1255 }
|
|
1256
|
|
1257 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
|
|
1258 * Mattis et al */
|
|
1259 gboolean
|
|
1260 text_get_extents(const gchar * fontname,
|
|
1261 const gchar * text,
|
|
1262 gint * width, gint * height, gint * ascent, gint * descent)
|
|
1263 {
|
|
1264 PangoFontDescription *font_desc;
|
|
1265 PangoLayout *layout;
|
|
1266 PangoRectangle rect;
|
|
1267
|
|
1268 g_return_val_if_fail(fontname != NULL, FALSE);
|
|
1269 g_return_val_if_fail(text != NULL, FALSE);
|
|
1270
|
|
1271 /* FIXME: resolution */
|
|
1272 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
|
|
1273
|
|
1274 font_desc = pango_font_description_from_string(fontname);
|
|
1275 pango_layout_set_font_description(layout, font_desc);
|
|
1276 pango_font_description_free(font_desc);
|
|
1277 pango_layout_get_pixel_extents(layout, NULL, &rect);
|
|
1278
|
|
1279 if (width)
|
|
1280 *width = rect.width;
|
|
1281 if (height)
|
|
1282 *height = rect.height;
|
|
1283
|
|
1284 if (ascent || descent) {
|
|
1285 PangoLayoutIter *iter;
|
|
1286 PangoLayoutLine *line;
|
|
1287
|
|
1288 iter = pango_layout_get_iter(layout);
|
|
1289 line = pango_layout_iter_get_line(iter);
|
|
1290 pango_layout_iter_free(iter);
|
|
1291
|
|
1292 pango_layout_line_get_pixel_extents(line, NULL, &rect);
|
|
1293
|
|
1294 if (ascent)
|
|
1295 *ascent = PANGO_ASCENT(rect);
|
|
1296 if (descent)
|
|
1297 *descent = -PANGO_DESCENT(rect);
|
|
1298 }
|
|
1299
|
|
1300 g_object_unref(layout);
|
|
1301
|
|
1302 return TRUE;
|
|
1303 }
|
|
1304
|
|
1305 /* counts number of digits in a gint */
|
|
1306 guint
|
|
1307 gint_count_digits(gint n)
|
|
1308 {
|
|
1309 guint count = 0;
|
|
1310
|
|
1311 n = ABS(n);
|
|
1312 do {
|
|
1313 count++;
|
|
1314 n /= 10;
|
|
1315 } while (n > 0);
|
|
1316
|
|
1317 return count;
|
|
1318 }
|
|
1319
|
|
1320 gboolean
|
|
1321 dir_foreach(const gchar * path, DirForeachFunc function,
|
|
1322 gpointer user_data, GError ** error)
|
|
1323 {
|
|
1324 GError *error_out = NULL;
|
|
1325 GDir *dir;
|
|
1326 const gchar *entry;
|
|
1327 gchar *entry_fullpath;
|
|
1328
|
|
1329 if (!(dir = g_dir_open(path, 0, &error_out))) {
|
|
1330 g_propagate_error(error, error_out);
|
|
1331 return FALSE;
|
|
1332 }
|
|
1333
|
|
1334 while ((entry = g_dir_read_name(dir))) {
|
|
1335 entry_fullpath = g_build_filename(path, entry, NULL);
|
|
1336
|
|
1337 if ((*function) (entry_fullpath, entry, user_data)) {
|
|
1338 g_free(entry_fullpath);
|
|
1339 break;
|
|
1340 }
|
|
1341
|
|
1342 g_free(entry_fullpath);
|
|
1343 }
|
|
1344
|
|
1345 g_dir_close(dir);
|
|
1346
|
|
1347 return TRUE;
|
|
1348 }
|
|
1349
|
|
1350 GtkWidget *
|
|
1351 make_filebrowser(const gchar * title,
|
|
1352 gboolean save)
|
|
1353 {
|
|
1354 GtkWidget *dialog;
|
|
1355 GtkWidget *button;
|
|
1356 GtkWidget *button_close;
|
|
1357
|
|
1358 g_return_val_if_fail(title != NULL, NULL);
|
|
1359
|
|
1360 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
|
|
1361 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
|
|
1362 if (save)
|
|
1363 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog),
|
|
1364 GTK_FILE_CHOOSER_ACTION_SAVE);
|
|
1365
|
|
1366 if (!save)
|
|
1367 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
|
|
1368
|
|
1369 g_signal_connect(dialog, "destroy",
|
|
1370 G_CALLBACK(gtk_widget_destroyed), &dialog);
|
|
1371
|
|
1372 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
|
|
1373 GTK_RESPONSE_REJECT);
|
|
1374 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
|
|
1375 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT);
|
|
1376 g_signal_connect_swapped(button_close, "clicked",
|
|
1377 G_CALLBACK(gtk_widget_destroy), dialog);
|
|
1378
|
|
1379 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
|
|
1380 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
|
|
1381 GTK_RESPONSE_ACCEPT);
|
|
1382 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
|
|
1383 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
|
1384 gtk_window_set_default(GTK_WINDOW(dialog), button);
|
|
1385
|
|
1386 gtk_widget_show(dialog);
|
|
1387
|
|
1388 return dialog;
|
|
1389 }
|
|
1390
|
|
1391 /*
|
|
1392 * Resizes a GDK pixmap.
|
|
1393 */
|
|
1394 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height)
|
|
1395 {
|
|
1396 GdkPixmap *out;
|
|
1397 gint owidth, oheight;
|
|
1398
|
|
1399 g_return_val_if_fail(src != NULL, NULL);
|
|
1400 g_return_val_if_fail(src_gc != NULL, NULL);
|
|
1401 g_return_val_if_fail(in != NULL, NULL);
|
|
1402 g_return_val_if_fail(width > 0 && height > 0, NULL);
|
|
1403
|
|
1404 gdk_drawable_get_size(in, &owidth, &oheight);
|
|
1405
|
|
1406 if (oheight == height && owidth == width)
|
|
1407 return NULL;
|
|
1408
|
|
1409 out = gdk_pixmap_new(src, width, height, -1);
|
|
1410
|
|
1411 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height);
|
|
1412
|
|
1413 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight);
|
|
1414 g_object_unref(src);
|
|
1415
|
|
1416 return out;
|
|
1417 }
|
|
1418
|
|
1419 GdkImage *create_dblsize_image(GdkImage * img)
|
|
1420 {
|
|
1421 GdkImage *dblimg;
|
|
1422 register guint x, y;
|
|
1423
|
|
1424 /*
|
|
1425 * This needs to be optimized
|
|
1426 */
|
|
1427
|
|
1428 dblimg =
|
|
1429 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(),
|
|
1430 img->width << 1, img->height << 1);
|
|
1431 if (dblimg->bpp == 1) {
|
|
1432 register guint8 *srcptr, *ptr, *ptr2, pix;
|
|
1433
|
|
1434 srcptr = GDK_IMAGE_XIMAGE(img)->data;
|
|
1435 ptr = GDK_IMAGE_XIMAGE(dblimg)->data;
|
|
1436 ptr2 = ptr + dblimg->bpl;
|
|
1437
|
|
1438 for (y = 0; y < img->height; y++) {
|
|
1439 for (x = 0; x < img->width; x++) {
|
|
1440 pix = *srcptr++;
|
|
1441 *ptr++ = pix;
|
|
1442 *ptr++ = pix;
|
|
1443 *ptr2++ = pix;
|
|
1444 *ptr2++ = pix;
|
|
1445 }
|
|
1446 srcptr += img->bpl - img->width;
|
|
1447 ptr += (dblimg->bpl << 1) - dblimg->width;
|
|
1448 ptr2 += (dblimg->bpl << 1) - dblimg->width;
|
|
1449 }
|
|
1450 }
|
|
1451 if (dblimg->bpp == 2) {
|
|
1452 guint16 *srcptr, *ptr, *ptr2, pix;
|
|
1453
|
|
1454 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data;
|
|
1455 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data;
|
|
1456 ptr2 = ptr + (dblimg->bpl >> 1);
|
|
1457
|
|
1458 for (y = 0; y < img->height; y++) {
|
|
1459 for (x = 0; x < img->width; x++) {
|
|
1460 pix = *srcptr++;
|
|
1461 *ptr++ = pix;
|
|
1462 *ptr++ = pix;
|
|
1463 *ptr2++ = pix;
|
|
1464 *ptr2++ = pix;
|
|
1465 }
|
|
1466 srcptr += (img->bpl >> 1) - img->width;
|
|
1467 ptr += (dblimg->bpl) - dblimg->width;
|
|
1468 ptr2 += (dblimg->bpl) - dblimg->width;
|
|
1469 }
|
|
1470 }
|
|
1471 if (dblimg->bpp == 3) {
|
|
1472 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3;
|
|
1473
|
|
1474 srcptr = GDK_IMAGE_XIMAGE(img)->data;
|
|
1475 ptr = GDK_IMAGE_XIMAGE(dblimg)->data;
|
|
1476 ptr2 = ptr + dblimg->bpl;
|
|
1477
|
|
1478 for (y = 0; y < img->height; y++) {
|
|
1479 for (x = 0; x < img->width; x++) {
|
|
1480 pix1 = *srcptr++;
|
|
1481 pix2 = *srcptr++;
|
|
1482 pix3 = *srcptr++;
|
|
1483 *ptr++ = pix1;
|
|
1484 *ptr++ = pix2;
|
|
1485 *ptr++ = pix3;
|
|
1486 *ptr++ = pix1;
|
|
1487 *ptr++ = pix2;
|
|
1488 *ptr++ = pix3;
|
|
1489 *ptr2++ = pix1;
|
|
1490 *ptr2++ = pix2;
|
|
1491 *ptr2++ = pix3;
|
|
1492 *ptr2++ = pix1;
|
|
1493 *ptr2++ = pix2;
|
|
1494 *ptr2++ = pix3;
|
|
1495
|
|
1496 }
|
|
1497 srcptr += img->bpl - (img->width * 3);
|
|
1498 ptr += (dblimg->bpl << 1) - (dblimg->width * 3);
|
|
1499 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3);
|
|
1500 }
|
|
1501 }
|
|
1502 if (dblimg->bpp == 4) {
|
|
1503 register guint32 *srcptr, *ptr, *ptr2, pix;
|
|
1504
|
|
1505 srcptr = (guint32 *) GDK_IMAGE_XIMAGE(img)->data;
|
|
1506 ptr = (guint32 *) GDK_IMAGE_XIMAGE(dblimg)->data;
|
|
1507 ptr2 = ptr + (dblimg->bpl >> 2);
|
|
1508
|
|
1509 for (y = 0; y < img->height; y++) {
|
|
1510 for (x = 0; x < img->width; x++) {
|
|
1511 pix = *srcptr++;
|
|
1512 *ptr++ = pix;
|
|
1513 *ptr++ = pix;
|
|
1514 *ptr2++ = pix;
|
|
1515 *ptr2++ = pix;
|
|
1516 }
|
|
1517 srcptr += (img->bpl >> 2) - img->width;
|
|
1518 ptr += (dblimg->bpl >> 1) - dblimg->width;
|
|
1519 ptr2 += (dblimg->bpl >> 1) - dblimg->width;
|
|
1520 }
|
|
1521 }
|
|
1522 return dblimg;
|
|
1523 }
|
|
1524
|
|
1525 /* URL-decode a file: URL path, return NULL if it's not what we expect */
|
|
1526 gchar *
|
|
1527 xmms_urldecode_path(const gchar * encoded_path)
|
|
1528 {
|
|
1529 const gchar *cur, *ext;
|
|
1530 gchar *path, *tmp;
|
|
1531 gint realchar;
|
|
1532
|
|
1533 if (!encoded_path)
|
|
1534 return NULL;
|
|
1535
|
|
1536 if (!str_has_prefix_nocase(encoded_path, "file:"))
|
|
1537 return NULL;
|
|
1538
|
|
1539 cur = encoded_path + 5;
|
|
1540
|
|
1541 if (str_has_prefix_nocase(cur, "//localhost"))
|
|
1542 cur += 11;
|
|
1543
|
|
1544 if (*cur == '/')
|
|
1545 while (cur[1] == '/')
|
|
1546 cur++;
|
|
1547
|
|
1548 tmp = g_malloc0(strlen(cur) + 1);
|
|
1549
|
|
1550 while ((ext = strchr(cur, '%')) != NULL) {
|
|
1551 strncat(tmp, cur, ext - cur);
|
|
1552 ext++;
|
|
1553 cur = ext + 2;
|
|
1554 if (!sscanf(ext, "%2x", &realchar)) {
|
|
1555 /* Assume it is a literal '%'. Several file
|
|
1556 * managers send unencoded file: urls on drag
|
|
1557 * and drop. */
|
|
1558 realchar = '%';
|
|
1559 cur -= 2;
|
|
1560 }
|
|
1561 tmp[strlen(tmp)] = realchar;
|
|
1562 }
|
|
1563
|
|
1564 path = g_strconcat(tmp, cur, NULL);
|
|
1565 g_free(tmp);
|
|
1566 return path;
|
|
1567 }
|
|
1568
|