Brian King's .rockbox browsing patch

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3964 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2003-09-29 21:26:53 +00:00
parent d527849e66
commit de5477cc00
7 changed files with 156 additions and 58 deletions

View file

@ -1727,3 +1727,33 @@ id: LANG_RECURSE_DIRECTORY_QUESTION
desc: Asked from onplay screen
eng: "Recursively?"
new:
id: LANG_CUSTOM_FONT
desc: in setting_menu()
eng: "Fonts"
new:
id: LANG_FIRMWARE
desc: in the main menu
eng: "Firmware"
new:
id: LANG_LANGUAGE
desc: in settings_menu
eng: "Language"
new:
id: LANG_WHILE_PLAYING
desc: in settings_menu()
eng: "While Playing Screen"
new:
id: LANG_CUSTOM_CFG
desc: in setting_menu()
eng: "Profiles"
new:
id: LANG_PLUGINS
desc: in main_menu()
eng: "Plugins"
new:

View file

@ -251,6 +251,16 @@ bool show_info(void)
return false;
}
static bool firmware_browse(void)
{
return rockbox_browse(ROCKBOX_DIR, SHOW_MOD);
}
static bool plugin_browse(void)
{
return rockbox_browse(PLUGIN_DIR, SHOW_PLUGINS);
}
bool main_menu(void)
{
int m;
@ -273,14 +283,8 @@ bool main_menu(void)
#ifdef HAVE_ALARM_MOD
{ str(LANG_ALARM_MOD_ALARM_MENU), alarm_screen },
#endif
#ifdef HAVE_LCD_BITMAP
#ifdef USE_GAMES
{ str(LANG_GAMES), games_menu },
#endif
#ifdef USE_DEMOS
{ str(LANG_DEMOS), demo_menu },
#endif /* end USE_DEMOS */
#endif
{ str(LANG_PLUGINS), plugin_browse },
{ str(LANG_FIRMWARE), firmware_browse },
{ str(LANG_INFO), show_info },
{ str(LANG_VERSION), show_credits },
#ifndef SIMULATOR

View file

@ -410,10 +410,11 @@ static int add_directory_to_playlist(char *dirname, int *position, bool queue,
int num_files = 0;
bool buffer_full = false;
int i;
int dirfilter = SHOW_ALL;
struct entry *files;
/* use the tree browser dircache to load files */
files = load_and_sort_directory(dirname, SHOW_ALL, &num_files,
files = load_and_sort_directory(dirname, &dirfilter, &num_files,
&buffer_full);
if(!files)
@ -456,7 +457,7 @@ static int add_directory_to_playlist(char *dirname, int *position, bool queue,
break;
/* we now need to reload our current directory */
files = load_and_sort_directory(dirname, SHOW_ALL, &num_files,
files = load_and_sort_directory(dirname, &dirfilter, &num_files,
&buffer_full);
if (!files)
{

View file

@ -25,6 +25,7 @@
#include "file.h"
#define ROCKBOX_DIR "/.rockbox"
#define PLUGIN_DIR ROCKBOX_DIR"/rocks"
#define MAX_FILENAME 20
@ -50,6 +51,7 @@
#define FF_REWIND_45000 12
#define FF_REWIND_60000 13
struct user_settings
{
/* audio settings */
@ -222,7 +224,11 @@ extern char rockboxdir[];
enum { REPEAT_OFF, REPEAT_ALL, REPEAT_ONE, NUM_REPEAT_MODES };
/* dir filter options */
enum { SHOW_ALL, SHOW_SUPPORTED, SHOW_MUSIC, SHOW_PLAYLIST, NUM_FILTER_MODES };
/* Note: Any new filter modes need to be added before NUM_FILTER_MODES.
* Any new rockbox browse filter modes (accessible through the menu)
* must be added after NUM_FILTER_MODES. */
enum { SHOW_ALL, SHOW_SUPPORTED, SHOW_MUSIC, SHOW_PLAYLIST, NUM_FILTER_MODES,
SHOW_WPS, SHOW_CFG, SHOW_LNG, SHOW_MOD, SHOW_FONT, SHOW_PLUGINS};
/* recursive dir insert options */
enum { RECURSE_OFF, RECURSE_ON, RECURSE_ASK };

View file

@ -37,6 +37,7 @@
#include "powermgmt.h"
#include "rtc.h"
#include "ata.h"
#include "tree.h"
#include "screens.h"
#ifdef HAVE_LCD_BITMAP
#include "peakmeter.h"
@ -683,6 +684,28 @@ static bool browse_current(void)
return set_bool( str(LANG_FOLLOW), &global_settings.browse_current );
}
static bool custom_wps_browse(void)
{
return rockbox_browse(ROCKBOX_DIR, SHOW_WPS);
}
static bool custom_cfg_browse(void)
{
return rockbox_browse(ROCKBOX_DIR, SHOW_CFG);
}
static bool language_browse(void)
{
return rockbox_browse(ROCKBOX_DIR, SHOW_LNG);
}
#ifdef HAVE_RECORDER_KEYPAD
static bool font_browse(void)
{
return rockbox_browse(ROCKBOX_DIR, SHOW_FONT);
}
#endif
#ifdef HAVE_LCD_BITMAP
static bool scroll_bar(void)
{
@ -894,8 +917,14 @@ bool settings_menu(void)
struct menu_items items[] = {
{ str(LANG_PLAYBACK), playback_settings_menu },
{ str(LANG_CUSTOM_CFG), custom_cfg_browse },
{ str(LANG_WHILE_PLAYING), custom_wps_browse },
{ str(LANG_LANGUAGE), language_browse },
{ str(LANG_FILE), fileview_settings_menu },
{ str(LANG_DISPLAY), display_settings_menu },
#ifdef HAVE_RECORDER_KEYPAD
{ str(LANG_CUSTOM_FONT), font_browse },
#endif
{ str(LANG_SYSTEM), system_settings_menu },
{ str(LANG_SAVE_SETTINGS), settings_save_config },
};

View file

@ -78,19 +78,20 @@ static int cursorpos[MAX_DIR_LEVELS];
static char lastdir[MAX_PATH];
static char lastfile[MAX_PATH];
static char currdir[MAX_PATH];
static char currdir_save[MAX_PATH];
static bool reload_dir = false;
static int boot_size = 0;
static int boot_cluster;
static bool boot_changed = false;
static bool dirbrowse(char *root);
static bool dirbrowse(char *root, int *dirfilter);
void browse_root(void)
{
#ifndef SIMULATOR
dirbrowse("/");
dirbrowse("/", &global_settings.dirfilter);
#else
if (!dirbrowse("/")) {
if (!dirbrowse("/", &global_settings.dirfilter)) {
DEBUGF("No filesystem found. Have you forgotten to create it?\n");
}
#endif
@ -189,7 +190,7 @@ static int compare(const void* p1, const void* p2)
return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY );
}
static void showfileline(int line, int direntry, bool scroll)
static void showfileline(int line, int direntry, bool scroll, int *dirfilter)
{
char* name = dircache[direntry].name;
int xpos = LINE_X;
@ -200,7 +201,7 @@ static void showfileline(int line, int direntry, bool scroll)
#endif
/* if any file filter is on, strip the extension */
if (global_settings.dirfilter != SHOW_ALL &&
if (*dirfilter != SHOW_ALL &&
!(dircache[direntry].attr & ATTR_DIRECTORY))
{
char* dotpos = strrchr(name, '.');
@ -235,7 +236,7 @@ static void showfileline(int line, int direntry, bool scroll)
}
/* load sorted directory into dircache. returns NULL on failure. */
struct entry* load_and_sort_directory(char *dirname, int dirfilter,
struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
int *num_files, bool *buffer_full)
{
int i;
@ -273,7 +274,7 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
}
/* filter out dotfiles and hidden files */
if (dirfilter != SHOW_ALL &&
if (*dirfilter != SHOW_ALL &&
((entry->d_name[0]=='.') ||
(entry->attribute & ATTR_HIDDEN))) {
i--;
@ -322,25 +323,19 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
boot_cluster = entry->startcluster;
}
/* filter out all non-playlist files */
if ( dirfilter == SHOW_PLAYLIST &&
(!(dptr->attr &
(ATTR_DIRECTORY|TREE_ATTR_M3U))) ) {
i--;
continue;
}
/* filter out non-music files */
if ( dirfilter == SHOW_MUSIC &&
(!(dptr->attr &
(ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ) {
i--;
continue;
}
/* filter out non-supported files */
if ( dirfilter == SHOW_SUPPORTED &&
(!(dptr->attr & TREE_ATTR_MASK)) ) {
/* filter out non-visible files */
if ((*dirfilter == SHOW_PLAYLIST &&
!(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_M3U))) ||
(*dirfilter == SHOW_MUSIC &&
!(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ||
(*dirfilter == SHOW_SUPPORTED && !(dptr->attr & TREE_ATTR_MASK)) ||
(*dirfilter == SHOW_WPS && !(dptr->attr & TREE_ATTR_WPS)) ||
(*dirfilter == SHOW_CFG && !(dptr->attr & TREE_ATTR_CFG)) ||
(*dirfilter == SHOW_LNG && !(dptr->attr & TREE_ATTR_LNG)) ||
(*dirfilter == SHOW_MOD && !(dptr->attr & TREE_ATTR_MOD)) ||
(*dirfilter == SHOW_FONT && !(dptr->attr & TREE_ATTR_FONT)) ||
(*dirfilter == SHOW_PLUGINS && !(dptr->attr & TREE_ATTR_ROCK)))
{
i--;
continue;
}
@ -363,7 +358,7 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
return dircache;
}
static int showdir(char *path, int start)
static int showdir(char *path, int start, int *dirfilter)
{
int icon_type = 0;
int i;
@ -383,7 +378,7 @@ static int showdir(char *path, int start)
/* new dir? cache it */
if (strncmp(path,lastdir,sizeof(lastdir)) || reload_dir) {
if (!load_and_sort_directory(path, global_settings.dirfilter,
if (!load_and_sort_directory(path, dirfilter,
&filesindir, &dir_buffer_full))
return -1;
@ -534,7 +529,7 @@ static int showdir(char *path, int start)
#endif
}
showfileline(i-start, i, false); /* no scroll */
showfileline(i-start, i, false, dirfilter); /* no scroll */
}
#ifdef HAVE_LCD_BITMAP
@ -606,7 +601,7 @@ void resume_directory(char *dir)
{
bool buffer_full;
if (!load_and_sort_directory(dir, global_settings.dirfilter, &filesindir,
if (!load_and_sort_directory(dir, &global_settings.dirfilter, &filesindir,
&buffer_full))
return;
lastdir[0] = 0;
@ -704,7 +699,7 @@ void set_current_file(char *path)
}
}
static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
static bool handle_on(int *ds, int *dc, int numentries, int tree_max_on_screen, int *dirfilter)
{
bool exit = false;
bool used = false;
@ -789,7 +784,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
#ifdef HAVE_LCD_BITMAP
int xpos,ypos;
#endif
showdir(currdir, dirstart);
showdir(currdir, dirstart, dirfilter);
#ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor) {
xpos = lcd_getxmargin();
@ -808,7 +803,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
return used;
}
static bool dirbrowse(char *root)
static bool dirbrowse(char *root, int *dirfilter)
{
int numentries=0;
char buf[MAX_PATH];
@ -817,11 +812,11 @@ static bool dirbrowse(char *root)
int button;
int tree_max_on_screen;
bool reload_root = false;
int lastfilter = global_settings.dirfilter;
int lastfilter = *dirfilter;
bool lastsortcase = global_settings.sort_case;
int lastdircursor=-1;
bool need_update = true;
bool exit_func = false;
bool update_all = false; /* set this to true when the whole file list
has been refreshed on screen */
@ -839,9 +834,10 @@ static bool dirbrowse(char *root)
memcpy(currdir,root,sizeof(currdir));
if (*dirfilter < NUM_FILTER_MODES)
start_resume(true);
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
if (numentries == -1)
return false; /* currdir is not a directory */
update_all = true;
@ -899,6 +895,8 @@ static bool dirbrowse(char *root)
restore = true;
}
if (*dirfilter > NUM_FILTER_MODES)
exit_func = true;
break;
#ifdef HAVE_RECORDER_KEYPAD
@ -1083,6 +1081,8 @@ static bool dirbrowse(char *root)
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
#endif
}
else if (*dirfilter > NUM_FILTER_MODES)
exit_func = true;
}
restore = true;
break;
@ -1099,7 +1099,7 @@ static bool dirbrowse(char *root)
else {
if (dirstart) {
dirstart--;
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
update_all=true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
@ -1114,7 +1114,7 @@ static bool dirbrowse(char *root)
else {
dirstart = numentries - tree_max_on_screen;
dircursor = tree_max_on_screen - 1;
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y +
tree_max_on_screen - 1, true);
@ -1138,7 +1138,7 @@ static bool dirbrowse(char *root)
}
else {
dirstart++;
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
@ -1151,7 +1151,7 @@ static bool dirbrowse(char *root)
}
else {
dirstart = dircursor = 0;
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
update_all=true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
@ -1169,7 +1169,7 @@ static bool dirbrowse(char *root)
case BUTTON_ON:
if (handle_on(&dirstart, &dircursor, numentries,
tree_max_on_screen))
tree_max_on_screen, dirfilter))
{
/* start scroll */
restore = true;
@ -1228,7 +1228,7 @@ static bool dirbrowse(char *root)
/* do we need to rescan dir? */
if (reload_dir || reload_root ||
lastfilter != global_settings.dirfilter ||
lastfilter != *dirfilter ||
lastsortcase != global_settings.sort_case)
{
if ( reload_root ) {
@ -1242,11 +1242,15 @@ static bool dirbrowse(char *root)
dirstart = 0;
lastdir[0] = 0;
}
lastfilter = global_settings.dirfilter;
lastfilter = *dirfilter;
lastsortcase = global_settings.sort_case;
restore = true;
}
if (exit_func)
break;
if (restore || reload_dir) {
/* restore display */
@ -1262,7 +1266,7 @@ static bool dirbrowse(char *root)
icon */
lcd_setfont(FONT_UI);
#endif
numentries = showdir(currdir, dirstart);
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
@ -1280,12 +1284,12 @@ static bool dirbrowse(char *root)
/* So if lastdircursor and dircursor differ, and then full
screen was not refreshed, restore the previous line */
if ((lastdircursor != dircursor) && !update_all ) {
showfileline(lastdircursor, lasti, false); /* no scroll */
showfileline(lastdircursor, lasti, false, dirfilter); /* no scroll */
}
lasti=i;
lastdircursor=dircursor;
showfileline(dircursor, i, true); /* scroll please */
showfileline(dircursor, i, true, dirfilter); /* scroll please */
need_update = true;
}
}
@ -1402,6 +1406,29 @@ bool create_playlist(void)
return true;
}
bool rockbox_browse(char *root, int dirfilter)
{
bool rc;
int dircursor_save = dircursor;
int dirstart_save = dirstart;
int dirlevel_save = dirlevel;
int dirpos_save = dirpos[0];
int cursorpos_save = cursorpos[0];
memcpy(currdir_save, currdir, sizeof(currdir));
rc = dirbrowse(root, &dirfilter);
memcpy(currdir, currdir_save, sizeof(currdir));
reload_dir = true;
dirstart = dirstart_save;
cursorpos[0] = cursorpos_save;
dirlevel = dirlevel_save;
dircursor = dircursor_save;
dirpos[0] = dirpos_save;
return false;
}
void tree_init(void)
{
/* We copy the settings value in case it is changed by the user. We can't

View file

@ -42,11 +42,12 @@ struct entry {
void tree_init(void);
void browse_root(void);
void set_current_file(char *path);
bool rockbox_browse(char *root, int dirfilter);
bool create_playlist(void);
void resume_directory(char *dir);
char *getcwd(char *buf, int size);
void reload_directory(void);
struct entry* load_and_sort_directory(char *dirname, int dirfilter,
struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
int *num_files, bool *buffer_full);
#endif