use the playlist catalog code to generate the playlists under Playlist > Create playlist

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17352 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2008-05-04 13:01:16 +00:00
parent 194b2ca887
commit 517aca8532
5 changed files with 19 additions and 99 deletions

View File

@ -236,12 +236,13 @@ static bool view_playlist(void)
static bool cat_add_to_a_playlist(void)
{
return catalog_add_to_a_playlist(selected_file, selected_file_attr,
false);
false, NULL);
}
static bool cat_add_to_a_new_playlist(void)
{
return catalog_add_to_a_playlist(selected_file, selected_file_attr, true);
return catalog_add_to_a_playlist(selected_file, selected_file_attr,
true, NULL);
}

View File

@ -419,7 +419,8 @@ bool catalog_view_playlists(void)
return true;
}
bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist)
bool catalog_add_to_a_playlist(char* sel, int sel_attr,
bool new_playlist, char *m3u8name)
{
char playlist[MAX_PATH];
@ -429,9 +430,14 @@ bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist)
if (new_playlist)
{
size_t len;
snprintf(playlist, MAX_PATH, "%s/", playlist_dir);
if (kbd_input(playlist, MAX_PATH))
return false;
if (m3u8name == NULL)
{
snprintf(playlist, MAX_PATH, "%s/", playlist_dir);
if (kbd_input(playlist, MAX_PATH))
return false;
}
else
strcpy(playlist, m3u8name);
len = strlen(playlist);

View File

@ -32,8 +32,10 @@ bool catalog_view_playlists(void);
* sel_attr : the attributes that tell what type of file we're adding
* new_playlist : whether we want to create a new playlist or add to an
* existing one.
* m3u8name : filename to save the playlist to, NULL to show the keyboard
* ret : true if the file was successfully added
*/
bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist);
bool catalog_add_to_a_playlist(char* sel, int sel_attr,
bool new_playlist, char* m3u8name);
#endif

View File

@ -486,7 +486,7 @@ static int onplay_menu(int index)
case 3: /* add to a new one */
catalog_add_to_a_playlist(current_track->name,
FILE_ATTR_AUDIO,
result==3 );
result==3, NULL);
ret = 0;
break;
}

View File

@ -69,6 +69,7 @@
#include "gwps-common.h"
#include "eeprom_settings.h"
#include "scrobbler.h"
#include "playlist_catalog.h"
/* gui api */
#include "list.h"
@ -883,107 +884,17 @@ static int dirbrowse()
return true;
}
static int plsize = 0;
static long pltick;
static bool add_dir(char* dirname, int len, int fd)
{
bool abort = false;
DIR* dir;
/* check for user abort */
if (action_userabort(TIMEOUT_NOBLOCK))
return true;
dir = opendir(dirname);
if(!dir)
return true;
while (true) {
struct dirent *entry;
entry = readdir(dir);
if (!entry)
break;
if (entry->attribute & ATTR_DIRECTORY) {
int dirlen = strlen(dirname);
bool result;
if (!strcmp((char *)entry->d_name, ".") ||
!strcmp((char *)entry->d_name, ".."))
continue;
if (dirname[1])
snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
else
snprintf(dirname, len, "/%s", entry->d_name);
result = add_dir(dirname, len, fd);
dirname[dirlen] = '\0';
if (result) {
abort = true;
break;
}
}
else {
int x = strlen((char *)entry->d_name);
int i;
char *cp = strrchr((char *)entry->d_name,'.');
if (cp) {
cp++;
/* add all supported audio files to playlists */
for (i=0; i < filetypes_count; i++) {
if (filetypes[i].tree_attr == FILE_ATTR_AUDIO) {
if (!strcasecmp(cp, filetypes[i].extension)) {
write(fd, dirname, strlen(dirname));
write(fd, "/", 1);
write(fd, entry->d_name, x);
write(fd, "\n", 1);
plsize++;
if(TIME_AFTER(current_tick, pltick+HZ/4)) {
pltick = current_tick;
gui_syncsplash(0, "%d %s",
plsize, str(LANG_DIR_BROWSER));
}
break;
}
}
}
}
}
}
closedir(dir);
return abort;
}
bool create_playlist(void)
{
int fd;
char filename[MAX_PATH];
pltick = current_tick;
snprintf(filename, sizeof filename, "%s.m3u8",
tc.currdir[1] ? tc.currdir : "/root");
gui_syncsplash(0, "%s %s", str(LANG_CREATING), filename);
fd = creat(filename);
if (fd < 0)
return false;
trigger_cpu_boost();
snprintf(filename, sizeof(filename), "%s",
tc.currdir[1] ? tc.currdir : "/");
plsize = 0;
add_dir(filename, sizeof(filename), fd);
close(fd);
catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
cancel_cpu_boost();
sleep(HZ);
return true;
}