summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/yesno.c113
-rw-r--r--apps/gui/yesno.h11
-rw-r--r--apps/menus/main_menu.c1
-rw-r--r--apps/tagcache.c33
4 files changed, 143 insertions, 15 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
34struct gui_yesno 36struct 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
43static void talk_text_message(const struct text_message * message, bool enqueue) 48static 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
156enum 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*/
219enum 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
361enum 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. */
diff --git a/apps/gui/yesno.h b/apps/gui/yesno.h
index 61bcf8d3c0..5f67733d79 100644
--- a/apps/gui/yesno.h
+++ b/apps/gui/yesno.h
@@ -27,7 +27,8 @@ enum yesno_res
27{ 27{
28 YESNO_YES, 28 YESNO_YES,
29 YESNO_NO, 29 YESNO_NO,
30 YESNO_USB 30 YESNO_USB,
31 YESNO_TMO
31}; 32};
32 33
33struct text_message 34struct text_message
@@ -48,7 +49,13 @@ extern enum yesno_res gui_syncyesno_run(
48 const struct text_message * main_message, 49 const struct text_message * main_message,
49 const struct text_message * yes_message, 50 const struct text_message * yes_message,
50 const struct text_message * no_message); 51 const struct text_message * no_message);
51 52
53extern enum yesno_res gui_syncyesno_run_w_tmo(
54 int ticks, enum yesno_res tmo_default_res,
55 const struct text_message * main_message,
56 const struct text_message * yes_message,
57 const struct text_message * no_message);
58
52bool yesno_pop(const char* text); 59bool yesno_pop(const char* text);
53 60
54#endif /* _GUI_YESNO_H_ */ 61#endif /* _GUI_YESNO_H_ */
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index eab675c4a0..71763af0ee 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -78,6 +78,7 @@ static int reset_settings(void)
78 settings_apply(true); 78 settings_apply(true);
79 settings_apply_skins(); 79 settings_apply_skins();
80 break; 80 break;
81 case YESNO_TMO:
81 case YESNO_NO: 82 case YESNO_NO:
82 break; 83 break;
83 case YESNO_USB: 84 case YESNO_USB:
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 6abf957bc2..f7746f1ec3 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -75,6 +75,7 @@
75#include "usb.h" 75#include "usb.h"
76#include "metadata.h" 76#include "metadata.h"
77#include "tagcache.h" 77#include "tagcache.h"
78#include "yesno.h"
78#include "core_alloc.h" 79#include "core_alloc.h"
79#include "crc32.h" 80#include "crc32.h"
80#include "misc.h" 81#include "misc.h"
@@ -5064,17 +5065,39 @@ void tagcache_unload_ramcache(void)
5064#endif /* HAVE_TC_RAMCACHE */ 5065#endif /* HAVE_TC_RAMCACHE */
5065 5066
5066#ifndef __PCTOOL__ 5067#ifndef __PCTOOL__
5068
5069/*
5070 * db_file_exists is noinline to minimize stack usage
5071 */
5072static bool NO_INLINE db_file_exists(const char* filename)
5073{
5074 char buf[MAX_PATH];
5075
5076 snprintf(buf, sizeof(buf), "%s/%s", tc_stat.db_path, filename);
5077
5078 return file_exists(buf);
5079}
5080
5067static void tagcache_thread(void) 5081static void tagcache_thread(void)
5068{ 5082{
5069 struct queue_event ev; 5083 struct queue_event ev;
5070 bool check_done = false; 5084 bool check_done = false;
5071 5085 cpu_boost(true);
5072 /* If the previous cache build/update was interrupted, commit 5086 /* If the previous cache build/update was interrupted, commit
5073 * the changes first in foreground. */ 5087 * the changes first in foreground. */
5074 cpu_boost(true); 5088 if (db_file_exists(TAGCACHE_FILE_TEMP))
5075 allocate_tempbuf(); 5089 {
5076 commit(); 5090 static const char *lines[] = {ID2P(LANG_TAGCACHE_BUSY),
5077 free_tempbuf(); 5091 ID2P(LANG_TAGCACHE_UPDATE)};
5092 static const struct text_message message = {lines, 2};
5093
5094 if (gui_syncyesno_run_w_tmo(HZ * 5, YESNO_YES, &message, NULL, NULL) == YESNO_YES)
5095 {
5096 allocate_tempbuf();
5097 commit();
5098 free_tempbuf();
5099 }
5100 }
5078 5101
5079#ifdef HAVE_TC_RAMCACHE 5102#ifdef HAVE_TC_RAMCACHE
5080#ifdef HAVE_EEPROM_SETTINGS 5103#ifdef HAVE_EEPROM_SETTINGS