Henrik Backes patch for WPS and tag database context menus. Tag database context menus still don't work as expected. Hold Play/Select to pop up the menu.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6835 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2005-06-23 01:31:26 +00:00
parent 8b493fa6c4
commit 6e0436f65c
11 changed files with 281 additions and 144 deletions

View file

@ -24,5 +24,6 @@
#define CONTEXT_TREE 2
#define CONTEXT_RECORD 3
#define CONTEXT_MAINMENU 4
#define CONTEXT_ID3DB 5
#endif

View file

@ -53,7 +53,6 @@
#define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
static bool add_bookmark(const char* bookmark_file_name, const char* bookmark);
static bool bookmark_load_menu(void);
static bool check_bookmark(const char* bookmark);
static char* create_bookmark(void);
static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id);
@ -86,38 +85,6 @@ static char global_read_buffer[MAX_BOOKMARK_SIZE];
static char global_bookmark[MAX_BOOKMARK_SIZE];
static char global_filename[MAX_PATH];
/* ----------------------------------------------------------------------- */
/* Displays the bookmark menu options for the user to decide. This is an */
/* interface function. */
/* ----------------------------------------------------------------------- */
bool bookmark_menu(void)
{
int m;
bool result;
static const struct menu_item items[] = {
{ ID2P(LANG_BOOKMARK_MENU_CREATE), bookmark_create_menu},
{ ID2P(LANG_BOOKMARK_MENU_LIST), bookmark_load_menu},
{ ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS), bookmark_mrb_load},
};
m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
NULL, NULL, NULL);
#ifdef HAVE_LCD_CHARCELLS
status_set_param(true);
#endif
result = menu_run(m);
#ifdef HAVE_LCD_CHARCELLS
status_set_param(false);
#endif
menu_exit(m);
settings_save();
return result;
}
/* ----------------------------------------------------------------------- */
/* This is the interface function from the main menu. */
/* ----------------------------------------------------------------------- */
@ -133,7 +100,7 @@ bool bookmark_create_menu(void)
/* for the user. The user can then select a bookmark to load. */
/* If no file/directory is currently playing, the menu item does not work. */
/* ----------------------------------------------------------------------- */
static bool bookmark_load_menu(void)
bool bookmark_load_menu(void)
{
bool success = true;
int offset;
@ -628,6 +595,8 @@ static char* select_bookmark(const char* bookmark_file_name)
int bookmark_count = 0;
#ifdef HAVE_LCD_BITMAP
int x = lcd_getxmargin();
int y = lcd_getymargin();
lcd_setmargins(0, 0);
#endif
@ -711,6 +680,9 @@ static char* select_bookmark(const char* bookmark_file_name)
#endif
#ifdef SETTINGS_OK2
case SETTINGS_OK2:
#endif
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(x, y);
#endif
return NULL;
@ -1141,6 +1113,31 @@ static bool generate_bookmark_file_name(const char *in)
return true;
}
/* ----------------------------------------------------------------------- */
/* Returns the bookmark name for the current playlist */
/* ----------------------------------------------------------------------- */
bool bookmark_exist(void)
{
bool exist=false;
if(system_check())
{
char* name = playlist_get_name(NULL, global_temp_buffer,
sizeof(global_temp_buffer));
if (generate_bookmark_file_name(name))
{
int fd=open(global_bookmark_file_name, O_RDONLY);
if (fd >=0)
{
close(fd);
exist=true;
}
}
}
return exist;
}
/* ----------------------------------------------------------------------- */
/* Checks the current state of the system and returns if it is in a */
/* bookmarkable state. */

View file

@ -21,7 +21,7 @@
#include <stdbool.h>
bool bookmark_menu(void);
bool bookmark_load_menu(void);
bool bookmark_autobookmark(void);
bool bookmark_create_menu(void);
bool bookmark_mrb_load(void);
@ -29,6 +29,7 @@ bool bookmark_autoload(const char* file);
bool bookmark_load(const char* file, bool autoload);
void bookmark_play(char* resume_file, int index, int offset, int seed,
char *filename);
bool bookmark_exist(void);
#endif /* __BOOKMARK_H__ */

View file

@ -32,7 +32,6 @@
#include "debug_menu.h"
#include "sprintf.h"
#include <string.h>
#include "playlist.h"
#include "settings.h"
#include "settings_menu.h"
#include "power.h"
@ -41,7 +40,6 @@
#include "status.h"
#include "fat.h"
#include "bookmark.h"
#include "wps.h"
#include "buffer.h"
#include "screens.h"
#include "playlist_menu.h"
@ -342,7 +340,6 @@ bool info_menu(void)
/* info menu */
static const struct menu_item items[] = {
{ ID2P(LANG_MENU_SHOW_ID3_INFO), browse_id3 },
{ ID2P(LANG_INFO_MENU), show_info },
{ ID2P(LANG_VERSION), show_credits },
#ifndef SIMULATOR
@ -373,8 +370,8 @@ bool main_menu(void)
/* main menu */
struct menu_item items[9];
items[i].desc = ID2P(LANG_BOOKMARK_MENU);
items[i++].function = bookmark_menu;
items[i].desc = ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS);
items[i++].function = bookmark_mrb_load;
items[i].desc = ID2P(LANG_SOUND_SETTINGS);
items[i++].function = sound_menu;

View file

@ -45,11 +45,68 @@
#include "onplay.h"
#include "filetypes.h"
#include "plugin.h"
#include "bookmark.h"
#include "wps.h"
#include "action.h"
#ifdef HAVE_LCD_BITMAP
#include "icons.h"
#endif
#define DEFAULT_PLAYLIST_NAME "/dynamic.m3u"
static int context;
static char* selected_file = NULL;
static int selected_file_attr = 0;
static int onplay_result = ONPLAY_OK;
/* For playlist options */
struct playlist_args {
int position;
bool queue;
};
/* ----------------------------------------------------------------------- */
/* Displays the bookmark menu options for the user to decide. This is an */
/* interface function. */
/* ----------------------------------------------------------------------- */
bool bookmark_menu(void)
{
int i,m;
bool result;
struct menu_item items[3];
i=0;
if ((audio_status() & AUDIO_STATUS_PLAY))
{
items[i].desc = ID2P(LANG_BOOKMARK_MENU_CREATE);
items[i].function = bookmark_create_menu;
i++;
if (bookmark_exist())
{
items[i].desc = ID2P(LANG_BOOKMARK_MENU_LIST);
items[i].function = bookmark_load_menu;
i++;
}
}
m=menu_init( items, i, NULL, NULL, NULL, NULL );
#ifdef HAVE_LCD_CHARCELLS
status_set_param(true);
#endif
result = menu_run(m);
#ifdef HAVE_LCD_CHARCELLS
status_set_param(false);
#endif
menu_exit(m);
settings_save();
return result;
}
static bool list_viewers(void)
{
struct menu_item menu[16];
@ -70,17 +127,28 @@ static bool list_viewers(void)
splash(HZ*2, true, "No viewers found");
}
if(ret == PLUGIN_USB_CONNECTED)
if (ret == PLUGIN_USB_CONNECTED)
onplay_result = ONPLAY_RELOAD_DIR;
return false;
}
/* For playlist options */
struct playlist_args {
int position;
bool queue;
};
static bool save_playlist(void)
{
char filename[MAX_PATH+1];
strncpy(filename, DEFAULT_PLAYLIST_NAME, sizeof(filename));
if (!kbd_input(filename, sizeof(filename)))
{
playlist_save(NULL, filename);
/* reload in case playlist was saved to cwd */
onplay_result = ONPLAY_RELOAD_DIR;
}
return false;
}
static bool add_to_playlist(int position, bool queue)
{
@ -168,12 +236,13 @@ static bool view_playlist(void)
/* Sub-menu for playlist options */
static bool playlist_options(void)
{
struct menu_item items[7];
struct playlist_args args[7]; /* increase these 2 if you add entries! */
struct menu_item items[10];
struct playlist_args args[10]; /* increase these 2 if you add entries! */
int m, i=0, pstart=0, result;
bool ret = false;
if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U)
if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U &&
context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_VIEW);
items[i].function = view_playlist;
@ -181,6 +250,26 @@ static bool playlist_options(void)
pstart++;
}
if (audio_status() & AUDIO_STATUS_PLAY)
{
items[i].desc = ID2P(LANG_VIEW_DYNAMIC_PLAYLIST);
items[i].function = playlist_viewer;
i++;
pstart++;
items[i].desc = ID2P(LANG_SAVE_DYNAMIC_PLAYLIST);
items[i].function = save_playlist;
i++;
pstart++;
}
if (context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_CREATE_PLAYLIST);
items[i].function = create_playlist;
i++;
pstart++;
if (audio_status() & AUDIO_STATUS_PLAY)
{
items[i].desc = ID2P(LANG_INSERT);
@ -221,6 +310,7 @@ static bool playlist_options(void)
args[i].queue = false;
i++;
}
}
m = menu_init( items, i, NULL, NULL, NULL, NULL );
result = menu_show(m);
@ -385,11 +475,11 @@ bool create_dir(void)
pathlen = strlen(dirname);
rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen);
if(rc < 0)
if (rc < 0)
return false;
rc = mkdir(dirname, 0);
if(rc < 0) {
if (rc < 0) {
splash(HZ, true, "%s %s", str(LANG_CREATE_DIR), str(LANG_FAILED));
} else {
onplay_result = ONPLAY_RELOAD_DIR;
@ -398,50 +488,70 @@ bool create_dir(void)
return true;
}
int onplay(char* file, int attr)
int onplay(char* file, int attr, int from)
{
struct menu_item items[6]; /* increase this if you add entries! */
struct menu_item items[8]; /* increase this if you add entries! */
int m, i=0, result;
onplay_result = ONPLAY_OK;
if(file)
{
context=from;
selected_file = file;
selected_file_attr = attr;
if (((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) ||
(attr & ATTR_DIRECTORY) ||
((attr & TREE_ATTR_MASK) == TREE_ATTR_M3U))
if (context == CONTEXT_WPS ||
context == CONTEXT_TREE ||
context == CONTEXT_ID3DB)
{
if ((audio_status() & AUDIO_STATUS_PLAY))
{
items[i].desc = ID2P(LANG_BOOKMARK_MENU);
items[i].function = bookmark_menu;
i++;
}
items[i].desc = ID2P(LANG_PLAYLIST);
items[i].function = playlist_options;
i++;
}
if (file)
{
if (context == CONTEXT_WPS)
{
items[i].desc = ID2P(LANG_MENU_SHOW_ID3_INFO);
items[i].function = browse_id3;
i++;
}
#ifdef HAVE_MULTIVOLUME
if (!(attr & ATTR_VOLUME)) /* no rename+delete for volumes */
#endif
{
if (context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_RENAME);
items[i].function = rename_file;
i++;
}
if (!(attr & ATTR_DIRECTORY))
if (!(attr & ATTR_DIRECTORY) && context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_DELETE);
items[i].function = delete_file;
i++;
}
else
{
if (context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_DELETE_DIR);
items[i].function = delete_dir;
i++;
}
}
}
if (!(attr & ATTR_DIRECTORY))
if (!(attr & ATTR_DIRECTORY) && attr)
{
items[i].desc = ID2P(LANG_ONPLAY_OPEN_WITH);
items[i].function = list_viewers;
@ -449,16 +559,30 @@ int onplay(char* file, int attr)
}
}
if (context == CONTEXT_TREE)
{
items[i].desc = ID2P(LANG_CREATE_DIR);
items[i].function = create_dir;
i++;
}
/* DIY menu handling, since we want to exit after selection */
button_clear_queue();
if (i)
{
m = menu_init( items, i, NULL, NULL, NULL, NULL );
result = menu_show(m);
if (result >= 0)
items[result].function();
menu_exit(m);
#ifdef HAVE_LCD_BITMAP
if (global_settings.statusbar)
lcd_setmargins(0, STATUSBAR_HEIGHT);
else
lcd_setmargins(0, 0);
#endif
}
return onplay_result;
}

View file

@ -19,7 +19,7 @@
#ifndef _ONPLAY_H_
#define _ONPLAY_H_
int onplay(char* file, int attr);
int onplay(char* file, int attr, int from_screen);
enum {
ONPLAY_OK,

View file

@ -20,34 +20,13 @@
#include <string.h>
#include "menu.h"
#include "file.h"
#include "keyboard.h"
#include "playlist.h"
#include "tree.h"
#include "settings.h"
#include "playlist_viewer.h"
#include "talk.h"
#include "lang.h"
#define DEFAULT_PLAYLIST_NAME "/dynamic.m3u"
static bool save_playlist(void)
{
char filename[MAX_PATH+1];
strncpy(filename, DEFAULT_PLAYLIST_NAME, sizeof(filename));
if (!kbd_input(filename, sizeof(filename)))
{
playlist_save(NULL, filename);
/* reload in case playlist was saved to cwd */
reload_directory();
}
return false;
}
static bool recurse_directory(void)
{
static const struct opt_items names[] = {
@ -67,9 +46,6 @@ bool playlist_menu(void)
bool result;
static const struct menu_item items[] = {
{ ID2P(LANG_CREATE_PLAYLIST), create_playlist },
{ ID2P(LANG_VIEW_DYNAMIC_PLAYLIST), playlist_viewer },
{ ID2P(LANG_SAVE_DYNAMIC_PLAYLIST), save_playlist },
{ ID2P(LANG_RECURSE_DIRECTORY), recurse_directory },
};

View file

@ -33,6 +33,7 @@
#include "onplay.h"
#include "talk.h"
#include "misc.h"
#include "action.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@ -728,7 +729,7 @@ static int onplay_menu(int index)
break;
case 2:
{
onplay(tracks[index].name, TREE_ATTR_MPA);
onplay(tracks[index].name, TREE_ATTR_MPA, CONTEXT_TREE);
if (!viewer.playlist)
ret = 1;

View file

@ -110,6 +110,7 @@ static bool reload_dir = false;
static bool start_wps = false;
static bool dirbrowse(void);
static int curr_context = false;
bool check_rockboxdir(void)
{
@ -625,11 +626,15 @@ static bool check_changed_id3mode(bool currmode)
if (currmode != (global_settings.dirfilter == SHOW_ID3DB)) {
currmode = global_settings.dirfilter == SHOW_ID3DB;
if (currmode) {
curr_context=CONTEXT_ID3DB;
db_load(&tc);
}
else
{
curr_context=CONTEXT_TREE;
ft_load(&tc, NULL);
}
}
return currmode;
}
@ -660,6 +665,11 @@ static bool dirbrowse(void)
char* currdir = tc.currdir; /* just a shortcut */
bool id3db = *tc.dirfilter == SHOW_ID3DB;
if (id3db)
curr_context=CONTEXT_ID3DB;
else
curr_context=CONTEXT_TREE;
#ifdef HAVE_LCD_BITMAP
tree_max_on_screen = recalc_screen_height();
#else
@ -1059,7 +1069,7 @@ static bool dirbrowse(void)
/* don't enter f2 from plugin browser */
if (*tc.dirfilter < NUM_FILTER_MODES)
{
if (quick_screen(CONTEXT_TREE, BUTTON_F2))
if (quick_screen(curr_context, BUTTON_F2))
reload_dir = true;
restore = true;
@ -1071,7 +1081,7 @@ static bool dirbrowse(void)
/* don't enter f3 from plugin browser */
if (*tc.dirfilter < NUM_FILTER_MODES)
{
if (quick_screen(CONTEXT_TREE, BUTTON_F3))
if (quick_screen(curr_context, BUTTON_F3))
reload_dir = true;
tree_max_on_screen = recalc_screen_height();
restore = true;
@ -1091,7 +1101,7 @@ static bool dirbrowse(void)
int attr = 0;
if(!numentries)
onplay_result = onplay(NULL, 0);
onplay_result = onplay(NULL, 0, curr_context);
else {
if (currdir[1])
snprintf(buf, sizeof buf, "%s/%s",
@ -1099,9 +1109,19 @@ static bool dirbrowse(void)
else
snprintf(buf, sizeof buf, "/%s",
dircache[tc.dircursor+tc.dirstart].name);
if (!id3db)
if (id3db)
switch (tc.currtable)
{
case allsongs:
case songs4album:
case songs4artist:
case searchsongs:
attr=TREE_ATTR_MPA;
break;
}
else
attr = dircache[tc.dircursor+tc.dirstart].attr;
onplay_result = onplay(buf, attr);
onplay_result = onplay(buf, attr, curr_context);
}
switch (onplay_result)

View file

@ -50,6 +50,7 @@
#include "bookmark.h"
#include "misc.h"
#include "sound.h"
#include "onplay.h"
#define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
/* 3% of 30min file == 54s step size */
@ -472,6 +473,12 @@ long wps_show(void)
switch(button)
{
#ifdef WPS_CONTEXT
case WPS_CONTEXT:
onplay(id3->path, TREE_ATTR_MPA, CONTEXT_WPS);
restore = true;
break;
#endif
#ifdef WPS_RC_BROWSE
case WPS_RC_BROWSE:
#endif
@ -502,6 +509,14 @@ long wps_show(void)
case WPS_PAUSE:
#ifdef WPS_RC_PAUSE
case WPS_RC_PAUSE:
#endif
#ifdef WPS_PAUSE_PRE
if ((lastbutton != WPS_PAUSE_PRE)
#ifdef WPS_RC_PAUSE_PRE
&& (lastbutton != WPS_RC_PAUSE_PRE)
#endif
)
break;
#endif
if ( paused )
{

View file

@ -38,6 +38,7 @@
#define WPS_BROWSE_PRE BUTTON_SELECT
#define WPS_EXIT BUTTON_OFF
#define WPS_ID3 (BUTTON_MODE | BUTTON_ON)
#define WPS_CONTEXT (BUTTON_SELECT | BUTTON_REPEAT)
#define WPS_RC_NEXT BUTTON_RC_FF
#define WPS_RC_PREV BUTTON_RC_REW
@ -59,7 +60,8 @@
#define WPS_REW (BUTTON_LEFT | BUTTON_REPEAT)
#define WPS_INCVOL BUTTON_UP
#define WPS_DECVOL BUTTON_DOWN
#define WPS_PAUSE BUTTON_PLAY
#define WPS_PAUSE_PRE BUTTON_PLAY
#define WPS_PAUSE (BUTTON_PLAY | BUTTON_REL)
#define WPS_MENU (BUTTON_F1 | BUTTON_REL)
#define WPS_MENU_PRE BUTTON_F1
#define WPS_BROWSE (BUTTON_ON | BUTTON_REL)
@ -67,6 +69,7 @@
#define WPS_EXIT BUTTON_OFF
#define WPS_KEYLOCK (BUTTON_F1 | BUTTON_DOWN)
#define WPS_ID3 (BUTTON_F1 | BUTTON_ON)
#define WPS_CONTEXT (BUTTON_PLAY | BUTTON_REPEAT)
#define WPS_RC_NEXT BUTTON_RC_RIGHT
#define WPS_RC_PREV BUTTON_RC_LEFT
@ -84,7 +87,8 @@
#define WPS_REW (BUTTON_LEFT | BUTTON_REPEAT)
#define WPS_INCVOL (BUTTON_MENU | BUTTON_RIGHT)
#define WPS_DECVOL (BUTTON_MENU | BUTTON_LEFT)
#define WPS_PAUSE BUTTON_PLAY
#define WPS_PAUSE_PRE BUTTON_PLAY
#define WPS_PAUSE (BUTTON_PLAY | BUTTON_REL)
#define WPS_MENU (BUTTON_MENU | BUTTON_REL)
#define WPS_MENU_PRE BUTTON_MENU
#define WPS_BROWSE (BUTTON_ON | BUTTON_REL)
@ -92,6 +96,7 @@
#define WPS_EXIT BUTTON_STOP
#define WPS_KEYLOCK (BUTTON_MENU | BUTTON_STOP)
#define WPS_ID3 (BUTTON_MENU | BUTTON_ON)
#define WPS_CONTEXT (BUTTON_PLAY | BUTTON_REPEAT)
#define WPS_RC_NEXT BUTTON_RC_RIGHT
#define WPS_RC_PREV BUTTON_RC_LEFT