From 4346a1e8e7ebde5864862a352581be74480f8e3f Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Fri, 18 Apr 2025 20:37:51 +0200 Subject: [PATCH] playlist catalog: sort independently from file browser Allow independent sorting of playlists in the playlist catalog, using the context menu. You may want to usually sort playlists by their date (modified), but sort audio tracks alphabetically. This is now possible without having to constantly adjust a setting. The fact that 'Sort Files' applied to both the file browser and playlist catalog seems more like a side effect of the implementation, rather than behavior that is wanted. Additionally, the 'By Type' sorting makes no sense when only a single type is displayed. Since many of the other File View settings don't apply to the playlist catalog, hide the menu there. Change-Id: Ic35038015d0860998ae117f472ce23ce3bc80cfa --- apps/filetree.c | 9 +++++++-- apps/lang/english.lang | 14 ++++++++++++++ apps/menu.c | 4 +++- apps/menus/playlist_menu.c | 4 +++- apps/menus/settings_menu.c | 7 +++++-- apps/onplay.c | 19 ++++++++++++++++++- apps/settings.h | 1 + apps/settings_list.c | 4 ++++ manual/appendix/config_file_options.tex | 1 + manual/configure_rockbox/playlist_options.tex | 6 ++++++ 10 files changed, 62 insertions(+), 7 deletions(-) diff --git a/apps/filetree.c b/apps/filetree.c index d6528d632a..bf32e7c1ae 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -58,6 +58,7 @@ static struct compare_data { int sort_dir; /* qsort key for sorting directories */ + int sort_file; /* ...for sorting files */ int(*_compar)(const char*, const char*, size_t); } cmp_data; @@ -234,7 +235,7 @@ static int compare(const void* p1, const void* p2) if (cmp_data.sort_dir == SORT_AS_FILE) { /* treat as two files */ - criteria = global_settings.sort_file; + criteria = cmp_data.sort_file; } else if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) { /* two directories */ @@ -253,7 +254,7 @@ static int compare(const void* p1, const void* p2) } else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY)) { /* two files */ - criteria = global_settings.sort_file; + criteria = cmp_data.sort_file; } else /* dir and file, dir goes first */ return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY); @@ -425,6 +426,10 @@ int ft_load(struct tree_context* c, const char* tempdir) /* allow directories to be sorted into file list */ cmp_data.sort_dir = (*c->dirfilter == SHOW_PLUGINS) ? SORT_AS_FILE : c->sort_dir; + /* playlist catalog uses sorting independent from file browser */ + cmp_data.sort_file = (*c->dirfilter == SHOW_M3U) ? + global_settings.sort_playlists : global_settings.sort_file; + if (global_settings.sort_case) { if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 64eea420f1..be94d5c2e2 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -16956,3 +16956,17 @@ *: "Playlist finished. Play again?" + + id: LANG_SORT_PLAYLISTS + desc: playlists sorting setting + user: core + + *: "Sort Playlists" + + + *: "Sort Playlists" + + + *: "sort playlists" + + diff --git a/apps/menu.c b/apps/menu.c index a1964983db..2a56292ec6 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -578,7 +578,9 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected, shortcuts_add(SHORTCUT_SETTING, (void*)setting); break; #endif - } /* swicth(do_menu()) */ + } /* switch(do_menu()) */ + if (menu->flags & MENU_EXITAFTERTHISMENU) + done = true; /* in case onplay menu contains setting */ redraw_lists = true; } } /* else if (!in_stringlist) */ diff --git a/apps/menus/playlist_menu.c b/apps/menus/playlist_menu.c index a1201d6589..9b5e8e99e0 100644 --- a/apps/menus/playlist_menu.c +++ b/apps/menus/playlist_menu.c @@ -157,9 +157,11 @@ MAKE_MENU(currentplaylist_settings_menu, ID2P(LANG_CURRENT_PLAYLIST), &show_shuffled_adding_options, &show_queue_options); +MENUITEM_SETTING(sort_playlists, &global_settings.sort_playlists, NULL); MAKE_MENU(playlist_settings, ID2P(LANG_PLAYLISTS), NULL, Icon_Playlist, - &viewer_settings_menu, &recursive_dir_insert, ¤tplaylist_settings_menu); + &sort_playlists, &viewer_settings_menu, &recursive_dir_insert, + ¤tplaylist_settings_menu); MAKE_MENU(playlist_options, ID2P(LANG_PLAYLISTS), NULL, Icon_Playlist, &view_cur_playlist, &save_playlist, diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 7774e05114..0c1d117460 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -220,10 +220,13 @@ static int filemenu_callback(int action, { (void)this_list; + /* Show File View menu in Settings or File Browser, + but not in Database or Playlist Catalog */ if (action == ACTION_REQUEST_MENUITEM && this_item == &file_menu && - get_onplay_context() == CONTEXT_ID3DB && - get_current_activity() != ACTIVITY_SETTINGS) + get_current_activity() != ACTIVITY_SETTINGS && + (get_onplay_context() != CONTEXT_TREE + || *tree_get_context()->dirfilter == SHOW_M3U)) return ACTION_EXIT_MENUITEM; return action; diff --git a/apps/onplay.c b/apps/onplay.c index f149aae63a..e6a7f05642 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -1132,6 +1132,23 @@ MAKE_ONPLAYMENU( wps_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE), #endif ); +int sort_playlists_callback(int action, + const struct menu_item_ex *this_item, + struct gui_synclist *this_list) +{ + (void) this_list; + (void) this_item; + + if (action == ACTION_REQUEST_MENUITEM && + *tree_get_context()->dirfilter != SHOW_M3U) + { + return ACTION_EXIT_MENUITEM; + } + return action; +} + +MENUITEM_SETTING(sort_playlists, &global_settings.sort_playlists, sort_playlists_callback); + MENUITEM_FUNCTION(view_playlist_item, 0, ID2P(LANG_VIEW), view_playlist, onplaymenu_callback, Icon_Playlist); @@ -1149,7 +1166,7 @@ MAKE_ONPLAYMENU( tree_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE), #if LCD_DEPTH > 1 &set_backdrop_item, #endif - &add_to_faves_item, &set_as_dir_menu, &file_menu, + &add_to_faves_item, &set_as_dir_menu, &file_menu, &sort_playlists, ); static int onplaymenu_callback(int action, const struct menu_item_ex *this_item, diff --git a/apps/settings.h b/apps/settings.h index 81c247abb0..7d8da0199a 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -682,6 +682,7 @@ struct user_settings bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */ int sort_dir; /* 0=alpha, 1=date (old first), 2=date (new first) */ int sort_file; /* 0=alpha, 1=date, 2=date (new first), 3=type */ + int sort_playlists; /* in playlist catalog 0=alpha, 1=date, 2=date (new first) */ int interpret_numbers; /* true=strnatcmp, false=strcmp */ /* power settings */ diff --git a/apps/settings_list.c b/apps/settings_list.c index b39f8f154f..db73f28035 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1415,6 +1415,10 @@ const struct settings_list settings[] = { "sort files", "alpha,oldest,newest,type", treesort_callback, 4, ID2P(LANG_SORT_ALPHA), ID2P(LANG_SORT_DATE), ID2P(LANG_SORT_DATE_REVERSE) , ID2P(LANG_SORT_TYPE)), + CHOICE_SETTING(0, sort_playlists, LANG_SORT_PLAYLISTS, 0 , + "sort playlists", "alpha,oldest,newest", treesort_callback, 3, + ID2P(LANG_SORT_ALPHA), ID2P(LANG_SORT_DATE), + ID2P(LANG_SORT_DATE_REVERSE)), CHOICE_SETTING(0, interpret_numbers, LANG_SORT_INTERPRET_NUMBERS, 1, "sort interpret number", "digits,numbers",treesort_callback, 2, ID2P(LANG_SORT_INTERPRET_AS_DIGIT), diff --git a/manual/appendix/config_file_options.tex b/manual/appendix/config_file_options.tex index a7807b7ae3..7622348e2a 100644 --- a/manual/appendix/config_file_options.tex +++ b/manual/appendix/config_file_options.tex @@ -150,6 +150,7 @@ delete, insert, insert shuffled & N/A\\} } sort files & alpha, oldest, newest, type & N/A\\ + sort playlists & alpha, oldest, newest & N/A\\ sort dirs & alpha, oldest, newest & N/A\\ sort interpret number & digits, numbers & N/A\\ tagcache\_autoupdate diff --git a/manual/configure_rockbox/playlist_options.tex b/manual/configure_rockbox/playlist_options.tex index a0b4e382af..50a832d022 100644 --- a/manual/configure_rockbox/playlist_options.tex +++ b/manual/configure_rockbox/playlist_options.tex @@ -7,6 +7,12 @@ related to playlists. \begin{description} +\item[Sort Playlists.] + This option adjusts the sorting of items listed in the \setting{Playlists} + menu (see \reference{ref:playlistoptions}). You can also press + \ActionStdContext{} in the \setting{Playlists} menu to access the option + from there, directly. + \item[Playlist Viewer Settings.] This submenu contains settings related to the Playlist Viewer. \begin{description}