Made bool options apply instantly (patch #729614). Also cleared up a long-standing issue with int/bool settings.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3732 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
d1a6fa113d
commit
26712d5104
4 changed files with 100 additions and 56 deletions
|
@ -1464,18 +1464,28 @@ void settings_reset(void) {
|
|||
bool set_bool(char* string, bool* variable )
|
||||
{
|
||||
return set_bool_options(string, variable, str(LANG_SET_BOOL_YES),
|
||||
str(LANG_SET_BOOL_NO));
|
||||
str(LANG_SET_BOOL_NO), NULL);
|
||||
}
|
||||
|
||||
/* wrapper to convert from int param to bool param in set_option */
|
||||
static void (*boolfunction)(bool);
|
||||
void bool_funcwrapper(int value)
|
||||
{
|
||||
if (value)
|
||||
boolfunction(true);
|
||||
else
|
||||
boolfunction(false);
|
||||
}
|
||||
|
||||
bool set_bool_options(char* string, bool* variable,
|
||||
char* yes_str, char* no_str )
|
||||
char* yes_str, char* no_str, void (*function)(bool))
|
||||
{
|
||||
char* names[] = { no_str, yes_str };
|
||||
int value = *variable;
|
||||
bool result;
|
||||
|
||||
result = set_option(string, &value, names, 2, NULL);
|
||||
*variable = value;
|
||||
boolfunction = function;
|
||||
result = set_option(string, variable, BOOL, names, 2,
|
||||
function ? bool_funcwrapper : NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1576,12 +1586,23 @@ bool set_int(char* string,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool set_option(char* string, int* variable, char* options[],
|
||||
int numoptions, void (*function)(int))
|
||||
/* NOTE: the 'type' parameter specifies the actual type of the variable
|
||||
that 'variable' points to. not the value within. Only variables with
|
||||
type 'bool' should use parameter BOOL.
|
||||
|
||||
The type separation is nececssary since int and bool are fundamentally
|
||||
different and bit-incompatible types and can not share the same access
|
||||
code. */
|
||||
|
||||
bool set_option(char* string, void* variable, enum optiontype type,
|
||||
char* options[], int numoptions, void (*function)(int))
|
||||
{
|
||||
bool done = false;
|
||||
int button;
|
||||
int org_value=*variable;
|
||||
int* intvar = (int*)variable;
|
||||
bool* boolvar = (bool*)variable;
|
||||
int orgint=*intvar;
|
||||
bool orgbool=*boolvar;
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
if(global_settings.statusbar)
|
||||
|
@ -1594,7 +1615,7 @@ bool set_option(char* string, int* variable, char* options[],
|
|||
lcd_puts_scroll(0, 0, string);
|
||||
|
||||
while ( !done ) {
|
||||
lcd_puts(0, 1, options[*variable]);
|
||||
lcd_puts(0, 1, options[type==INT ? *intvar : (int)*boolvar]);
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
status_draw(true);
|
||||
#endif
|
||||
|
@ -1609,10 +1630,14 @@ bool set_option(char* string, int* variable, char* options[],
|
|||
case BUTTON_RIGHT:
|
||||
case BUTTON_RIGHT | BUTTON_REPEAT:
|
||||
#endif
|
||||
if ( *variable < (numoptions-1) )
|
||||
(*variable)++;
|
||||
if (type == INT) {
|
||||
if ( *intvar < (numoptions-1) )
|
||||
(*intvar)++;
|
||||
else
|
||||
(*intvar) -= (numoptions-1);
|
||||
}
|
||||
else
|
||||
(*variable) -= (numoptions-1);
|
||||
*boolvar = !*boolvar;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
|
@ -1622,10 +1647,14 @@ bool set_option(char* string, int* variable, char* options[],
|
|||
case BUTTON_LEFT:
|
||||
case BUTTON_LEFT | BUTTON_REPEAT:
|
||||
#endif
|
||||
if ( *variable > 0 )
|
||||
(*variable)--;
|
||||
if (type == INT) {
|
||||
if ( *intvar > 0 )
|
||||
(*intvar)--;
|
||||
else
|
||||
(*intvar) += (numoptions-1);
|
||||
}
|
||||
else
|
||||
(*variable) += (numoptions-1);
|
||||
*boolvar = !*boolvar;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
|
@ -1643,8 +1672,12 @@ bool set_option(char* string, int* variable, char* options[],
|
|||
case BUTTON_STOP:
|
||||
case BUTTON_MENU:
|
||||
#endif
|
||||
if (*variable != org_value) {
|
||||
*variable=org_value;
|
||||
if (((type==INT) && (*intvar != orgint)) ||
|
||||
((type==BOOL) && (*boolvar != orgbool))) {
|
||||
if (type==INT)
|
||||
*intvar=orgint;
|
||||
else
|
||||
*boolvar=orgbool;
|
||||
lcd_stop_scroll();
|
||||
lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL));
|
||||
lcd_update();
|
||||
|
@ -1658,8 +1691,12 @@ bool set_option(char* string, int* variable, char* options[],
|
|||
return true;
|
||||
}
|
||||
|
||||
if ( function && button != BUTTON_NONE)
|
||||
function(*variable);
|
||||
if ( function && button != BUTTON_NONE) {
|
||||
if (type == INT)
|
||||
function(*intvar);
|
||||
else
|
||||
function(*boolvar);
|
||||
}
|
||||
}
|
||||
lcd_stop_scroll();
|
||||
return false;
|
||||
|
|
|
@ -180,6 +180,8 @@ struct user_settings
|
|||
bool show_icons; /* 0=hide 1=show */
|
||||
};
|
||||
|
||||
enum optiontype { INT, BOOL };
|
||||
|
||||
/* prototypes */
|
||||
|
||||
int settings_save(void);
|
||||
|
@ -192,11 +194,11 @@ void settings_display(void);
|
|||
bool settings_load_config(char* file);
|
||||
bool settings_save_config(void);
|
||||
bool set_bool_options(char* string, bool* variable,
|
||||
char* yes_str, char* no_str );
|
||||
char* yes_str, char* no_str, void (*function)(bool));
|
||||
|
||||
bool set_bool(char* string, bool* variable );
|
||||
bool set_option(char* string, int* variable, char* options[],
|
||||
int numoptions, void (*function)(int));
|
||||
bool set_option(char* string, void* variable, enum optiontype type,
|
||||
char* options[], int numoptions, void (*function)(int));
|
||||
bool set_int(char* string, char* unit, int* variable,
|
||||
void (*function)(int), int step, int min, int max );
|
||||
bool set_time(char* string, int timedate[]);
|
||||
|
|
|
@ -75,9 +75,8 @@ static bool invert(void)
|
|||
bool rc = set_bool_options(str(LANG_INVERT),
|
||||
&global_settings.invert,
|
||||
str(LANG_INVERT_LCD_INVERSE),
|
||||
str(LANG_INVERT_LCD_NORMAL));
|
||||
|
||||
lcd_set_invert_display(global_settings.invert);
|
||||
str(LANG_INVERT_LCD_NORMAL),
|
||||
lcd_set_invert_display);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -89,7 +88,8 @@ static bool invert_cursor(void)
|
|||
return set_bool_options(str(LANG_INVERT_CURSOR),
|
||||
&global_settings.invert_cursor,
|
||||
str(LANG_INVERT_CURSOR_BAR),
|
||||
str(LANG_INVERT_CURSOR_POINTER));
|
||||
str(LANG_INVERT_CURSOR_POINTER),
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +101,7 @@ static bool battery_type(void)
|
|||
str(LANG_DISPLAY_NUMERIC) };
|
||||
|
||||
return set_option( str(LANG_BATTERY_DISPLAY),
|
||||
&global_settings.battery_type, names, 2, NULL);
|
||||
&global_settings.battery_type, INT, names, 2, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ static bool volume_type(void)
|
|||
str(LANG_DISPLAY_NUMERIC) };
|
||||
|
||||
return set_option( str(LANG_VOLUME_DISPLAY), &global_settings.volume_type,
|
||||
names, 2, NULL);
|
||||
INT, names, 2, NULL);
|
||||
}
|
||||
|
||||
#ifdef PM_DEBUG
|
||||
|
@ -137,9 +137,9 @@ static bool peak_meter_hold(void) {
|
|||
"8 s", "9 s", "10 s", "15 s", "20 s",
|
||||
"30 s", "1 min"
|
||||
};
|
||||
retval = set_option( str(LANG_PM_PEAK_HOLD),
|
||||
&global_settings.peak_meter_hold, names,
|
||||
18, NULL);
|
||||
retval = set_option( str(LANG_PM_PEAK_HOLD),
|
||||
&global_settings.peak_meter_hold, INT, names,
|
||||
18, NULL);
|
||||
|
||||
peak_meter_init_times(global_settings.peak_meter_release,
|
||||
global_settings.peak_meter_hold,
|
||||
|
@ -163,8 +163,8 @@ static bool peak_meter_clip_hold(void) {
|
|||
};
|
||||
|
||||
retval = set_option( str(LANG_PM_CLIP_HOLD),
|
||||
&global_settings.peak_meter_clip_hold, names,
|
||||
25, peak_meter_set_clip_hold);
|
||||
&global_settings.peak_meter_clip_hold, INT, names,
|
||||
25, peak_meter_set_clip_hold);
|
||||
|
||||
peak_meter_init_times(global_settings.peak_meter_release,
|
||||
global_settings.peak_meter_hold,
|
||||
|
@ -203,7 +203,8 @@ static bool peak_meter_scale(void) {
|
|||
bool use_dbfs = global_settings.peak_meter_dbfs;
|
||||
retval = set_bool_options(str(LANG_PM_SCALE),
|
||||
&use_dbfs,
|
||||
str(LANG_PM_DBFS), str(LANG_PM_LINEAR));
|
||||
str(LANG_PM_DBFS), str(LANG_PM_LINEAR),
|
||||
NULL);
|
||||
|
||||
/* has the user really changed the scale? */
|
||||
if (use_dbfs != global_settings.peak_meter_dbfs) {
|
||||
|
@ -315,7 +316,8 @@ static bool peak_meter_performance(void) {
|
|||
bool retval = false;
|
||||
retval = set_bool_options(str(LANG_PM_PERFORMANCE),
|
||||
&global_settings.peak_meter_performance,
|
||||
str(LANG_PM_HIGH_PERFORMANCE), str(LANG_PM_ENERGY_SAVER));
|
||||
str(LANG_PM_HIGH_PERFORMANCE), str(LANG_PM_ENERGY_SAVER),
|
||||
NULL);
|
||||
|
||||
if (global_settings.peak_meter_performance) {
|
||||
peak_meter_fps = 25;
|
||||
|
@ -368,7 +370,7 @@ static bool repeat_mode(void)
|
|||
int old_repeat = global_settings.repeat_mode;
|
||||
|
||||
result = set_option( str(LANG_REPEAT), &global_settings.repeat_mode,
|
||||
names, 3, NULL );
|
||||
INT, names, 3, NULL );
|
||||
|
||||
if (old_repeat != global_settings.repeat_mode)
|
||||
mpeg_flush_and_reload_tracks();
|
||||
|
@ -388,7 +390,7 @@ static bool dir_filter(void)
|
|||
str(LANG_FILTER_MUSIC),
|
||||
str(LANG_FILTER_PLAYLIST) };
|
||||
|
||||
return set_option( str(LANG_FILTER), &global_settings.dirfilter,
|
||||
return set_option( str(LANG_FILTER), &global_settings.dirfilter, INT,
|
||||
names, 4, NULL );
|
||||
}
|
||||
|
||||
|
@ -404,7 +406,7 @@ static bool resume(void)
|
|||
str(LANG_RESUME_SETTING_ASK_ONCE),
|
||||
str(LANG_SET_BOOL_YES) };
|
||||
|
||||
return set_option( str(LANG_RESUME), &global_settings.resume,
|
||||
return set_option( str(LANG_RESUME), &global_settings.resume, INT,
|
||||
names, 4, NULL );
|
||||
}
|
||||
|
||||
|
@ -425,7 +427,7 @@ static bool backlight_timer(void)
|
|||
"60s", "90s"};
|
||||
|
||||
return set_option(str(LANG_BACKLIGHT), &global_settings.backlight_timeout,
|
||||
names, 19, backlight_set_timeout );
|
||||
INT, names, 19, backlight_set_timeout );
|
||||
}
|
||||
|
||||
static bool poweroff_idle_timer(void)
|
||||
|
@ -436,7 +438,7 @@ static bool poweroff_idle_timer(void)
|
|||
"15m", "30m", "45m", "60m"};
|
||||
|
||||
return set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff,
|
||||
names, 15, set_poweroff_timeout);
|
||||
INT, names, 15, set_poweroff_timeout);
|
||||
}
|
||||
|
||||
static bool scroll_speed(void)
|
||||
|
@ -477,7 +479,7 @@ static bool jump_scroll(void)
|
|||
"3", "4", str(LANG_ALWAYS)};
|
||||
bool ret;
|
||||
ret=set_option(str(LANG_JUMP_SCROLL), &global_settings.jump_scroll,
|
||||
names, 6, lcd_jump_scroll);
|
||||
INT, names, 6, lcd_jump_scroll);
|
||||
if (!ret && global_settings.jump_scroll>=JUMP_SCROLL_ALWAYS) {
|
||||
global_settings.jump_scroll=254; /* Nice future "safe" value */
|
||||
}
|
||||
|
@ -609,7 +611,8 @@ static bool timeformat_set(void)
|
|||
char* names[] = { str(LANG_24_HOUR_CLOCK),
|
||||
str(LANG_12_HOUR_CLOCK) };
|
||||
|
||||
return set_option(str(LANG_TIMEFORMAT), &global_settings.timeformat, names, 2, NULL);
|
||||
return set_option(str(LANG_TIMEFORMAT), &global_settings.timeformat,
|
||||
INT, names, 2, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -657,7 +660,7 @@ static bool ff_rewind_min_step(void)
|
|||
"45s", "60s" };
|
||||
|
||||
return set_option(str(LANG_FFRW_STEP), &global_settings.ff_rewind_min_step,
|
||||
names, 14, NULL );
|
||||
INT, names, 14, NULL );
|
||||
}
|
||||
|
||||
static bool set_fade_on_stop(void)
|
||||
|
@ -674,7 +677,7 @@ static bool ff_rewind_accel(void)
|
|||
"2x/12s", "2x/13s", "2x/14s", "2x/15s", };
|
||||
|
||||
return set_option(str(LANG_FFRW_ACCEL), &global_settings.ff_rewind_accel,
|
||||
names, 16, NULL );
|
||||
INT, names, 16, NULL );
|
||||
}
|
||||
|
||||
static bool browse_current(void)
|
||||
|
|
|
@ -181,7 +181,7 @@ static void set_avc(int val)
|
|||
static bool avc(void)
|
||||
{
|
||||
char* names[] = { str(LANG_OFF), "2s", "4s", "8s" };
|
||||
return set_option(str(LANG_DECAY), &global_settings.avc,
|
||||
return set_option(str(LANG_DECAY), &global_settings.avc, INT,
|
||||
names, 4, set_avc);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ static bool recsource(void)
|
|||
char *names[] = {str(LANG_RECORDING_SRC_MIC), str(LANG_RECORDING_SRC_LINE),
|
||||
str(LANG_RECORDING_SRC_DIGITAL) };
|
||||
return set_option(str(LANG_RECORDING_SOURCE),
|
||||
&global_settings.rec_source,
|
||||
&global_settings.rec_source, INT,
|
||||
names, 3, NULL );
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ static bool recfrequency(void)
|
|||
"22.05kHz", "24kHz", "16kHz"};
|
||||
|
||||
return set_option(str(LANG_RECORDING_FREQUENCY),
|
||||
&global_settings.rec_frequency,
|
||||
&global_settings.rec_frequency, INT,
|
||||
names, 6, NULL );
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ static bool recchannels(void)
|
|||
char *names[] = {str(LANG_CHANNEL_STEREO), str(LANG_CHANNEL_MONO)};
|
||||
|
||||
return set_option(str(LANG_RECORDING_CHANNELS),
|
||||
&global_settings.rec_channels,
|
||||
&global_settings.rec_channels, INT,
|
||||
names, 2, NULL );
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ static bool rectimesplit(void)
|
|||
"00:30","01:00","02:00","04:00"};
|
||||
|
||||
return set_option(str(LANG_RECORD_TIMESPLIT),
|
||||
&global_settings.rec_timesplit,
|
||||
&global_settings.rec_timesplit, INT,
|
||||
names, 8, NULL );
|
||||
}
|
||||
|
||||
|
@ -245,16 +245,18 @@ static void set_chanconf(int val)
|
|||
|
||||
static bool chanconf(void)
|
||||
{
|
||||
char *names[] = {str(LANG_CHANNEL_STEREO),
|
||||
char *names[] = {
|
||||
str(LANG_CHANNEL_STEREO),
|
||||
#ifdef HAVE_LCD_CHARCELLS
|
||||
str(LANG_CHANNEL_STEREO_NARROW_PLAYER),
|
||||
str(LANG_CHANNEL_STEREO_NARROW_PLAYER),
|
||||
#else
|
||||
str(LANG_CHANNEL_STEREO_NARROW_RECORDER),
|
||||
str(LANG_CHANNEL_STEREO_NARROW_RECORDER),
|
||||
#endif
|
||||
str(LANG_CHANNEL_MONO),
|
||||
str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT),
|
||||
str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE) };
|
||||
return set_option(str(LANG_CHANNEL), &global_settings.channel_config,
|
||||
str(LANG_CHANNEL_MONO),
|
||||
str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT),
|
||||
str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE)
|
||||
};
|
||||
return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT,
|
||||
names, 7, set_chanconf );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue