annotate audacious/playlist.c @ 1064:13d721835794 trunk

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