summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2008-10-08 16:32:01 +0000
committerNils Wallménius <nils@rockbox.org>2008-10-08 16:32:01 +0000
commit48b52aec468309ef00fc4bfee3b3fff969969661 (patch)
tree1c74a2cb6c17840b080e0e09fdcad0bae05fbb8c /apps/playlist.c
parent88c60e6b07b00e737e75d157a2a9b72908d627e8 (diff)
downloadrockbox-48b52aec468309ef00fc4bfee3b3fff969969661.tar.gz
rockbox-48b52aec468309ef00fc4bfee3b3fff969969661.zip
Fix FS#8949 - Alphabetical directory listing reversed after "Error Accessing Directory", patch by pondlife, some long line police by me, also kill a few error splashes in functions that could be called by threads other than UI
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18742 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c74
1 files changed, 45 insertions, 29 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 018a39ae41..6768ac8708 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -179,7 +179,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek,
179static int get_next_directory(char *dir); 179static int get_next_directory(char *dir);
180static int get_next_dir(char *dir, bool is_forward, bool recursion); 180static int get_next_dir(char *dir, bool is_forward, bool recursion);
181static int get_previous_directory(char *dir); 181static int get_previous_directory(char *dir);
182static int check_subdir_for_music(char *dir, char *subdir, bool recurse); 182static int check_subdir_for_music(char *dir, const char *subdir, bool recurse);
183static int format_track_path(char *dest, char *src, int buf_length, int max, 183static int format_track_path(char *dest, char *src, int buf_length, int max,
184 const char *dir); 184 const char *dir);
185static void display_playlist_count(int count, const unsigned char *fmt, 185static void display_playlist_count(int count, const unsigned char *fmt,
@@ -1425,20 +1425,23 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1425{ 1425{
1426 struct playlist_info* playlist = &current_playlist; 1426 struct playlist_info* playlist = &current_playlist;
1427 int result = -1; 1427 int result = -1;
1428 int sort_dir = global_settings.sort_dir;
1429 char *start_dir = NULL; 1428 char *start_dir = NULL;
1430 bool exit = false; 1429 bool exit = false;
1430 int i;
1431 struct tree_context* tc = tree_get_context(); 1431 struct tree_context* tc = tree_get_context();
1432 int dirfilter = *(tc->dirfilter); 1432 int saved_dirfilter = *(tc->dirfilter);
1433
1434 /* process random folder advance */
1433 if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) 1435 if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM)
1434 { 1436 {
1435 int fd = open(ROCKBOX_DIR "/folder_advance_list.dat",O_RDONLY); 1437 int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY);
1436 char buffer[MAX_PATH];
1437 int folder_count = 0,i;
1438 srand(current_tick);
1439 *(tc->dirfilter) = SHOW_MUSIC;
1440 if (fd >= 0) 1438 if (fd >= 0)
1441 { 1439 {
1440 char buffer[MAX_PATH];
1441 int folder_count = 0;
1442 srand(current_tick);
1443 *(tc->dirfilter) = SHOW_MUSIC;
1444 tc->sort_dir = global_settings.sort_dir;
1442 read(fd,&folder_count,sizeof(int)); 1445 read(fd,&folder_count,sizeof(int));
1443 if (!folder_count) 1446 if (!folder_count)
1444 exit = true; 1447 exit = true;
@@ -1453,17 +1456,21 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1453 if (folder_count) 1456 if (folder_count)
1454 strcpy(dir,buffer); 1457 strcpy(dir,buffer);
1455 close(fd); 1458 close(fd);
1456 *(tc->dirfilter) = dirfilter; 1459 *(tc->dirfilter) = saved_dirfilter;
1460 tc->sort_dir = global_settings.sort_dir;
1457 reload_directory(); 1461 reload_directory();
1458 return 0; 1462 return 0;
1459 } 1463 }
1460 } 1464 }
1461 /* not random folder advance */ 1465
1462 if (recursion){ 1466 /* not random folder advance (or random folder advance unavailable) */
1467 if (recursion)
1468 {
1463 /* start with root */ 1469 /* start with root */
1464 dir[0] = '\0'; 1470 dir[0] = '\0';
1465 } 1471 }
1466 else{ 1472 else
1473 {
1467 /* start with current directory */ 1474 /* start with current directory */
1468 strncpy(dir, playlist->filename, playlist->dirlen-1); 1475 strncpy(dir, playlist->filename, playlist->dirlen-1);
1469 dir[playlist->dirlen-1] = '\0'; 1476 dir[playlist->dirlen-1] = '\0';
@@ -1472,16 +1479,27 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1472 /* use the tree browser dircache to load files */ 1479 /* use the tree browser dircache to load files */
1473 *(tc->dirfilter) = SHOW_ALL; 1480 *(tc->dirfilter) = SHOW_ALL;
1474 1481
1475 /* sort in another direction if previous dir is requested */ 1482 /* set up sorting/direction */
1476 if(!is_forward){ 1483 tc->sort_dir = global_settings.sort_dir;
1477 if ((global_settings.sort_dir == 0) || (global_settings.sort_dir == 3)) 1484 if (!is_forward)
1478 global_settings.sort_dir = 4; 1485 {
1479 else if (global_settings.sort_dir == 1) 1486 /* Sort options, indices of forward/reverse options differ in bit 0 */
1480 global_settings.sort_dir = 2; 1487 const int sortpairs[] =
1481 else if (global_settings.sort_dir == 2) 1488 {
1482 global_settings.sort_dir = 1; 1489 SORT_ALPHA, SORT_ALPHA_REVERSED,
1483 else if (global_settings.sort_dir == 4) 1490 SORT_DATE, SORT_DATE_REVERSED,
1484 global_settings.sort_dir = 0; 1491 SORT_TYPE, SORT_TYPE_REVERSED,
1492 -1
1493 };
1494
1495 for (i = 0; sortpairs[i] >= 0; i++)
1496 {
1497 if (sortpairs[i] == global_settings.sort_dir)
1498 {
1499 tc->sort_dir = sortpairs[i^1];
1500 break;
1501 }
1502 }
1485 } 1503 }
1486 1504
1487 while (!exit) 1505 while (!exit)
@@ -1492,7 +1510,6 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1492 1510
1493 if (ft_load(tc, (dir[0]=='\0')?"/":dir) < 0) 1511 if (ft_load(tc, (dir[0]=='\0')?"/":dir) < 0)
1494 { 1512 {
1495 splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
1496 exit = true; 1513 exit = true;
1497 result = -1; 1514 result = -1;
1498 break; 1515 break;
@@ -1542,13 +1559,13 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1542 } 1559 }
1543 } 1560 }
1544 1561
1545 /* restore dirfilter & sort_dir */ 1562 /* restore dirfilter */
1546 *(tc->dirfilter) = dirfilter; 1563 *(tc->dirfilter) = saved_dirfilter;
1547 global_settings.sort_dir = sort_dir; 1564 tc->sort_dir = global_settings.sort_dir;
1548 1565
1549 /* special case if nothing found: try start searching again from root */ 1566 /* special case if nothing found: try start searching again from root */
1550 if (result == -1 && !recursion){ 1567 if (result == -1 && !recursion){
1551 result = get_next_dir(dir,is_forward, true); 1568 result = get_next_dir(dir, is_forward, true);
1552 } 1569 }
1553 1570
1554 return result; 1571 return result;
@@ -1558,7 +1575,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1558 * Checks if there are any music files in the dir or any of its 1575 * Checks if there are any music files in the dir or any of its
1559 * subdirectories. May be called recursively. 1576 * subdirectories. May be called recursively.
1560 */ 1577 */
1561static int check_subdir_for_music(char *dir, char *subdir, bool recurse) 1578static int check_subdir_for_music(char *dir, const char *subdir, bool recurse)
1562{ 1579{
1563 int result = -1; 1580 int result = -1;
1564 int dirlen = strlen(dir); 1581 int dirlen = strlen(dir);
@@ -1573,7 +1590,6 @@ static int check_subdir_for_music(char *dir, char *subdir, bool recurse)
1573 1590
1574 if (ft_load(tc, dir) < 0) 1591 if (ft_load(tc, dir) < 0)
1575 { 1592 {
1576 splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
1577 return -2; 1593 return -2;
1578 } 1594 }
1579 1595