annotate audacious/playlist.c @ 1942:4a1e5cb81524 trunk

[svn] - add keypad-enter binding for queueing files in jump-to-file. closes #295.
author nenolod
date Sun, 05 Nov 2006 13:29:22 -0800
parents 1a801187f510
children f027afc2ca2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP (C) GPL 2003 $top_src_dir/AUTHORS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * based on:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * XMMS - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * Thomas Nilsson and 4Front Technologies
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * Copyright (C) 1999-2003 Haavard Kvaalen
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1430
diff changeset
23 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include "playlist.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <glib/gprintf.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include <time.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #include <sys/errno.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 #include "input.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 #include "main.h"
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
45 #include "mainwin.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 #include "libaudacious/util.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #include "libaudacious/configdb.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 #include "libaudacious/vfs.h"
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
49 #include "equalizer.h"
538
e4e897d20791 [svn] remove libaudcore, we never did anything with it
nenolod
parents: 418
diff changeset
50 #include "playback.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 #include "playlist.h"
1550
be50c53aee09 [svn] - some minimal integration
nenolod
parents: 1541
diff changeset
52 #include "playlist_container.h"
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
53 #include "ui_playlist.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 #include "urldecode.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 #include "util.h"
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
56 #include "ui_fileinfo.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 #include "debug.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
60 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 typedef void (*PlaylistSaveFunc) (FILE * file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 PlaylistEntry *playlist_position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 G_LOCK_DEFINE(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 static GList *playlist = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 static GList *shuffle_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static GList *queued_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
70 /* If this is set to TRUE, we do not probe upon playlist add.
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
71 *
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
72 * Under Audacious 0.1.x, this was not a big deal because we used
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
73 * file extension introspection instead of looking for file format magic
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
74 * strings.
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
75 *
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
76 * Because we use file magic strings, we have to fstat a file being added
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
77 * to a playlist up to 1 * <number of input plugins installed> times.
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
78 *
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
79 * This can get really slow now that we're looking for files to add to a
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
80 * playlist. (Up to 5 minutes for 5000 songs, etcetera.)
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
81 *
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
82 * So, we obviously don't want to probe while opening a large playlist
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
83 * up. Hince the boolean below.
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
84 *
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
85 * January 7, 2006, William Pitcock <nenolod@nenolod.net>
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
86 */
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
87 static gboolean loading_playlist = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 G_LOCK_DEFINE(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 static gchar *playlist_current_name = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 static gboolean playlist_get_info_scan_active = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 static gboolean playlist_get_info_going = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 static GThread *playlist_get_info_thread;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 static gint path_compare(const gchar * a, const gchar * b);
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
99 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
100 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
101 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
102 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b);
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
103 static time_t playlist_get_mtime(const gchar *filename);
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
104 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b);
1415
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
105 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b);
1430
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
106 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b);
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
107
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
108 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
109 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
110 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b);
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
111
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 static PlaylistCompareFunc playlist_compare_func_table[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 playlist_compare_path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 playlist_compare_filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 playlist_compare_title,
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
116 playlist_compare_artist,
1415
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
117 playlist_compare_date,
1430
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
118 playlist_compare_track,
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
119 playlist_compare_playlist
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 static guint playlist_load_ins(const gchar * filename, gint pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 static void playlist_generate_shuffle_list(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 static void playlist_generate_shuffle_list_nolock(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 static void playlist_recalc_total_time_nolock(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 static void playlist_recalc_total_time(void);
1825
8b71a2b0577b [svn] - results from more profiling
nenolod
parents: 1824
diff changeset
129 static gboolean playlist_entry_get_info(PlaylistEntry * entry);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 PlaylistEntry *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 playlist_entry_new(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 const gchar * title,
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
134 const gint length,
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
135 InputPlugin * dec)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 entry = g_new0(PlaylistEntry, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 entry->filename = g_strdup(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 entry->title = str_to_utf8(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 entry->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 entry->selected = FALSE;
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
144 entry->decoder = dec;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
1825
8b71a2b0577b [svn] - results from more profiling
nenolod
parents: 1824
diff changeset
146 /* only do this if we have a decoder, otherwise it just takes too long */
1824
2a5621bfc610 [svn] - more mtime = 0 checks
nenolod
parents: 1823
diff changeset
147 if (entry->decoder)
1825
8b71a2b0577b [svn] - results from more profiling
nenolod
parents: 1824
diff changeset
148 playlist_entry_get_info(entry);
1824
2a5621bfc610 [svn] - more mtime = 0 checks
nenolod
parents: 1823
diff changeset
149
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 return entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 playlist_entry_free(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 if (!entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
159 if (entry->tuple != NULL) {
1232
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
160 bmp_title_input_free(entry->tuple);
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
161 entry->tuple = NULL;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
162 }
1232
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
163
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
164 if (entry->filename != NULL)
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
165 g_free(entry->filename);
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
166
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
167 if (entry->title != NULL)
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
168 g_free(entry->title);
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
169
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 g_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 playlist_entry_get_info(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 {
1232
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
176 TitleInput *tuple;
1711
c7c1e346bb55 [svn] - no more busy loop if a file in playlist disappears.
yaz
parents: 1706
diff changeset
177 time_t modtime;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 g_return_val_if_fail(entry != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
181 if (entry->tuple == NULL || entry->tuple->mtime > 0 || entry->tuple->mtime == -1)
1824
2a5621bfc610 [svn] - more mtime = 0 checks
nenolod
parents: 1823
diff changeset
182 modtime = playlist_get_mtime(entry->filename);
2a5621bfc610 [svn] - more mtime = 0 checks
nenolod
parents: 1823
diff changeset
183 else
2a5621bfc610 [svn] - more mtime = 0 checks
nenolod
parents: 1823
diff changeset
184 modtime = 0; /* URI -nenolod */
1711
c7c1e346bb55 [svn] - no more busy loop if a file in playlist disappears.
yaz
parents: 1706
diff changeset
185
1690
bb1323938306 [svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents: 1653
diff changeset
186 if (entry->decoder == NULL)
bb1323938306 [svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents: 1653
diff changeset
187 entry->decoder = input_check_file(entry->filename, FALSE);
bb1323938306 [svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents: 1653
diff changeset
188
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
189 /* renew tuple if file mtime is newer than tuple mtime. */
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
190 if(entry->tuple){
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
191 if(entry->tuple->mtime == modtime)
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
192 return TRUE;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
193 else {
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
194 bmp_title_input_free(entry->tuple);
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
195 entry->tuple = NULL;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
196 }
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
197 }
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
198
1232
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
199 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL)
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
200 tuple = input_get_song_tuple(entry->filename);
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
201 else
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
202 tuple = entry->decoder->get_song_tuple(entry->filename);
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
203
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
204 if (tuple == NULL)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
207 /* attach mtime */
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
208 tuple->mtime = modtime;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
209
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 /* entry is still around */
1356
e6cf73d27ea4 [svn] - hookup tuple->formatter
nenolod
parents: 1351
diff changeset
211 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple);
1232
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
212 entry->length = tuple->length;
56b57ed0a136 [svn] - use tuples internally
nenolod
parents: 1165
diff changeset
213 entry->tuple = tuple;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 playlist_get_current_name(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 return playlist_current_name;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 playlist_set_current_name(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 g_free(playlist_current_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 if (!filename) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 playlist_current_name = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 playlist_current_name = g_strdup(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 find_playlist_position_list(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 return shuffle_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 return playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 return g_list_find(shuffle_list, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 return g_list_find(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 play_queued(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 GList *tmp = queued_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 playlist_position = queued_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 queued_list = g_list_remove_link(queued_list, queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 playlist_clear(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 {
905
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
271 if (bmp_playback_get_playing()) {
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
272 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 bmp_playback_stop();
905
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
274 ip_data.stop = FALSE;
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
275 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 if (playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 g_list_foreach(playlist, (GFunc) playlist_entry_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 g_list_free(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 playlist = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 playlist_delete_node(GList * node, gboolean * set_info_text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 gboolean * restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 GList *playing_song = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 /* We call g_list_find manually here because we don't want an item
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 * in the shuffle_list */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 if (playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 playing_song = g_list_find(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 if (playing_song == node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 *set_info_text = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 PLAYLIST_UNLOCK();
905
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
316 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 bmp_playback_stop();
905
e5727eb096a6 [svn] - more output-stopping fun!
nhjm449
parents: 904
diff changeset
318 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 *restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 playing_song = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 if (g_list_next(playing_song))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 playlist_position = g_list_next(playing_song)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 else if (g_list_previous(playing_song))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 playlist_position = g_list_previous(playing_song)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 /* Make sure the entry did not disappear under us */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 else if (g_list_position(playlist, playing_song) >
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 g_list_position(playlist, node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 *set_info_text = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 shuffle_list = g_list_remove(shuffle_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 playlist = g_list_remove_link(playlist, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 playlist_entry_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 g_list_free_1(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 playlist_recalc_total_time_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 playlist_delete_index(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 gboolean restart_playing = FALSE, set_info_text = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 else if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 playlist_delete_filenames(GList * filenames)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 GList *node, *fnode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 gboolean set_info_text = FALSE, restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 node = playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 while (node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 GList *next = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 if (!strcmp(entry->filename, fnode->data))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 node = next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 else if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 playlist_delete(gboolean crop)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 gboolean restart_playing = FALSE, set_info_text = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 GList *node, *next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 node = playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 while (node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 next_node = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 if ((entry->selected && !crop) || (!entry->selected && crop)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 node = next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 __playlist_ins_with_info(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 const gchar * title,
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
478 gint len,
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
479 InputPlugin * dec)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 g_return_if_fail(filename != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 playlist = g_list_insert(playlist,
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
485 playlist_entry_new(filename, title, len, dec),
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 playlist_get_info_scan_active = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 static void
1584
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
493 __playlist_ins_with_info_tuple(const gchar * filename,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
494 gint pos,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
495 TitleInput *tuple,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
496 InputPlugin * dec)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
497 {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
498 GList *node;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
499 PlaylistEntry *entry;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
500
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
501 g_return_if_fail(filename != NULL);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
502
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
503 PLAYLIST_LOCK();
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
504 playlist = g_list_insert(playlist,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
505 playlist_entry_new(filename, tuple->track_name, tuple->length, dec),
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
506 pos);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
507
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
508 if(pos < 0 ) {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
509 pos = g_list_length(playlist) - 1; /* last element. */
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
510 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
511
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
512 node = g_list_nth(playlist, pos);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
513 entry = PLAYLIST_ENTRY(node->data);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
514
1587
c073fd82ded6 [svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents: 1584
diff changeset
515 if (tuple != NULL) {
c073fd82ded6 [svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents: 1584
diff changeset
516 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple);
c073fd82ded6 [svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents: 1584
diff changeset
517 entry->length = tuple->length;
c073fd82ded6 [svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents: 1584
diff changeset
518 entry->tuple = tuple;
c073fd82ded6 [svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents: 1584
diff changeset
519 }
1584
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
520
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
521 PLAYLIST_UNLOCK();
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
522
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
523 playlist_get_info_scan_active = TRUE;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
524 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
525
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
526 static void
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
527 __playlist_ins(const gchar * filename, gint pos, InputPlugin *dec)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 {
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
529 __playlist_ins_with_info(filename, pos, NULL, -1, dec);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 playlist_ins(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 gchar buf[64], *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 gint r;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 VFSFile *file;
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
539 InputPlugin *dec;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 if (is_playlist_name(filename)) {
1607
57676c0f2f33 [svn] - prevents input_check_file() working on loading playlist.
yaz
parents: 1588
diff changeset
542 loading_playlist = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 playlist_load_ins(filename, pos);
1607
57676c0f2f33 [svn] - prevents input_check_file() working on loading playlist.
yaz
parents: 1588
diff changeset
544 loading_playlist = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547
1165
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
548 if (loading_playlist == TRUE || cfg.playlist_detect == TRUE)
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
549 dec = NULL;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
550 else
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
551 dec = input_check_file(filename, TRUE);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
552
1165
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
553 if (cfg.playlist_detect == TRUE || loading_playlist == TRUE || (loading_playlist == FALSE && dec != NULL))
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
554 {
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
555 __playlist_ins(filename, pos, dec);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
556 playlist_generate_shuffle_list();
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
557 playlistwin_update_list();
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 /* Some files (typically produced by some cgi-scripts) don't have
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 * the correct extension. Try to recognize these files by looking
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 * at their content. We only check for http entries since it does
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 * not make sense to have file entries in a playlist fetched from
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 * the net. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 /* Some strange people put fifo's with the .mp3 extension, so we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 * need to make sure it's a real file (otherwise fread() may block
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 * and stall the entire program) */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 /* FIXME: bah, FIFOs actually pass this regular file test */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 if (!(file = vfs_fopen(filename, "rb")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 r = vfs_fread(buf, 1, sizeof(buf), file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 vfs_fclose(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 if (r > 5 && str_has_prefix_nocase(p, "http:")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 playlist_load_ins(filename, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 /* FIXME: The next few functions are specific to Unix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592 * filesystems. Either abstract it away, or don't even bother checking
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 * at such low level */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 dev_t dev;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 ino_t ino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 } DeviceInode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 static DeviceInode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 devino_new(dev_t device,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 ino_t inode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 DeviceInode *devino = g_new0(DeviceInode, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 if (devino)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 devino->dev = device;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 devino->ino = inode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 return devino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616 devino_hash(gconstpointer key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 const DeviceInode *d = key;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619 return d->ino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 devino_compare(gconstpointer a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 gconstpointer b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 const DeviceInode *da = a, *db = b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 return (da->dev == db->dev && da->ino == db->ino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 devino_destroy(gpointer key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 gpointer value,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635 g_free(key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 file_is_hidden(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 // FIXME: remove the const cast
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 return (g_basename((gchar *) filename)[0] == '.');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 playlist_dir_find_files(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 gboolean background,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 GHashTable * htab)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 GDir *dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 GList *list = NULL, *ilist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 const gchar *dir_entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 struct stat statbuf;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 DeviceInode *devino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 if (!g_file_test(path, G_FILE_TEST_IS_DIR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 stat(path, &statbuf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 devino = devino_new(statbuf.st_dev, statbuf.st_ino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665 if (g_hash_table_lookup(htab, devino)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 g_free(devino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 if ((ilist = input_scan_dir(path))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 for (node = ilist; node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 gchar *name = g_build_filename(path, node->data, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676 list = g_list_prepend(list, name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 g_list_free(ilist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 if (!(dir = g_dir_open(path, 0, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686 while ((dir_entry = g_dir_read_name(dir))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 if (file_is_hidden(dir_entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 filename = g_build_filename(path, dir_entry, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 GList *sub;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696 sub = playlist_dir_find_files(filename, background, htab);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
697 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
698 list = g_list_concat(list, sub);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 }
1165
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
700 else if (cfg.playlist_detect == TRUE)
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
701 list = g_list_prepend(list, filename);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702 else if (input_check_file(filename, TRUE))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703 list = g_list_prepend(list, filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 while (background && gtk_events_pending())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 gtk_main_iteration();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 g_dir_close(dir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 playlist_add(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 return playlist_ins(filename, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722 playlist_add_dir(const gchar * directory)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 return playlist_ins_dir(directory, -1, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
727 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 playlist_add_url(const gchar * url)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 return playlist_ins_url(url, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 playlist_ins_dir(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 gboolean background)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
738 guint entries = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
739 GList *list, *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
740 GHashTable *htab;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
741
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742 htab = g_hash_table_new(devino_hash, devino_compare);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744 list = playlist_dir_find_files(path, background, htab);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 list = g_list_sort(list, (GCompareFunc) path_compare);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
746
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
747 g_hash_table_foreach_remove(htab, devino_destroy, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 for (node = list; node; node = g_list_next(node)) {
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
750 __playlist_ins(node->data, pos, NULL);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 entries++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754 pos++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757 g_list_free(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762 return entries;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
763 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
764
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
765 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
766 playlist_ins_url(const gchar * string,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
767 gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
768 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
769 gchar *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
770 gint i = 1, entries = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
771 gboolean first = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
772 guint firstpos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
773 gboolean success = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
774 gchar *decoded = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
775
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
776 g_return_val_if_fail(string != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
777
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
778 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
779
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
780 while (*string) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
781 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
782 tmp = strchr(string, '\n');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
783 if (tmp) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
784 if (*(tmp - 1) == '\r')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
785 *(tmp - 1) = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
786 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
787 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
788
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
789 if (!(decoded = xmms_urldecode_path(string)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
790 decoded = g_strdup(string);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
791
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
792 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
793 i = playlist_ins_dir(decoded, pos, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
794 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
795 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
796 if (is_playlist_name(decoded)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
797 i = playlist_load_ins(decoded, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
798 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
799 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
800 success = playlist_ins(decoded, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
801 i = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
802 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
803 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
804
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
805 g_free(decoded);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
806
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
807 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
808 node = g_list_nth(playlist_get(), pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
809 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
810
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
811 entries += i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
812
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
813 if (first) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
814 first = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
815 firstpos = pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
816 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
817
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
818 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
819 pos += i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
820 if (!tmp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
821 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
822
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
823 string = tmp + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
824 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
825
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
826 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
827 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
828 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
829
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
830 return entries;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
831 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
832
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
833 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
834 playlist_set_info(const gchar * title, gint length, gint rate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
835 gint freq, gint nch)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
836 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
837 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
838
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
839 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
840 g_free(playlist_position->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
841 playlist_position->title = g_strdup(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
842 playlist_position->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
843 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
844
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
845 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
846
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
847 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
848
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
849 mainwin_set_song_info(rate, freq, nch);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
850 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
851
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
852 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
853 playlist_check_pos_current(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
854 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
855 gint pos, row, bottom;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
856
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
857 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
858 if (!playlist || !playlist_position || !playlistwin_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
859 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
860 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
861 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
862
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
863 pos = g_list_index(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
864
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
865 if (playlistwin_item_visible(pos)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
866 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
867 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
868 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
869
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
870 bottom = MAX(0, playlist_get_length_nolock() -
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
871 playlistwin_list->pl_num_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
872 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
873 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
874 playlistwin_set_toprow(row);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
875 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
876
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
877 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
878 playlist_next(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
879 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
880 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
881 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
882
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
883 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
884 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
885 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
886 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
887 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
888
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
889 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
890
1026
1a73946ddfbd [svn] - Queue fix from ircubic (bug #490)
nhjm449
parents: 984
diff changeset
891 if (!cfg.repeat && !g_list_next(plist_pos_list) && !queued_list) {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
892 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
893 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
894 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
895
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
896 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
897 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
898 PLAYLIST_UNLOCK();
895
1b919783797e [svn] - should fix the ability to change songs while paused
nhjm449
parents: 853
diff changeset
899 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
900 bmp_playback_stop();
895
1b919783797e [svn] - should fix the ability to change songs while paused
nhjm449
parents: 853
diff changeset
901 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
902 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
903 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
904 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
905
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
906 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
907 if (queued_list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
908 play_queued();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
909 else if (g_list_next(plist_pos_list))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
910 playlist_position = g_list_next(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
911 else if (cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
912 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
913 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
914 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
915 playlist_position = shuffle_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
916 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
917 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
918 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
919 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
920 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
921
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
922 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
923 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
924 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
925 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
926 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
927 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
928 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
929
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
930 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
931 playlist_prev(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
932 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
933 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
934 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
935
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
936 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
937 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
938 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
939 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
940 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
941
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
942 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
943
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
944 if (!cfg.repeat && !g_list_previous(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
945 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
946 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
947 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
948
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
949 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
950 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
951 PLAYLIST_UNLOCK();
895
1b919783797e [svn] - should fix the ability to change songs while paused
nhjm449
parents: 853
diff changeset
952 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
953 bmp_playback_stop();
895
1b919783797e [svn] - should fix the ability to change songs while paused
nhjm449
parents: 853
diff changeset
954 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
955 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
956 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
957 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
958
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
959 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
960 if (g_list_previous(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
961 playlist_position = g_list_previous(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
962 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
963 else if (cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
964 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
965 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
966 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
967 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
968 node = g_list_last(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
969 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
970 node = g_list_last(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
971 if (node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
972 playlist_position = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
973 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
974
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
975 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
976
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
977 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
978
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
979 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
980 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
981 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
982 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
983 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
984 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
985 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
986
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
987 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
988 playlist_queue(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
989 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
990 GList *list = playlist_get_selected();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
991 GList *it = list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
992
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
993 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
994
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
995 while (it) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
996 GList *next = g_list_next(it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
997 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
998
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
999 it->data = g_list_nth_data(playlist, GPOINTER_TO_INT(it->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1000 if ((tmp = g_list_find(queued_list, it->data))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1001 queued_list = g_list_remove_link(queued_list, tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1002 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1003 list = g_list_remove_link(list, it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1004 g_list_free_1(it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1005 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1006
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1007 it = next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1008 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1009
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1010 queued_list = g_list_concat(queued_list, list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1011
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1012 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1013
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1014 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1015 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1016 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1017
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1018 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1019 playlist_queue_position(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1020 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1021 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1022 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1023
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1024 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1025 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1026 if ((tmp = g_list_find(queued_list, entry))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1027 queued_list = g_list_remove_link(queued_list, tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1028 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1029 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1030 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1031 queued_list = g_list_append(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1032 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1033
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1034 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1035 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1036 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1037
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1038 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1039 playlist_is_position_queued(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1040 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1041 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1042 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1043
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1044 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1045 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1046 tmp = g_list_find(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1047 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1048
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1049 return tmp != NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1050 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1051
984
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1052 gint
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1053 playlist_get_queue_position_number(guint pos)
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1054 {
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1055 PlaylistEntry *entry;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1056 gint tmp;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1057
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1058 PLAYLIST_LOCK();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1059 entry = g_list_nth_data(playlist, pos);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1060 tmp = g_list_index(queued_list, entry);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1061 PLAYLIST_UNLOCK();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1062
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1063 return tmp;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1064 }
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1065
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1066 gint
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1067 playlist_get_queue_qposition_number(guint pos)
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1068 {
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1069 PlaylistEntry *entry;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1070 gint tmp;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1071
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1072 PLAYLIST_LOCK();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1073 entry = g_list_nth_data(queued_list, pos);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1074 tmp = g_list_index(playlist, entry);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1075 PLAYLIST_UNLOCK();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1076
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1077 return tmp;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1078 }
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 944
diff changeset
1079
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1080 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1081 playlist_clear_queue(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1082 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1083 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1084 g_list_free(queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1085 queued_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1086 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1087
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1088 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1089 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1090 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1091
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1092 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1093 playlist_queue_remove(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1094 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1095 void *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1096
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1097 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1098 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1099 queued_list = g_list_remove(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1100 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1102 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1103 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1105 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1106 playlist_get_queue_position(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1107 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1108 return g_list_index(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1109 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1111 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1112 playlist_set_position(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1113 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1114 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1115 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1117 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1118 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1119 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1120 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1123 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1124 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1125 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1126 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1127 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1129 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1130 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1131 PLAYLIST_UNLOCK();
923
ddadd6828a1a [svn] - Fix playlist_set_position when paused
nhjm449
parents: 905
diff changeset
1132 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1133 bmp_playback_stop();
923
ddadd6828a1a [svn] - Fix playlist_set_position when paused
nhjm449
parents: 905
diff changeset
1134 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1135 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1136 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1137 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1139 playlist_position = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1140 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1141 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1143 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1144 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1145 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1146 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1147 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1148 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1149
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1150 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1151 * Regenerate the shuffle list when the user set a position
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1152 * manually
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1153 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1154 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1155 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1158 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1159 playlist_eof_reached(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1161 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1162
904
2cb51ff37e8d [svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents: 898
diff changeset
1163 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong)
2cb51ff37e8d [svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents: 898
diff changeset
1164 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1165 bmp_playback_stop();
904
2cb51ff37e8d [svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents: 898
diff changeset
1166 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong)
2cb51ff37e8d [svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents: 898
diff changeset
1167 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1168
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1169 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1170 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1171
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1172 if (cfg.no_playlist_advance) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1173 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1174 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1175 if (cfg.repeat)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1176 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1177 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1178 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1179
898
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1180 if (cfg.stopaftersong) {
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1181 PLAYLIST_UNLOCK();
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1182 mainwin_clear_song_info();
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1183 mainwin_set_stopaftersong(FALSE);
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1184 return;
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1185 }
c800beaac0f9 [svn] - 'stop after current song' feature
nhjm449
parents: 895
diff changeset
1186
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1187 if (queued_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1188 play_queued();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1189 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1190 else if (!g_list_next(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1191 if (cfg.shuffle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1192 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1193 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1194 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1195 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1196 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1197
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1198 if (!cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1199 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1200 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1201 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1202 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1203 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1204 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1205 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1206 playlist_position = g_list_next(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1207
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1208 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1210 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1211 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1212 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1213 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1214 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1215
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1216 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1217 playlist_get_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1218 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1219 gint retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1220
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1221 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1222 retval = playlist_get_length_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1223 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1224
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1225 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1226 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1228 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1229 playlist_queue_get_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1230 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1231 gint length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1232
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1233 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1234 length = g_list_length(queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1235 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1236
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1237 return length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1238 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1239
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1240 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1241 playlist_get_length_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1242 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1243 return g_list_length(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1244 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1245
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1246 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1247 playlist_get_info_text(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1248 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1249 gchar *text, *title, *numbers, *length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1250
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1251 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1252 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1253 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1254 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1255 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1257 /* FIXME: there should not be a need to do additional conversion,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1258 * if playlist is properly maintained */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1259 if (playlist_position->title) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1260 title = str_to_utf8(playlist_position->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1261 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1262 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1263 gchar *basename = g_path_get_basename(playlist_position->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1264 title = filename_to_utf8(basename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1265 g_free(basename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1268 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1269 * If the user don't want numbers in the playlist, don't
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1270 * display them in other parts of XMMS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1271 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1273 if (cfg.show_numbers_in_pl)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1274 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock() + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1275 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1276 numbers = g_strdup("");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1278 if (playlist_position->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1279 length = g_strdup_printf(" (%d:%-2.2d)",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1280 playlist_position->length / 60000,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1281 (playlist_position->length / 1000) % 60);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1282 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1283 length = g_strdup("");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1284
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1285 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1287 text = convert_title_text(g_strconcat(numbers, title, length, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1288
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1289 g_free(numbers);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1290 g_free(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1291 g_free(length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1292
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1293 return text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1294 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1296 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1297 playlist_get_current_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1298 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1299 gint len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1300
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1301 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1302 if (playlist && playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1303 len = playlist_position->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1304 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1305
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1306 return len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1307 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1309 gboolean
1553
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1310 playlist_save(const gchar * filename)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1311 {
1553
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1312 PlaylistContainer *plc = NULL;
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1313 gchar *ext;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1314
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1315 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1316
1553
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1317 ext = strrchr(filename, '.') + 1;
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1318
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1319 playlist_set_current_name(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1320
1553
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1321 if ((plc = playlist_container_find(ext)) == NULL)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1322 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1323
1555
56536f498eb8 [svn] - sanity checking for saving
nenolod
parents: 1554
diff changeset
1324 if (plc->plc_write == NULL)
56536f498eb8 [svn] - sanity checking for saving
nenolod
parents: 1554
diff changeset
1325 return FALSE;
56536f498eb8 [svn] - sanity checking for saving
nenolod
parents: 1554
diff changeset
1326
1553
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1327 plc->plc_write(filename, 0);
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1328
f4ece39e4252 [svn] - saving now uses PlaylistContainer class.
nenolod
parents: 1550
diff changeset
1329 return TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1330 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1332 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1333 playlist_load(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1334 {
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1335 gboolean ret = FALSE;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1336
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1337 loading_playlist = TRUE;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1338 ret = playlist_load_ins(filename, -1);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1339 loading_playlist = FALSE;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1340
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1341 return ret;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1342 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1343
1554
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1344 void
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1345 playlist_load_ins_file(const gchar * filename_p,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1346 const gchar * playlist_name, gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1347 const gchar * title, gint len)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1348 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1349 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1350 gchar *tmp, *path;
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1351 InputPlugin *dec; /* for decoder cache */
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1352
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1353 g_return_if_fail(filename_p != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1354 g_return_if_fail(playlist_name != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1355
633
bf9bc9a514ba [svn] Use g_strchug instead of g_strstrip during playlist load. Trailing whitespace can be a valid occurance. Closes bug #282.
chainsaw
parents: 538
diff changeset
1356 filename = g_strchug(g_strdup(filename_p));
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1357
944
03d141f44b4d [svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents: 923
diff changeset
1358 while ((tmp = strchr(filename, '\\')) != NULL)
03d141f44b4d [svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents: 923
diff changeset
1359 *tmp = '/';
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1360
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1361 if (filename[0] != '/' && !strstr(filename, "://")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1362 path = g_strdup(playlist_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1363 if ((tmp = strrchr(path, '/')))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1364 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1365 else {
1163
ff71f891265b [svn] - Allow to do format detection on demand; instead of immediately on add
nenolod
parents: 1026
diff changeset
1366 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE)
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1367 dec = input_check_file(filename, FALSE);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1368 else
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1369 dec = NULL;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1370
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1371 __playlist_ins_with_info(filename, pos, title, len, dec);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1372 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1374 tmp = g_build_filename(path, filename, NULL);
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1375
1165
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
1376 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE)
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1377 dec = input_check_file(tmp, FALSE);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1378 else
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1379 dec = NULL;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1380
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1381 __playlist_ins_with_info(tmp, pos, title, len, dec);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1382 g_free(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1383 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1384 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1385 else
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1386 {
1165
6fe822f5a3c0 [svn] - make it work for real
nenolod
parents: 1163
diff changeset
1387 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE)
397
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1388 dec = input_check_file(filename, FALSE);
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1389 else
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1390 dec = NULL;
4fa1244ad483 [svn] Do not generate a cache when loading a playlist.
nenolod
parents: 383
diff changeset
1391
355
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1392 __playlist_ins_with_info(filename, pos, title, len, dec);
1c701dfe5098 [svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents: 284
diff changeset
1393 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1394
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1395 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1396 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1397
1584
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1398 void
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1399 playlist_load_ins_file_tuple(const gchar * filename_p,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1400 const gchar * playlist_name,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1401 gint pos,
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1402 TitleInput *tuple)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1403 {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1404 gchar *filename;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1405 gchar *tmp, *path;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1406 InputPlugin *dec; /* for decoder cache */
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1407
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1408 g_return_if_fail(filename_p != NULL);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1409 g_return_if_fail(playlist_name != NULL);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1410
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1411 filename = g_strchug(g_strdup(filename_p));
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1412
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1413 while ((tmp = strchr(filename, '\\')) != NULL)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1414 *tmp = '/';
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1415
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1416 if (filename[0] != '/' && !strstr(filename, "://")) {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1417 path = g_strdup(playlist_name);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1418 if ((tmp = strrchr(path, '/')))
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1419 *tmp = '\0';
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1420 else {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1421 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1422 dec = input_check_file(filename, FALSE);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1423 else
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1424 dec = NULL;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1425
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1426 __playlist_ins_with_info_tuple(filename, pos, tuple, dec);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1427 return;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1428 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1429 tmp = g_build_filename(path, filename, NULL);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1430
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1431 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1432 dec = input_check_file(tmp, FALSE);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1433 else
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1434 dec = NULL;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1435
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1436 __playlist_ins_with_info_tuple(tmp, pos, tuple, dec);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1437 g_free(tmp);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1438 g_free(path);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1439 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1440 else
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1441 {
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1442 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE)
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1443 dec = input_check_file(filename, FALSE);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1444 else
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1445 dec = NULL;
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1446
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1447 __playlist_ins_with_info_tuple(filename, pos, tuple, dec);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1448 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1449
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1450 g_free(filename);
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1451 }
2229b67f1b89 [svn] - xspf stores all meta data in tuples now.
yaz
parents: 1560
diff changeset
1452
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1453 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1454 playlist_load_ins(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1455 {
1554
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1456 PlaylistContainer *plc;
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1457 gchar *ext;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1458
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1459 g_return_val_if_fail(filename != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1460
1554
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1461 ext = strrchr(filename, '.') + 1;
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1462 plc = playlist_container_find(ext);
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1463
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1464 g_return_val_if_fail(plc != NULL, 0);
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1465 g_return_val_if_fail(plc->plc_read != NULL, 0);
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1466
1560
5840d797ea02 [svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents: 1559
diff changeset
1467 plc->plc_read(filename, pos);
5840d797ea02 [svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents: 1559
diff changeset
1468
1554
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1469 playlist_generate_shuffle_list();
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1470 playlistwin_update_list();
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1471
51c1bf500d3f [svn] - some experimental shit
nenolod
parents: 1553
diff changeset
1472 return 1;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1473 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1474
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1475 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1476 get_playlist_nth(guint nth)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1477 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1478 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1479 return g_list_nth(playlist, nth);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1480 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1481
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1482
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1483 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1484 playlist_get(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1485 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1486 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1487 return playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1488 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1489
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1490 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1491 playlist_get_position_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1492 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1493 if (playlist && playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1494 return g_list_index(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1495 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1496 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1497
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1498 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1499 playlist_get_position(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1500 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1501 gint pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1502
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1503 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1504 pos = playlist_get_position_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1505 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1506
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1507 return pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1508 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1509
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1510 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1511 playlist_get_filename(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1512 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1513 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1514 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1515 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1516
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1517 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1518 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1519 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1520 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1521 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1522 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1523 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1524 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1525 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1526 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1527 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1528
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1529 filename = g_strdup(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1530 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1531
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1532 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1533 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1534
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1535 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1536 playlist_get_songtitle(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1537 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1538 gchar *title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1539 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1540 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1541
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1542 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1543
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1544 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1545 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1546 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1547 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1548
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1549 if (!(node = g_list_nth(playlist, pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1550 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1551 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1552 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1553
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1554 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1555
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1556 /* FIXME: simplify this logic */
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1557 if ((entry->title == NULL && entry->length == -1) ||
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1558 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename))))
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1559 {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1560 if (playlist_entry_get_info(entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1561 title = entry->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1562 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1563 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1564 title = entry->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1565 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1566
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1567 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1568
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1569 if (!title) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1570 title = g_path_get_basename(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1571 return str_replace(title, filename_to_utf8(title));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1572 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1573
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1574 return str_to_utf8(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1575 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1576
1235
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1577 TitleInput *
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1578 playlist_get_tuple(guint pos)
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1579 {
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1580 PlaylistEntry *entry;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1581 TitleInput *tuple = NULL;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1582 GList *node;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1583
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1584 PLAYLIST_LOCK();
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1585
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1586 if (!playlist) {
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1587 PLAYLIST_UNLOCK();
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1588 return NULL;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1589 }
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1590
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1591 if (!(node = g_list_nth(playlist, pos))) {
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1592 PLAYLIST_UNLOCK();
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1593 return NULL;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1594 }
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1595
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1596 entry = (PlaylistEntry *) node->data;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1597
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1598 tuple = entry->tuple;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1599
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1600 // if no tuple or tuple with old mtime, get new one.
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1601 if (tuple == NULL ||
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1602 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename))))
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1603 {
1237
17630223d25b [svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents: 1235
diff changeset
1604 playlist_entry_get_info(entry);
17630223d25b [svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents: 1235
diff changeset
1605 tuple = entry->tuple;
17630223d25b [svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents: 1235
diff changeset
1606 }
17630223d25b [svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents: 1235
diff changeset
1607
1235
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1608 PLAYLIST_UNLOCK();
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1609
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1610 return tuple;
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1611 }
7918849bad3e [svn] - more sanity for input_get_song_tuple()
nenolod
parents: 1232
diff changeset
1612
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1613 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1614 playlist_get_songtime(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1615 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1616 gint song_time = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1617 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1618 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1619
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1620 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1621
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1622 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1623 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1624 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1625 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1626
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1627 if (!(node = g_list_nth(playlist, pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1628 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1629 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1630 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1631
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1632 entry = node->data;
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1633 if (entry->tuple == NULL ||
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
1634 (entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) {
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1635
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1636 if (playlist_entry_get_info(entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1637 song_time = entry->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1638
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1639 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1640 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1641 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1642 song_time = entry->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1643 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1644 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1645
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1646 return song_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1647 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1648
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1649 static gint
1415
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1650 playlist_compare_track(PlaylistEntry * a,
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1651 PlaylistEntry * b)
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1652 {
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1653 g_return_val_if_fail(a != NULL, 0);
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1654 g_return_val_if_fail(b != NULL, 0);
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1655
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1656 g_return_val_if_fail(a->tuple != NULL, 0);
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1657 g_return_val_if_fail(b->tuple != NULL, 0);
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1658
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1659 return (a->tuple->track_number - b->tuple->track_number);
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1660 }
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1661
01dcb223833a [svn] - sort by track number
nenolod
parents: 1357
diff changeset
1662 static gint
1430
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1663 playlist_compare_playlist(PlaylistEntry * a,
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1664 PlaylistEntry * b)
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1665 {
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1666 const gchar *a_title = NULL, *b_title = NULL;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1667
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1668 g_return_val_if_fail(a != NULL, 0);
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1669 g_return_val_if_fail(b != NULL, 0);
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1670
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1671 if (a->title != NULL)
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1672 a_title = a->title;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1673 else {
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1674 if (strrchr(a->filename, '/'))
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1675 a_title = strrchr(a->filename, '/') + 1;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1676 else
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1677 a_title = a->filename;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1678 }
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1679
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1680 if (b->title != NULL)
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1681 b_title = b->title;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1682 else {
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1683 if (strrchr(a->filename, '/'))
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1684 b_title = strrchr(b->filename, '/') + 1;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1685 else
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1686 b_title = b->filename;
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1687 }
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1688
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1689 return strcasecmp(a_title, b_title);
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1690 }
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1691
740c08db08d9 [svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents: 1415
diff changeset
1692 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1693 playlist_compare_title(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1694 PlaylistEntry * b)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1695 {
1250
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1696 const gchar *a_title = NULL, *b_title = NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1697
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1698 g_return_val_if_fail(a != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1699 g_return_val_if_fail(b != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1700
1250
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1701 if (a->tuple != NULL && a->tuple->track_name != NULL)
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1702 a_title = a->tuple->track_name;
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1703 if (b->tuple != NULL && b->tuple->track_name != NULL)
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1704 b_title = b->tuple->track_name;
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1705
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1706 if (a_title != NULL && b_title != NULL)
1250
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1707 return strcasecmp(a_title, b_title);
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1708
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1709 if (a->title != NULL)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1710 a_title = a->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1711 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1712 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1713 a_title = strrchr(a->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1714 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1715 a_title = a->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1716 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1717
1250
4c9cc4f67818 [svn] - use tuplecache to optimise title sorts
nenolod
parents: 1237
diff changeset
1718 if (b->title != NULL)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1719 b_title = b->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1720 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1721 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1722 b_title = strrchr(b->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1723 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1724 b_title = b->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1725 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1726
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1727 return strcasecmp(a_title, b_title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1728 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1729
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1730 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1731 playlist_compare_artist(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1732 PlaylistEntry * b)
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1733 {
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1734 const gchar *a_artist = NULL, *b_artist = NULL;
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1735
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1736 g_return_val_if_fail(a != NULL, 0);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1737 g_return_val_if_fail(b != NULL, 0);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1738
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1739 if (a->tuple != NULL)
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1740 playlist_entry_get_info(a);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1741
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1742 if (b->tuple != NULL)
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1743 playlist_entry_get_info(b);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1744
1253
665dfbf5e9a1 [svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents: 1251
diff changeset
1745 if (a->tuple != NULL && a->tuple->performer != NULL)
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1746 a_artist = a->tuple->performer;
1253
665dfbf5e9a1 [svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents: 1251
diff changeset
1747 if (b->tuple != NULL && b->tuple->performer != NULL)
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1748 b_artist = b->tuple->performer;
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1749
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1750 if (a_artist != NULL && b_artist != NULL)
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1751 return strcasecmp(a_artist, b_artist);
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1752
1253
665dfbf5e9a1 [svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents: 1251
diff changeset
1753 return 0;
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1754 }
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1755
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1756 static gint
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1757 playlist_compare_filename(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1758 PlaylistEntry * b)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1759 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1760 gchar *a_filename, *b_filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1761
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1762 g_return_val_if_fail(a != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1763 g_return_val_if_fail(b != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1764
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1765 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1766 a_filename = strrchr(a->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1767 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1768 a_filename = a->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1769
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1770 if (strrchr(b->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1771 b_filename = strrchr(b->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1772 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1773 b_filename = b->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1774
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1775
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1776 return strcasecmp(a_filename, b_filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1777 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1778
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1779 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1780 path_compare(const gchar * a, const gchar * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1781 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1782 gchar *posa, *posb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1783 gint len, ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1784
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1785 posa = strrchr(a, '/');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1786 posb = strrchr(b, '/');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1787
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1788 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1789 * Sort directories before files
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1790 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1791 if (posa && posb && (posa - a != posb - b)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1792 if (posa - a > posb - b) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1793 len = posb - b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1794 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1795 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1796 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1797 len = posa - a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1798 ret = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1799 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1800 if (!strncasecmp(a, b, len))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1801 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1802 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1803 return strcasecmp(a, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1804 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1805
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1806 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1807 playlist_compare_path(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1808 PlaylistEntry * b)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1809 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1810 return path_compare(a->filename, b->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1811 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1812
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1813
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1814 static time_t
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1815 playlist_get_mtime(const gchar *filename)
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1816 {
1706
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
1817 struct stat buf;
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1818 gint rv;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1819
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1820 rv = stat(filename, &buf);
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1821
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1822 if (rv == 0) {
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1823 return buf.st_mtime;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1824 } else {
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1825 return 0; //error
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1826 }
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1827 }
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1828
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
1829
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1830 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1831 playlist_compare_date(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
1832 PlaylistEntry * b)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1833 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1834 struct stat buf;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1835 time_t modtime;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1836
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1837 gint rv;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1838
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1839
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1840 rv = stat(a->filename, &buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1841
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1842 if (rv == 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1843 modtime = buf.st_mtime;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1844 rv = stat(b->filename, &buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1845
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1846 if (stat(b->filename, &buf) == 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1847 if (buf.st_mtime == modtime)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1848 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1849 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1850 return (buf.st_mtime - modtime) > 0 ? -1 : 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1851 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1852 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1853 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1854 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1855 else if (!lstat(b->filename, &buf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1856 return 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1857 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1858 return playlist_compare_filename(a, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1859 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1860
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1861
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1862 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1863 playlist_sort(PlaylistSortType type)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1864 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1865 playlist_remove_dead_files();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1866 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1867 playlist =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1868 g_list_sort(playlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1869 (GCompareFunc) playlist_compare_func_table[type]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1870 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1871 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1872
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1873 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1874 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1875 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1876 GList *list1, *list2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1877 GList *tmp_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1878 GList *index_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1879
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1880 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1881 * We take all the selected entries out of the playlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1882 * sorts them, and then put them back in again.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1883 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1884
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1885 list1 = g_list_last(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1886
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1887 while (list1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1888 list2 = g_list_previous(list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1889 if (PLAYLIST_ENTRY(list1->data)->selected) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1890 gpointer idx;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1891 idx = GINT_TO_POINTER(g_list_position(list, list1));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1892 index_list = g_list_prepend(index_list, idx);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1893 list = g_list_remove_link(list, list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1894 tmp_list = g_list_concat(list1, tmp_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1895 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1896 list1 = list2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1897 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1898
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1899 tmp_list = g_list_sort(tmp_list, cmpfunc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1900 list1 = tmp_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1901 list2 = index_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1902
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1903 while (list2) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1904 if (!list1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1905 g_critical(G_STRLOC ": Error during list sorting. "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1906 "Possibly dropped some playlist-entries.");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1907 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1908 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1909
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1910 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1911
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1912 list2 = g_list_next(list2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1913 list1 = g_list_next(list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1914 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1915
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1916 g_list_free(index_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1917 g_list_free(tmp_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1918
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1919 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1920 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1921
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1922 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1923 playlist_sort_selected(PlaylistSortType type)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1924 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1925 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1926 playlist = playlist_sort_selected_generic(playlist, (GCompareFunc)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1927 playlist_compare_func_table
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1928 [type]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1929 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1930 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1931
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1932 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1933 playlist_reverse(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1934 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1935 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1936 playlist = g_list_reverse(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1937 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1938 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1939
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1940 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1941 playlist_shuffle_list(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1942 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1943 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1944 * Note that this doesn't make a copy of the original list.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1945 * The pointer to the original list is not valid after this
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1946 * fuction is run.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1947 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1948 gint len = g_list_length(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1949 gint i, j;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1950 GList *node, **ptrs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1951
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1952 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1953
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1954 if (!len)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1955 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1956
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1957 ptrs = g_new(GList *, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1958
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1959 for (node = list, i = 0; i < len; node = g_list_next(node), i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1960 ptrs[i] = node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1961
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1962 j = g_random_int_range(0, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1963 list = ptrs[j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1964 ptrs[j]->next = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1965 ptrs[j] = ptrs[0];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1966
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1967 for (i = 1; i < len; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1968 j = g_random_int_range(0, len - i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1969 list->prev = ptrs[i + j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1970 ptrs[i + j]->next = list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1971 list = ptrs[i + j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1972 ptrs[i + j] = ptrs[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1973 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1974 list->prev = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1975
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1976 g_free(ptrs);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1977
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1978 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1979 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1980
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1981 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1982 playlist_random(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1983 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1984 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1985 playlist = playlist_shuffle_list(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1986 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1987 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1988
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1989 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1990 playlist_get_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1991 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1992 GList *node, *list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1993 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1994
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1995 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1996 for (node = playlist_get(); node; node = g_list_next(node), i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1997 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1998 if (entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1999 list = g_list_prepend(list, GINT_TO_POINTER(i));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2000 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2001 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2002 return g_list_reverse(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2003 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2004
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2005 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2006 playlist_clear_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2007 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2008 GList *node = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2009 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2010
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2011 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2012 for (node = playlist_get(); node; node = g_list_next(node), i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2013 PLAYLIST_ENTRY(node->data)->selected = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2014 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2015 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2016 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2017 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2018
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2019 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2020 playlist_get_num_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2021 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2022 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2023 gint num = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2024
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2025 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2026 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2027 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2028 if (entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2029 num++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2030 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2031 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2032 return num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2033 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2034
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2035
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2036 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2037 playlist_generate_shuffle_list(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2038 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2039 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2040 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2041 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2042 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2043
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2044 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2045 playlist_generate_shuffle_list_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2046 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2047 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2048 gint numsongs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2049
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2050 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2051
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2052 if (shuffle_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2053 g_list_free(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2054 shuffle_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2055 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2056
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2057 if (!cfg.shuffle || !playlist)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2058 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2059
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2060 shuffle_list = playlist_shuffle_list(g_list_copy(playlist));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2061 numsongs = g_list_length(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2062
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2063 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2064 gint i = g_list_index(shuffle_list, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2065 node = g_list_nth(shuffle_list, i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2066 shuffle_list = g_list_remove_link(shuffle_list, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2067 shuffle_list = g_list_prepend(shuffle_list, node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2068 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2069 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2070
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2071 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2072 playlist_fileinfo(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2073 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2074 gchar *path = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2075 GList *node;
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2076 PlaylistEntry *entry = NULL;
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2077 TitleInput *tuple = NULL;
1818
e3e31a084b09 [svn] - try not to reject tuples that have an mtime of 0. (special tuples referring to URIs)
nenolod
parents: 1817
diff changeset
2078 gint mtime;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2079
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2080 PLAYLIST_LOCK();
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2081
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2082 if ((node = g_list_nth(playlist_get(), pos)))
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2083 {
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2084 entry = node->data;
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2085 tuple = entry->tuple;
1516
3483fb26b9fb [svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents: 1459
diff changeset
2086 path = g_strdup(entry->filename);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2087 }
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2088
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2089 PLAYLIST_UNLOCK();
1277
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2090
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2091 /* No tuple? Try to set this entry up properly. --nenolod */
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
2092 if (entry->tuple == NULL || entry->tuple->mtime == -1 ||
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
2093 entry->tuple->mtime == 0 || entry->tuple->mtime != playlist_get_mtime(entry->filename))
1277
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2094 {
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2095 playlist_entry_get_info(entry);
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2096 tuple = entry->tuple;
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2097 }
8c8d4841efae [svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents: 1270
diff changeset
2098
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2099 if (tuple != NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2100 {
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2101 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2102 fileinfo_show_for_tuple(tuple);
1270
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2103 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL)
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2104 entry->decoder->file_info_box(path);
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2105 else
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2106 fileinfo_show_for_path(path);
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2107 g_free(path);
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2108 }
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2109 else if (path != NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2110 {
1270
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2111 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL)
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2112 entry->decoder->file_info_box(path);
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2113 else
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2114 fileinfo_show_for_path(path);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2115 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2116 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2117 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2119 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2120 playlist_fileinfo_current(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2121 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2122 gchar *path = NULL;
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2123 TitleInput *tuple = NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2124
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2125 PLAYLIST_LOCK();
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2126
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2127 if (playlist_get() && playlist_position)
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2128 {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2129 path = g_strdup(playlist_position->filename);
1690
bb1323938306 [svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents: 1653
diff changeset
2130 if (( playlist_position->tuple == NULL ) || ( playlist_position->decoder == NULL ))
1516
3483fb26b9fb [svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents: 1459
diff changeset
2131 playlist_entry_get_info(playlist_position);
3483fb26b9fb [svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents: 1459
diff changeset
2132 tuple = playlist_position->tuple;
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2133 }
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2134
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2135 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2136
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2137 if (tuple != NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2138 {
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2139 if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box == NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2140 fileinfo_show_for_tuple(tuple);
1270
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2141 else if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL)
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2142 playlist_position->decoder->file_info_box(path);
1269
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2143 else
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2144 fileinfo_show_for_path(path);
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2145 g_free(path);
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2146 }
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2147 else if (path != NULL)
681b629322c4 [svn] - hook up fileinfo box stuff
nenolod
parents: 1253
diff changeset
2148 {
1270
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2149 if (playlist_position != NULL && playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL)
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2150 playlist_position->decoder->file_info_box(path);
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2151 else
feff5a622f06 [svn] - improvements
nenolod
parents: 1269
diff changeset
2152 fileinfo_show_for_path(path);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2153 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2154 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2155 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2156
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2158 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2159 playlist_get_info_is_going(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2161 gboolean result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2163 G_LOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2164 result = playlist_get_info_going;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2165 G_UNLOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2166
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2167 return result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2168 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2169
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2170 static gpointer
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2171 playlist_get_info_func(gpointer arg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2172 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2173 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2174 gboolean update_playlistwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2175 gboolean update_mainwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2176
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2177 while (playlist_get_info_is_going()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2178 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2179
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2180 if (cfg.use_pl_metadata &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2181 cfg.get_info_on_load &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2182 playlist_get_info_scan_active) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2184 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2185 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2186 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2187
1826
d66712838e9f [svn] - and finally special tuples are treated as they should be
nenolod
parents: 1825
diff changeset
2188 if(entry->tuple && (entry->tuple->length > -1)) {
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
2189 continue;
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
2190 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2191
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2192 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2193 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2194 /* Entry disappeared while we looked it up.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2195 Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2196 node = playlist_get();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2197 }
1834
cf41677e2d7c [svn] - better handle the stream condition
nenolod
parents: 1826
diff changeset
2198 else if (entry->tuple == NULL && entry->title != NULL && entry->length == -1) {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2199 update_playlistwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2200 if (entry == playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2201 update_mainwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2202 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2203 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2204 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2205 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2206
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2207 if (!node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2208 playlist_get_info_scan_active = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2209 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2210 else if (!cfg.get_info_on_load &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2211 cfg.get_info_on_demand &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2212 cfg.playlist_visible &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2213 !cfg.playlist_shaded &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2214 cfg.use_pl_metadata) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2215
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2216 gboolean found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2217
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2218 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2219
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2220 if (!playlist_get()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2221 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2222 g_usleep(1000000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2223 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2224 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2225
1706
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
2226 for (node = g_list_nth(playlist_get(), playlistwin_get_toprow());
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
2227 node && playlistwin_item_visible(g_list_position(playlist_get(), node));
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2228 node = g_list_next(node)) {
1706
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
2229
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2230 entry = node->data;
1706
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
2231
1826
d66712838e9f [svn] - and finally special tuples are treated as they should be
nenolod
parents: 1825
diff changeset
2232 if(entry->tuple && (entry->tuple->length > -1)) {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2233 continue;
1706
15e53bf1b389 [svn] - omit get_mtime from playlist_get_info_func().
yaz
parents: 1690
diff changeset
2234 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2235
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2236 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2237 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2238 /* Entry disapeared while we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2239 looked it up. Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2240 node =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2241 g_list_nth(playlist_get(),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2242 playlistwin_get_toprow());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2243 }
1834
cf41677e2d7c [svn] - better handle the stream condition
nenolod
parents: 1826
diff changeset
2244 else if (entry->tuple == NULL && entry->title != NULL && entry->length == -1) {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2245 update_playlistwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2246 if (entry == playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2247 update_mainwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2248 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2249 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2250 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2251 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2253 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2255 if (!found) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2256 g_usleep(500000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2257 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2258 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2259 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2260 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2261 g_usleep(500000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2263 if (update_playlistwin) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2264 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2265 update_playlistwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2268 if (update_mainwin) {
1826
d66712838e9f [svn] - and finally special tuples are treated as they should be
nenolod
parents: 1825
diff changeset
2269
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2270 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2271 update_mainwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2272 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2273 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2275 g_thread_exit(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2276 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2277 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2278
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2279 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2280 playlist_start_get_info_thread(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2281 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2282 playlist_get_info_going = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2283 playlist_get_info_thread = g_thread_create(playlist_get_info_func,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2284 NULL, TRUE, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2285 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2287 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2288 playlist_stop_get_info_thread(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2289 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2290 G_LOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2291 playlist_get_info_going = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2292 G_UNLOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2293 g_thread_join(playlist_get_info_thread);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2294 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2296 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2297 playlist_start_get_info_scan(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2298 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2299 playlist_get_info_scan_active = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2300 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2302 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2303 playlist_remove_dead_files(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2304 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2305 GList *node, *next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2307 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2309 for (node = playlist; node; node = next_node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2310 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2311 next_node = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2312
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2313 if (!entry || !entry->filename) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2314 g_message(G_STRLOC ": Playlist entry is invalid!");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2315 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2316 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2318 /* FIXME: What about 'file:///'? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2319 /* Don't kill URLs */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2320 if (strstr(entry->filename, "://"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2321 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2323 /* FIXME: Should test for readability */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2324 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2325 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2326
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2327 if (entry == playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2328 /* Don't remove the currently playing song */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2329 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2330 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2332 if (next_node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2333 playlist_position = PLAYLIST_ENTRY(next_node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2334 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2335 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2336 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2337
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2338 playlist_entry_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2339 playlist = g_list_delete_link(playlist, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2340 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2341
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2342 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2344 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2345 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2346 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2347 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2348
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2349
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2350 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2351 playlist_dupscmp_title(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2352 PlaylistEntry * b)
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2353 {
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2354 const gchar *a_title, *b_title;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2355
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2356 g_return_val_if_fail(a != NULL, 0);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2357 g_return_val_if_fail(b != NULL, 0);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2358
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2359 if (a->title)
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2360 a_title = a->title;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2361 else {
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2362 if (strrchr(a->filename, '/'))
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2363 a_title = strrchr(a->filename, '/') + 1;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2364 else
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2365 a_title = a->filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2366 }
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2367
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2368 if (b->title)
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2369 b_title = b->title;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2370 else {
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2371 if (strrchr(a->filename, '/'))
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2372 b_title = strrchr(b->filename, '/') + 1;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2373 else
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2374 b_title = b->filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2375 }
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2376
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2377 return strcmp(a_title, b_title);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2378 }
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2379
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2380 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2381 playlist_dupscmp_filename(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2382 PlaylistEntry * b )
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2383 {
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2384 gchar *a_filename, *b_filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2385
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2386 g_return_val_if_fail(a != NULL, 0);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2387 g_return_val_if_fail(b != NULL, 0);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2388
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2389 if (strrchr(a->filename, '/'))
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2390 a_filename = strrchr(a->filename, '/') + 1;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2391 else
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2392 a_filename = a->filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2393
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2394 if (strrchr(b->filename, '/'))
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2395 b_filename = strrchr(b->filename, '/') + 1;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2396 else
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2397 b_filename = b->filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2398
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2399 return strcmp(a_filename, b_filename);
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2400 }
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2401
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2402 static gint
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2403 playlist_dupscmp_path(PlaylistEntry * a,
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2404 PlaylistEntry * b)
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2405 {
853
74576869a506 [svn] shortened the compare-dups-by-path function
giacomo
parents: 852
diff changeset
2406 /* simply compare the entire filename string */
74576869a506 [svn] shortened the compare-dups-by-path function
giacomo
parents: 852
diff changeset
2407 return strcmp(a->filename, b->filename);
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2408 }
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2409
840
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2410 void
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2411 playlist_remove_duplicates( PlaylistDupsType type )
840
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2412 {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2413 GList *node, *next_node;
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2414 GList *node_cmp, *next_node_cmp;
1251
5f09d64c61e2 [svn] - sort by Artist
nenolod
parents: 1250
diff changeset
2415 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *);
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2416
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2417 switch ( type )
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2418 {
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2419 case PLAYLIST_DUPS_TITLE:
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2420 dups_compare_func = playlist_dupscmp_title;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2421 break;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2422 case PLAYLIST_DUPS_PATH:
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2423 dups_compare_func = playlist_dupscmp_path;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2424 break;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2425 case PLAYLIST_DUPS_FILENAME:
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2426 default:
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2427 dups_compare_func = playlist_dupscmp_filename;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2428 break;
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2429 }
840
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2430
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2431 PLAYLIST_LOCK();
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2432
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2433 for (node = playlist; node; node = next_node) {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2434 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2435 next_node = g_list_next(node);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2436
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2437 if (!entry || !entry->filename) {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2438 g_message(G_STRLOC ": Playlist entry is invalid!");
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2439 continue;
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2440 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2441
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2442 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2443 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2444 next_node_cmp = g_list_next(node_cmp);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2445
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2446 if (!entry_cmp || !entry_cmp->filename) {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2447 g_message(G_STRLOC ": Playlist entry is invalid!");
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2448 continue;
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2449 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2450
852
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2451 /* compare using the chosen dups_compare_func */
bcff46a2558d [svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents: 840
diff changeset
2452 if ( !dups_compare_func( entry , entry_cmp ) ) {
840
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2453
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2454 if (entry_cmp == playlist_position) {
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2455 /* Don't remove the currently playing song */
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2456 if (bmp_playback_get_playing())
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2457 continue;
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2458
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2459 if (next_node_cmp)
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2460 playlist_position = PLAYLIST_ENTRY(next_node_cmp->data);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2461 else
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2462 playlist_position = NULL;
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2463 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2464
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2465 /* check if this was the next item of the external
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2466 loop; if true, replace it with the next of the next*/
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2467 if ( node_cmp == next_node )
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2468 next_node = g_list_next(next_node);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2469
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2470 playlist_entry_free(entry_cmp);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2471 playlist = g_list_delete_link(playlist, node_cmp);
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2472 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2473 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2474 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2475
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2476 PLAYLIST_UNLOCK();
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2477
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2478 playlistwin_update_list();
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2479 playlist_recalc_total_time();
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2480 }
ffc5ab7b4b2c [svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents: 633
diff changeset
2481
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2482 static gulong pl_total_time = 0, pl_selection_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2483 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2484
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2485 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2486 playlist_get_total_time(gulong * total_time,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2487 gulong * selection_time,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2488 gboolean * total_more,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2489 gboolean * selection_more)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2490 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2491 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2492 *total_time = pl_total_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2493 *selection_time = pl_selection_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2494 *total_more = pl_total_more;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2495 *selection_more = pl_selection_more;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2496 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2497 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2498
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2499
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2500 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2501 playlist_recalc_total_time_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2502 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2503 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2504 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2505
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2506 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2507
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2508 pl_total_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2509 pl_selection_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2510 pl_total_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2511 pl_selection_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2512
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2513 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2514 entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2515
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2516 if (entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2517 pl_total_time += entry->length / 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2518 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2519 pl_total_more = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2520
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2521 if (entry->selected) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2522 if (entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2523 pl_selection_time += entry->length / 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2524 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2525 pl_selection_more = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2526 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2527 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2528 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2529
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2530 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2531 playlist_recalc_total_time(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2532 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2533 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2534 playlist_recalc_total_time_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2535 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2536 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2537
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2538
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2539 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2540 playlist_select_all(gboolean set)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2541 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2542 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2543
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2544 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2545
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2546 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2547 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2548 entry->selected = set;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2549 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2550
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2551 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2552 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2553 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2554
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2555 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2556 playlist_select_invert_all(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2557 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2558 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2559
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2560 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2561
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2562 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2563 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2564 entry->selected = !entry->selected;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2565 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2566
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2567 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2568 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2569 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2570
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2571 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2572 playlist_select_invert(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2573 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2574 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2575 gboolean invert_ok = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2576
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2577 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2578
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2579 if ((list = g_list_nth(playlist_get(), pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2580 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2581 entry->selected = !entry->selected;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2582 invert_ok = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2583 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2584
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2585 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2586 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2587
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2588 return invert_ok;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2589 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2590
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2591
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2592 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2593 playlist_select_range(gint min_pos, gint max_pos, gboolean select)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2594 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2595 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2596 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2597
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2598 if (min_pos > max_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2599 SWAP(min_pos, max_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2600
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2601 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2602
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2603 list = g_list_nth(playlist_get(), min_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2604 for (i = min_pos; i <= max_pos && list; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2605 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2606 entry->selected = select;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2607 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2608 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2609
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2610 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2611
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2612 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2613 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2614
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2615 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2616 playlist_read_info_selection(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2617 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2618 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2619 gboolean retval = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2620
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2621 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2622
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2623 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2624 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2625 if (!entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2626 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2627
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2628 retval = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2629
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2630 str_replace_in(&entry->title, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2631 entry->length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2632
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
2633 /* invalidate mtime to reread */
1817
0734a9808884 [svn] - make sure the PlaylistEntry has a tuple.
nenolod
parents: 1760
diff changeset
2634 if (entry->tuple != NULL)
1841
7d0cd3fab6a2 [svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents: 1834
diff changeset
2635 entry->tuple->mtime = -1; /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */
1588
15d92c51bde6 [svn] - modified time (mtime) has been introduced into tuple
yaz
parents: 1587
diff changeset
2636
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2637 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2638 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2639 /* Entry disappeared while we looked it up. Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2640 node = playlist_get();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2641 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2642 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2643
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2644 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2645
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2646 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2647 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2648
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2649 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2650 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2651
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2652 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2653 playlist_read_info(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2654 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2655 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2656
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2657 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2658
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2659 if ((node = g_list_nth(playlist_get(), pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2660 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2661 str_replace_in(&entry->title, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2662 entry->length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2663 playlist_entry_get_info(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2664 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2665
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2666 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2667
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2668 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2669 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2670 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2671
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2672 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2673 playlist_set_shuffle(gboolean shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2674 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2675 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2676
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2677 cfg.shuffle = shuffle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2678 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2679
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2680 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2681 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2682
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2683 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2684 playlist_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2685 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2686 playlist_set_current_name(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2687 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2688 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2689 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2690 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2691
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2692
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2693 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2694 playlist_get_filename_to_play(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2695 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2696 const gchar *filename = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2697
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2698 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2699
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2700 if (playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2701 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2702 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2703 playlist_position = shuffle_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2704 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2705 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2706 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2707
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2708 filename = playlist_position->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2709 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2710
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2711 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2712
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2713 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2714 }
356
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2715
398
f908bcd87c3d [svn] Generate cache content on demand if it was not previously there.
nenolod
parents: 397
diff changeset
2716 PlaylistEntry *
356
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2717 playlist_get_entry_to_play(void)
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2718 {
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2719 PLAYLIST_LOCK();
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2720
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2721 if (playlist) {
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2722 if (!playlist_position) {
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2723 if (cfg.shuffle)
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2724 playlist_position = shuffle_list->data;
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2725 else
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2726 playlist_position = playlist->data;
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2727 }
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2728 }
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2729
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2730 PLAYLIST_UNLOCK();
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2731
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2732 return playlist_position;
99928e1275a1 [svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents: 355
diff changeset
2733 }