Index: apps/playlist.c =================================================================== --- apps/playlist.c (revision 18740) +++ apps/playlist.c (working copy) @@ -29,7 +29,7 @@ directory, there will be no playlist file. 2. Control file : This file is automatically created when a playlist is started and contains all the commands done to it. - + The first non-comment line in a control file must begin with "P:VERSION:DIR:FILE" where VERSION is the playlist control file version, DIR is the directory where the playlist is located and FILE is the @@ -110,7 +110,7 @@ Each playlist index has a flag associated with it which identifies what type of track it is. These flags are stored in the 4 high order bits of the index. - + NOTE: This limits the playlist file size to a max of 256M. Bits 31-30: @@ -210,14 +210,14 @@ } -/* Convert a filename in an M3U playlist to UTF-8. +/* Convert a filename in an M3U playlist to UTF-8 * * buf - the filename to convert; can contain more than one line from the * playlist. * buf_len - amount of buf that is used. * buf_max - total size of buf. * temp - temporary conversion buffer, at least buf_max bytes. - * + * * Returns the length of the converted filename. */ static int convert_m3u(char* buf, int buf_len, int buf_max, char* temp) @@ -227,28 +227,22 @@ /* Locate EOL. */ while ((buf[i] != '\n') && (buf[i] != '\r') && (i < buf_len)) - { i++; - } /* Work back killing white space. */ while ((i > 0) && isspace(buf[i - 1])) - { i--; - } - + buf_len = i; dest = temp; - + /* Convert char by char, so as to not overflow temp (iso_decode should * preferably handle this). No more than 4 bytes should be generated for * each input char. */ for (i = 0; i < buf_len && dest < (temp + buf_max - 4); i++) - { dest = iso_decode(&buf[i], dest, -1, 1); - } - + *dest = 0; strcpy(buf, temp); return dest - temp; @@ -320,7 +314,7 @@ else dirused = ""; /* empty playlist */ } - + update_playlist_filename(playlist, dirused, fileused); if (playlist->control_fd >= 0) @@ -420,7 +414,7 @@ return -1; playlist->filename[playlist->dirlen-1] = '\0'; - + /* cannot call update_control() because of mutex */ result = fdprintf(playlist->control_fd, "P:%d:%s:%s\n", PLAYLIST_CONTROL_FILE_VERSION, dir, file); @@ -491,7 +485,7 @@ int dirlen = strlen(dir); playlist->utf8 = is_m3u8(file); - + /* If the dir does not end in trailing slash, we use a separator. Otherwise we don't. */ if('/' != dir[dirlen-1]) @@ -501,7 +495,7 @@ } playlist->dirlen = dirlen; - + snprintf(playlist->filename, sizeof(playlist->filename), "%s%s%s", dir, sep, file); } @@ -519,7 +513,7 @@ unsigned char *p; int result = 0; - if(-1 == playlist->fd) + if(playlist->fd == -1) playlist->fd = open_utf8(playlist->filename, O_RDONLY); if(playlist->fd < 0) return -1; /* failure */ @@ -738,16 +732,16 @@ int offset; int n = playlist->amount - rotate_index(playlist, playlist->index); - + if (n > 0) offset = rand() % n; else offset = 0; - + position = playlist->index + offset + 1; if (position >= playlist->amount) position -= playlist->amount; - + insert_position = position; } else @@ -757,11 +751,11 @@ case PLAYLIST_REPLACE: if (playlist_remove_all_tracks(playlist) < 0) return -1; - + position = insert_position = playlist->index + 1; break; } - + if (queue) flags |= PLAYLIST_QUEUED; @@ -774,7 +768,7 @@ playlist->filenames[i] = playlist->filenames[i-1]; #endif } - + /* update stored indices if needed */ if (playlist->amount > 0 && insert_position <= playlist->index && playlist->started) @@ -829,14 +823,14 @@ if (insert_pos < 0) return -1; - + (c->count)++; - + /* Make sure tracks are inserted in correct order if user requests INSERT_FIRST */ if (c->position == PLAYLIST_INSERT_FIRST || c->position >= 0) c->position = insert_pos + 1; - + if (((c->count)%PLAYLIST_DISPLAY_COUNT) == 0) { unsigned char* count_str; @@ -847,7 +841,7 @@ count_str = ID2P(LANG_PLAYLIST_INSERT_COUNT); display_playlist_count(c->count, count_str, false); - + if ((c->count) == PLAYLIST_DISPLAY_COUNT && (audio_status() & AUDIO_STATUS_PLAY) && c->playlist->started) @@ -926,7 +920,7 @@ int candidate; long store; unsigned int current = playlist->indices[playlist->index]; - + /* seed 0 is used to identify sorted playlist for resume purposes */ if (seed == 0) seed = 1; @@ -1019,7 +1013,7 @@ int i, count, direction; int index; int stepped_count = 0; - + if (steps < 0) { direction = -1; @@ -1066,7 +1060,7 @@ if (playlist == NULL) playlist = ¤t_playlist; - + /* need to account for already skipped tracks */ steps = calculate_step_count(playlist, steps); @@ -1157,7 +1151,7 @@ /* No luck if the whole playlist was bad. */ if (playlist->indices[next_index] & PLAYLIST_SKIPPED) return -1; - + return next_index; } @@ -1169,7 +1163,7 @@ unsigned int seek) { int i; - + /* Set the index to the current song */ for (i=0; iamount; i++) { @@ -1231,7 +1225,7 @@ } return true; } - + static void playlist_thread(void) { struct queue_event ev; @@ -1287,7 +1281,7 @@ /* Process only pointers that are not already loaded. */ if (playlist->filenames[index]) continue ; - + control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK; seek = playlist->indices[index] & PLAYLIST_SEEK_MASK; @@ -1308,7 +1302,7 @@ #endif dirty_pointers = false; break ; - + #ifndef SIMULATOR case SYS_USB_CONNECTED: usb_acknowledge(SYS_USB_CONNECTED_ACK); @@ -1347,7 +1341,7 @@ #else (void)index; #endif - + if (playlist->in_ram && !control_file && max < 0) { strncpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); @@ -1365,21 +1359,20 @@ } else { - if(-1 == playlist->fd) + if (playlist->fd == -1) playlist->fd = open(playlist->filename, O_RDONLY); - + fd = playlist->fd; } - - if(-1 != fd) + + if (fd != -1) { - + if (lseek(fd, seek, SEEK_SET) != seek) max = -1; else { max = read(fd, tmp_buf, MIN((size_t) buf_length, sizeof(tmp_buf))); - if ((max > 0) && !utf8) { /* Use dir_buf as a temporary buffer. Note that dir_buf must @@ -1409,12 +1402,14 @@ return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf)); } -static int get_next_directory(char *dir){ - return get_next_dir(dir,true,false); +static int get_next_directory(char *dir) +{ + return get_next_dir(dir,true,false); } -static int get_previous_directory(char *dir){ - return get_next_dir(dir,false,false); +static int get_previous_directory(char *dir) +{ + return get_next_dir(dir,false,false); } /* @@ -1425,20 +1420,23 @@ { struct playlist_info* playlist = ¤t_playlist; int result = -1; - int sort_dir = global_settings.sort_dir; char *start_dir = NULL; bool exit = false; struct tree_context* tc = tree_get_context(); - int dirfilter = *(tc->dirfilter); + int saved_dirfilter = *(tc->dirfilter); + int saved_sort_dir = *(tc->sort_dir); + + /* process random folder advance */ if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) { int fd = open(ROCKBOX_DIR "/folder_advance_list.dat",O_RDONLY); - char buffer[MAX_PATH]; - int folder_count = 0,i; - srand(current_tick); - *(tc->dirfilter) = SHOW_MUSIC; if (fd >= 0) { + char buffer[MAX_PATH]; + int folder_count = 0,i; + srand(current_tick); + *(tc->dirfilter) = SHOW_MUSIC; + *(tc->sort_dir) = global_settings.sort_dir; read(fd,&folder_count,sizeof(int)); if (!folder_count) exit = true; @@ -1453,17 +1451,21 @@ if (folder_count) strcpy(dir,buffer); close(fd); - *(tc->dirfilter) = dirfilter; + *(tc->dirfilter) = saved_dirfilter; + *(tc->sort_dir) = saved_sort_dir; reload_directory(); return 0; } } - /* not random folder advance */ - if (recursion){ + + /* not random folder advance (or random folder advance unavailable) */ + if (recursion) + { /* start with root */ dir[0] = '\0'; } - else{ + else + { /* start with current directory */ strncpy(dir, playlist->filename, playlist->dirlen-1); dir[playlist->dirlen-1] = '\0'; @@ -1472,16 +1474,34 @@ /* use the tree browser dircache to load files */ *(tc->dirfilter) = SHOW_ALL; - /* sort in another direction if previous dir is requested */ - if(!is_forward){ - if ((global_settings.sort_dir == 0) || (global_settings.sort_dir == 3)) - global_settings.sort_dir = 4; - else if (global_settings.sort_dir == 1) - global_settings.sort_dir = 2; - else if (global_settings.sort_dir == 2) - global_settings.sort_dir = 1; - else if (global_settings.sort_dir == 4) - global_settings.sort_dir = 0; + /* set up sorting/direction */ + if (is_forward) + *(tc->sort_dir) = global_settings.sort_dir; + else + { + int new_sort_dir; + switch(global_settings.sort_dir) + { + case SORT_ALPHA: + new_sort_dir = SORT_ALPHA_REVERSED; + break; + case SORT_DATE: + new_sort_dir = SORT_DATE_REVERSED; + break; + case SORT_DATE_REVERSED: + new_sort_dir = SORT_DATE; + break; + case SORT_TYPE: + new_sort_dir = SORT_TYPE_REVERSED; + break; + case SORT_ALPHA_REVERSED: + new_sort_dir = SORT_ALPHA; + break; + case SORT_TYPE_REVERSED: + new_sort_dir = SORT_TYPE; + break; + } + *(tc->sort_dir) = new_sort_dir; } while (!exit) @@ -1490,14 +1510,14 @@ int num_files = 0; int i; - if (ft_load(tc, (dir[0]=='\0')?"/":dir) < 0) + if (ft_load(tc, (dir[0] == '\0') ? "/" : dir) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); exit = true; result = -1; break; } - + files = (struct entry*) tc->dircache; num_files = tc->filesindir; @@ -1510,7 +1530,7 @@ exit = true; break; } - + if (files[i].attr & ATTR_DIRECTORY) { if (!start_dir) @@ -1542,14 +1562,13 @@ } } - /* restore dirfilter & sort_dir */ - *(tc->dirfilter) = dirfilter; - global_settings.sort_dir = sort_dir; + /* restore dirfilter */ + *(tc->dirfilter) = saved_dirfilter; + *(tc->sort_dir) = saved_sort_dir; /* special case if nothing found: try start searching again from root */ - if (result == -1 && !recursion){ - result = get_next_dir(dir,is_forward, true); - } + if (result == -1 && !recursion) + result = get_next_dir(dir, is_forward, true); return result; } @@ -1570,16 +1589,16 @@ struct tree_context* tc = tree_get_context(); snprintf(dir+dirlen, MAX_PATH-dirlen, "/%s", subdir); - + if (ft_load(tc, dir) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); return -2; } - + files = (struct entry*) tc->dircache; num_files = tc->filesindir; - + for (i=0; icontrol_mutex); - + return result; } @@ -2025,13 +2040,13 @@ char *str3 = NULL; unsigned long last_tick = current_tick; bool useraborted = false; - + for(count=0; count HZ/4) { - splashf(0, str(LANG_LOADING_PERCENT), + splashf(0, str(LANG_LOADING_PERCENT), (total_read+count)*100/control_file_size, str(LANG_OFF_ABORT)); if (action_userabort(TIMEOUT_NOBLOCK)) @@ -2041,7 +2056,7 @@ } last_tick = current_tick; } - + /* Are we on a new line? */ if((*p == '\n') || (*p == '\r')) { @@ -2063,20 +2078,20 @@ exit_loop = true; break; } - + if (!str2) str2 = ""; - + if (!str3) str3 = ""; - + version = atoi(str1); - + if (version != PLAYLIST_CONTROL_FILE_VERSION) return -1; - + update_playlist_filename(playlist, str2, str3); - + if (str3[0] != '\0') { /* NOTE: add_indices_to_playlist() overwrites the @@ -2089,7 +2104,7 @@ playlist->in_ram = true; resume_directory(str2); } - + /* load the rest of the data */ first = false; exit_loop = true; @@ -2102,17 +2117,17 @@ /* str1=position str2=last_position str3=file */ int position, last_position; bool queue; - + if (!str1 || !str2 || !str3) { result = -1; exit_loop = true; break; } - + position = atoi(str1); last_position = atoi(str2); - + queue = (current_command == PLAYLIST_COMMAND_ADD)? false:true; @@ -2121,7 +2136,7 @@ if (add_track_to_playlist(playlist, str3, position, queue, total_read+(str3-buffer)) < 0) return -1; - + playlist->last_insert_pos = last_position; break; @@ -2130,16 +2145,16 @@ { /* str1=position */ int position; - + if (!str1) { result = -1; exit_loop = true; break; } - + position = atoi(str1); - + if (remove_track_from_playlist(playlist, position, false) < 0) return -1; @@ -2150,14 +2165,14 @@ { /* str1=seed str2=first_index */ int seed; - + if (!str1 || !str2) { result = -1; exit_loop = true; break; } - + if (!sorted) { /* Always sort list before shuffling */ @@ -2166,7 +2181,7 @@ seed = atoi(str1); playlist->first_index = atoi(str2); - + if (randomise_playlist(playlist, seed, false, false) < 0) return -1; @@ -2182,9 +2197,9 @@ exit_loop = true; break; } - + playlist->first_index = atoi(str1); - + if (sort_playlist(playlist, false, false) < 0) return -1; @@ -2352,7 +2367,7 @@ { struct playlist_info* playlist = ¤t_playlist; int len = strlen(filename); - + if((len+1 > playlist->buffer_size - playlist->buffer_end_pos) || (playlist->amount >= playlist->max_playlist_size)) { @@ -2365,7 +2380,7 @@ playlist->filenames[playlist->amount] = NULL; #endif playlist->amount++; - + strcpy(&playlist->buffer[playlist->buffer_end_pos], filename); playlist->buffer_end_pos += len; playlist->buffer[playlist->buffer_end_pos++] = '\0'; @@ -2388,7 +2403,7 @@ playlist->index = playlist->first_index = start_index; start_current = true; } - + randomise_playlist(playlist, random_seed, start_current, true); return playlist->index; @@ -2501,7 +2516,7 @@ for (i=0, j=steps; iindices[index] & PLAYLIST_QUEUE_MASK) { remove_track_from_playlist(playlist, index, true); @@ -2515,7 +2530,7 @@ if (index < 0) { /* end of playlist... or is it */ - if (global_settings.repeat_mode == REPEAT_SHUFFLE && + if (global_settings.repeat_mode == REPEAT_SHUFFLE && playlist->amount > 1) { /* Repeat shuffle mode. Re-shuffle playlist and resume play */ @@ -2742,7 +2757,7 @@ playlist->max_playlist_size*sizeof(int)); #endif } - + current_playlist.first_index = playlist->first_index; current_playlist.amount = playlist->amount; current_playlist.last_insert_pos = playlist->last_insert_pos; @@ -2750,7 +2765,7 @@ current_playlist.shuffle_modified = playlist->shuffle_modified; current_playlist.deleted = playlist->deleted; current_playlist.num_inserted_tracks = playlist->num_inserted_tracks; - + memcpy(current_playlist.control_cache, playlist->control_cache, sizeof(current_playlist.control_cache)); current_playlist.num_cached = playlist->num_cached; @@ -2781,7 +2796,7 @@ { if (!playlist) playlist = ¤t_playlist; - + sync_control(playlist, false); if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started) audio_flush_and_reload_tracks(); @@ -2799,7 +2814,7 @@ int position, bool queue, bool sync) { int result; - + if (!playlist) playlist = ¤t_playlist; @@ -2859,7 +2874,7 @@ context.position = position; context.queue = queue; context.count = 0; - + cpu_boost(true); result = playlist_directory_tracksearch(dirname, recurse, @@ -2944,11 +2959,11 @@ /* user abort */ if (action_userabort(TIMEOUT_NOBLOCK)) break; - + if (temp_buf[0] != '#' && temp_buf[0] != '\0') { int insert_pos; - + if (!utf8) { /* Use trackname as a temporay buffer. Note that trackname must @@ -2965,7 +2980,7 @@ result = -1; break; } - + insert_pos = add_track_to_playlist(playlist, trackname, position, queue, -1); @@ -2981,7 +2996,7 @@ position = insert_pos + 1; count++; - + if ((count%PLAYLIST_DISPLAY_COUNT) == 0) { display_playlist_count(count, count_str, false); @@ -3039,7 +3054,7 @@ index = playlist->index; result = remove_track_from_playlist(playlist, index, true); - + if (result != -1 && (audio_status() & AUDIO_STATUS_PLAY) && playlist->started) audio_flush_and_reload_tracks(); @@ -3107,7 +3122,7 @@ result = add_track_to_playlist(playlist, filename, new_index, queue, -1); - + if (result != -1) { if (current) @@ -3231,7 +3246,7 @@ playlist = ¤t_playlist; strncpy(buf, playlist->filename+playlist->dirlen, buf_size); - + if (!buf[0]) return NULL; @@ -3287,12 +3302,11 @@ info->attr |= PLAYLIST_ATTR_QUEUED; else info->attr |= PLAYLIST_ATTR_INSERTED; - } if (playlist->indices[index] & PLAYLIST_SKIPPED) info->attr |= PLAYLIST_ATTR_SKIPPED; - + info->index = index; info->display_index = rotate_index(playlist, index) + 1; @@ -3479,7 +3493,6 @@ /* use the tree browser dircache to load files */ *(tc->dirfilter) = SHOW_ALL; - if (ft_load(tc, dirname) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); @@ -3520,7 +3533,7 @@ result = -1; break; } - + files = (struct entry*) tc->dircache; num_files = tc->filesindir; if (!num_files) Index: apps/tree.c =================================================================== --- apps/tree.c (revision 18740) +++ apps/tree.c (working copy) @@ -184,12 +184,11 @@ struct tree_context * local_tc=(struct tree_context *)data; #ifdef HAVE_TAGCACHE bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB; - if (id3db) { + if (id3db) return tagtree_get_icon(&tc); - } else #endif - { + { struct entry* dc = local_tc->dircache; struct entry* e = &dc[selected_item]; return filetype_get_icon(e->attr); @@ -567,10 +566,8 @@ strcpy(tc.currdir, "/"); name = path+1; } - strcpy(lastfile, name); - /* If we changed dir we must recalculate the dirlevel and adjust the selected history properly */ if (strncmp(tc.currdir,lastdir,sizeof(lastdir))) @@ -589,9 +586,7 @@ } } if (ft_load(&tc, NULL) >= 0) - { tc.selected_item = tree_get_file_position(lastfile); - } } @@ -900,6 +895,7 @@ int ret_val = 0; int *last_filter = tc.dirfilter; tc.dirfilter = &dirfilter; + tc.sort_dir = &global_settings.sort_dir; reload_dir = true; if (dirfilter >= NUM_FILTER_MODES) @@ -940,6 +936,7 @@ /* initialize tree context struct */ memset(&tc, 0, sizeof(tc)); tc.dirfilter = &global_settings.dirfilter; + tc.sort_dir = &global_settings.sort_dir; tc.name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files; tc.name_buffer = buffer_alloc(tc.name_buffer_size); Index: apps/tree.h =================================================================== --- apps/tree.h (revision 18740) +++ apps/tree.h (working copy) @@ -67,6 +67,7 @@ int name_buffer_size; int dentry_size; bool dirfull; + int *sort_dir; /* directory sort order */ }; void tree_mem_init(void); Index: apps/settings.h =================================================================== --- apps/settings.h (revision 18740) +++ apps/settings.h (working copy) @@ -139,6 +139,10 @@ NUM_FILTER_MODES, SHOW_WPS, SHOW_RWPS, SHOW_FMR, SHOW_CFG, SHOW_LNG, SHOW_MOD, SHOW_FONT, SHOW_PLUGINS}; +/* file and dir sort options */ +enum { SORT_ALPHA, SORT_DATE, SORT_DATE_REVERSED, SORT_TYPE, /* available as settings */ + SORT_ALPHA_REVERSED, SORT_TYPE_REVERSED }; /* internal use only */ + /* recursive dir insert options */ enum { RECURSE_OFF, RECURSE_ON, RECURSE_ASK }; @@ -413,7 +417,7 @@ int backlight_fade_in; /* backlight fade in timing: 0..3 */ int backlight_fade_out; /* backlight fade in timing: 0..7 */ #endif -#ifdef HAVE_BACKLIGHT_BRIGHTNESS +#ifdef HAVE_BACKLIGHT_BRIGHTNESS int brightness; #endif int battery_capacity; /* in mAh */ @@ -542,8 +546,8 @@ bool talk_battery_level; /* file browser sorting */ - int sort_file; /* 0=alpha, 1=date, 2=date (new first), 3=type */ - int sort_dir; /* 0=alpha, 1=date (old first), 2=date (new first) */ + int sort_file; /* 0=alpha, 1=date, 2=reverse date, 3=type */ + int sort_dir; /* 0=alpha, 1=date, 2=reverse date, 3=type */ #ifdef HAVE_REMOTE_LCD /* remote lcd */ Index: apps/menus/settings_menu.c =================================================================== --- apps/menus/settings_menu.c (revision 18740) +++ apps/menus/settings_menu.c (working copy) @@ -57,7 +57,7 @@ static void tagcache_rebuild_with_splash(void) { tagcache_rebuild(); - splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); + splash(HZ*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); } static void tagcache_update_with_splash(void) @@ -71,17 +71,17 @@ #endif MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL); MENUITEM_FUNCTION(tc_init, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE), - (int(*)(void))tagcache_rebuild_with_splash, + (int(*)(void))tagcache_rebuild_with_splash, NULL, NULL, Icon_NOICON); MENUITEM_FUNCTION(tc_update, 0, ID2P(LANG_TAGCACHE_UPDATE), - (int(*)(void))tagcache_update_with_splash, + (int(*)(void))tagcache_update_with_splash, NULL, NULL, Icon_NOICON); MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL); MENUITEM_FUNCTION(tc_export, 0, ID2P(LANG_TAGCACHE_EXPORT), - (int(*)(void))tagtree_export, NULL, + (int(*)(void))tagtree_export, NULL, NULL, Icon_NOICON); MENUITEM_FUNCTION(tc_import, 0, ID2P(LANG_TAGCACHE_IMPORT), - (int(*)(void))tagtree_import, NULL, + (int(*)(void))tagtree_import, NULL, NULL, Icon_NOICON); MAKE_MENU(tagcache_menu, ID2P(LANG_TAGCACHE), 0, Icon_NOICON, #ifdef HAVE_TC_RAMCACHE @@ -225,7 +225,7 @@ /* This prevents problems with time/date setting after a power loss */ if (!valid_time(&tm)) { -/* Macros to convert a 2-digit string to a decimal constant. +/* Macros to convert a 2-digit string to a decimal constant. (YEAR), MONTH and DAY are set by the date command, which outputs DAY as 00..31 and MONTH as 01..12. The leading zero would lead to misinterpretation as an octal constant. */ @@ -249,7 +249,7 @@ return result; } -MENUITEM_FUNCTION(time_set, 0, ID2P(LANG_SET_TIME), +MENUITEM_FUNCTION(time_set, 0, ID2P(LANG_SET_TIME), timedate_set, NULL, NULL, Icon_NOICON); MENUITEM_SETTING(timeformat, &global_settings.timeformat, NULL); MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), 0, Icon_NOICON, &time_set, &timeformat); @@ -305,7 +305,7 @@ i++; #endif return set_option(str(LANG_ALARM_WAKEUP_SCREEN), - &global_settings.alarm_wake_up_screen, + &global_settings.alarm_wake_up_screen, INT, items, i, NULL); } @@ -368,7 +368,7 @@ #endif -MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), +MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu, &start_screen, #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1) @@ -428,7 +428,6 @@ { if(global_settings.usemrb == BOOKMARK_NO) global_settings.usemrb = BOOKMARK_YES; - } break; } @@ -467,7 +466,7 @@ if (this_item == &talk_dir_clip_item) break; if (!oldval && global_settings.talk_file_clip) - { + { /* force reload if newly talking thumbnails, because the clip presence is cached only if enabled */ reload_directory(); @@ -480,7 +479,7 @@ MENUITEM_SETTING(talk_battery_level_item, &global_settings.talk_battery_level, NULL); MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice, - &talk_menu_item, &talk_dir_item, &talk_dir_clip_item, + &talk_menu_item, &talk_dir_item, &talk_dir_clip_item, &talk_file_item, &talk_file_clip_item, &talk_filetype_item, &talk_battery_level_item); /* VOICE MENU */ Index: apps/filetree.c =================================================================== --- apps/filetree.c (revision 18740) +++ apps/filetree.c (working copy) @@ -55,6 +55,8 @@ #include "backdrop.h" +static int compare_sort_dir; /* qsort key for sorting directories */ + int ft_build_playlist(struct tree_context* c, int start_index) { int i; @@ -85,12 +87,12 @@ * or started via bookmark autoload, true otherwise. * * Pointers to both the full pathname and the separated parts needed to - * avoid allocating yet another path buffer on the stack (and save some + * avoid allocating yet another path buffer on the stack (and save some * code; the caller typically needs to create the full pathname anyway)... */ bool ft_play_playlist(char* pathname, char* dirname, char* filename) { - if (global_settings.party_mode && audio_status()) + if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); return false; @@ -111,14 +113,11 @@ if (playlist_create(dirname, filename) != -1) { if (global_settings.playlist_shuffle) - { playlist_shuffle(current_tick, -1); - } - playlist_start(0, 0); return true; } - + return false; } @@ -188,14 +187,15 @@ int criteria; if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) - { /* two directories */ - criteria = global_settings.sort_dir; + { + /* two directories */ + criteria = compare_sort_dir; #ifdef HAVE_MULTIVOLUME if (e1->attr & ATTR_VOLUME || e2->attr & ATTR_VOLUME) { /* a volume identifier is involved */ if (e1->attr & ATTR_VOLUME && e2->attr & ATTR_VOLUME) - criteria = 0; /* two volumes: sort alphabetically */ + criteria = SORT_ALPHA; /* two volumes: sort alphabetically */ else /* only one is a volume: volume first */ return (e2->attr & ATTR_VOLUME) - (e1->attr & ATTR_VOLUME); } @@ -203,7 +203,8 @@ } else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY)) - { /* two files */ + { + /* two files */ criteria = global_settings.sort_file; } else /* dir and file, dir goes first */ @@ -211,37 +212,30 @@ switch(criteria) { - case 3: /* sort type */ + case SORT_TYPE: + case SORT_TYPE_REVERSED: { int t1 = e1->attr & FILE_ATTR_MASK; int t2 = e2->attr & FILE_ATTR_MASK; - if (!t1) /* unknown type */ t1 = INT_MAX; /* gets a high number, to sort after known */ if (!t2) /* unknown type */ t2 = INT_MAX; /* gets a high number, to sort after known */ - if (t1 - t2) /* if different */ - return t1 - t2; + if (t1 != t2) /* if different */ + return (t1 - t2) * (criteria == SORT_TYPE_REVERSED ? -1 : 1); /* else fall through to alphabetical sorting */ } - case 0: /* sort alphabetically asc */ + case SORT_ALPHA: + case SORT_ALPHA_REVERSED: if (global_settings.sort_case) - return strncmp(e1->name, e2->name, MAX_PATH); + return strncmp(e1->name, e2->name, MAX_PATH) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); else - return strncasecmp(e1->name, e2->name, MAX_PATH); + return strncasecmp(e1->name, e2->name, MAX_PATH) * (criteria == SORT_ALPHA_REVERSED ? -1 : 1); - case 4: /* sort alphabetically desc */ - if (global_settings.sort_case) - return strncmp(e2->name, e1->name, MAX_PATH); - else - return strncasecmp(e2->name, e1->name, MAX_PATH); - - case 1: /* sort date */ - return e1->time_write - e2->time_write; - - case 2: /* sort date, newest first */ - return e2->time_write - e1->time_write; + case SORT_DATE: + case SORT_DATE_REVERSED: + return (e1->time_write - e2->time_write) * (criteria == SORT_DATE_REVERSED ? -1 : 1); } return 0; /* never reached */ } @@ -345,6 +339,7 @@ c->dirlength = i; closedir(dir); + compare_sort_dir = *(c->sort_dir); qsort(c->dircache,i,sizeof(struct entry),compare); /* If thumbnail talking is enabled, make an extra run to mark files with @@ -370,14 +365,16 @@ else snprintf(buf,sizeof(buf),"/%s",file->name); - if (file->attr & ATTR_DIRECTORY) { + if (file->attr & ATTR_DIRECTORY) + { memcpy(c->currdir, buf, sizeof(c->currdir)); if ( c->dirlevel < MAX_DIR_LEVELS ) c->selected_item_history[c->dirlevel] = c->selected_item; c->dirlevel++; c->selected_item=0; } - else { + else + { int seed = current_tick; bool play = false; int start_index=0; @@ -385,12 +382,8 @@ switch ( file->attr & FILE_ATTR_MASK ) { case FILE_ATTR_M3U: play = ft_play_playlist(buf, c->currdir, file->name); - if (play) - { start_index = 0; - } - break; case FILE_ATTR_AUDIO: @@ -404,7 +397,7 @@ if (!warn_on_pl_erase()) break; - if (global_settings.party_mode && audio_status()) + if (global_settings.party_mode && audio_status()) { playlist_insert_track(NULL, buf, PLAYLIST_INSERT_LAST, true, true); @@ -456,7 +449,6 @@ break; #endif - /* wps config file */ case FILE_ATTR_WPS: splash(0, ID2P(LANG_WAIT)); Index: apps/playlist_catalog.c =================================================================== --- apps/playlist_catalog.c (revision 18740) +++ apps/playlist_catalog.c (working copy) @@ -120,13 +120,12 @@ bool most_recent = false; struct entry *files; struct tree_context* tc = tree_get_context(); - int dirfilter = *(tc->dirfilter); + int saved_dirfilter = *(tc->dirfilter); *num_playlists = 0; /* use the tree browser dircache to load only playlists */ *(tc->dirfilter) = SHOW_PLAYLIST; - if (ft_load(tc, playlist_dir) < 0) { splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir); @@ -172,16 +171,13 @@ { for (i=0; idirfilter) = dirfilter; + *(tc->dirfilter) = saved_dirfilter; return result; } @@ -198,11 +194,8 @@ && global_settings.dirfilter == 0))) { char* dot = strrchr(buffer, '.'); - if (dot != NULL) - { *dot = '\0'; - } } return buffer;