From 517aca8532af3121d9c75ff293c5269f20c0b540 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Sun, 4 May 2008 13:01:16 +0000 Subject: 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 --- apps/onplay.c | 5 +-- apps/playlist_catalog.c | 14 +++++--- apps/playlist_catalog.h | 4 ++- apps/playlist_viewer.c | 2 +- apps/tree.c | 93 ++----------------------------------------------- 5 files changed, 19 insertions(+), 99 deletions(-) diff --git a/apps/onplay.c b/apps/onplay.c index a0de6f2e81..45b18608e8 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -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); } diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 52210580ad..17db24984b 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -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); diff --git a/apps/playlist_catalog.h b/apps/playlist_catalog.h index 591906e64f..92cfa15ed9 100644 --- a/apps/playlist_catalog.h +++ b/apps/playlist_catalog.h @@ -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 diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index c9a9f4b7af..8ad3d263de 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -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; } diff --git a/apps/tree.c b/apps/tree.c index a5741dfc31..97f152ff74 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -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; } -- cgit v1.2.3