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