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