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
113
apps/gui/yesno.c
113
apps/gui/yesno.c
|
@ -30,6 +30,8 @@
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
#include "appevents.h"
|
#include "appevents.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "splash.h"
|
||||||
|
|
||||||
struct gui_yesno
|
struct gui_yesno
|
||||||
{
|
{
|
||||||
|
@ -38,6 +40,9 @@ struct gui_yesno
|
||||||
|
|
||||||
struct viewport *vp;
|
struct viewport *vp;
|
||||||
struct screen * display;
|
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)
|
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;
|
struct viewport *vp = yn->vp;
|
||||||
int nb_lines, vp_lines, line_shift=0;
|
int nb_lines, vp_lines, line_shift=0;
|
||||||
struct viewport *last_vp;
|
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);
|
last_vp = display->set_viewport(vp);
|
||||||
display->clear_viewport();
|
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 += put_message(display, yn->main_message,
|
||||||
line_shift, vp_lines);
|
line_shift, vp_lines);
|
||||||
|
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
if (display->screen_type == SCREEN_MAIN)
|
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 rect_w = vp->width/2, rect_h = vp->height/2;
|
||||||
int old_pattern = vp->fg_pattern;
|
int old_pattern = vp->fg_pattern;
|
||||||
vp->fg_pattern = LCD_RGBPACK(0,255,0);
|
vp->fg_pattern = LCD_RGBPACK(0,255,0);
|
||||||
display->drawrect(0, rect_h, rect_w, rect_h);
|
display->drawrect(0, rect_h, rect_w, rect_h);
|
||||||
display->getstringsize(str(LANG_SET_BOOL_YES), &w, &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);
|
vp->fg_pattern = LCD_RGBPACK(255,0,0);
|
||||||
display->drawrect(rect_w, rect_h, rect_w, rect_h);
|
display->drawrect(rect_w, rect_h, rect_w, rect_h);
|
||||||
display->getstringsize(str(LANG_SET_BOOL_NO), &w, &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;
|
vp->fg_pattern = old_pattern;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -115,6 +155,15 @@ static void gui_yesno_draw(struct gui_yesno * yn)
|
||||||
line_shift++;
|
line_shift++;
|
||||||
display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON));
|
display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON));
|
||||||
display->puts(0, line_shift+1, str(LANG_CANCEL_WITH_ANY));
|
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
|
#endif
|
||||||
display->update_viewport();
|
display->update_viewport();
|
||||||
|
@ -124,7 +173,7 @@ static void gui_yesno_draw(struct gui_yesno * yn)
|
||||||
/*
|
/*
|
||||||
* Draws the yesno result
|
* Draws the yesno result
|
||||||
* - yn : the yesno structure
|
* - yn : the yesno structure
|
||||||
* - result : the result tha must be displayed :
|
* - result : the result to be displayed :
|
||||||
* YESNO_NO if no
|
* YESNO_NO if no
|
||||||
* YESNO_YES if yes
|
* 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]);
|
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
|
||||||
const struct text_message * yes_message,
|
*
|
||||||
const struct text_message * no_message)
|
* 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 button;
|
||||||
int result=-1;
|
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 gui_yesno yn[NB_SCREENS];
|
||||||
struct viewport vp[NB_SCREENS];
|
struct viewport vp[NB_SCREENS];
|
||||||
long talked_tick = 0;
|
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)
|
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].main_message=main_message;
|
||||||
yn[i].result_message[YESNO_YES]=yes_message;
|
yn[i].result_message[YESNO_YES]=yes_message;
|
||||||
yn[i].result_message[YESNO_NO]=no_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;
|
talked_tick = current_tick;
|
||||||
talk_text_message(main_message, false);
|
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)
|
switch (button)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
@ -222,6 +305,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
||||||
result=YESNO_YES;
|
result=YESNO_YES;
|
||||||
break;
|
break;
|
||||||
case ACTION_NONE:
|
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 ACTION_UNKNOWN:
|
||||||
case SYS_CHARGER_DISCONNECTED:
|
case SYS_CHARGER_DISCONNECTED:
|
||||||
case SYS_BATTERY_UPDATE:
|
case SYS_BATTERY_UPDATE:
|
||||||
|
@ -268,6 +358,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
||||||
return result;
|
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.
|
/* Function to manipulate all yesno dialogues.
|
||||||
This function needs the output text as an argument. */
|
This function needs the output text as an argument. */
|
||||||
|
|
|
@ -27,7 +27,8 @@ enum yesno_res
|
||||||
{
|
{
|
||||||
YESNO_YES,
|
YESNO_YES,
|
||||||
YESNO_NO,
|
YESNO_NO,
|
||||||
YESNO_USB
|
YESNO_USB,
|
||||||
|
YESNO_TMO
|
||||||
};
|
};
|
||||||
|
|
||||||
struct text_message
|
struct text_message
|
||||||
|
@ -48,7 +49,13 @@ extern enum yesno_res gui_syncyesno_run(
|
||||||
const struct text_message * main_message,
|
const struct text_message * main_message,
|
||||||
const struct text_message * yes_message,
|
const struct text_message * yes_message,
|
||||||
const struct text_message * no_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);
|
bool yesno_pop(const char* text);
|
||||||
|
|
||||||
#endif /* _GUI_YESNO_H_ */
|
#endif /* _GUI_YESNO_H_ */
|
||||||
|
|
|
@ -78,6 +78,7 @@ static int reset_settings(void)
|
||||||
settings_apply(true);
|
settings_apply(true);
|
||||||
settings_apply_skins();
|
settings_apply_skins();
|
||||||
break;
|
break;
|
||||||
|
case YESNO_TMO:
|
||||||
case YESNO_NO:
|
case YESNO_NO:
|
||||||
break;
|
break;
|
||||||
case YESNO_USB:
|
case YESNO_USB:
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "tagcache.h"
|
#include "tagcache.h"
|
||||||
|
#include "yesno.h"
|
||||||
#include "core_alloc.h"
|
#include "core_alloc.h"
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -5064,17 +5065,39 @@ void tagcache_unload_ramcache(void)
|
||||||
#endif /* HAVE_TC_RAMCACHE */
|
#endif /* HAVE_TC_RAMCACHE */
|
||||||
|
|
||||||
#ifndef __PCTOOL__
|
#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)
|
static void tagcache_thread(void)
|
||||||
{
|
{
|
||||||
struct queue_event ev;
|
struct queue_event ev;
|
||||||
bool check_done = false;
|
bool check_done = false;
|
||||||
|
cpu_boost(true);
|
||||||
/* If the previous cache build/update was interrupted, commit
|
/* If the previous cache build/update was interrupted, commit
|
||||||
* the changes first in foreground. */
|
* the changes first in foreground. */
|
||||||
cpu_boost(true);
|
if (db_file_exists(TAGCACHE_FILE_TEMP))
|
||||||
allocate_tempbuf();
|
{
|
||||||
commit();
|
static const char *lines[] = {ID2P(LANG_TAGCACHE_BUSY),
|
||||||
free_tempbuf();
|
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_TC_RAMCACHE
|
||||||
#ifdef HAVE_EEPROM_SETTINGS
|
#ifdef HAVE_EEPROM_SETTINGS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue