diff options
Diffstat (limited to 'apps/gui/yesno.c')
-rw-r--r-- | apps/gui/yesno.c | 113 |
1 files changed, 105 insertions, 8 deletions
diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c index c763753cd7..421e158c78 100644 --- a/apps/gui/yesno.c +++ b/apps/gui/yesno.c @@ -30,6 +30,8 @@ #include "viewport.h" #include "appevents.h" +#include <stdio.h> +#include "splash.h" struct gui_yesno { @@ -38,6 +40,9 @@ struct gui_yesno struct viewport *vp; struct screen * display; + /* timeout data */ + long end_tick; + enum yesno_res tmo_default_res; }; static void talk_text_message(const struct text_message * message, bool enqueue) @@ -80,6 +85,8 @@ static void gui_yesno_draw(struct gui_yesno * yn) struct viewport *vp = yn->vp; int nb_lines, vp_lines, line_shift=0; struct viewport *last_vp; + enum yesno_res def_res = yn->tmo_default_res; + long end_tick = yn->end_tick; last_vp = display->set_viewport(vp); display->clear_viewport(); @@ -91,20 +98,53 @@ static void gui_yesno_draw(struct gui_yesno * yn) line_shift += put_message(display, yn->main_message, line_shift, vp_lines); + #ifdef HAVE_TOUCHSCREEN if (display->screen_type == SCREEN_MAIN) { - int w,h; + int w,h,tmo_w; + int tm_rem = 0; + const char *btn_fmt; int rect_w = vp->width/2, rect_h = vp->height/2; int old_pattern = vp->fg_pattern; vp->fg_pattern = LCD_RGBPACK(0,255,0); display->drawrect(0, rect_h, rect_w, rect_h); display->getstringsize(str(LANG_SET_BOOL_YES), &w, &h); - display->putsxy((rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_YES)); + + if (def_res == YESNO_YES) + { + display->getstringsize(" (0)", &tmo_w, NULL); + tm_rem = ((end_tick - current_tick) / 100); + btn_fmt = "%s (%d)"; + } + else + { + btn_fmt = "%s\0%d"; + tmo_w = 0; + } + + display->putsxyf((rect_w-(w+tmo_w))/2, rect_h+(rect_h-h)/2, + btn_fmt, str(LANG_SET_BOOL_YES), tm_rem); + vp->fg_pattern = LCD_RGBPACK(255,0,0); display->drawrect(rect_w, rect_h, rect_w, rect_h); display->getstringsize(str(LANG_SET_BOOL_NO), &w, &h); - display->putsxy(rect_w + (rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_NO)); + + if (def_res == YESNO_NO) + { + display->getstringsize(" (0)", &tmo_w, NULL); + tm_rem = ((end_tick - current_tick) / 100); + btn_fmt = "%s (%d)"; + } + else + { + btn_fmt = "%s\0%d"; + tmo_w = 0; + } + + display->putsxyf(rect_w + (rect_w-(w+tmo_w))/2, rect_h+(rect_h-h)/2, + btn_fmt, str(LANG_SET_BOOL_NO), tm_rem); + vp->fg_pattern = old_pattern; } #else @@ -115,6 +155,15 @@ static void gui_yesno_draw(struct gui_yesno * yn) line_shift++; display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON)); display->puts(0, line_shift+1, str(LANG_CANCEL_WITH_ANY)); + + if (def_res == YESNO_YES || def_res == YESNO_NO) + { + int tm_rem = ((end_tick - current_tick) / 100); + if (def_res == YESNO_YES) + display->putsf(0, line_shift, "%s (%d)", str(LANG_CONFIRM_WITH_BUTTON), tm_rem); + else + display->putsf(0, line_shift+1, "%s (%d)", str(LANG_CANCEL_WITH_ANY), tm_rem); + } } #endif display->update_viewport(); @@ -124,7 +173,7 @@ static void gui_yesno_draw(struct gui_yesno * yn) /* * Draws the yesno result * - yn : the yesno structure - * - result : the result tha must be displayed : + * - result : the result to be displayed : * YESNO_NO if no * YESNO_YES if yes */ @@ -153,9 +202,24 @@ static void gui_yesno_ui_update(unsigned short id, void *event_data, void *user_ gui_yesno_draw(&yn[i]); } -enum yesno_res gui_syncyesno_run(const struct text_message * main_message, - const struct text_message * yes_message, - const struct text_message * no_message) +/* Display a YES_NO prompt to the user + * + * ticks < HZ will be ignored and the prompt will be blocking + * tmo_default_res is the answer that is returned when the timeout expires + * a default result of YESNO_TMO will also make the prompt blocking + * if tmo_default_res is YESNO_YES or YESNO_NO a seconds countdown will + * be present next to the default option + * + * ticks - timeout if (>=HZ) otherwise ignored + * default_res - result returned on timeout YESNO_TMO creates a blocking prompt + * main_message - prompt to the user + * yes_message - displayed when YESNO_YES is choosen + * no_message - displayed when YESNO_NO is choosen +*/ +enum yesno_res gui_syncyesno_run_w_tmo(int ticks, enum yesno_res tmo_default_res, + const struct text_message * main_message, + const struct text_message * yes_message, + const struct text_message * no_message) { int button; int result=-1; @@ -163,8 +227,24 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, struct gui_yesno yn[NB_SCREENS]; struct viewport vp[NB_SCREENS]; long talked_tick = 0; + long end_tick = current_tick + ticks; + long button_scan_tmo; + + if (ticks >= HZ) /* Display a prompt with timeout to the user */ + { + button_scan_tmo = HZ/2; + } + else + { + tmo_default_res = YESNO_TMO; + button_scan_tmo = HZ*5; + } + FOR_NB_SCREENS(i) { + yn[i].end_tick = end_tick; + yn[i].tmo_default_res = tmo_default_res; + yn[i].main_message=main_message; yn[i].result_message[YESNO_YES]=yes_message; yn[i].result_message[YESNO_NO]=no_message; @@ -198,7 +278,10 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, talked_tick = current_tick; talk_text_message(main_message, false); } - button = get_action(CONTEXT_YESNOSCREEN, HZ*5); + send_event(GUI_EVENT_NEED_UI_UPDATE, NULL); + + button = get_action(CONTEXT_YESNOSCREEN, button_scan_tmo); + switch (button) { #ifdef HAVE_TOUCHSCREEN @@ -222,6 +305,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, result=YESNO_YES; break; case ACTION_NONE: + if(tmo_default_res != YESNO_TMO && end_tick <= current_tick) + { + splash(HZ/2, ID2P(LANG_TIMEOUT)); + result = tmo_default_res; + break; + } + /*fall-through*/ case ACTION_UNKNOWN: case SYS_CHARGER_DISCONNECTED: case SYS_BATTERY_UPDATE: @@ -268,6 +358,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, return result; } +enum yesno_res gui_syncyesno_run(const struct text_message * main_message, + const struct text_message * yes_message, + const struct text_message * no_message) +{ + return gui_syncyesno_run_w_tmo(TIMEOUT_BLOCK, YESNO_TMO, + main_message, yes_message, no_message); +} /* Function to manipulate all yesno dialogues. This function needs the output text as an argument. */ |