mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
[Feature] add a prompt to database commit on start-up
adds a new function: gui_syncyesno_run_w_tmo(ticks, tmo_default_res, main_msg,yes_msg, no_msg) when a database needs committed on start-up a yes no prompt will appear if not answered within 5 seconds it defaults to Yes if instead you choose No next start-up you will be asked again you could rebuild the db still and waste time but it wouldn't hurt anything so I don't think that path needs blocked Change-Id: I58411f6e6bfebb6f142d99f33a1e8885ae7785c1
This commit is contained in:
parent
7ccbd705f4
commit
1c47722226
4 changed files with 143 additions and 15 deletions
109
apps/gui/yesno.c
109
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,7 +202,22 @@ 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,
|
||||
/* 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)
|
||||
{
|
||||
|
@ -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. */
|
||||
|
|
|
@ -27,7 +27,8 @@ enum yesno_res
|
|||
{
|
||||
YESNO_YES,
|
||||
YESNO_NO,
|
||||
YESNO_USB
|
||||
YESNO_USB,
|
||||
YESNO_TMO
|
||||
};
|
||||
|
||||
struct text_message
|
||||
|
@ -49,6 +50,12 @@ extern enum yesno_res gui_syncyesno_run(
|
|||
const struct text_message * yes_message,
|
||||
const struct text_message * no_message);
|
||||
|
||||
extern 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);
|
||||
|
||||
bool yesno_pop(const char* text);
|
||||
|
||||
#endif /* _GUI_YESNO_H_ */
|
||||
|
|
|
@ -78,6 +78,7 @@ static int reset_settings(void)
|
|||
settings_apply(true);
|
||||
settings_apply_skins();
|
||||
break;
|
||||
case YESNO_TMO:
|
||||
case YESNO_NO:
|
||||
break;
|
||||
case YESNO_USB:
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#include "usb.h"
|
||||
#include "metadata.h"
|
||||
#include "tagcache.h"
|
||||
#include "yesno.h"
|
||||
#include "core_alloc.h"
|
||||
#include "crc32.h"
|
||||
#include "misc.h"
|
||||
|
@ -5064,17 +5065,39 @@ void tagcache_unload_ramcache(void)
|
|||
#endif /* HAVE_TC_RAMCACHE */
|
||||
|
||||
#ifndef __PCTOOL__
|
||||
|
||||
/*
|
||||
* db_file_exists is noinline to minimize stack usage
|
||||
*/
|
||||
static bool NO_INLINE db_file_exists(const char* filename)
|
||||
{
|
||||
char buf[MAX_PATH];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", tc_stat.db_path, filename);
|
||||
|
||||
return file_exists(buf);
|
||||
}
|
||||
|
||||
static void tagcache_thread(void)
|
||||
{
|
||||
struct queue_event ev;
|
||||
bool check_done = false;
|
||||
|
||||
cpu_boost(true);
|
||||
/* If the previous cache build/update was interrupted, commit
|
||||
* the changes first in foreground. */
|
||||
cpu_boost(true);
|
||||
if (db_file_exists(TAGCACHE_FILE_TEMP))
|
||||
{
|
||||
static const char *lines[] = {ID2P(LANG_TAGCACHE_BUSY),
|
||||
ID2P(LANG_TAGCACHE_UPDATE)};
|
||||
static const struct text_message message = {lines, 2};
|
||||
|
||||
if (gui_syncyesno_run_w_tmo(HZ * 5, YESNO_YES, &message, NULL, NULL) == YESNO_YES)
|
||||
{
|
||||
allocate_tempbuf();
|
||||
commit();
|
||||
free_tempbuf();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_TC_RAMCACHE
|
||||
#ifdef HAVE_EEPROM_SETTINGS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue