diff --git a/apps/SOURCES b/apps/SOURCES index 67e09ed53d..dc93eeebbc 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -41,6 +41,7 @@ gui/statusbar.c gui/gwps.c gui/gwps-common.c gui/textarea.c +gui/yesno.c #ifdef HAVE_LCD_CHARCELLS player/icons.c diff --git a/apps/gui/textarea.c b/apps/gui/textarea.c index d8e730fdc2..d73f20d0e7 100644 --- a/apps/gui/textarea.c +++ b/apps/gui/textarea.c @@ -41,6 +41,18 @@ void gui_textarea_update(struct screen * display) } #endif +int gui_textarea_put_message(struct screen * display, + struct text_message * message, + int ystart) +{ + int i; + gui_textarea_clear(display); + for(i=0;inb_lines && i+ystartnb_lines;i++) + display->puts(0, i+ystart, message->message_lines[i]); + gui_textarea_update(display); + return(i); +} + void gui_textarea_update_nblines(struct screen * display) { #ifdef HAVE_LCD_BITMAP diff --git a/apps/gui/textarea.h b/apps/gui/textarea.h index 5249aed7a5..b1af1a5aba 100644 --- a/apps/gui/textarea.h +++ b/apps/gui/textarea.h @@ -23,6 +23,12 @@ #include "settings.h" #include "statusbar.h" +struct text_message +{ + char **message_lines; + int nb_lines; +}; + /* * Clears the area in the screen in which text can be displayed * and sets the y margin properly @@ -45,6 +51,16 @@ extern void gui_textarea_update(struct screen * display); #endif #endif +/* + * Displays message lines on the given screen + * - display : the screen structure + * - message : the lines to display + * - ystart : the lineon which we start displaying + * returns : the number of lines effectively displayed + */ +extern int gui_textarea_put_message(struct screen * display, + struct text_message * message, + int ystart); /* * Compute the number of text lines the display can draw with the current font * Also updates the char height and width diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c new file mode 100644 index 0000000000..65f81aaf3e --- /dev/null +++ b/apps/gui/yesno.c @@ -0,0 +1,96 @@ +#include "yesno.h" +#include "kernel.h" +#include "misc.h" +#include "lang.h" + +void gui_yesno_init(struct gui_yesno * yn, + struct text_message * main_message, + struct text_message * yes_message, + struct text_message * no_message) +{ + yn->main_message=main_message; + yn->result_message[YESNO_YES]=yes_message; + yn->result_message[YESNO_NO]=no_message; + yn->display=0; +} + +void gui_yesno_set_display(struct gui_yesno * yn, + struct screen * display) +{ + yn->display=display; +} + +void gui_yesno_draw(struct gui_yesno * yn) +{ + struct screen * display=yn->display; + int nb_lines, line_shift=0; +#ifdef HAS_LCD_BITMAP + screen_set_xmargin(display, 0); +#endif + gui_textarea_clear(display); + nb_lines=yn->main_message->nb_lines; + + if(nb_lines+3nb_lines) + line_shift=1; + nb_lines=gui_textarea_put_message(display, yn->main_message, line_shift); + + /* Space remaining for yes / no text ? */ + if(nb_lines+line_shift+2<=display->nb_lines) + { + if(nb_lines+line_shift+3<=display->nb_lines) + nb_lines++; + display->puts(0, nb_lines+line_shift, str(LANG_CONFIRM_WITH_PLAY_RECORDER)); + display->puts(0, nb_lines+line_shift+1, str(LANG_CANCEL_WITH_ANY_RECORDER)); + } + gui_textarea_update(display); +} + +bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result) +{ + struct text_message * message=yn->result_message[result]; + if(message==NULL) + return false; + gui_textarea_put_message(yn->display, message, 0); + return(true); +} + +enum yesno_res gui_syncyesno_run(struct text_message * main_message, + struct text_message * yes_message, + struct text_message * no_message) +{ + int i; + unsigned button; + int result=-1; + bool result_displayed; + struct gui_yesno yn[NB_SCREENS]; + FOR_NB_SCREENS(i) + { + gui_yesno_init(&(yn[i]), main_message, yes_message, no_message); + gui_yesno_set_display(&(yn[i]), &(screens[i])); + gui_yesno_draw(&(yn[i])); + } + while (result==-1) + { + button = button_get(true); + switch (button) + { + case YESNO_OK: +#ifdef TREE_RC_RUN + case YESNO_RC_OK: +#endif + result=YESNO_YES; + break; + + default: + if(default_event_handler(button) == SYS_USB_CONNECTED) + return(YESNO_USB); + if(!(button & BUTTON_REL)) + result=YESNO_NO; + } + } + FOR_NB_SCREENS(i) + result_displayed=gui_yesno_draw_result(&(yn[i]), result); + if(result_displayed) + sleep(HZ); + return(result); +} diff --git a/apps/gui/yesno.h b/apps/gui/yesno.h new file mode 100644 index 0000000000..ac6500daf8 --- /dev/null +++ b/apps/gui/yesno.h @@ -0,0 +1,91 @@ +#ifndef _GUI_YESNO_H_ +#define _GUI_YESNO_H_ + +#include "screen_access.h" +#include "textarea.h" + +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) +#define YESNO_OK BUTTON_SELECT +#define YESNO_RC_OK BUTTON_RC_MENU + +#elif CONFIG_KEYPAD == RECORDER_PAD +#define YESNO_OK BUTTON_PLAY +#define YESNO_RC_OK BUTTON_RC_PLAY + +#elif CONFIG_KEYPAD == PLAYER_PAD +#define YESNO_OK BUTTON_PLAY +#define YESNO_RC_OK BUTTON_RC_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define YESNO_OK BUTTON_RIGHT + +#elif CONFIG_KEYPAD == GMINI100_PAD +#define YESNO_OK BUTTON_PLAY + +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_NANO_PAD) +#define YESNO_OK BUTTON_RIGHT +#endif +enum yesno_res +{ + YESNO_YES, + YESNO_NO, + YESNO_USB +}; + +struct gui_yesno +{ + struct text_message * main_message; + struct text_message * result_message[2]; + + struct screen * display; +}; + +/* + * Initializes the yesno asker + * - yn : the yesno structure + * - main_message : the question the user has to answer + * - yes_message : message displayed if answer is 'yes' + * - no_message : message displayed if answer is 'no' + */ +extern void gui_yesno_init(struct gui_yesno * yn, + struct text_message * main_message, + struct text_message * yes_message, + struct text_message * no_message); + +/* + * Attach the yesno to a screen + * - yn : the yesno structure + * - display : the screen to attach + */ +extern void gui_yesno_set_display(struct gui_yesno * yn, + struct screen * display); + +/* + * Draws the yesno + * - yn : the yesno structure + */ +extern void gui_yesno_draw(struct gui_yesno * yn); + +/* + * Draws the yesno result + * - yn : the yesno structure + * - result : the result tha must be displayed : + * YESNO_NO if no + * YESNO_YES if yes + */ +extern bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result); + +/* + * Runs the yesno asker : + * it will display the 'main_message' question, and wait for user keypress + * PLAY means yes, other keys means no + * - main_message : the question the user has to answer + * - yes_message : message displayed if answer is 'yes' + * - no_message : message displayed if answer is 'no' + */ +extern enum yesno_res gui_syncyesno_run( + struct text_message * main_message, + struct text_message * yes_message, + struct text_message * no_message); +#endif /* _GUI_YESNO_H_ */ diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 8695177a00..82c25af433 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -52,6 +52,7 @@ #include "dir.h" #include "dircache.h" #include "splash.h" +#include "yesno.h" #ifdef HAVE_LCD_BITMAP #include "peakmeter.h" @@ -1428,49 +1429,24 @@ static bool bookmark_settings_menu(void) } static bool reset_settings(void) { - bool done=false; - int line; - int button; - - lcd_clear_display(); + char *lines[]={str(LANG_RESET_ASK_RECORDER)}; + char *yes_lines[]={str(LANG_RESET_DONE_SETTING), str(LANG_RESET_DONE_CLEAR)}; + char *no_lines[]={yes_lines[0], str(LANG_RESET_DONE_CANCEL)}; + struct text_message message={lines, 1}; + struct text_message yes_message={yes_lines, 2}; + struct text_message no_message={no_lines, 2}; -#ifdef HAVE_LCD_CHARCELLS - line = 0; -#else - line = 1; - lcd_puts(0,0,str(LANG_RESET_ASK_RECORDER)); -#endif - lcd_puts(0,line,str(LANG_RESET_CONFIRM)); - lcd_puts(0,line+1,str(LANG_RESET_CANCEL)); - - lcd_update(); - - while(!done) { - button = button_get(true); - switch(button) { - case SETTINGS_OK: - settings_reset(); - settings_apply(); - lcd_clear_display(); - lcd_puts(0,1,str(LANG_RESET_DONE_CLEAR)); - done = true; - break; - - case SETTINGS_CANCEL: - lcd_clear_display(); - lcd_puts(0,1,str(LANG_RESET_DONE_CANCEL)); - done = true; - break; - - default: - if(default_event_handler(button) == SYS_USB_CONNECTED) - return true; - } + switch(gui_syncyesno_run(&message, &yes_message, &no_message)) + { + case YESNO_YES: + settings_reset(); + settings_apply(); + break; + case YESNO_NO: + break; + case YESNO_USB: + return true; } - - lcd_puts(0,0,str(LANG_RESET_DONE_SETTING)); - lcd_update(); - sleep(HZ); return false; } diff --git a/apps/tree.c b/apps/tree.c index 39980b1b81..284fdcbdc7 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -61,6 +61,7 @@ #include "recorder/recording.h" #include "rtc.h" #include "dircache.h" +#include "yesno.h" /* gui api */ #include "list.h" @@ -561,47 +562,17 @@ static bool dirbrowse(void) while(1) { struct entry *dircache = tc.dircache; bool restore = false; - - button = button_get_w_tmo(HZ/5); #ifdef BOOTFILE if (boot_changed) { - bool stop = false; - unsigned int button; - int i; - FOR_NB_SCREENS(i) - { - gui_textarea_clear(&screens[i]); - screens[i].puts(0,0,str(LANG_BOOT_CHANGED)); - screens[i].puts(0,1,str(LANG_REBOOT_NOW)); -#ifdef HAVE_LCD_BITMAP - screens[i].puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER)); - screens[i].puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER)); - gui_textarea_update(&screens[i]); -#endif - } - while (!stop) { - button = button_get(true); - switch (button) { - case TREE_RUN: -#ifdef TREE_RC_RUN - case TREE_RC_RUN: -#endif - rolo_load("/" BOOTFILE); - stop = true; - break; - - default: - if(default_event_handler(button) || - (button & BUTTON_REL)) - stop = true; - break; - } - } - + char *lines[]={str(LANG_BOOT_CHANGED), str(LANG_REBOOT_NOW)}; + struct text_message message={lines, 2}; + if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) + rolo_load("/" BOOTFILE); restore = true; boot_changed = false; } #endif + button = button_get_w_tmo(HZ/5); need_update = gui_synclist_do_button(&tree_lists, button); switch ( button ) { diff --git a/apps/tree.h b/apps/tree.h index 55dfc562b9..aa7571acdc 100644 --- a/apps/tree.h +++ b/apps/tree.h @@ -46,18 +46,18 @@ #define TREE_QUICK (BUTTON_MODE | BUTTON_REPEAT) /* Remote keys */ -#define TREE_RC_NEXT BUTTON_RC_FF -#define TREE_RC_PREV BUTTON_RC_REW -#define TREE_RC_PGUP BUTTON_RC_SOURCE -#define TREE_RC_PGDN BUTTON_RC_BITRATE -#define TREE_RC_EXIT BUTTON_RC_STOP -#define TREE_RC_RUN (BUTTON_RC_MENU | BUTTON_REL) -#define TREE_RC_RUN_PRE BUTTON_RC_MENU -#define TREE_RC_MENU ( BUTTON_RC_MODE | BUTTON_REL) +#define TREE_RC_NEXT BUTTON_RC_FF +#define TREE_RC_PREV BUTTON_RC_REW +#define TREE_RC_PGUP BUTTON_RC_SOURCE +#define TREE_RC_PGDN BUTTON_RC_BITRATE +#define TREE_RC_EXIT BUTTON_RC_STOP +#define TREE_RC_RUN (BUTTON_RC_MENU | BUTTON_REL) +#define TREE_RC_RUN_PRE BUTTON_RC_MENU +#define TREE_RC_MENU (BUTTON_RC_MODE | BUTTON_REL) #define TREE_RC_MENU_PRE BUTTON_RC_MODE -#define TREE_RC_WPS (BUTTON_RC_ON | BUTTON_REL) -#define TREE_RC_WPS_PRE BUTTON_RC_ON -#define TREE_RC_CONTEXT (BUTTON_RC_ON | BUTTON_REPEAT) +#define TREE_RC_WPS (BUTTON_RC_ON | BUTTON_REL) +#define TREE_RC_WPS_PRE BUTTON_RC_ON +#define TREE_RC_CONTEXT (BUTTON_RC_ON | BUTTON_REPEAT) #elif CONFIG_KEYPAD == RECORDER_PAD #define TREE_NEXT BUTTON_DOWN