Index: apps/iap.c =================================================================== --- apps/iap.c (revision 29783) +++ apps/iap.c (working copy) @@ -43,6 +43,10 @@ #include "tuner.h" #include "ipod_remote_tuner.h" +#define MAX_NAME_LENGTH 20 +#include "filetree.h" +#include "dir.h" + static volatile int iap_pollspeed = 0; static volatile bool iap_remotetick = true; static bool iap_setupflag = false, iap_updateflag = false; @@ -58,6 +62,8 @@ static unsigned char response[TX_BUFLEN]; static int responselen; +static char cur_dbrecord[5] = {0}; + static void iap_task(void) { static int count = 0; @@ -527,6 +533,28 @@ iap_send_pkt(data, sizeof(data)); } +static void get_playlist_name(unsigned char *dest, unsigned long item_offset) +{ + if (item_offset == 0) return; + DIR* dp; + struct dirent* playlist_file = NULL; + + dp = opendir(global_settings.playlist_catalog_dir); + + unsigned long nbr = 0; + while ((nbr < item_offset) && ((playlist_file = readdir(dp)) != NULL)) + { + if (strcmp(playlist_file->d_name, ".") != 0 && + strcmp(playlist_file->d_name, "..") != 0) + nbr++; + } + + if (playlist_file != NULL) { + strlcpy(dest, playlist_file->d_name, MAX_NAME_LENGTH); + } + closedir(dp); +} + static void iap_handlepkt_mode4(void) { unsigned int cmd = (serbuf[2] << 8) | serbuf[3]; @@ -559,20 +587,38 @@ iap_send_pkt(data, sizeof(data)); break; } - + + /* SelectDBRecord */ + case 0x0017: + { + memcpy(cur_dbrecord, serbuf + 4, 5); + cmd_ok_mode4(cmd); + break; + } + /* GetNumberCategorizedDBRecords */ case 0x0018: { /* ReturnNumberCategorizedDBRecords */ unsigned char data[] = {0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00}; unsigned long num = 0; + + DIR* dp; + unsigned long nbr_total_playlists = 0; + switch(serbuf[4]) /* type number */ { case 0x01: /* total number of playlists */ - num = 1; + dp = opendir(global_settings.playlist_catalog_dir); + while (readdir(dp) != NULL) + nbr_total_playlists++; + closedir(dp); + /*We must not take . and .. into account,*/ + num = nbr_total_playlists - 1; break; case 0x05: /* total number of songs */ num = 1; + break; } data[3] = num >> 24; data[4] = num >> 16; @@ -582,6 +628,23 @@ break; } + /* RetrieveCategorizedDatabaseRecords */ + case 0x001A: + { + /* ReturnCategorizedDatabaseRecord */ + unsigned char data[7 + MAX_NAME_LENGTH] = + {0x04, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, + 'R', 'O', 'C', 'K', 'B', 'O', 'X', '\0'}; + + unsigned long item_offset = (serbuf[5] << 24) | (serbuf[6] << 16) | + (serbuf[7] << 8) | serbuf[8]; + + get_playlist_name(data + 7, item_offset); + + iap_send_pkt(data, sizeof(data)); + break; + } + /* GetPlayStatus */ case 0x001C: { @@ -685,6 +748,34 @@ break; } + /* PlayCurrentSelection */ + case 0x0028: + { + switch (cur_dbrecord[0]) + { + case 0x01: + {/*Playlist*/ + unsigned long item_offset = (cur_dbrecord[1] << 24)| + (cur_dbrecord[2] << 16)| + (cur_dbrecord[3] << 8) | + cur_dbrecord[4]; + unsigned char selected_playlist[2*MAX_NAME_LENGTH] = {'\0'}; + strlcpy(selected_playlist, + global_settings.playlist_catalog_dir, + MAX_NAME_LENGTH); + int len = strlen(selected_playlist); + selected_playlist[len] = '/'; + get_playlist_name(selected_playlist + len + 1, item_offset); + ft_play_playlist(selected_playlist, + global_settings.playlist_catalog_dir, + strrchr(selected_playlist, '/') + 1); + break; + } + } + cmd_ok_mode4(cmd); + break; + } + /* PlayControl */ case 0x0029: {