mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Code police raid on the settings code, consting and putting headers alongside their implementation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16798 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
222994f180
commit
cd88e2ad93
8 changed files with 158 additions and 82 deletions
|
@ -65,4 +65,5 @@ extern void option_select_next(struct option_select * opt);
|
|||
*/
|
||||
extern void option_select_prev(struct option_select * opt);
|
||||
|
||||
|
||||
#endif /* _GUI_OPTION_SELECT_H_ */
|
||||
|
|
|
@ -275,7 +275,7 @@ static int talk_menu_item(int selected_item, void *data)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#define MAX_OPTIONS 32
|
||||
|
||||
bool do_setting_from_menu(const struct menu_item_ex *temp)
|
||||
{
|
||||
int setting_id;
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#if CONFIG_TUNER
|
||||
#include "radio.h"
|
||||
#endif
|
||||
#if CONFIG_RTC
|
||||
#include "screens.h"
|
||||
#endif
|
||||
|
||||
/***********************************/
|
||||
/* TAGCACHE MENU */
|
||||
|
|
|
@ -119,12 +119,12 @@
|
|||
#define PLUGIN_MAGIC 0x526F634B /* RocK */
|
||||
|
||||
/* increase this every time the api struct changes */
|
||||
#define PLUGIN_API_VERSION 101
|
||||
#define PLUGIN_API_VERSION 102
|
||||
|
||||
/* update this to latest version if a change to the api struct breaks
|
||||
backwards compatibility (and please take the opportunity to sort in any
|
||||
new function which are "waiting" at the end of the function table) */
|
||||
#define PLUGIN_MIN_API_VERSION 101
|
||||
#define PLUGIN_MIN_API_VERSION 102
|
||||
|
||||
/* plugin return codes */
|
||||
enum plugin_status {
|
||||
|
@ -562,20 +562,21 @@ struct plugin_api {
|
|||
void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
|
||||
|
||||
/* options */
|
||||
const struct settings_list* (*find_setting)(void* variable, int *id);
|
||||
const struct settings_list* (*find_setting)(const void* variable, int *id);
|
||||
bool (*option_screen)(struct settings_list *setting,
|
||||
bool use_temp_var, unsigned char* option_title);
|
||||
bool (*set_option)(const char* string, void* variable,
|
||||
enum optiontype type, const struct opt_items* options,
|
||||
int numoptions, void (*function)(int));
|
||||
bool (*set_bool_options)(const char* string, bool* variable,
|
||||
const char* yes_str, int yes_voice,
|
||||
const char* no_str, int no_voice,
|
||||
bool (*set_option)(const char* string, const void* variable,
|
||||
const enum optiontype type, const struct opt_items* options,
|
||||
const int numoptions, void (*function)(int));
|
||||
bool (*set_bool_options)(const char* string, const bool* variable,
|
||||
const char* yes_str, const int yes_voice,
|
||||
const char* no_str, const int no_voice,
|
||||
void (*function)(bool));
|
||||
bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
|
||||
int* variable, void (*function)(int), int step, int min,
|
||||
int max, void (*formatter)(char*, size_t, int, const char*) );
|
||||
bool (*set_bool)(const char* string, bool* variable );
|
||||
bool (*set_int)(const unsigned char* string, const char* unit, const int voice_unit,
|
||||
const int* variable, void (*function)(int), const int step,
|
||||
const int min, const int max,
|
||||
void (*formatter)(char*, size_t, int, const char*) );
|
||||
bool (*set_bool)(const char* string, const bool* variable );
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
bool (*set_color)(struct screen *display, char *title, unsigned *color,
|
||||
|
|
137
apps/settings.c
137
apps/settings.c
|
@ -7,7 +7,7 @@
|
|||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by wavey@wavey.org
|
||||
* Copyright (C) 2002 by Stuart Martin
|
||||
* RTC config saving code (C) 2002 by hessu@hes.iki.fi
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
|
@ -62,6 +62,7 @@
|
|||
#include "list.h"
|
||||
#include "settings_list.h"
|
||||
#include "filetypes.h"
|
||||
#include "option_select.h"
|
||||
|
||||
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
|
||||
#include "backdrop.h"
|
||||
|
@ -112,7 +113,7 @@ long lasttime = 0;
|
|||
#define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
|
||||
static char nvram_buffer[NVRAM_BLOCK_SIZE];
|
||||
|
||||
static bool read_nvram_data(char* buf, int max_len)
|
||||
static bool read_nvram_data(char* buf, const int max_len)
|
||||
{
|
||||
unsigned crc32 = 0xffffffff;
|
||||
int var_count = 0, i = 0, buf_pos = 0;
|
||||
|
@ -162,7 +163,7 @@ static bool read_nvram_data(char* buf, int max_len)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
static bool write_nvram_data(char* buf, int max_len)
|
||||
static bool write_nvram_data(char* buf, const int max_len)
|
||||
{
|
||||
unsigned crc32 = 0xffffffff;
|
||||
int i = 0, buf_pos = 0;
|
||||
|
@ -220,7 +221,7 @@ static bool write_nvram_data(char* buf, int max_len)
|
|||
/*
|
||||
* load settings from disk or RTC RAM
|
||||
*/
|
||||
void settings_load(int which)
|
||||
void settings_load(const int which)
|
||||
{
|
||||
DEBUGF( "reload_all_settings()\n" );
|
||||
if (which&SETTINGS_RTC)
|
||||
|
@ -232,7 +233,7 @@ void settings_load(int which)
|
|||
}
|
||||
}
|
||||
|
||||
static bool cfg_string_to_int(int setting_id, int* out, char* str)
|
||||
static bool cfg_string_to_int(const int setting_id, int* out, const char* str)
|
||||
{
|
||||
const char* start = settings[setting_id].cfg_vals;
|
||||
char* end = NULL;
|
||||
|
@ -263,7 +264,7 @@ static bool cfg_string_to_int(int setting_id, int* out, char* str)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool settings_load_config(const char* file, bool apply)
|
||||
bool settings_load_config(const char* file, const bool apply)
|
||||
{
|
||||
int fd;
|
||||
char line[128];
|
||||
|
@ -361,7 +362,7 @@ bool settings_load_config(const char* file, bool apply)
|
|||
|
||||
/** Writing to a config file and saving settings **/
|
||||
|
||||
bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
|
||||
bool cfg_int_to_string(const int setting_id, const int val, char* buf, const int buf_len)
|
||||
{
|
||||
int flags = settings[setting_id].flags;
|
||||
const char* start = settings[setting_id].cfg_vals;
|
||||
|
@ -416,7 +417,9 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
static bool is_changed(int setting_id)
|
||||
|
||||
|
||||
static bool is_changed(const int setting_id)
|
||||
{
|
||||
const struct settings_list *setting = &settings[setting_id];
|
||||
switch (setting->flags&F_T_MASK)
|
||||
|
@ -450,7 +453,7 @@ static bool is_changed(int setting_id)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool settings_write_config(char* filename, int options)
|
||||
static bool settings_write_config(const char* filename, const int options)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
|
@ -604,7 +607,8 @@ int settings_save( void )
|
|||
register_ata_idle_func(flush_config_block_callback);
|
||||
return 0;
|
||||
}
|
||||
bool settings_save_config(int options)
|
||||
|
||||
bool settings_save_config(const int options)
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
char *folder;
|
||||
|
@ -714,7 +718,7 @@ void sound_settings_apply(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void settings_apply(bool read_disk)
|
||||
void settings_apply(const bool read_disk)
|
||||
{
|
||||
char buf[64];
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
|
@ -945,8 +949,8 @@ void settings_apply(bool read_disk)
|
|||
/*
|
||||
* reset all settings to their default value
|
||||
*/
|
||||
void settings_reset(void) {
|
||||
|
||||
void settings_reset(void)
|
||||
{
|
||||
int i;
|
||||
DEBUGF( "settings_reset()\n" );
|
||||
|
||||
|
@ -979,7 +983,7 @@ void settings_reset(void) {
|
|||
}
|
||||
|
||||
/** Changing setting values **/
|
||||
const struct settings_list* find_setting(void* variable, int *id)
|
||||
const struct settings_list* find_setting(const void* variable, int *id)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nb_settings;i++)
|
||||
|
@ -994,19 +998,7 @@ const struct settings_list* find_setting(void* variable, int *id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void talk_setting(void *global_settings_variable)
|
||||
{
|
||||
const struct settings_list *setting;
|
||||
if (!global_settings.talk_menu)
|
||||
return;
|
||||
setting = find_setting(global_settings_variable, NULL);
|
||||
if (setting == NULL)
|
||||
return;
|
||||
if (setting->lang_id)
|
||||
talk_id(setting->lang_id,false);
|
||||
}
|
||||
|
||||
bool set_bool(const char* string, bool* variable )
|
||||
bool set_bool(const char* string, const bool* variable )
|
||||
{
|
||||
return set_bool_options(string, variable,
|
||||
(char *)STR(LANG_SET_BOOL_YES),
|
||||
|
@ -1015,14 +1007,14 @@ bool set_bool(const char* string, bool* variable )
|
|||
}
|
||||
|
||||
|
||||
bool set_bool_options(const char* string, bool* variable,
|
||||
const char* yes_str, int yes_voice,
|
||||
const char* no_str, int no_voice,
|
||||
bool set_bool_options(const char* string, const bool* variable,
|
||||
const char* yes_str, const int yes_voice,
|
||||
const char* no_str, const int no_voice,
|
||||
void (*function)(bool))
|
||||
{
|
||||
struct opt_items names[] = {
|
||||
{(unsigned char *)no_str, no_voice},
|
||||
{(unsigned char *)yes_str, yes_voice}
|
||||
{(unsigned const char *)no_str, no_voice},
|
||||
{(unsigned const char *)yes_str, yes_voice}
|
||||
};
|
||||
bool result;
|
||||
|
||||
|
@ -1033,22 +1025,89 @@ bool set_bool_options(const char* string, bool* variable,
|
|||
|
||||
bool set_int(const unsigned char* string,
|
||||
const char* unit,
|
||||
int voice_unit,
|
||||
int* variable,
|
||||
const int voice_unit,
|
||||
const int* variable,
|
||||
void (*function)(int),
|
||||
int step,
|
||||
int min,
|
||||
int max,
|
||||
const int step,
|
||||
const int min,
|
||||
const int max,
|
||||
void (*formatter)(char*, size_t, int, const char*) )
|
||||
{
|
||||
return set_int_ex(string, unit, voice_unit, variable, function,
|
||||
step, min, max, formatter, NULL);
|
||||
}
|
||||
|
||||
bool set_int_ex(const unsigned char* string,
|
||||
const char* unit,
|
||||
const int voice_unit,
|
||||
const int* variable,
|
||||
void (*function)(int),
|
||||
const int step,
|
||||
const int min,
|
||||
const int max,
|
||||
void (*formatter)(char*, size_t, int, const char*),
|
||||
int32_t (*get_talk_id)(int, int))
|
||||
{
|
||||
(void)unit;
|
||||
struct settings_list item;
|
||||
struct int_setting data = {
|
||||
function, voice_unit, min, max, step,
|
||||
formatter, get_talk_id
|
||||
};
|
||||
item.int_setting = &data;
|
||||
item.flags = F_INT_SETTING|F_T_INT;
|
||||
item.lang_id = -1;
|
||||
item.cfg_vals = (char*)string;
|
||||
item.setting = (void *)variable;
|
||||
return option_screen(&item, false, NULL);
|
||||
}
|
||||
|
||||
/** extra stuff which is probably misplaced **/
|
||||
|
||||
void set_file(char* filename, char* setting, int maxlen)
|
||||
static const struct opt_items *set_option_options;
|
||||
static void set_option_formatter(char* buf, size_t size, int item, const char* unit)
|
||||
{
|
||||
(void)unit;
|
||||
const unsigned char *text = set_option_options[item].string;
|
||||
snprintf(buf, size, "%s", P2STR(text));
|
||||
}
|
||||
static int32_t set_option_get_talk_id(int value, int unit)
|
||||
{
|
||||
(void)unit;
|
||||
return set_option_options[value].voice_id;
|
||||
}
|
||||
bool set_option(const char* string, const void* variable, const enum optiontype type,
|
||||
const struct opt_items* options,
|
||||
const int numoptions, void (*function)(int))
|
||||
{
|
||||
int temp;
|
||||
struct settings_list item;
|
||||
struct int_setting data = {
|
||||
function, UNIT_INT, 0, numoptions-1, 1,
|
||||
set_option_formatter, set_option_get_talk_id
|
||||
};
|
||||
set_option_options = options;
|
||||
item.int_setting = &data;
|
||||
item.flags = F_INT_SETTING|F_T_INT;
|
||||
item.lang_id = -1;
|
||||
item.cfg_vals = (char*)string;
|
||||
item.setting = &temp;
|
||||
if (type == BOOL)
|
||||
temp = *(bool*)variable? 1: 0;
|
||||
else
|
||||
temp = *(int*)variable;
|
||||
if (!option_screen(&item, false, NULL))
|
||||
{
|
||||
if (type == BOOL)
|
||||
*(bool*)variable = (temp == 1? true: false);
|
||||
else
|
||||
*(int*)variable = temp;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void set_file(const char* filename, char* setting, const int maxlen)
|
||||
{
|
||||
char* fptr = strrchr(filename,'/');
|
||||
int len;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by wavey@wavey.org
|
||||
* Copyright (C) 2002 by Stuart Martin
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
|
@ -195,8 +195,8 @@ extern unsigned char vp_dummy[VIRT_SIZE];
|
|||
#define SETTINGS_RTC 1 /* only the settings from the RTC nonvolatile RAM */
|
||||
#define SETTINGS_HD 2 /* only the settings from the disk sector */
|
||||
#define SETTINGS_ALL 3 /* both */
|
||||
void settings_load(int which);
|
||||
bool settings_load_config(const char* file, bool apply);
|
||||
void settings_load(const int which);
|
||||
bool settings_load_config(const char* file, const bool apply);
|
||||
|
||||
void status_save(void);
|
||||
int settings_save(void);
|
||||
|
@ -213,44 +213,41 @@ enum {
|
|||
SETTINGS_SAVE_EQPRESET,
|
||||
#endif
|
||||
};
|
||||
bool settings_save_config(int options);
|
||||
bool settings_save_config(const int options);
|
||||
|
||||
void settings_reset(void);
|
||||
void sound_settings_apply(void);
|
||||
void settings_apply(bool read_disk);
|
||||
void settings_apply(const bool read_disk);
|
||||
void settings_apply_pm_range(void);
|
||||
void settings_display(void);
|
||||
|
||||
enum optiontype { INT, BOOL };
|
||||
|
||||
const struct settings_list* find_setting(void* variable, int *id);
|
||||
bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len);
|
||||
void talk_setting(void *global_settings_variable);
|
||||
bool set_sound(const unsigned char * string,
|
||||
int* variable, int setting);
|
||||
bool set_bool_options(const char* string, bool* variable,
|
||||
const char* yes_str, int yes_voice,
|
||||
const char* no_str, int no_voice,
|
||||
const struct settings_list* find_setting(const void* variable, int *id);
|
||||
bool cfg_int_to_string(const int setting_id, const int val, char* buf, const int buf_len);
|
||||
bool set_bool_options(const char* string, const bool* variable,
|
||||
const char* yes_str, const int yes_voice,
|
||||
const char* no_str, const int no_voice,
|
||||
void (*function)(bool));
|
||||
|
||||
bool set_bool(const char* string, bool* variable );
|
||||
bool set_option(const char* string, void* variable, enum optiontype type,
|
||||
const struct opt_items* options, int numoptions, void (*function)(int));
|
||||
bool set_int(const unsigned char* string, const char* unit, int voice_unit,
|
||||
int* variable,
|
||||
void (*function)(int), int step, int min, int max,
|
||||
bool set_bool(const char* string, const bool* variable);
|
||||
bool set_int(const unsigned char* string, const char* unit, const int voice_unit,
|
||||
const int* variable,
|
||||
void (*function)(int), const int step, const int min, const int max,
|
||||
void (*formatter)(char*, size_t, int, const char*) );
|
||||
|
||||
/* use this one if you need to create a lang from the value (i.e with TALK_ID()) */
|
||||
bool set_int_ex(const unsigned char* string, const char* unit, int voice_unit,
|
||||
int* variable,
|
||||
void (*function)(int), int step, int min, int max,
|
||||
bool set_int_ex(const unsigned char* string, const char* unit, const int voice_unit,
|
||||
const int* variable,
|
||||
void (*function)(int), const int step, const int min, const int max,
|
||||
void (*formatter)(char*, size_t, int, const char*),
|
||||
int32_t (*get_talk_id)(int, int));
|
||||
|
||||
/* the following are either not in setting.c or shouldnt be */
|
||||
bool set_time_screen(const char* string, struct tm *tm);
|
||||
int read_line(int fd, char* buffer, int buffer_size);
|
||||
void set_file(char* filename, char* setting, int maxlen);
|
||||
void set_file(const char* filename, char* setting, const int maxlen);
|
||||
|
||||
bool set_option(const char* string, const void* variable, const enum optiontype type,
|
||||
const struct opt_items* options, const int numoptions, void (*function)(int));
|
||||
|
||||
|
||||
|
||||
/** global_settings and global_status struct definitions **/
|
||||
|
|
14
apps/talk.c
14
apps/talk.c
|
@ -29,6 +29,7 @@
|
|||
#include "system.h"
|
||||
#include "kernel.h"
|
||||
#include "settings.h"
|
||||
#include "settings_list.h"
|
||||
#include "mp3_playback.h"
|
||||
#include "audio.h"
|
||||
#include "lang.h"
|
||||
|
@ -876,6 +877,19 @@ void talk_disable(bool disable)
|
|||
talk_temp_disable_count--;
|
||||
}
|
||||
|
||||
void talk_setting(const void *global_settings_variable)
|
||||
{
|
||||
const struct settings_list *setting;
|
||||
if (!global_settings.talk_menu)
|
||||
return;
|
||||
setting = find_setting(global_settings_variable, NULL);
|
||||
if (setting == NULL)
|
||||
return;
|
||||
if (setting->lang_id)
|
||||
talk_id(setting->lang_id,false);
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_RTC
|
||||
void talk_date(struct tm *tm, bool enqueue)
|
||||
{
|
||||
|
|
|
@ -78,6 +78,7 @@ int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file
|
|||
int talk_number(long n, bool enqueue); /* say a number */
|
||||
int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
|
||||
int talk_spell(const char* spell, bool enqueue); /* spell a string */
|
||||
void talk_setting(const void *global_settings_variable); /* read a setting */
|
||||
void talk_disable(bool disable); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
|
||||
void talk_force_shutup(void); /* kill voice unconditionally */
|
||||
void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue