summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2008-05-04 13:01:16 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2008-05-04 13:01:16 +0000
commit517aca8532af3121d9c75ff293c5269f20c0b540 (patch)
treeb8e14baa69ff80d6734d8358864ff4859dc5f566
parent194b2ca887f44e6c3e0244e7f4733060e7aa1618 (diff)
downloadrockbox-517aca8532af3121d9c75ff293c5269f20c0b540.tar.gz
rockbox-517aca8532af3121d9c75ff293c5269f20c0b540.zip
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
-rw-r--r--apps/onplay.c5
-rw-r--r--apps/playlist_catalog.c14
-rw-r--r--apps/playlist_catalog.h4
-rw-r--r--apps/playlist_viewer.c2
-rw-r--r--apps/tree.c93
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)
236static bool cat_add_to_a_playlist(void) 236static bool cat_add_to_a_playlist(void)
237{ 237{
238 return catalog_add_to_a_playlist(selected_file, selected_file_attr, 238 return catalog_add_to_a_playlist(selected_file, selected_file_attr,
239 false); 239 false, NULL);
240} 240}
241 241
242static bool cat_add_to_a_new_playlist(void) 242static bool cat_add_to_a_new_playlist(void)
243{ 243{
244 return catalog_add_to_a_playlist(selected_file, selected_file_attr, true); 244 return catalog_add_to_a_playlist(selected_file, selected_file_attr,
245 true, NULL);
245} 246}
246 247
247 248
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)
419 return true; 419 return true;
420} 420}
421 421
422bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist) 422bool catalog_add_to_a_playlist(char* sel, int sel_attr,
423 bool new_playlist, char *m3u8name)
423{ 424{
424 char playlist[MAX_PATH]; 425 char playlist[MAX_PATH];
425 426
@@ -429,9 +430,14 @@ bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist)
429 if (new_playlist) 430 if (new_playlist)
430 { 431 {
431 size_t len; 432 size_t len;
432 snprintf(playlist, MAX_PATH, "%s/", playlist_dir); 433 if (m3u8name == NULL)
433 if (kbd_input(playlist, MAX_PATH)) 434 {
434 return false; 435 snprintf(playlist, MAX_PATH, "%s/", playlist_dir);
436 if (kbd_input(playlist, MAX_PATH))
437 return false;
438 }
439 else
440 strcpy(playlist, m3u8name);
435 441
436 len = strlen(playlist); 442 len = strlen(playlist);
437 443
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);
32 * sel_attr : the attributes that tell what type of file we're adding 32 * sel_attr : the attributes that tell what type of file we're adding
33 * new_playlist : whether we want to create a new playlist or add to an 33 * new_playlist : whether we want to create a new playlist or add to an
34 * existing one. 34 * existing one.
35 * m3u8name : filename to save the playlist to, NULL to show the keyboard
35 * ret : true if the file was successfully added 36 * ret : true if the file was successfully added
36 */ 37 */
37bool catalog_add_to_a_playlist(char* sel, int sel_attr, bool new_playlist); 38bool catalog_add_to_a_playlist(char* sel, int sel_attr,
39 bool new_playlist, char* m3u8name);
38 40
39#endif 41#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)
486 case 3: /* add to a new one */ 486 case 3: /* add to a new one */
487 catalog_add_to_a_playlist(current_track->name, 487 catalog_add_to_a_playlist(current_track->name,
488 FILE_ATTR_AUDIO, 488 FILE_ATTR_AUDIO,
489 result==3 ); 489 result==3, NULL);
490 ret = 0; 490 ret = 0;
491 break; 491 break;
492 } 492 }
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 @@
69#include "gwps-common.h" 69#include "gwps-common.h"
70#include "eeprom_settings.h" 70#include "eeprom_settings.h"
71#include "scrobbler.h" 71#include "scrobbler.h"
72#include "playlist_catalog.h"
72 73
73/* gui api */ 74/* gui api */
74#include "list.h" 75#include "list.h"
@@ -883,107 +884,17 @@ static int dirbrowse()
883 return true; 884 return true;
884} 885}
885 886
886static int plsize = 0;
887static long pltick;
888static bool add_dir(char* dirname, int len, int fd)
889{
890 bool abort = false;
891 DIR* dir;
892
893 /* check for user abort */
894 if (action_userabort(TIMEOUT_NOBLOCK))
895 return true;
896
897 dir = opendir(dirname);
898 if(!dir)
899 return true;
900
901 while (true) {
902 struct dirent *entry;
903
904 entry = readdir(dir);
905 if (!entry)
906 break;
907 if (entry->attribute & ATTR_DIRECTORY) {
908 int dirlen = strlen(dirname);
909 bool result;
910
911 if (!strcmp((char *)entry->d_name, ".") ||
912 !strcmp((char *)entry->d_name, ".."))
913 continue;
914
915 if (dirname[1])
916 snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
917 else
918 snprintf(dirname, len, "/%s", entry->d_name);
919
920 result = add_dir(dirname, len, fd);
921 dirname[dirlen] = '\0';
922 if (result) {
923 abort = true;
924 break;
925 }
926 }
927 else {
928 int x = strlen((char *)entry->d_name);
929 int i;
930 char *cp = strrchr((char *)entry->d_name,'.');
931
932 if (cp) {
933 cp++;
934
935 /* add all supported audio files to playlists */
936 for (i=0; i < filetypes_count; i++) {
937 if (filetypes[i].tree_attr == FILE_ATTR_AUDIO) {
938 if (!strcasecmp(cp, filetypes[i].extension)) {
939 write(fd, dirname, strlen(dirname));
940 write(fd, "/", 1);
941 write(fd, entry->d_name, x);
942 write(fd, "\n", 1);
943
944 plsize++;
945 if(TIME_AFTER(current_tick, pltick+HZ/4)) {
946 pltick = current_tick;
947 gui_syncsplash(0, "%d %s",
948 plsize, str(LANG_DIR_BROWSER));
949 }
950 break;
951 }
952 }
953 }
954 }
955 }
956 }
957 closedir(dir);
958
959 return abort;
960}
961
962bool create_playlist(void) 887bool create_playlist(void)
963{ 888{
964 int fd;
965 char filename[MAX_PATH]; 889 char filename[MAX_PATH];
966 890
967 pltick = current_tick;
968
969 snprintf(filename, sizeof filename, "%s.m3u8", 891 snprintf(filename, sizeof filename, "%s.m3u8",
970 tc.currdir[1] ? tc.currdir : "/root"); 892 tc.currdir[1] ? tc.currdir : "/root");
971 gui_syncsplash(0, "%s %s", str(LANG_CREATING), filename); 893 gui_syncsplash(0, "%s %s", str(LANG_CREATING), filename);
972
973 fd = creat(filename);
974 if (fd < 0)
975 return false;
976 894
977 trigger_cpu_boost(); 895 trigger_cpu_boost();
978 896 catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
979 snprintf(filename, sizeof(filename), "%s",
980 tc.currdir[1] ? tc.currdir : "/");
981 plsize = 0;
982 add_dir(filename, sizeof(filename), fd);
983 close(fd);
984
985 cancel_cpu_boost(); 897 cancel_cpu_boost();
986 sleep(HZ);
987 898
988 return true; 899 return true;
989} 900}