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