From 5cd393c772ce6d9f8f7eff5dc97b007b8249d9f6 Mon Sep 17 00:00:00 2001 From: Kjell Ericson Date: Wed, 29 Jan 2003 08:26:11 +0000 Subject: New onplay-menu for the Player. The menu_run() function is split into two functions, where the new menu_run() works like before, and the new function menu_show() returns the menu item number you selected. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3180 a1c6a512-1295-4272-9138-f99709370657 --- apps/menu.c | 34 +++++++++++-------- apps/menu.h | 8 +++++ apps/tree.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 14 deletions(-) diff --git a/apps/menu.c b/apps/menu.c index 9cedbebed8..4f15b4b8ae 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -231,7 +231,7 @@ void menu_exit(int m) inuse[m] = false; } -bool menu_run(int m) +int menu_show(int m) { bool exit = false; @@ -289,17 +289,7 @@ bool menu_run(int m) case BUTTON_PLAY: /* Erase current display state */ lcd_clear_display(); - - /* if a child returns that USB was used, - we return immediately */ - if (menus[m].items[menus[m].cursor].function()) { - lcd_stop_scroll(); /* just in case */ - return true; - } - - /* Return to previous display state */ - menu_draw(m); - break; + return menus[m].cursor; #ifdef HAVE_RECORDER_KEYPAD case BUTTON_LEFT: @@ -331,11 +321,27 @@ bool menu_run(int m) #ifdef HAVE_LCD_CHARCELLS status_set_param(false); #endif - return true; + return MENU_ATTACHED_USB; } status_draw(); } + return MENU_SELECTED_EXIT; +} + - return false; +bool menu_run(int m) +{ + bool stop=false; + while (!stop) { + int result=menu_show(m); + if (result == MENU_SELECTED_EXIT) + return false; + else if (result == MENU_ATTACHED_USB) + return true; + if (menus[m].items[menus[m].cursor].function()) { + return true; + } + } + return false; } diff --git a/apps/menu.h b/apps/menu.h index a21d07a7ee..632db87e4b 100644 --- a/apps/menu.h +++ b/apps/menu.h @@ -32,6 +32,14 @@ void menu_exit(int menu); void put_cursorxy(int x, int y, bool on); + /* Returns below define, or number of selected menu item*/ +int menu_show(int m); +#define MENU_ATTACHED_USB -1 +#define MENU_SELECTED_EXIT -2 + bool menu_run(int menu); #endif /* End __MENU_H__ */ + + + diff --git a/apps/tree.c b/apps/tree.c index a918ecd8fa..43bd5e6f5c 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -642,6 +642,7 @@ void set_current_file(char *path) } } +#ifdef HAVE_LCD_BITMAP static int onplay_screen(char* dir, char* file) { bool exit = false; @@ -789,6 +790,115 @@ static int onplay_screen(char* dir, char* file) return false; } +#else + +static int onplay_screen(char* dir, char* file) +{ + bool exit = false; + bool playing = mpeg_status() & MPEG_STATUS_PLAY; + char buf[MAX_PATH]; + struct entry* f = &dircache[dirstart + dircursor]; + bool isdir = f->attr & ATTR_DIRECTORY; + struct menu_items items[3]; + int ids[3]; + int lastitem=0; + int m_handle; + int selected; + + if ((dir[0]=='/') && (dir[1]==0)) + snprintf(buf, sizeof buf, "%s%s", dir, file); + else + snprintf(buf, sizeof buf, "%s/%s", dir, file); + + if (playing) { + items[lastitem].desc=str(LANG_QUEUE); + ids[lastitem]=1; + lastitem++; + } + + items[lastitem].desc=str(LANG_RENAME); + ids[lastitem]=2; + lastitem++; + + /* don't delete directories */ + if (!isdir) { + items[lastitem].desc=str(LANG_DELETE); + ids[lastitem]=3; + lastitem++; + } + m_handle=menu_init(items, lastitem); + + selected=menu_show(m_handle); + if (selected>=0) { + switch(ids[selected]) { + case 1: + if (playing) + queue_add(buf); + break; + case 2: + { + char newname[MAX_PATH]; + char* ptr = strrchr(buf, '/') + 1; + int pathlen = (ptr - buf); + strncpy(newname, buf, sizeof newname); + if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { + if (rename(buf, newname) < 0) { + lcd_clear_display(); + lcd_puts(0,0,str(LANG_RENAME)); + lcd_puts(0,1,str(LANG_FAILED)); + lcd_update(); + sleep(HZ*2); + } + else + reload_dir = true; + } + } + break; + case 3: + lcd_clear_display(); +#ifdef HAVE_LCD_CHARCELLS + lcd_puts(0,0,file); + lcd_puts(0,1,str(LANG_REALLY_DELETE)); +#else + lcd_puts(0,0,str(LANG_REALLY_DELETE)); + lcd_puts(0,1,file); + lcd_puts(0,3,str(LANG_RESUME_CONFIRM_RECORDER)); + lcd_puts(0,4,str(LANG_RESUME_CANCEL_RECORDER)); +#endif + lcd_update(); + { + while (!exit) { + int btn = button_get(true); + switch (btn) { + case BUTTON_PLAY: + case BUTTON_PLAY | BUTTON_REL: + if (!remove(buf)) { + reload_dir = true; + lcd_clear_display(); + lcd_puts(0,0,file); + lcd_puts(0,1,str(LANG_DELETED)); + lcd_update(); + sleep(HZ); + exit = true; + break; + } + + default: + /* ignore button releases */ + if (!(btn & BUTTON_REL)) + exit = true; + break; + } + } + } + break; + } + } + menu_exit(m_handle); + return false; +} +#endif + static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) -- cgit v1.2.3