annotate audacious/playlist.c @ 1420:0aa4bee03747 trunk

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