settings: Remove setting ID return from find_setting()

Now that all users have replaced setting IDs with direct pointers,
find_setting() and friends don't need to return an ID value.

Change-Id: I8c5c31bb68d3bca5350d43538335265a55fd5517
This commit is contained in:
Aidan MacDonald 2022-11-30 14:50:18 +00:00
parent 767ddef550
commit 701e262d3d
15 changed files with 56 additions and 67 deletions

View file

@ -823,7 +823,7 @@ static int parse_setting_and_lang(struct skin_element *element,
else else
{ {
#ifndef __PCTOOL__ #ifndef __PCTOOL__
const struct settings_list *setting = find_setting_by_cfgname(temp, NULL); const struct settings_list *setting = find_setting_by_cfgname(temp);
if (!setting) if (!setting)
return WPS_ERROR_INVALID_PARAM; return WPS_ERROR_INVALID_PARAM;
@ -1158,7 +1158,7 @@ static int parse_progressbar_tag(struct skin_element* element,
param++; param++;
text = SKINOFFSETTOPTR(skin_buffer, param->data.text); text = SKINOFFSETTOPTR(skin_buffer, param->data.text);
#ifndef __PCTOOL__ #ifndef __PCTOOL__
pb->setting = find_setting_by_cfgname(text, NULL); pb->setting = find_setting_by_cfgname(text);
if (!pb->setting) if (!pb->setting)
return WPS_ERROR_INVALID_PARAM; return WPS_ERROR_INVALID_PARAM;
#endif #endif
@ -1548,7 +1548,7 @@ static int touchregion_setup_setting(struct skin_element *element, int param_no,
#ifndef __PCTOOL__ #ifndef __PCTOOL__
int p = param_no; int p = param_no;
char *name = get_param_text(element, p++); char *name = get_param_text(element, p++);
const struct settings_list *setting = find_setting_by_cfgname(name, NULL); const struct settings_list *setting = find_setting_by_cfgname(name);
if (!setting) if (!setting)
return WPS_ERROR_INVALID_PARAM; return WPS_ERROR_INVALID_PARAM;

View file

@ -300,7 +300,7 @@ int skin_get_touchaction(struct gui_wps *gwps, int* edge_offset)
case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */ case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
{ {
const struct settings_list *rep_setting = const struct settings_list *rep_setting =
find_setting(&global_settings.repeat_mode, NULL); find_setting(&global_settings.repeat_mode);
option_select_next_val(rep_setting, false, true); option_select_next_val(rep_setting, false, true);
audio_flush_and_reload_tracks(); audio_flush_and_reload_tracks();
returncode = ACTION_REDRAW; returncode = ACTION_REDRAW;

View file

@ -147,7 +147,7 @@ static const char* get_menu_item_name(int selected_item,
type = (menu->flags&MENU_TYPE_MASK); type = (menu->flags&MENU_TYPE_MASK);
if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT)) if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT))
{ {
const struct settings_list *v = find_setting(menu->variable, NULL); const struct settings_list *v = find_setting(menu->variable);
if (v) if (v)
return str(v->lang_id); return str(v->lang_id);
else return "Not Done yet!"; else return "Not Done yet!";
@ -356,14 +356,12 @@ void do_setting_from_menu(const struct menu_item_ex *temp,
struct viewport parent[NB_SCREENS]) struct viewport parent[NB_SCREENS])
{ {
char *title; char *title;
int setting_id;
if (!temp) if (!temp)
{ {
panicf("do_setting_from_menu, NULL pointer"); panicf("do_setting_from_menu, NULL pointer");
return; return;
} }
const struct settings_list *setting = const struct settings_list *setting = find_setting(temp->variable);
find_setting(temp->variable, &setting_id);
if ((temp->flags&MENU_TYPE_MASK) == MT_SETTING_W_TEXT) if ((temp->flags&MENU_TYPE_MASK) == MT_SETTING_W_TEXT)
title = temp->callback_and_desc->desc; title = temp->callback_and_desc->desc;
@ -523,7 +521,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected,
ID2P(LANG_RESET_SETTING)); ID2P(LANG_RESET_SETTING));
const struct menu_item_ex *context_menu; const struct menu_item_ex *context_menu;
const struct settings_list *setting = const struct settings_list *setting =
find_setting(temp->variable, NULL); find_setting(temp->variable);
#ifdef HAVE_QUICKSCREEN #ifdef HAVE_QUICKSCREEN
if (is_setting_quickscreenable(setting)) if (is_setting_quickscreenable(setting))
context_menu = &quickscreen_able_option; context_menu = &quickscreen_able_option;

View file

@ -462,30 +462,30 @@ int rectrigger(void)
/* TODO: what to do if there is < 4 lines on the screen? */ /* TODO: what to do if there is < 4 lines on the screen? */
settings[TRIGGER_MODE] = settings[TRIGGER_MODE] =
find_setting(&global_settings.rec_trigger_mode, NULL); find_setting(&global_settings.rec_trigger_mode);
settings[TRIGGER_TYPE] = settings[TRIGGER_TYPE] =
find_setting(&global_settings.rec_trigger_type, NULL); find_setting(&global_settings.rec_trigger_type);
settings[PRERECORD_TIME] = settings[PRERECORD_TIME] =
find_setting(&global_settings.rec_prerecord_time, NULL); find_setting(&global_settings.rec_prerecord_time);
settings[START_DURATION] = settings[START_DURATION] =
find_setting(&global_settings.rec_start_duration, NULL); find_setting(&global_settings.rec_start_duration);
settings[STOP_POSTREC] = settings[STOP_POSTREC] =
find_setting(&global_settings.rec_stop_postrec, NULL); find_setting(&global_settings.rec_stop_postrec);
settings[STOP_GAP] = settings[STOP_GAP] =
find_setting(&global_settings.rec_stop_gap, NULL); find_setting(&global_settings.rec_stop_gap);
if (global_settings.peak_meter_dbfs) /* show the dB settings */ if (global_settings.peak_meter_dbfs) /* show the dB settings */
{ {
settings[START_THRESHOLD] = settings[START_THRESHOLD] =
find_setting(&global_settings.rec_start_thres_db, NULL); find_setting(&global_settings.rec_start_thres_db);
settings[STOP_THRESHOLD] = settings[STOP_THRESHOLD] =
find_setting(&global_settings.rec_stop_thres_db, NULL); find_setting(&global_settings.rec_stop_thres_db);
} }
else else
{ {
settings[START_THRESHOLD] = settings[START_THRESHOLD] =
find_setting(&global_settings.rec_start_thres_linear, NULL); find_setting(&global_settings.rec_start_thres_linear);
settings[STOP_THRESHOLD] = settings[STOP_THRESHOLD] =
find_setting(&global_settings.rec_stop_thres_linear, NULL); find_setting(&global_settings.rec_stop_thres_linear);
} }
gui_synclist_init(&lists, trigger_get_name, settings, false, 2, vp); gui_synclist_init(&lists, trigger_get_name, settings, false, 2, vp);
gui_synclist_set_nb_items(&lists, TRIG_OPTION_COUNT*2); gui_synclist_set_nb_items(&lists, TRIG_OPTION_COUNT*2);

View file

@ -669,10 +669,13 @@ static const struct plugin_api rockbox_api = {
tagcache_retrieve, tagcache_retrieve,
tagcache_search_finish, tagcache_search_finish,
tagcache_get_numeric, tagcache_get_numeric,
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) tagcache_get_stat,
#if defined(HAVE_TC_RAMCACHE)
tagcache_is_in_ram,
#if defined(HAVE_DIRCACHE)
tagcache_fill_tags, tagcache_fill_tags,
#endif #endif
tagcache_get_stat, #endif
#endif /* HAVE_TAGCACHE */ #endif /* HAVE_TAGCACHE */
#ifdef HAVE_ALBUMART #ifdef HAVE_ALBUMART
@ -820,11 +823,6 @@ static const struct plugin_api rockbox_api = {
/* new stuff at the end, sort into place next time /* new stuff at the end, sort into place next time
the API gets incompatible */ the API gets incompatible */
#ifdef HAVE_TAGCACHE
#ifdef HAVE_TC_RAMCACHE
tagcache_is_in_ram,
#endif
#endif
}; };
static int plugin_buffer_handle; static int plugin_buffer_handle;

View file

@ -157,12 +157,12 @@ int plugin_open(const char *plugin, const char *parameter);
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 256 #define PLUGIN_API_VERSION 257
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 255 #define PLUGIN_MIN_API_VERSION 257
/* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */
@ -766,10 +766,13 @@ struct plugin_api {
int tag, char *buf, long size); int tag, char *buf, long size);
void (*tagcache_search_finish)(struct tagcache_search *tcs); void (*tagcache_search_finish)(struct tagcache_search *tcs);
long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag); long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) struct tagcache_stat* (*tagcache_get_stat)(void);
#if defined(HAVE_TC_RAMCACHE)
bool (*tagcache_is_in_ram)(void);
#if defined(HAVE_DIRCACHE)
bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename); bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename);
#endif #endif
struct tagcache_stat* (*tagcache_get_stat)(void); #endif
#endif /* HAVE_TAGCACHE */ #endif /* HAVE_TAGCACHE */
#ifdef HAVE_ALBUMART #ifdef HAVE_ALBUMART
@ -824,7 +827,7 @@ struct plugin_api {
/* options */ /* options */
const struct settings_list* (*get_settings_list)(int*count); const struct settings_list* (*get_settings_list)(int*count);
const struct settings_list* (*find_setting)(const void* variable, int *id); const struct settings_list* (*find_setting)(const void* variable);
int (*settings_save)(void); int (*settings_save)(void);
bool (*option_screen)(const struct settings_list *setting, bool (*option_screen)(const struct settings_list *setting,
struct viewport parent[NB_SCREENS], struct viewport parent[NB_SCREENS],
@ -946,11 +949,6 @@ struct plugin_api {
#endif #endif
/* new stuff at the end, sort into place next time /* new stuff at the end, sort into place next time
the API gets incompatible */ the API gets incompatible */
#ifdef HAVE_TAGCACHE
#ifdef HAVE_TC_RAMCACHE
bool (*tagcache_is_in_ram)(void);
#endif
#endif
}; };
/* plugin header */ /* plugin header */

View file

@ -65,21 +65,21 @@ static bool nexttrack(void)
static bool volume(void) static bool volume(void)
{ {
const struct settings_list* vol = const struct settings_list* vol =
rb->find_setting(&rb->global_settings->volume, NULL); rb->find_setting(&rb->global_settings->volume);
return rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume"); return rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume");
} }
static bool shuffle(void) static bool shuffle(void)
{ {
const struct settings_list* shuffle = const struct settings_list* shuffle =
rb->find_setting(&rb->global_settings->playlist_shuffle, NULL); rb->find_setting(&rb->global_settings->playlist_shuffle);
return rb->option_screen((struct settings_list*)shuffle, parentvp, false, "Shuffle"); return rb->option_screen((struct settings_list*)shuffle, parentvp, false, "Shuffle");
} }
static bool repeat_mode(void) static bool repeat_mode(void)
{ {
const struct settings_list* repeat = const struct settings_list* repeat =
rb->find_setting(&rb->global_settings->repeat_mode, NULL); rb->find_setting(&rb->global_settings->repeat_mode);
int old_repeat = rb->global_settings->repeat_mode; int old_repeat = rb->global_settings->repeat_mode;
rb->option_screen((struct settings_list*)repeat, parentvp, false, "Repeat"); rb->option_screen((struct settings_list*)repeat, parentvp, false, "Repeat");

View file

@ -428,7 +428,7 @@ static void do_opt_menu(void)
options.dirty=1; /* Assume that the settings have been changed */ options.dirty=1; /* Assume that the settings have been changed */
struct viewport *parentvp = NULL; struct viewport *parentvp = NULL;
const struct settings_list* vol = rb->find_setting(&rb->global_settings->volume, NULL); const struct settings_list* vol = rb->find_setting(&rb->global_settings->volume);
while(!done) while(!done)
{ {

View file

@ -286,7 +286,7 @@ static void do_sound_settings(struct System* sys)
case 2: case 2:
{ {
const struct settings_list* vol = const struct settings_list* vol =
rb->find_setting(&rb->global_settings->volume, NULL); rb->find_setting(&rb->global_settings->volume);
rb->option_screen((struct settings_list*)vol, NULL, false, "Volume"); rb->option_screen((struct settings_list*)vol, NULL, false, "Volume");
break; break;
} }

View file

@ -335,7 +335,6 @@ bool settings_load_config(const char* file, bool apply)
{ {
logf("%s()\r\n", __func__); logf("%s()\r\n", __func__);
const struct settings_list *setting; const struct settings_list *setting;
int index;
int fd; int fd;
char line[128]; char line[128];
char* name; char* name;
@ -351,7 +350,7 @@ bool settings_load_config(const char* file, bool apply)
if (!settings_parseline(line, &name, &value)) if (!settings_parseline(line, &name, &value))
continue; continue;
setting = find_setting_by_cfgname(name, &index); setting = find_setting_by_cfgname(name);
if (!setting) if (!setting)
continue; continue;
@ -1158,36 +1157,32 @@ void settings_reset(void)
} }
/** Changing setting values **/ /** Changing setting values **/
const struct settings_list* find_setting(const void* variable, int *id) const struct settings_list* find_setting(const void* variable)
{ {
int i; for(int i = 0; i < nb_settings; i++)
for(i=0;i<nb_settings;i++)
{ {
if (settings[i].setting == variable) const struct settings_list *setting = &settings[i];
{ if (setting->setting == variable)
if (id) return setting;
*id = i;
return &settings[i];
}
} }
return NULL; return NULL;
} }
const struct settings_list* find_setting_by_cfgname(const char* name, int *id) const struct settings_list* find_setting_by_cfgname(const char* name)
{ {
int i;
logf("Searching for Setting: '%s'",name); logf("Searching for Setting: '%s'",name);
for (i=0; i<nb_settings; i++) for(int i = 0; i < nb_settings; i++)
{ {
if (settings[i].cfg_name && const struct settings_list *setting = &settings[i];
!strcasecmp(settings[i].cfg_name, name)) if (setting->cfg_name && !strcasecmp(setting->cfg_name, name))
{ {
logf("Found, flags: %s", debug_get_flags(settings[i].flags)); logf("Found, flags: %s", debug_get_flags(settings[i].flags));
if (id) *id = i; return setting;
return &settings[i];
} }
} }
logf("Setting: '%s' Not Found!",name); logf("Setting: '%s' Not Found!",name);
return NULL; return NULL;
} }

View file

@ -263,8 +263,8 @@ void settings_display(void);
enum optiontype { INT, BOOL }; enum optiontype { INT, BOOL };
const struct settings_list* find_setting(const void* variable, int *id); const struct settings_list* find_setting(const void* variable);
const struct settings_list* find_setting_by_cfgname(const char* name, int *id); const struct settings_list* find_setting_by_cfgname(const char* name);
bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len); bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len);
bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str); bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str);
void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len); void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len);

View file

@ -600,7 +600,7 @@ static void qs_load_from_cfg(void *var, char *value)
if (*value == '-') if (*value == '-')
*item = NULL; *item = NULL;
else else
*item = find_setting_by_cfgname(value, NULL); *item = find_setting_by_cfgname(value);
} }
static char* qs_write_to_cfg(void *var, char *buf, int buf_len) static char* qs_write_to_cfg(void *var, char *buf, int buf_len)
@ -613,14 +613,14 @@ static char* qs_write_to_cfg(void *var, char *buf, int buf_len)
static bool qs_is_changed(void* var, void* defaultval) static bool qs_is_changed(void* var, void* defaultval)
{ {
const struct settings_list *defaultsetting = find_setting(defaultval, NULL); const struct settings_list *defaultsetting = find_setting(defaultval);
return var != defaultsetting; return var != defaultsetting;
} }
static void qs_set_default(void* var, void* defaultval) static void qs_set_default(void* var, void* defaultval)
{ {
*(const struct settings_list **)var = find_setting(defaultval, NULL); *(const struct settings_list **)var = find_setting(defaultval);
} }
#endif #endif
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN

View file

@ -342,7 +342,7 @@ static int readline_cb(int n, char *buf, void *parameters)
strmemccpy(sc->u.path, value, MAX_PATH); strmemccpy(sc->u.path, value, MAX_PATH);
break; break;
case SHORTCUT_SETTING: case SHORTCUT_SETTING:
sc->u.setting = find_setting_by_cfgname(value, NULL); sc->u.setting = find_setting_by_cfgname(value);
break; break;
case SHORTCUT_TIME: case SHORTCUT_TIME:
#if CONFIG_RTC #if CONFIG_RTC

View file

@ -1488,7 +1488,7 @@ void talk_setting(const void *global_settings_variable)
const struct settings_list *setting; const struct settings_list *setting;
if (!global_settings.talk_menu) if (!global_settings.talk_menu)
return; return;
setting = find_setting(global_settings_variable, NULL); setting = find_setting(global_settings_variable);
if (setting == NULL) if (setting == NULL)
return; return;
if (setting->lang_id) if (setting->lang_id)

View file

@ -1759,7 +1759,7 @@ void semaphore_wait(struct semaphore *s)
\param s \param s
\description \description
const struct settings_list* find_setting(const void* variable, int *id) const struct settings_list* find_setting(const void* variable)
\group options \group options
\param variable \param variable
\param id \param id