Index: rockbox_svn/apps/filetree.c =================================================================== --- rockbox_svn.orig/apps/filetree.c +++ rockbox_svn/apps/filetree.c @@ -42,6 +42,7 @@ #include "splash.h" #include "yesno.h" #include "cuesheet.h" +#include #ifdef HAVE_LCD_BITMAP #include "keyboard.h" #endif @@ -145,11 +146,32 @@ static void check_file_thumbnails(struct closedir_cached(dir); } +/* If string starts with 'the', advance pointer beyond it; used by compare() */ +static void ignore_the_sort(char **name) +{ + + if (strncasecmp(*name, "the", 3) == 0) + { + if (islower(*(*name + 3)) == 0) /* Only ignore if next char isn't a lowercase (eg, "There...") */ + { + if (*(*name + 3) == ' ' || (ispunct(*(*name + 3)) != 0)) /* Kill trailing space or punct */ + *name = *name + 4; + else + *name = *name + 3; + } + } + + return; +} + /* support function for qsort() */ static int compare(const void* p1, const void* p2) { struct entry* e1 = (struct entry*)p1; struct entry* e2 = (struct entry*)p2; + char *name1 = e1->name; + char *name2 = e2->name; + int criteria; if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) @@ -188,16 +210,32 @@ static int compare(const void* p1, const /* else fall through to alphabetical sorting */ } case 0: /* sort alphabetically asc */ + +#ifdef HAVE_TAGCACHE + if (global_settings.ignore_the==2 || global_settings.ignore_the==3){ +#else + if (global_settings.ignore_the){ +#endif + /* If name starts with 'the', ignore it when sorting */ + ignore_the_sort(&name1); + ignore_the_sort(&name2); + } if (global_settings.sort_case) - return strncmp(e1->name, e2->name, MAX_PATH); + return strncmp(name1, name2, MAX_PATH); else - return strncasecmp(e1->name, e2->name, MAX_PATH); + return strncasecmp(name1, name2, MAX_PATH); case 4: /* sort alphabetically desc */ + + if (global_settings.ignore_the){ + /* If name starts with 'the', ignore it when sorting */ + ignore_the_sort(&name1); + ignore_the_sort(&name2); + } if (global_settings.sort_case) - return strncmp(e2->name, e1->name, MAX_PATH); + return strncmp(name2, name1, MAX_PATH); else - return strncasecmp(e2->name, e1->name, MAX_PATH); + return strncasecmp(name2, name1, MAX_PATH); case 1: /* sort date */ return e1->time_write - e2->time_write; Index: rockbox_svn/apps/tagcache.c =================================================================== --- rockbox_svn.orig/apps/tagcache.c +++ rockbox_svn/apps/tagcache.c @@ -1735,6 +1735,22 @@ static bool tempbuf_insert(char *str, in return true; } +static void ignore_the_artist(char **name) +{ + + if (strncasecmp(*name, "the", 3) == 0) + { + if (islower(*(*name + 3)) == 0) /* Only ignore if next char isn't a lowercase (eg, "There...") */ + { + if (*(*name + 3) == ' ' || (ispunct(*(*name + 3)) != 0)) /* Kill trailing space or punct */ + *name = *name + 4; + else + *name = *name + 3; + } + } + return; +} + static int compare(const void *p1, const void *p2) { struct tempbuf_searchidx *e1 = (struct tempbuf_searchidx *)p1; @@ -1749,7 +1765,16 @@ static int compare(const void *p1, const else if (strcmp(e2->str, UNTAGGED) == 0) return 1; - return strncasecmp(e1->str, e2->str, TAG_MAXLEN); + char* name1=e1->str; + char* name2=e2->str; + + if (global_settings.ignore_the==1 || global_settings.ignore_the==3){ + /* If name starts with 'the', ignore it when sorting */ + ignore_the_artist(&name1); + ignore_the_artist(&name2); + } + + return strncasecmp(name1, name2, TAG_MAXLEN); } static int tempbuf_sort(int fd) Index: rockbox_svn/apps/settings.h =================================================================== --- rockbox_svn.orig/apps/settings.h +++ rockbox_svn/apps/settings.h @@ -452,6 +452,11 @@ struct user_settings int dirfilter; /* 0=display all, 1=only supported, 2=only music, 3=dirs+playlists, 4=ID3 database */ bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */ +#ifdef HAVE_TAGCACHE + int ignore_the; /* ignore loading the : 0=dont ignore, 1=ignore in browse 2=ignore in id3 3=ignore in both*/ +#else + bool ignore_the; /* ignore loading the : 0=dont ignore, 1=ignore */ +#endif int volume_type; /* how volume is displayed: 0=graphic, 1=percent */ int battery_display; /* how battery is displayed: 0=graphic, 1=percent */ int timeformat; /* time format: 0=24 hour clock, 1=12 hour clock */ Index: rockbox_svn/apps/lang/english.lang =================================================================== --- rockbox_svn.orig/apps/lang/english.lang +++ rockbox_svn/apps/lang/english.lang @@ -1804,6 +1804,76 @@ + id: LANG_IGNORE_THE + desc: in settings_menu + user: + + *: "Ignore leading 'The' in sort" + + + *: "Ignore leading 'The' in sort" + + + *: "Ignore leading 'The' in sort" + + + + id: LANG_IGNORE_THE_NO + desc: in settings_menu + user: + + *: "No" + + + *: "No" + + + *: "No" + + + + id: LANG_IGNORE_THE_BOTH + desc: in settings_menu + user: + + *: "Both" + + + *: "Both" + + + *: "Both" + + + + id: LANG_IGNORE_THE_ID3 + desc: in settings_menu + user: + + *: "ID3 Database only" + + + *: "ID3 Database only" + + + *: "ID3 Database only" + + + + id: LANG_IGNORE_THE_BROWSE + desc: in settings_menu + user: + + *: "File View only" + + + *: "File View only" + + + *: "File View only" + + + id: LANG_SORT_DIR desc: browser sorting setting user: Index: rockbox_svn/apps/settings_list.c =================================================================== --- rockbox_svn.orig/apps/settings_list.c +++ rockbox_svn/apps/settings_list.c @@ -1098,6 +1098,17 @@ const struct settings_list settings[] = {F_T_INT,&global_settings.listwidth,-1,INT(0),"listwidth",NULL,UNUSED}, #endif +#ifdef HAVE_TAGCACHE + CHOICE_SETTING(0, ignore_the, LANG_IGNORE_THE, 0 , + "ignore_the", "no,id3 database,browser,both", NULL, 4, + ID2P(LANG_IGNORE_THE_NO), ID2P(LANG_IGNORE_THE_ID3), + ID2P(LANG_IGNORE_THE_BROWSE) , ID2P(LANG_IGNORE_THE_BOTH)), +#else + CHOICE_SETTING(0, ignore_the, LANG_IGNORE_THE, 0 , + "ignore_the", "no, browser", NULL, 4, + ID2P(LANG_IGNORE_THE_NO), ID2P(LANG_IGNORE_THE_BROWSE)), +#endif + CHOICE_SETTING(0, start_in_screen, LANG_START_SCREEN, 1, "start in screen", "previous,root,files,db,wps,menu," #ifdef HAVE_RECORDING Index: rockbox_svn/apps/menus/settings_menu.c =================================================================== --- rockbox_svn.orig/apps/menus/settings_menu.c +++ rockbox_svn/apps/menus/settings_menu.c @@ -87,6 +87,7 @@ static int fileview_callback(int action, MENUITEM_SETTING(sort_case, &global_settings.sort_case, NULL); MENUITEM_SETTING(sort_dir, &global_settings.sort_dir, fileview_callback); MENUITEM_SETTING(sort_file, &global_settings.sort_file, fileview_callback); +MENUITEM_SETTING(ignore_the, &global_settings.ignore_the, fileview_callback); MENUITEM_SETTING(dirfilter, &global_settings.dirfilter, NULL); MENUITEM_SETTING(browse_current, &global_settings.browse_current, NULL); MENUITEM_SETTING(show_path_in_browser, &global_settings.show_path_in_browser, NULL); @@ -108,7 +109,7 @@ static int fileview_callback(int action, } MAKE_MENU(file_menu, ID2P(LANG_FILE), 0, Icon_file_view_menu, - &sort_case, &sort_dir, &sort_file, + &sort_case, &sort_dir, &sort_file, &ignore_the, &dirfilter, &browse_current, &show_path_in_browser); /* FILE VIEW MENU */ /***********************************/