annotate audacious/playlist.c @ 351:c6e9eb0ee70b trunk

[svn] filterchain stuff
author nenolod
date Mon, 26 Dec 2005 13:56:03 -0800
parents 763afa52f416
children 1c701dfe5098
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02111-1307, USA.
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"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 #include "mainwin.h"
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"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 #include "equalizer.h"
284
763afa52f416 [svn] Update header locations.
nenolod
parents: 0
diff changeset
50 #include "libaudcore/playback.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 #include "playlist.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 #include "playlistwin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #include "playlist_list.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 #include "skin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 #include "urldecode.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 #include "util.h"
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 typedef gint (*PlaylistCompareFunc) (const PlaylistEntry * a, const PlaylistEntry * b);
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 /* NOTE: match the order listed in PlaylistFormat enum */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 static const gchar *playlist_format_suffixes[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 ".m3u", ".pls", NULL
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 static GList *playlist = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 static GList *shuffle_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 static GList *queued_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 G_LOCK_DEFINE(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 static gchar *playlist_current_name = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 static gboolean playlist_get_info_scan_active = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 static gboolean playlist_get_info_going = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 static GThread *playlist_get_info_thread;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 static gint path_compare(const gchar * a, const gchar * b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 static gint playlist_compare_path(const PlaylistEntry * a, const PlaylistEntry * b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 static gint playlist_compare_filename(const PlaylistEntry * a, const PlaylistEntry * b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 static gint playlist_compare_title(const PlaylistEntry * a, const PlaylistEntry * b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 static gint playlist_compare_date(const PlaylistEntry * a, const PlaylistEntry * b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 static PlaylistCompareFunc playlist_compare_func_table[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 playlist_compare_path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 playlist_compare_filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 playlist_compare_title,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 playlist_compare_date
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 void playlist_save_m3u(FILE * file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 static void playlist_save_pls(FILE * file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 static PlaylistSaveFunc playlist_save_func_table[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 playlist_save_m3u,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 playlist_save_pls
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 static guint playlist_load_ins(const gchar * filename, gint pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 static void playlist_load_ins_file(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 const gchar * playlist_name, gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 const gchar * title, gint len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 static void playlist_generate_shuffle_list(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 static void playlist_generate_shuffle_list_nolock(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 static void playlist_recalc_total_time_nolock(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 static void playlist_recalc_total_time(void);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 PlaylistEntry *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 playlist_entry_new(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 const gchar * title,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 const gint length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 entry = g_new0(PlaylistEntry, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 entry->filename = g_strdup(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 entry->title = str_to_utf8(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 entry->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 entry->selected = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 return entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 playlist_entry_free(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if (!entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 g_free(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 g_free(entry->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 g_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 playlist_entry_get_info(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 gchar *title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 gint length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 g_return_val_if_fail(entry != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 input_get_song_info(entry->filename, &title, &length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 if (!title && length == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 /* entry is still around */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 entry->title = title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 entry->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 playlist_get_current_name(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 return playlist_current_name;
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 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 playlist_set_current_name(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 g_free(playlist_current_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 if (!filename) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 playlist_current_name = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 playlist_current_name = g_strdup(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 find_playlist_position_list(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 return shuffle_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 return playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 return g_list_find(shuffle_list, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 return g_list_find(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 play_queued(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 GList *tmp = queued_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 playlist_position = queued_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 queued_list = g_list_remove_link(queued_list, queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 playlist_clear(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 if (playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 g_list_foreach(playlist, (GFunc) playlist_entry_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 g_list_free(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 playlist = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 playlist_delete_node(GList * node, gboolean * set_info_text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 gboolean * restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 GList *playing_song = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 /* We call g_list_find manually here because we don't want an item
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 * in the shuffle_list */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 if (playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 playing_song = 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 entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 if (playing_song == node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 *set_info_text = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 *restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 playing_song = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 if (g_list_next(playing_song))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 playlist_position = g_list_next(playing_song)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 else if (g_list_previous(playing_song))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 playlist_position = g_list_previous(playing_song)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 /* Make sure the entry did not disappear under us */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 else if (g_list_position(playlist, playing_song) >
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 g_list_position(playlist, node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 *set_info_text = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 shuffle_list = g_list_remove(shuffle_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 playlist = g_list_remove_link(playlist, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 playlist_entry_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 g_list_free_1(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 playlist_recalc_total_time_nolock();
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_index(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 gboolean restart_playing = FALSE, set_info_text = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 else if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 playlist_delete_filenames(GList * filenames)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 GList *node, *fnode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 gboolean set_info_text = FALSE, restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 node = playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 while (node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 GList *next = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 if (!strcmp(entry->filename, fnode->data))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 node = next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 else if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 playlist_delete(gboolean crop)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 gboolean restart_playing = FALSE, set_info_text = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 GList *node, *next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 node = playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 while (node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 next_node = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 if ((entry->selected && !crop) || (!entry->selected && crop)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 playlist_delete_node(node, &set_info_text, &restart_playing);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 node = next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 if (set_info_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 if (restart_playing) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 }
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 __playlist_ins_with_info(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 const gchar * title,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 gint len)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 g_return_if_fail(filename != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 playlist = g_list_insert(playlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 playlist_entry_new(filename, title, len),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 playlist_get_info_scan_active = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 __playlist_ins(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 __playlist_ins_with_info(filename, pos, NULL, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 PlaylistFormat
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 playlist_format_get_from_name(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 for (i = 0; i < PLAYLIST_FORMAT_COUNT; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 if (str_has_suffix_nocase(filename, playlist_format_suffixes[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 return i;
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 return PLAYLIST_FORMAT_UNKNOWN;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 is_playlist_name(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 return playlist_format_get_from_name(filename) != PLAYLIST_FORMAT_UNKNOWN;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 playlist_ins(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 gchar buf[64], *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 gint r;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 VFSFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 if (is_playlist_name(filename)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 playlist_load_ins(filename, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 if (input_check_file(filename, TRUE)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 __playlist_ins(filename, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 /* Some files (typically produced by some cgi-scripts) don't have
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 * the correct extension. Try to recognize these files by looking
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 * at their content. We only check for http entries since it does
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 * not make sense to have file entries in a playlist fetched from
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 * the net. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 /* Some strange people put fifo's with the .mp3 extension, so we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 * need to make sure it's a real file (otherwise fread() may block
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 * and stall the entire program) */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 /* FIXME: bah, FIFOs actually pass this regular file test */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 if (!(file = vfs_fopen(filename, "rb")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 r = vfs_fread(buf, 1, sizeof(buf), file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 vfs_fclose(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 if (r > 5 && str_has_prefix_nocase(p, "http:")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 playlist_load_ins(filename, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 /* FIXME: The next few functions are specific to Unix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 * filesystems. Either abstract it away, or don't even bother checking
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 * at such low level */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 dev_t dev;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 ino_t ino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 } DeviceInode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 static DeviceInode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 devino_new(dev_t device,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 ino_t inode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 DeviceInode *devino = g_new0(DeviceInode, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 if (devino)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 devino->dev = device;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 devino->ino = inode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 return devino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 devino_hash(gconstpointer key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 const DeviceInode *d = key;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 return d->ino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 devino_compare(gconstpointer a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 gconstpointer b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 const DeviceInode *da = a, *db = b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 return (da->dev == db->dev && da->ino == db->ino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 devino_destroy(gpointer key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 gpointer value,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 g_free(key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 file_is_hidden(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 // FIXME: remove the const cast
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 return (g_basename((gchar *) filename)[0] == '.');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 playlist_dir_find_files(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 gboolean background,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 GHashTable * htab)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 GDir *dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 GList *list = NULL, *ilist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 const gchar *dir_entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 struct stat statbuf;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 DeviceInode *devino;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 if (!g_file_test(path, G_FILE_TEST_IS_DIR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 stat(path, &statbuf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 devino = devino_new(statbuf.st_dev, statbuf.st_ino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 if (g_hash_table_lookup(htab, devino)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 g_free(devino);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 if ((ilist = input_scan_dir(path))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 for (node = ilist; node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 gchar *name = g_build_filename(path, node->data, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 list = g_list_prepend(list, name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 g_list_free(ilist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 if (!(dir = g_dir_open(path, 0, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 while ((dir_entry = g_dir_read_name(dir))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 if (file_is_hidden(dir_entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 filename = g_build_filename(path, dir_entry, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 GList *sub;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619 sub = playlist_dir_find_files(filename, background, htab);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 list = g_list_concat(list, sub);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 else if (input_check_file(filename, TRUE))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 list = g_list_prepend(list, filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 while (background && gtk_events_pending())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 gtk_main_iteration();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 g_dir_close(dir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 playlist_add(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 return playlist_ins(filename, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 playlist_add_dir(const gchar * directory)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645 return playlist_ins_dir(directory, -1, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 playlist_add_url(const gchar * url)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651 return playlist_ins_url(url, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 playlist_ins_dir(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 gboolean background)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 guint entries = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 GList *list, *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661 GHashTable *htab;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 htab = g_hash_table_new(devino_hash, devino_compare);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665 list = playlist_dir_find_files(path, background, htab);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 list = g_list_sort(list, (GCompareFunc) path_compare);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668 g_hash_table_foreach_remove(htab, devino_destroy, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 for (node = list; node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 __playlist_ins(node->data, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 entries++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 pos++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 g_list_free(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 return entries;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 playlist_ins_url(const gchar * string,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 gchar *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691 gint i = 1, entries = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 gboolean first = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 guint firstpos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 gboolean success = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 gchar *decoded = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
697 g_return_val_if_fail(string != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
698
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
700
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
701 while (*string) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703 tmp = strchr(string, '\n');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 if (tmp) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 if (*(tmp - 1) == '\r')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706 *(tmp - 1) = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 if (!(decoded = xmms_urldecode_path(string)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 decoded = g_strdup(string);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714 i = playlist_ins_dir(decoded, pos, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 if (is_playlist_name(decoded)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 i = playlist_load_ins(decoded, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 success = playlist_ins(decoded, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722 i = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726 g_free(decoded);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
727
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 node = g_list_nth(playlist_get(), pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732 entries += i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 if (first) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 first = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 firstpos = pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
738
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
739 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
740 pos += i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
741 if (!tmp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744 string = tmp + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
746
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
747 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
750
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 return entries;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 playlist_set_info(const gchar * title, gint length, gint rate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756 gint freq, gint nch)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761 g_free(playlist_position->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762 playlist_position->title = g_strdup(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
763 playlist_position->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
764 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
765
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
766 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
767
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
768 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
769
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
770 mainwin_set_song_info(rate, freq, nch);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
771 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
772
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
773 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
774 playlist_check_pos_current(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
775 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
776 gint pos, row, bottom;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
777
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
778 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
779 if (!playlist || !playlist_position || !playlistwin_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
780 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
781 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
782 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
783
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
784 pos = g_list_index(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
785
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
786 if (playlistwin_item_visible(pos)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
787 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
788 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
789 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
790
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
791 bottom = MAX(0, playlist_get_length_nolock() -
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
792 playlistwin_list->pl_num_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
793 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
794 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
795 playlistwin_set_toprow(row);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
796 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
797
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
798 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
799 playlist_next(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
800 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
801 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
802 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
803
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
804 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
805 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
806 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
807 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
808 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
809
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
810 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
811
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
812 if (!cfg.repeat && !g_list_next(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
813 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
814 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
815 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
816
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
817 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
818 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
819 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
820 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
821 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
822 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
823 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
824
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
825 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
826 if (queued_list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
827 play_queued();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
828 else if (g_list_next(plist_pos_list))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
829 playlist_position = g_list_next(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
830 else if (cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
831 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
832 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
833 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
834 playlist_position = shuffle_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
835 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
836 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
837 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
838 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
839 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
840
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
841 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
842 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
843 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
844 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
845 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
846 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
847 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
848
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
849 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
850 playlist_prev(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
851 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
852 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
853 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
854
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
855 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
856 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
857 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
858 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
859 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
860
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
861 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
862
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
863 if (!cfg.repeat && !g_list_previous(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
864 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
865 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
866 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
867
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
868 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
869 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
870 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
871 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
872 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
873 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
874 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
875
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
876 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
877 if (g_list_previous(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
878 playlist_position = g_list_previous(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
879 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
880 else if (cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
881 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
882 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
883 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
884 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
885 node = g_list_last(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
886 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
887 node = g_list_last(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
888 if (node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
889 playlist_position = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
890 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
891
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
892 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
893
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
894 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
895
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
896 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
897 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
898 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
899 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
900 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
901 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
902 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
903
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
904 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
905 playlist_queue(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
906 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
907 GList *list = playlist_get_selected();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
908 GList *it = list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
909
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
910 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
911
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
912 while (it) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
913 GList *next = g_list_next(it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
914 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
915
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
916 it->data = g_list_nth_data(playlist, GPOINTER_TO_INT(it->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
917 if ((tmp = g_list_find(queued_list, it->data))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
918 queued_list = g_list_remove_link(queued_list, tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
919 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
920 list = g_list_remove_link(list, it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
921 g_list_free_1(it);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
922 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
923
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
924 it = next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
925 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
926
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
927 queued_list = g_list_concat(queued_list, list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
928
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
929 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
930
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
931 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
932 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
933 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
934
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
935 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
936 playlist_queue_position(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
937 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
938 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
939 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
940
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
941 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
942 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
943 if ((tmp = g_list_find(queued_list, entry))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
944 queued_list = g_list_remove_link(queued_list, tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
945 g_list_free_1(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
946 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
947 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
948 queued_list = g_list_append(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
949 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
950
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
951 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
952 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
953 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
954
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
955 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
956 playlist_is_position_queued(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
957 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
958 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
959 GList *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
960
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
961 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
962 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
963 tmp = g_list_find(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
964 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
965
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
966 return tmp != NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
967 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
968
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
969 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
970 playlist_clear_queue(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
971 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
972 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
973 g_list_free(queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
974 queued_list = NULL;
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_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
978 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
979 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
980
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
981 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
982 playlist_queue_remove(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
983 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
984 void *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
985
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
986 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
987 entry = g_list_nth_data(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
988 queued_list = g_list_remove(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
989 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
990
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
991 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
992 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
993
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
994 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
995 playlist_get_queue_position(PlaylistEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
996 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
997 return g_list_index(queued_list, entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
998 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
999
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1000 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1001 playlist_set_position(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1002 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1003 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1004 gboolean restart_playing = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1005
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1006 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1007 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1008 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1009 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1010 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1011
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1012 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1013 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1014 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1015 return;
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 if (bmp_playback_get_playing()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1019 /* We need to stop before changing playlist_position */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1020 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1021 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1022 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1023 restart_playing = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1024 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1025
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1026 playlist_position = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1027 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1028 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1029
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1030 if (restart_playing)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1031 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1032 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1033 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1034 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1035 }
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 * Regenerate the shuffle list when the user set a position
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1039 * manually
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1040 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1041 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1042 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1043 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1044
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1045 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1046 playlist_eof_reached(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1047 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1048 GList *plist_pos_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1049
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1050 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1051
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1052 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1053 plist_pos_list = find_playlist_position_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1054
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1055 if (cfg.no_playlist_advance) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1056 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1057 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1058 if (cfg.repeat)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1059 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1060 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1061 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1062
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1063 if (queued_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1064 play_queued();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1065 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1066 else if (!g_list_next(plist_pos_list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1067 if (cfg.shuffle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1068 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1069 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1070 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1071 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1072 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1073
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1074 if (!cfg.repeat) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1075 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1076 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1077 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1078 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1079 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1080 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1081 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1082 playlist_position = g_list_next(plist_pos_list)->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1083
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1084 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1085
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1086 playlist_check_pos_current();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1087 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1088 mainwin_set_info_text();
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 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1093 playlist_get_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1094 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1095 gint retval;
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 retval = playlist_get_length_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1099 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1100
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1101 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1102 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1104 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1105 playlist_queue_get_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1106 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1107 gint length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1109 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1110 length = g_list_length(queued_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1111 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1113 return length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1114 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1116 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1117 playlist_get_length_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1118 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1119 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1120 return g_list_length(playlist);
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 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1124 playlist_get_info_text(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1125 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1126 gchar *text, *title, *numbers, *length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1127
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1128 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1129 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1130 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1131 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1132 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1134 /* FIXME: there should not be a need to do additional conversion,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1135 * if playlist is properly maintained */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1136 if (playlist_position->title) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1137 title = str_to_utf8(playlist_position->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1138 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1139 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1140 gchar *basename = g_path_get_basename(playlist_position->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1141 title = filename_to_utf8(basename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1142 g_free(basename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1143 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1144
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1145 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1146 * If the user don't want numbers in the playlist, don't
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1147 * display them in other parts of XMMS
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 if (cfg.show_numbers_in_pl)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1151 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock() + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1152 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1153 numbers = g_strdup("");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1155 if (playlist_position->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1156 length = g_strdup_printf(" (%d:%-2.2d)",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1157 playlist_position->length / 60000,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1158 (playlist_position->length / 1000) % 60);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1159 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1160 length = g_strdup("");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1161
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1162 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1164 text = convert_title_text(g_strconcat(numbers, title, length, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1166 g_free(numbers);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1167 g_free(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1168 g_free(length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1169
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1170 return text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1171 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1172
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1173 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1174 playlist_get_current_length(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1175 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1176 gint len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1177
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1178 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1179 if (playlist && playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1180 len = playlist_position->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1181 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1183 return len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1184 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1186 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1187 playlist_save_m3u(FILE * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1188 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1189 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1191 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1192
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1193 if (cfg.use_pl_metadata)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1194 g_fprintf(file, "#EXTM3U\n");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1196 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1197
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1198 for (node = playlist; node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1199 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1201 if (entry->title && cfg.use_pl_metadata) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1202 gint seconds;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1203
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1204 if (entry->length > 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1205 seconds = (entry->length) / 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1206 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1207 seconds = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1208
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1209 g_fprintf(file, "#EXTINF:%d,%s\n", seconds, entry->title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1210 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1211
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1212 g_fprintf(file, "%s\n", entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1213 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1214
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1215 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1216 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1217
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1218 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1219 playlist_save_pls(FILE * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1220 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1221 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1222
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1223 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1224
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1225 g_fprintf(file, "[playlist]\n");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1226 g_fprintf(file, "NumberOfEntries=%d\n", playlist_get_length());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1228 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1229
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1230 for (node = playlist; node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1231 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1232
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1233 g_fprintf(file, "File%d=%s\n", g_list_position(playlist, node) + 1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1234 entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1235 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1236
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1237 PLAYLIST_UNLOCK();
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 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1241 playlist_save(const gchar * filename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1242 PlaylistFormat format)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1243 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1244 FILE *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1245
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1246 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1247
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1248 playlist_set_current_name(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1249
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1250 if ((file = fopen(filename, "w")) == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1251 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1253 playlist_save_func_table[format](file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1255 return (fclose(file) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1256 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1258 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1259 playlist_load(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1260 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1261 return playlist_load_ins(filename, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1262 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1264
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1265 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1266 playlist_load_ins_file(const gchar * filename_p,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1267 const gchar * playlist_name, gint pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1268 const gchar * title, gint len)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1269 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1270 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1271 gchar *tmp, *path;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1273 g_return_if_fail(filename_p != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1274 g_return_if_fail(playlist_name != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1276 filename = g_strstrip(g_strdup(filename_p));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1278 if (cfg.use_backslash_as_dir_delimiter) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1279 while ((tmp = strchr(filename, '\\')) != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1280 *tmp = '/';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1281 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1282
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1283 if (filename[0] != '/' && !strstr(filename, "://")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1284 path = g_strdup(playlist_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1285 if ((tmp = strrchr(path, '/')))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1286 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1287 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1288 __playlist_ins_with_info(filename, pos, title, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1289 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1290 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1291 tmp = g_build_filename(path, filename, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1292 __playlist_ins_with_info(tmp, pos, title, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1293 g_free(tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1294 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1295 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1296 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1297 __playlist_ins_with_info(filename, pos, title, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1299 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1300 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1302 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1303 parse_extm3u_info(const gchar * info, gchar ** title, gint * length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1304 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1305 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1307 g_return_if_fail(info != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1308 g_return_if_fail(title != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1309 g_return_if_fail(length != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1310
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1311 *title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1312 *length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1314 if (!str_has_prefix_nocase(info, "#EXTINF:")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1315 g_message("Invalid m3u metadata (%s)", info);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1316 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1317 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1318
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1319 info += 8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1321 *length = atoi(info);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1322 if (*length <= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1323 *length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1324 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1325 *length *= 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1326
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1327 if ((str = strchr(info, ','))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1328 *title = g_strstrip(g_strdup(str + 1));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1329 if (strlen(*title) < 1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1330 g_free(*title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1331 *title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1333 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1334 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1335
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1336 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1337 playlist_load_pls(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1338 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1339 guint i, count, added_count = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1340 gchar key[10];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1341 gchar *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1342
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1343 g_return_val_if_fail(filename != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1344
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1345 if (!str_has_suffix_nocase(filename, ".pls"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1346 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1348 if (!(line = read_ini_string(filename, "playlist", "NumberOfEntries")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1349 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1350
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1351 count = atoi(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1352 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1353
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1354 for (i = 1; i <= count; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1355 g_snprintf(key, sizeof(key), "File%d", i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1356 if ((line = read_ini_string(filename, "playlist", key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1357 playlist_load_ins_file(line, filename, pos, NULL, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1358 added_count++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1359
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1360 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1361 pos++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1362
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1363 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1364 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1365 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1366
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1367 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1368 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1369
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1370 return added_count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1371 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1372
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1373 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1374 playlist_load_m3u(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1375 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1376 FILE *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1377 gchar *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1378 gchar *ext_info = NULL, *ext_title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1379 gsize line_len = 1024;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1380 gint ext_len = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1381 gboolean is_extm3u = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1382 guint added_count = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1384 if (!(file = fopen(filename, "r")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1385 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1386
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1387 line = g_malloc(line_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1388 while (fgets(line, line_len, file)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1389 while (strlen(line) == line_len - 1 && line[strlen(line) - 1] != '\n') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1390 line_len += 1024;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1391 line = g_realloc(line, line_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1392 fgets(&line[strlen(line)], 1024, file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1393 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1394
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1395 while (line[strlen(line) - 1] == '\r' ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1396 line[strlen(line) - 1] == '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1397 line[strlen(line) - 1] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1398
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1399 if (str_has_prefix_nocase(line, "#EXTM3U")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1400 is_extm3u = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1401 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1402 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1403
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1404 if (is_extm3u && str_has_prefix_nocase(line, "#EXTINF:")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1405 str_replace_in(&ext_info, g_strdup(line));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1406 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1407 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1408
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1409 if (line[0] == '#' || strlen(line) == 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1410 if (ext_info) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1411 g_free(ext_info);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1412 ext_info = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1413 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1414 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1415 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1416
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1417 if (is_extm3u) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1418 if (cfg.use_pl_metadata && ext_info)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1419 parse_extm3u_info(ext_info, &ext_title, &ext_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1420 g_free(ext_info);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1421 ext_info = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1422 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1423
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1424 playlist_load_ins_file(line, filename, pos, ext_title, ext_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1425
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1426 str_replace_in(&ext_title, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1427 ext_len = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1428
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1429 added_count++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1430 if (pos >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1431 pos++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1432 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1433
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1434 fclose(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1435 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1436
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1437 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1438 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1439
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1440 if (g_ascii_strcasecmp(filename, BMP_PLAYLIST_BASENAME))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1441 playlist_set_current_name(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1442 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1443 playlist_set_current_name(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1444
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1445 return added_count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1446 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1447
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1448 static guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1449 playlist_load_ins(const gchar * filename, gint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1450 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1451 guint added_count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1452
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1453 g_return_val_if_fail(filename != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1454
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1455 /* .pls ? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1456 if ((added_count = playlist_load_pls(filename, pos)) > 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1457 return added_count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1458
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1459 /* Assume .m3u */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1460 return playlist_load_m3u(filename, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1461 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1462
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1463 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1464 get_playlist_nth(guint nth)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1465 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1466 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1467 return g_list_nth(playlist, nth);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1468 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1469
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1470
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1471 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1472 playlist_get(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1473 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1474 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1475 return playlist;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1476 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1477
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1478 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1479 playlist_get_position_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1480 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1481 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1482
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1483 if (playlist && playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1484 return g_list_index(playlist, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1485 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1486 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1487
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1488 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1489 playlist_get_position(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1490 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1491 gint pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1492
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1493 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1494 pos = playlist_get_position_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1495 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1496
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1497 return pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1498 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1499
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1500 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1501 playlist_get_filename(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1502 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1503 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1504 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1505 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1506
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1507 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1508 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1509 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1510 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1511 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1512 node = g_list_nth(playlist, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1513 if (!node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1514 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1515 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1516 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1517 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1518
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1519 filename = g_strdup(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1520 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1521
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1522 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1523 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1524
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1525 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1526 playlist_get_songtitle(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1527 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1528 gchar *title = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1529 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1530 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1531
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1532 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1533
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1534 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1535 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1536 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1537 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1538
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1539 if (!(node = g_list_nth(playlist, pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1540 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1541 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1542 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1543
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1544 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1545
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1546 /* FIXME: simplify this logic */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1547 if (!entry->title && entry->length == -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1548 if (playlist_entry_get_info(entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1549 title = entry->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1550 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1551 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1552 title = entry->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1553 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1554
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1555 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1556
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1557 if (!title) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1558 title = g_path_get_basename(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1559 return str_replace(title, filename_to_utf8(title));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1560 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1561
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1562 return str_to_utf8(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1563 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1564
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1565 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1566 playlist_get_songtime(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1567 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1568 gint song_time = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1569 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1570 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1571
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1572 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1573
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1574 if (!playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1575 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1576 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1577 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1578
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1579 if (!(node = g_list_nth(playlist, pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1580 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1581 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1582 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1583
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1584 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1585
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1586 if (!entry->title && entry->length == -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1587 if (playlist_entry_get_info(entry))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1588 song_time = entry->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1589
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1590 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1591 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1592 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1593 song_time = entry->length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1594 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1595 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1596
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1597 return song_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1598 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1599
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1600 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1601 playlist_compare_title(const PlaylistEntry * a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1602 const PlaylistEntry * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1603 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1604 const gchar *a_title, *b_title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1605
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1606 g_return_val_if_fail(a != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1607 g_return_val_if_fail(b != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1608
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1609 if (a->title)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1610 a_title = a->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1611 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1612 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1613 a_title = strrchr(a->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1614 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1615 a_title = a->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1616 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1617
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1618 if (b->title)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1619 b_title = b->title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1620 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1621 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1622 b_title = strrchr(b->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1623 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1624 b_title = b->filename;
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 return strcasecmp(a_title, b_title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1628 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1629
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1630 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1631 playlist_compare_filename(const PlaylistEntry * a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1632 const PlaylistEntry * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1633 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1634 gchar *a_filename, *b_filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1635
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1636 g_return_val_if_fail(a != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1637 g_return_val_if_fail(b != NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1638
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1639 if (strrchr(a->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1640 a_filename = strrchr(a->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1641 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1642 a_filename = a->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1643
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1644 if (strrchr(b->filename, '/'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1645 b_filename = strrchr(b->filename, '/') + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1646 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1647 b_filename = b->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1648
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1649
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1650 return strcasecmp(a_filename, b_filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1651 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1652
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1653 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1654 path_compare(const gchar * a, const gchar * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1655 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1656 gchar *posa, *posb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1657 gint len, ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1658
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1659 posa = strrchr(a, '/');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1660 posb = strrchr(b, '/');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1661
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1662 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1663 * Sort directories before files
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1664 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1665 if (posa && posb && (posa - a != posb - b)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1666 if (posa - a > posb - b) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1667 len = posb - b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1668 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1669 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1670 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1671 len = posa - a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1672 ret = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1673 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1674 if (!strncasecmp(a, b, len))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1675 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1676 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1677 return strcasecmp(a, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1678 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1679
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1680 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1681 playlist_compare_path(const PlaylistEntry * a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1682 const PlaylistEntry * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1683 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1684 return path_compare(a->filename, b->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1685 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1686
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1687 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1688 playlist_compare_date(const PlaylistEntry * a,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1689 const PlaylistEntry * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1690 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1691 struct stat buf;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1692 time_t modtime;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1693
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1694 gint rv;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1695
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1696
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1697 rv = stat(a->filename, &buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1698
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1699 if (rv == 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1700 modtime = buf.st_mtime;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1701 rv = stat(b->filename, &buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1702
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1703 if (stat(b->filename, &buf) == 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1704 if (buf.st_mtime == modtime)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1705 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1706 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1707 return (buf.st_mtime - modtime) > 0 ? -1 : 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1708 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1709 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1710 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1711 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1712 else if (!lstat(b->filename, &buf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1713 return 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1714 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1715 return playlist_compare_filename(a, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1716 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1717
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1718
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1719 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1720 playlist_sort(PlaylistSortType type)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1721 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1722 playlist_remove_dead_files();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1723 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1724 playlist =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1725 g_list_sort(playlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1726 (GCompareFunc) playlist_compare_func_table[type]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1727 PLAYLIST_UNLOCK();
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 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1731 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1732 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1733 GList *list1, *list2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1734 GList *tmp_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1735 GList *index_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1736
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1737 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1738 * We take all the selected entries out of the playlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1739 * sorts them, and then put them back in again.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1740 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1741
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1742 list1 = g_list_last(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1743
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1744 while (list1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1745 list2 = g_list_previous(list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1746 if (PLAYLIST_ENTRY(list1->data)->selected) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1747 gpointer idx;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1748 idx = GINT_TO_POINTER(g_list_position(list, list1));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1749 index_list = g_list_prepend(index_list, idx);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1750 list = g_list_remove_link(list, list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1751 tmp_list = g_list_concat(list1, tmp_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1752 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1753 list1 = list2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1754 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1755
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1756 tmp_list = g_list_sort(tmp_list, cmpfunc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1757 list1 = tmp_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1758 list2 = index_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1759
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1760 while (list2) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1761 if (!list1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1762 g_critical(G_STRLOC ": Error during list sorting. "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1763 "Possibly dropped some playlist-entries.");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1764 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1765 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1766
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1767 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1768
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1769 list2 = g_list_next(list2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1770 list1 = g_list_next(list1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1771 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1772
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1773 g_list_free(index_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1774 g_list_free(tmp_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1775
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1776 return list;
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 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1780 playlist_sort_selected(PlaylistSortType type)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1781 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1782 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1783 playlist = playlist_sort_selected_generic(playlist, (GCompareFunc)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1784 playlist_compare_func_table
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1785 [type]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1786 PLAYLIST_UNLOCK();
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 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1790 playlist_reverse(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1791 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1792 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1793 playlist = g_list_reverse(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1794 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1795 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1796
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1797 static GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1798 playlist_shuffle_list(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1799 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1800 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1801 * Note that this doesn't make a copy of the original list.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1802 * The pointer to the original list is not valid after this
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1803 * fuction is run.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1804 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1805 gint len = g_list_length(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1806 gint i, j;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1807 GList *node, **ptrs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1808
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1809 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1810
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1811 if (!len)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1812 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1813
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1814 ptrs = g_new(GList *, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1815
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1816 for (node = list, i = 0; i < len; node = g_list_next(node), i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1817 ptrs[i] = node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1818
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1819 j = g_random_int_range(0, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1820 list = ptrs[j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1821 ptrs[j]->next = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1822 ptrs[j] = ptrs[0];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1823
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1824 for (i = 1; i < len; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1825 j = g_random_int_range(0, len - i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1826 list->prev = ptrs[i + j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1827 ptrs[i + j]->next = list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1828 list = ptrs[i + j];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1829 ptrs[i + j] = ptrs[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1830 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1831 list->prev = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1832
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1833 g_free(ptrs);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1834
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1835 return list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1836 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1837
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1838 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1839 playlist_random(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1840 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1841 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1842 playlist = playlist_shuffle_list(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1843 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1844 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1845
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1846 GList *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1847 playlist_get_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1848 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1849 GList *node, *list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1850 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1851
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1852 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1853 for (node = playlist_get(); node; node = g_list_next(node), i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1854 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1855 if (entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1856 list = g_list_prepend(list, GINT_TO_POINTER(i));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1857 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1858 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1859 return g_list_reverse(list);
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_clear_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1864 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1865 GList *node = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1866 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1867
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1868 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1869 for (node = playlist_get(); node; node = g_list_next(node), i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1870 PLAYLIST_ENTRY(node->data)->selected = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1871 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1872 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1873 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1874 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1875
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1876 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1877 playlist_get_num_selected(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1878 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1879 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1880 gint num = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1881
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1882 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1883 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1884 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1885 if (entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1886 num++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1887 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1888 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1889 return num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1890 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1891
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1892
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1893 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1894 playlist_generate_shuffle_list(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1895 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1896 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1897 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1898 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1899 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1900
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1901 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1902 playlist_generate_shuffle_list_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1903 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1904 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1905 gint numsongs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1906
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1907 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1908
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1909 if (shuffle_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1910 g_list_free(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1911 shuffle_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1912 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1913
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1914 if (!cfg.shuffle || !playlist)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1915 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1916
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1917 shuffle_list = playlist_shuffle_list(g_list_copy(playlist));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1918 numsongs = g_list_length(shuffle_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1919
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1920 if (playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1921 gint i = g_list_index(shuffle_list, playlist_position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1922 node = g_list_nth(shuffle_list, i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1923 shuffle_list = g_list_remove_link(shuffle_list, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1924 shuffle_list = g_list_prepend(shuffle_list, node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1925 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1926 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1927
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1928 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1929 playlist_fileinfo(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1930 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1931 gchar *path = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1932 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1933
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1934 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1935 if ((node = g_list_nth(playlist_get(), pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1936 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1937 path = g_strdup(entry->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1938 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1939 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1940 if (path) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1941 input_file_info_box(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1942 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1943 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1944 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1945
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1946 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1947 playlist_fileinfo_current(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1948 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1949 gchar *path = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1950
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1951 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1952 if (playlist_get() && playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1953 path = g_strdup(playlist_position->filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1954 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1955
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1956 if (path) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1957 input_file_info_box(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1958 g_free(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1959 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1960 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1961
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1962
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1963 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1964 playlist_get_info_is_going(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1965 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1966 gboolean result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1967
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1968 G_LOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1969 result = playlist_get_info_going;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1970 G_UNLOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1971
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1972 return result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1973 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1974
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1975 static gpointer
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1976 playlist_get_info_func(gpointer arg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1977 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1978 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1979 gboolean update_playlistwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1980 gboolean update_mainwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1981
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1982 while (playlist_get_info_is_going()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1983 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1984
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1985 if (cfg.use_pl_metadata &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1986 cfg.get_info_on_load &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1987 playlist_get_info_scan_active) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1988
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1989 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1990 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1991 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1992
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1993 if (entry->title || entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1994 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1995
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1996 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1997 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1998 /* Entry disappeared while we looked it up.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1999 Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2000 node = playlist_get();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2001 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2002 else if (entry->title || entry->length != -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2003 update_playlistwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2004 if (entry == playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2005 update_mainwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2006 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2007 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2008 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2009 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2010
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2011 if (!node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2012 playlist_get_info_scan_active = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2013 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2014 else if (!cfg.get_info_on_load &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2015 cfg.get_info_on_demand &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2016 cfg.playlist_visible &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2017 !cfg.playlist_shaded &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2018 cfg.use_pl_metadata) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2019
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2020 gboolean found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2021
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2022 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2023
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2024 if (!playlist_get()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2025 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2026 g_usleep(1000000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2027 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2028 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2029
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2030 for (node =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2031 g_list_nth(playlist_get(), playlistwin_get_toprow());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2032 node
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2033 &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2034 playlistwin_item_visible(g_list_position
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2035 (playlist_get(), node));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2036 node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2037 entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2038 if (entry->title || entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2039 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2040
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2041 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2042 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2043 /* Entry disapeared while we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2044 looked it up. Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2045 node =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2046 g_list_nth(playlist_get(),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2047 playlistwin_get_toprow());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2048 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2049 else if (entry->title || entry->length != -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2050 update_playlistwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2051 if (entry == playlist_position)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2052 update_mainwin = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2053 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2054 break;
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2058 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2059
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2060 if (!found) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2061 g_usleep(500000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2062 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2063 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2064 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2065 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2066 g_usleep(500000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2067
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2068 if (update_playlistwin) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2069 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2070 update_playlistwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2071 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2072
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2073 if (update_mainwin) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2074 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2075 update_mainwin = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2076 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2077 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2078
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2079 g_thread_exit(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2080 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2081 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2082
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2083 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2084 playlist_start_get_info_thread(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2085 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2086 playlist_get_info_going = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2087 playlist_get_info_thread = g_thread_create(playlist_get_info_func,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2088 NULL, TRUE, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2089 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2090
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2091 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2092 playlist_stop_get_info_thread(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2093 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2094 G_LOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2095 playlist_get_info_going = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2096 G_UNLOCK(playlist_get_info_going);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2097 g_thread_join(playlist_get_info_thread);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2098 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2099
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2100 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2101 playlist_start_get_info_scan(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2102 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2103 playlist_get_info_scan_active = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2104 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2106 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2107 playlist_remove_dead_files(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2108 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2109 GList *node, *next_node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2111 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2113 for (node = playlist; node; node = next_node) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2114 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2115 next_node = g_list_next(node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2117 if (!entry || !entry->filename) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2118 g_message(G_STRLOC ": Playlist entry is invalid!");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2119 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2120 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2121
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2122 /* FIXME: What about 'file:///'? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2123 /* Don't kill URLs */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2124 if (strstr(entry->filename, "://"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2125 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2127 /* FIXME: Should test for readability */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2128 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2129 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2130
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2131 if (entry == playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2132 /* Don't remove the currently playing song */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2133 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2134 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2135
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2136 if (next_node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2137 playlist_position = PLAYLIST_ENTRY(next_node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2138 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2139 playlist_position = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2140 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2142 playlist_entry_free(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2143 playlist = g_list_delete_link(playlist, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2144 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2146 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2148 playlist_generate_shuffle_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2149 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2150 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2151 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2152
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2153 static gulong pl_total_time = 0, pl_selection_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2154 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2155
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2156 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2157 playlist_get_total_time(gulong * total_time,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2158 gulong * selection_time,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2159 gboolean * total_more,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2160 gboolean * selection_more)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2161 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2162 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2163 *total_time = pl_total_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2164 *selection_time = pl_selection_time;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2165 *total_more = pl_total_more;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2166 *selection_more = pl_selection_more;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2167 PLAYLIST_UNLOCK();
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2171 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2172 playlist_recalc_total_time_nolock(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2173 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2174 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2175 PlaylistEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2176
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2177 REQUIRE_STATIC_LOCK(playlist);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2178
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2179 pl_total_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2180 pl_selection_time = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2181 pl_total_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2182 pl_selection_more = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2184 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2185 entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2186
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2187 if (entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2188 pl_total_time += entry->length / 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2189 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2190 pl_total_more = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2191
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2192 if (entry->selected) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2193 if (entry->length != -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2194 pl_selection_time += entry->length / 1000;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2195 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2196 pl_selection_more = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2197 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2198 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2199 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2201 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2202 playlist_recalc_total_time(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2203 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2204 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2205 playlist_recalc_total_time_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2206 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2207 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2208
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2210 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2211 playlist_select_all(gboolean set)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2212 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2213 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2214
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2215 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2216
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2217 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2218 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2219 entry->selected = set;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2220 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2221
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2222 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2223 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2224 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2225
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2226 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2227 playlist_select_invert_all(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2228 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2229 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2231 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2232
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2233 for (list = playlist_get(); list; list = g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2234 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2235 entry->selected = !entry->selected;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2236 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2237
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2238 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2239 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2240 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2241
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2242 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2243 playlist_select_invert(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2244 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2245 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2246 gboolean invert_ok = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2247
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2248 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2249
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2250 if ((list = g_list_nth(playlist_get(), pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2251 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2252 entry->selected = !entry->selected;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2253 invert_ok = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2254 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2256 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2257 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2258
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2259 return invert_ok;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2260 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2261
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2263 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2264 playlist_select_range(gint min_pos, gint max_pos, gboolean select)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2265 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2266 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2267 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2268
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2269 if (min_pos > max_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2270 SWAP(min_pos, max_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2272 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2273
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2274 list = g_list_nth(playlist_get(), min_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2275 for (i = min_pos; i <= max_pos && list; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2276 PlaylistEntry *entry = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2277 entry->selected = select;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2278 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2279 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2280
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2281 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2282
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2283 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2284 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2285
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2286 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2287 playlist_read_info_selection(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2288 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2289 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2290 gboolean retval = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2291
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2292 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2293
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2294 for (node = playlist_get(); node; node = g_list_next(node)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2295 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2296 if (!entry->selected)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2297 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2299 retval = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2300
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2301 str_replace_in(&entry->title, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2302 entry->length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2303
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2304 if (!playlist_entry_get_info(entry)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2305 if (g_list_index(playlist_get(), entry) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2306 /* Entry disappeared while we looked it up. Restart. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2307 node = playlist_get();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2308 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2309 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2310
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2311 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2312
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2313 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2314 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2316 return retval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2317 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2318
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2319 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2320 playlist_read_info(guint pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2321 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2322 GList *node;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2323
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2324 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2325
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2326 if ((node = g_list_nth(playlist_get(), pos))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2327 PlaylistEntry *entry = node->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2328 str_replace_in(&entry->title, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2329 entry->length = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2330 playlist_entry_get_info(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2331 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2332
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2333 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2334
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2335 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2336 playlist_recalc_total_time();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2337 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2338
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2339 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2340 playlist_set_shuffle(gboolean shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2341 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2342 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2344 cfg.shuffle = shuffle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2345 playlist_generate_shuffle_list_nolock();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2346
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2347 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2348 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2349
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2350 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2351 playlist_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2352 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2353 playlist_set_current_name(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2354 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2355 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2356 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2357 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2359
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2360 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2361 playlist_get_filename_to_play(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2362 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2363 const gchar *filename = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2364
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2365 PLAYLIST_LOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2366
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2367 if (playlist) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2368 if (!playlist_position) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2369 if (cfg.shuffle)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2370 playlist_position = shuffle_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2371 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2372 playlist_position = playlist->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2374
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2375 filename = playlist_position->filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2376 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2377
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2378 PLAYLIST_UNLOCK();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2379
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2380 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2381 }