annotate Gui/win32/playlist.c @ 20542:ebfc1eb11ebf

Run dirclean instead of clean on distclean, this way we only need to recurse through subdirectories once.
author diego
date Tue, 31 Oct 2006 13:34:17 +0000
parents d450ec82ae57
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18914
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
1 /*
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
2 MPlayer Gui for win32
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
3 Copyright (c) 2003 Sascha Sommer <saschasommer@freenet.de>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
4 Copyright (c) 2006 Erik Augustson <erik_27can@yahoo.com>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
5 Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
6
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
10 (at your option) any later version.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
11
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
15 GNU General Public License for more details.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
16
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
18 along with this program; if not, write to the Free Software
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
20 */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
21
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
22 #include <windows.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
23 #include <mp_msg.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
24 #include "playlist.h"
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
25
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
26 /* TODO: implement sort_playlist */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
27
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
28 BOOL adddirtoplaylist(playlist_t *playlist, const char *path, BOOL recursive)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
29 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
30 HANDLE findHandle = INVALID_HANDLE_VALUE;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
31 WIN32_FIND_DATA finddata;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
32 char findpath[MAX_PATH], filename[MAX_PATH];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
33 char *filepart;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
34
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
35 sprintf(findpath, "%s\\*.*", path);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
36
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
37 findHandle = FindFirstFile(findpath, &finddata);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
38
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
39 if (findHandle == INVALID_HANDLE_VALUE) return FALSE;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
40 do
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
41 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
42 if (finddata.cFileName[0] == '.' || strstr(finddata.cFileName, "Thumbs.db")) continue;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
43 sprintf(findpath, "%s\\%s", path, finddata.cFileName);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
44
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
45 if (GetFileAttributes(findpath) & FILE_ATTRIBUTE_DIRECTORY)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
46 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
47 if(recursive)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
48 adddirtoplaylist(playlist, findpath, recursive);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
49 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
50 else
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
51 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
52 if (GetFullPathName(findpath, MAX_PATH, filename, &filepart))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
53 playlist->add_track(playlist, filename, NULL, filepart, 0);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
54 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
55 } while (FindNextFile(findHandle, &finddata));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
56 FindClose(findHandle);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
57 return TRUE;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
58 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
59
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
60 static void add_track(playlist_t *playlist, const char *filename, const char *artist, const char *title, int duration)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
61 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
62 (playlist->trackcount)++;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
63 playlist->tracks = realloc(playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
64 playlist->tracks[playlist->trackcount - 1] = calloc(1, sizeof(pl_track_t));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
65 if(filename) playlist->tracks[playlist->trackcount - 1]->filename = strdup(filename);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
66 if(artist) playlist->tracks[playlist->trackcount - 1]->artist = strdup(artist);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
67 if(title) playlist->tracks[playlist->trackcount - 1]->title = strdup(title);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
68 if(duration) playlist->tracks[playlist->trackcount - 1]->duration = duration;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
69 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
70
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
71 static void remove_track(playlist_t *playlist, int number)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
72 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
73 pl_track_t **tmp = calloc(1, playlist->trackcount * sizeof(pl_track_t *));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
74 int i, p = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
75 memcpy(tmp, playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
76 (playlist->trackcount)--;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
77 playlist->tracks = realloc(playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
78 for(i=0; i<playlist->trackcount + 1; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
79 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
80 if(i != (number - 1))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
81 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
82 playlist->tracks[p] = tmp[i];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
83 p++;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
84 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
85 else
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
86 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
87 if(tmp[i]->filename) free(tmp[i]->filename);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
88 if(tmp[i]->artist) free(tmp[i]->artist);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
89 if(tmp[i]->title) free(tmp[i]->title);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
90 free(tmp[i]);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
91 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
92 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
93 free(tmp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
94 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
95
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
96 static void moveup_track(playlist_t *playlist, int number)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
97 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
98 pl_track_t *tmp;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
99 if(number == 1) return; /* already first */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
100 tmp = playlist->tracks[number - 2];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
101 playlist->tracks[number - 2] = playlist->tracks[number - 1];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
102 playlist->tracks[number - 1] = tmp;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
103 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
104
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
105 static void movedown_track(playlist_t *playlist, int number)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
106 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
107 pl_track_t *tmp;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
108 if(number == playlist->trackcount) return; /* already latest */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
109 tmp = playlist->tracks[number];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
110 playlist->tracks[number] = playlist->tracks[number - 1];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
111 playlist->tracks[number - 1] = tmp;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
112 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
113
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
114 static void sort_playlist(playlist_t *playlist, int opt) {}
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
115
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
116 static void clear_playlist(playlist_t *playlist)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
117 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
118 while(playlist->trackcount) playlist->remove_track(playlist, 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
119 playlist->tracks = NULL;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
120 playlist->current = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
121 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
122
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
123 static void free_playlist(playlist_t *playlist)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
124 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
125 if(playlist->tracks) playlist->clear_playlist(playlist);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
126 free(playlist);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
127 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
128
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
129 static void dump_playlist(playlist_t *playlist)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
130 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
131 int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
132 for (i=0; i<playlist->trackcount; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
133 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
134 mp_msg(MSGT_GPLAYER, MSGL_V, "track %i %s ", i + 1, playlist->tracks[i]->filename);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
135 if(playlist->tracks[i]->artist) mp_msg(MSGT_GPLAYER, MSGL_V, "%s ", playlist->tracks[i]->artist);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
136 if(playlist->tracks[i]->title) mp_msg(MSGT_GPLAYER, MSGL_V, "- %s ", playlist->tracks[i]->title);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
137 if(playlist->tracks[i]->duration) mp_msg(MSGT_GPLAYER, MSGL_V, "%i ", playlist->tracks[i]->duration);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
138 mp_msg(MSGT_GPLAYER, MSGL_V, "\n");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
139 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
140 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
141
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
142 playlist_t *create_playlist(void)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
143 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
144 playlist_t *playlist = calloc(1, sizeof(playlist_t));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
145 playlist->add_track = add_track;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
146 playlist->remove_track = remove_track;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
147 playlist->moveup_track = moveup_track;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
148 playlist->movedown_track = movedown_track;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
149 playlist->dump_playlist = dump_playlist;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
150 playlist->sort_playlist = sort_playlist;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
151 playlist->clear_playlist = clear_playlist;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
152 playlist->free_playlist = free_playlist;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
153 return playlist;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
154 }