annotate gui/win32/playlist.c @ 33984:60449f4234f7

Add doxygen comments to bitmap.c and bitmap.h.
author ib
date Tue, 06 Sep 2011 15:10:01 +0000
parents e2e7d9d88063
children dbf5042ab255
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
1 /*
23079
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
2 * MPlayer GUI for Win32
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
6 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
7 * This file is part of MPlayer.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
8 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
10 * it under the terms of the GNU General Public License as published by
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
12 * (at your option) any later version.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
13 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
17 * GNU General Public License for more details.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
18 *
26457
9ba6d4487292 Use standard GPL header.
diego
parents: 26193
diff changeset
19 * You should have received a copy of the GNU General Public License along
9ba6d4487292 Use standard GPL header.
diego
parents: 26193
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
9ba6d4487292 Use standard GPL header.
diego
parents: 26193
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23079
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
22 */
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 #include <windows.h>
26193
609236ad27f4 more header / declaration cleanups; fixes a lot of warnings as well as a preempt to removal of redundant wincfg.h.
vayne
parents: 23091
diff changeset
25 #include <stdio.h>
27469
c889ecd297c9 Add necessary #include <stdlib.h> for realloc/calloc/free.
diego
parents: 26457
diff changeset
26 #include <stdlib.h>
23091
52488bb09d90 Consistently use quotes instead of angled brackets in #include
diego
parents: 23079
diff changeset
27 #include "mp_msg.h"
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28 #include "playlist.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
29
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30 /* TODO: implement sort_playlist */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31
33854
e2e7d9d88063 win32 gui: replace C99 bool type by int
diego
parents: 33800
diff changeset
32 int adddirtoplaylist(playlist_t *playlist, const char *path, int recursive)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34 HANDLE findHandle = INVALID_HANDLE_VALUE;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35 WIN32_FIND_DATA finddata;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
36 char findpath[MAX_PATH], filename[MAX_PATH];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37 char *filepart;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
39 sprintf(findpath, "%s\\*.*", path);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41 findHandle = FindFirstFile(findpath, &finddata);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42
33854
e2e7d9d88063 win32 gui: replace C99 bool type by int
diego
parents: 33800
diff changeset
43 if (findHandle == INVALID_HANDLE_VALUE) return 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44 do
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46 if (finddata.cFileName[0] == '.' || strstr(finddata.cFileName, "Thumbs.db")) continue;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 sprintf(findpath, "%s\\%s", path, finddata.cFileName);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49 if (GetFileAttributes(findpath) & FILE_ATTRIBUTE_DIRECTORY)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 if(recursive)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 adddirtoplaylist(playlist, findpath, recursive);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
53 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 else
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 if (GetFullPathName(findpath, MAX_PATH, filename, &filepart))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
57 playlist->add_track(playlist, filename, NULL, filepart, 0);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59 } while (FindNextFile(findHandle, &finddata));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 FindClose(findHandle);
33854
e2e7d9d88063 win32 gui: replace C99 bool type by int
diego
parents: 33800
diff changeset
61 return 1;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 static void add_track(playlist_t *playlist, const char *filename, const char *artist, const char *title, int duration)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 (playlist->trackcount)++;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 playlist->tracks = realloc(playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68 playlist->tracks[playlist->trackcount - 1] = calloc(1, sizeof(pl_track_t));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69 if(filename) playlist->tracks[playlist->trackcount - 1]->filename = strdup(filename);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 if(artist) playlist->tracks[playlist->trackcount - 1]->artist = strdup(artist);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
71 if(title) playlist->tracks[playlist->trackcount - 1]->title = strdup(title);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 if(duration) playlist->tracks[playlist->trackcount - 1]->duration = duration;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75 static void remove_track(playlist_t *playlist, int number)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
77 pl_track_t **tmp = calloc(1, playlist->trackcount * sizeof(pl_track_t *));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78 int i, p = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 memcpy(tmp, playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
80 (playlist->trackcount)--;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
81 playlist->tracks = realloc(playlist->tracks, playlist->trackcount * sizeof(pl_track_t *));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 for(i=0; i<playlist->trackcount + 1; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
83 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84 if(i != (number - 1))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 playlist->tracks[p] = tmp[i];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 p++;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 else
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90 {
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 27469
diff changeset
91 free(tmp[i]->filename);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 27469
diff changeset
92 free(tmp[i]->artist);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 27469
diff changeset
93 free(tmp[i]->title);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94 free(tmp[i]);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
97 free(tmp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
98 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
99
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
100 static void moveup_track(playlist_t *playlist, int number)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
101 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
102 pl_track_t *tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
103 if(number == 1) return; /* already first */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
104 tmp = playlist->tracks[number - 2];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 playlist->tracks[number - 2] = playlist->tracks[number - 1];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
106 playlist->tracks[number - 1] = tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
107 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
108
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
109 static void movedown_track(playlist_t *playlist, int number)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
110 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
111 pl_track_t *tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 if(number == playlist->trackcount) return; /* already latest */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113 tmp = playlist->tracks[number];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114 playlist->tracks[number] = playlist->tracks[number - 1];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115 playlist->tracks[number - 1] = tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 static void sort_playlist(playlist_t *playlist, int opt) {}
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120 static void clear_playlist(playlist_t *playlist)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
122 while(playlist->trackcount) playlist->remove_track(playlist, 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 playlist->tracks = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
124 playlist->current = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
125 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
126
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
127 static void free_playlist(playlist_t *playlist)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
128 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129 if(playlist->tracks) playlist->clear_playlist(playlist);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 free(playlist);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
131 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
132
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
133 static void dump_playlist(playlist_t *playlist)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
134 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
135 int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
136 for (i=0; i<playlist->trackcount; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
137 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
138 mp_msg(MSGT_GPLAYER, MSGL_V, "track %i %s ", i + 1, playlist->tracks[i]->filename);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
139 if(playlist->tracks[i]->artist) mp_msg(MSGT_GPLAYER, MSGL_V, "%s ", playlist->tracks[i]->artist);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
140 if(playlist->tracks[i]->title) mp_msg(MSGT_GPLAYER, MSGL_V, "- %s ", playlist->tracks[i]->title);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 if(playlist->tracks[i]->duration) mp_msg(MSGT_GPLAYER, MSGL_V, "%i ", playlist->tracks[i]->duration);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
142 mp_msg(MSGT_GPLAYER, MSGL_V, "\n");
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
143 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
146 playlist_t *create_playlist(void)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
147 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
148 playlist_t *playlist = calloc(1, sizeof(playlist_t));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
149 playlist->add_track = add_track;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
150 playlist->remove_track = remove_track;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
151 playlist->moveup_track = moveup_track;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
152 playlist->movedown_track = movedown_track;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153 playlist->dump_playlist = dump_playlist;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
154 playlist->sort_playlist = sort_playlist;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
155 playlist->clear_playlist = clear_playlist;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
156 playlist->free_playlist = free_playlist;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
157 return playlist;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
158 }