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 @@ | |||
30 | #include "viewport.h" | 30 | #include "viewport.h" |
31 | #include "appevents.h" | 31 | #include "appevents.h" |
32 | 32 | ||
33 | #include <stdio.h> | ||
34 | #include "splash.h" | ||
33 | 35 | ||
34 | struct gui_yesno | 36 | struct gui_yesno |
35 | { | 37 | { |
@@ -38,6 +40,9 @@ struct gui_yesno | |||
38 | 40 | ||
39 | struct viewport *vp; | 41 | struct viewport *vp; |
40 | struct screen * display; | 42 | struct screen * display; |
43 | /* timeout data */ | ||
44 | long end_tick; | ||
45 | enum yesno_res tmo_default_res; | ||
41 | }; | 46 | }; |
42 | 47 | ||
43 | static void talk_text_message(const struct text_message * message, bool enqueue) | 48 | 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) | |||
80 | struct viewport *vp = yn->vp; | 85 | struct viewport *vp = yn->vp; |
81 | int nb_lines, vp_lines, line_shift=0; | 86 | int nb_lines, vp_lines, line_shift=0; |
82 | struct viewport *last_vp; | 87 | struct viewport *last_vp; |
88 | enum yesno_res def_res = yn->tmo_default_res; | ||
89 | long end_tick = yn->end_tick; | ||
83 | 90 | ||
84 | last_vp = display->set_viewport(vp); | 91 | last_vp = display->set_viewport(vp); |
85 | display->clear_viewport(); | 92 | display->clear_viewport(); |
@@ -91,20 +98,53 @@ static void gui_yesno_draw(struct gui_yesno * yn) | |||
91 | 98 | ||
92 | line_shift += put_message(display, yn->main_message, | 99 | line_shift += put_message(display, yn->main_message, |
93 | line_shift, vp_lines); | 100 | line_shift, vp_lines); |
101 | |||
94 | #ifdef HAVE_TOUCHSCREEN | 102 | #ifdef HAVE_TOUCHSCREEN |
95 | if (display->screen_type == SCREEN_MAIN) | 103 | if (display->screen_type == SCREEN_MAIN) |
96 | { | 104 | { |
97 | int w,h; | 105 | int w,h,tmo_w; |
106 | int tm_rem = 0; | ||
107 | const char *btn_fmt; | ||
98 | int rect_w = vp->width/2, rect_h = vp->height/2; | 108 | int rect_w = vp->width/2, rect_h = vp->height/2; |
99 | int old_pattern = vp->fg_pattern; | 109 | int old_pattern = vp->fg_pattern; |
100 | vp->fg_pattern = LCD_RGBPACK(0,255,0); | 110 | vp->fg_pattern = LCD_RGBPACK(0,255,0); |
101 | display->drawrect(0, rect_h, rect_w, rect_h); | 111 | display->drawrect(0, rect_h, rect_w, rect_h); |
102 | display->getstringsize(str(LANG_SET_BOOL_YES), &w, &h); | 112 | display->getstringsize(str(LANG_SET_BOOL_YES), &w, &h); |
103 | display->putsxy((rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_YES)); | 113 | |
114 | if (def_res == YESNO_YES) | ||
115 | { | ||
116 | display->getstringsize(" (0)", &tmo_w, NULL); | ||
117 | tm_rem = ((end_tick - current_tick) / 100); | ||
118 | btn_fmt = "%s (%d)"; | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | btn_fmt = "%s\0%d"; | ||
123 | tmo_w = 0; | ||
124 | } | ||
125 | |||
126 | display->putsxyf((rect_w-(w+tmo_w))/2, rect_h+(rect_h-h)/2, | ||
127 | btn_fmt, str(LANG_SET_BOOL_YES), tm_rem); | ||
128 | |||
104 | vp->fg_pattern = LCD_RGBPACK(255,0,0); | 129 | vp->fg_pattern = LCD_RGBPACK(255,0,0); |
105 | display->drawrect(rect_w, rect_h, rect_w, rect_h); | 130 | display->drawrect(rect_w, rect_h, rect_w, rect_h); |
106 | display->getstringsize(str(LANG_SET_BOOL_NO), &w, &h); | 131 | display->getstringsize(str(LANG_SET_BOOL_NO), &w, &h); |
107 | display->putsxy(rect_w + (rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_NO)); | 132 | |
133 | if (def_res == YESNO_NO) | ||
134 | { | ||
135 | display->getstringsize(" (0)", &tmo_w, NULL); | ||
136 | tm_rem = ((end_tick - current_tick) / 100); | ||
137 | btn_fmt = "%s (%d)"; | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | btn_fmt = "%s\0%d"; | ||
142 | tmo_w = 0; | ||
143 | } | ||
144 | |||
145 | display->putsxyf(rect_w + (rect_w-(w+tmo_w))/2, rect_h+(rect_h-h)/2, | ||
146 | btn_fmt, str(LANG_SET_BOOL_NO), tm_rem); | ||
147 | |||
108 | vp->fg_pattern = old_pattern; | 148 | vp->fg_pattern = old_pattern; |
109 | } | 149 | } |
110 | #else | 150 | #else |
@@ -115,6 +155,15 @@ static void gui_yesno_draw(struct gui_yesno * yn) | |||
115 | line_shift++; | 155 | line_shift++; |
116 | display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON)); | 156 | display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON)); |
117 | display->puts(0, line_shift+1, str(LANG_CANCEL_WITH_ANY)); | 157 | display->puts(0, line_shift+1, str(LANG_CANCEL_WITH_ANY)); |
158 | |||
159 | if (def_res == YESNO_YES || def_res == YESNO_NO) | ||
160 | { | ||
161 | int tm_rem = ((end_tick - current_tick) / 100); | ||
162 | if (def_res == YESNO_YES) | ||
163 | display->putsf(0, line_shift, "%s (%d)", str(LANG_CONFIRM_WITH_BUTTON), tm_rem); | ||
164 | else | ||
165 | display->putsf(0, line_shift+1, "%s (%d)", str(LANG_CANCEL_WITH_ANY), tm_rem); | ||
166 | } | ||
118 | } | 167 | } |
119 | #endif | 168 | #endif |
120 | display->update_viewport(); | 169 | display->update_viewport(); |
@@ -124,7 +173,7 @@ static void gui_yesno_draw(struct gui_yesno * yn) | |||
124 | /* | 173 | /* |
125 | * Draws the yesno result | 174 | * Draws the yesno result |
126 | * - yn : the yesno structure | 175 | * - yn : the yesno structure |
127 | * - result : the result tha must be displayed : | 176 | * - result : the result to be displayed : |
128 | * YESNO_NO if no | 177 | * YESNO_NO if no |
129 | * YESNO_YES if yes | 178 | * YESNO_YES if yes |
130 | */ | 179 | */ |
@@ -153,9 +202,24 @@ static void gui_yesno_ui_update(unsigned short id, void *event_data, void *user_ | |||
153 | gui_yesno_draw(&yn[i]); | 202 | gui_yesno_draw(&yn[i]); |
154 | } | 203 | } |
155 | 204 | ||
156 | enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | 205 | /* Display a YES_NO prompt to the user |
157 | const struct text_message * yes_message, | 206 | * |
158 | const struct text_message * no_message) | 207 | * ticks < HZ will be ignored and the prompt will be blocking |
208 | * tmo_default_res is the answer that is returned when the timeout expires | ||
209 | * a default result of YESNO_TMO will also make the prompt blocking | ||
210 | * if tmo_default_res is YESNO_YES or YESNO_NO a seconds countdown will | ||
211 | * be present next to the default option | ||
212 | * | ||
213 | * ticks - timeout if (>=HZ) otherwise ignored | ||
214 | * default_res - result returned on timeout YESNO_TMO creates a blocking prompt | ||
215 | * main_message - prompt to the user | ||
216 | * yes_message - displayed when YESNO_YES is choosen | ||
217 | * no_message - displayed when YESNO_NO is choosen | ||
218 | */ | ||
219 | enum yesno_res gui_syncyesno_run_w_tmo(int ticks, enum yesno_res tmo_default_res, | ||
220 | const struct text_message * main_message, | ||
221 | const struct text_message * yes_message, | ||
222 | const struct text_message * no_message) | ||
159 | { | 223 | { |
160 | int button; | 224 | int button; |
161 | int result=-1; | 225 | int result=-1; |
@@ -163,8 +227,24 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
163 | struct gui_yesno yn[NB_SCREENS]; | 227 | struct gui_yesno yn[NB_SCREENS]; |
164 | struct viewport vp[NB_SCREENS]; | 228 | struct viewport vp[NB_SCREENS]; |
165 | long talked_tick = 0; | 229 | long talked_tick = 0; |
230 | long end_tick = current_tick + ticks; | ||
231 | long button_scan_tmo; | ||
232 | |||
233 | if (ticks >= HZ) /* Display a prompt with timeout to the user */ | ||
234 | { | ||
235 | button_scan_tmo = HZ/2; | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | tmo_default_res = YESNO_TMO; | ||
240 | button_scan_tmo = HZ*5; | ||
241 | } | ||
242 | |||
166 | FOR_NB_SCREENS(i) | 243 | FOR_NB_SCREENS(i) |
167 | { | 244 | { |
245 | yn[i].end_tick = end_tick; | ||
246 | yn[i].tmo_default_res = tmo_default_res; | ||
247 | |||
168 | yn[i].main_message=main_message; | 248 | yn[i].main_message=main_message; |
169 | yn[i].result_message[YESNO_YES]=yes_message; | 249 | yn[i].result_message[YESNO_YES]=yes_message; |
170 | yn[i].result_message[YESNO_NO]=no_message; | 250 | yn[i].result_message[YESNO_NO]=no_message; |
@@ -198,7 +278,10 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
198 | talked_tick = current_tick; | 278 | talked_tick = current_tick; |
199 | talk_text_message(main_message, false); | 279 | talk_text_message(main_message, false); |
200 | } | 280 | } |
201 | button = get_action(CONTEXT_YESNOSCREEN, HZ*5); | 281 | send_event(GUI_EVENT_NEED_UI_UPDATE, NULL); |
282 | |||
283 | button = get_action(CONTEXT_YESNOSCREEN, button_scan_tmo); | ||
284 | |||
202 | switch (button) | 285 | switch (button) |
203 | { | 286 | { |
204 | #ifdef HAVE_TOUCHSCREEN | 287 | #ifdef HAVE_TOUCHSCREEN |
@@ -222,6 +305,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
222 | result=YESNO_YES; | 305 | result=YESNO_YES; |
223 | break; | 306 | break; |
224 | case ACTION_NONE: | 307 | case ACTION_NONE: |
308 | if(tmo_default_res != YESNO_TMO && end_tick <= current_tick) | ||
309 | { | ||
310 | splash(HZ/2, ID2P(LANG_TIMEOUT)); | ||
311 | result = tmo_default_res; | ||
312 | break; | ||
313 | } | ||
314 | /*fall-through*/ | ||
225 | case ACTION_UNKNOWN: | 315 | case ACTION_UNKNOWN: |
226 | case SYS_CHARGER_DISCONNECTED: | 316 | case SYS_CHARGER_DISCONNECTED: |
227 | case SYS_BATTERY_UPDATE: | 317 | case SYS_BATTERY_UPDATE: |
@@ -268,6 +358,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
268 | return result; | 358 | return result; |
269 | } | 359 | } |
270 | 360 | ||
361 | enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | ||
362 | const struct text_message * yes_message, | ||
363 | const struct text_message * no_message) | ||
364 | { | ||
365 | return gui_syncyesno_run_w_tmo(TIMEOUT_BLOCK, YESNO_TMO, | ||
366 | main_message, yes_message, no_message); | ||
367 | } | ||
271 | 368 | ||
272 | /* Function to manipulate all yesno dialogues. | 369 | /* Function to manipulate all yesno dialogues. |
273 | This function needs the output text as an argument. */ | 370 | This function needs the output text as an argument. */ |