forked from len0rd/rockbox
settings: Clean up and simplify settings_load_config()
Use find_setting_by_cfgname() instead of doing it manually. Reduce the excessive level of indentation. Change-Id: I410fd7e0c26d065bc479dad3b6facfb5368cd091
This commit is contained in:
parent
5b1dd64f50
commit
6346be51a3
1 changed files with 61 additions and 61 deletions
|
|
@ -310,12 +310,14 @@ bool copy_filename_setting(char *buf, size_t buflen, const char *input,
|
||||||
|
|
||||||
bool settings_load_config(const char* file, bool apply)
|
bool settings_load_config(const char* file, bool apply)
|
||||||
{
|
{
|
||||||
|
const struct settings_list *setting;
|
||||||
|
int index;
|
||||||
int fd;
|
int fd;
|
||||||
char line[128];
|
char line[128];
|
||||||
char* name;
|
char* name;
|
||||||
char* value;
|
char* value;
|
||||||
int i;
|
|
||||||
bool theme_changed = false;
|
bool theme_changed = false;
|
||||||
|
|
||||||
fd = open_utf8(file, O_RDONLY);
|
fd = open_utf8(file, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -324,38 +326,38 @@ bool settings_load_config(const char* file, bool apply)
|
||||||
{
|
{
|
||||||
if (!settings_parseline(line, &name, &value))
|
if (!settings_parseline(line, &name, &value))
|
||||||
continue;
|
continue;
|
||||||
for(i=0; i<nb_settings; i++)
|
|
||||||
{
|
setting = find_setting_by_cfgname(name, &index);
|
||||||
if (settings[i].cfg_name == NULL)
|
if (!setting)
|
||||||
continue;
|
continue;
|
||||||
if (!strcasecmp(name,settings[i].cfg_name))
|
|
||||||
{
|
if (setting->flags & F_THEMESETTING)
|
||||||
if (settings[i].flags&F_THEMESETTING)
|
|
||||||
theme_changed = true;
|
theme_changed = true;
|
||||||
switch (settings[i].flags&F_T_MASK)
|
|
||||||
|
switch (setting->flags & F_T_MASK)
|
||||||
{
|
{
|
||||||
case F_T_CUSTOM:
|
case F_T_CUSTOM:
|
||||||
settings[i].custom_setting->load_from_cfg(settings[i].setting, value);
|
setting->custom_setting->load_from_cfg(setting->setting, value);
|
||||||
break;
|
break;
|
||||||
case F_T_INT:
|
case F_T_INT:
|
||||||
case F_T_UINT:
|
case F_T_UINT:
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
if (settings[i].flags&F_RGB)
|
if (setting->flags & F_RGB)
|
||||||
hex_to_rgb(value, (int*)settings[i].setting);
|
hex_to_rgb(value, (int*)setting->setting);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (settings[i].cfg_vals == NULL)
|
if (setting->cfg_vals == NULL)
|
||||||
{
|
{
|
||||||
*(int*)settings[i].setting = atoi(value);
|
*(int*)setting->setting = atoi(value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int temp, *v = (int*)settings[i].setting;
|
int temp, *v = (int*)setting->setting;
|
||||||
bool found = cfg_string_to_int(i, &temp, value);
|
bool found = cfg_string_to_int(index, &temp, value);
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
if (settings[i].flags&F_TABLE_SETTING)
|
if (setting->flags & F_TABLE_SETTING)
|
||||||
*v = settings[i].table_setting->values[temp];
|
*v = setting->table_setting->values[temp];
|
||||||
else
|
else
|
||||||
*v = temp;
|
*v = temp;
|
||||||
}
|
}
|
||||||
|
|
@ -364,7 +366,7 @@ bool settings_load_config(const char* file, bool apply)
|
||||||
* don't have int-like values, and would
|
* don't have int-like values, and would
|
||||||
* fall back to the first value (i.e. 0)
|
* fall back to the first value (i.e. 0)
|
||||||
* due to atoi */
|
* due to atoi */
|
||||||
if (!(settings[i].flags&F_CHOICE_SETTING))
|
if (setting->flags & F_CHOICE_SETTING)
|
||||||
*v = atoi(value);
|
*v = atoi(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -372,24 +374,22 @@ bool settings_load_config(const char* file, bool apply)
|
||||||
case F_T_BOOL:
|
case F_T_BOOL:
|
||||||
{
|
{
|
||||||
int temp;
|
int temp;
|
||||||
if (cfg_string_to_int(i,&temp,value))
|
if (cfg_string_to_int(index, &temp, value))
|
||||||
*(bool*)settings[i].setting = (temp!=0);
|
*(bool*)setting->setting = !!temp;
|
||||||
if (settings[i].bool_setting->option_callback)
|
if (setting->bool_setting->option_callback)
|
||||||
settings[i].bool_setting->option_callback(temp!=0);
|
setting->bool_setting->option_callback(!!temp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* these can be plain text, filenames, or dirnames */
|
||||||
case F_T_CHARPTR:
|
case F_T_CHARPTR:
|
||||||
case F_T_UCHARPTR:
|
case F_T_UCHARPTR:
|
||||||
{
|
{
|
||||||
const struct filename_setting *fs = settings[i].filename_setting;
|
const struct filename_setting *fs = setting->filename_setting;
|
||||||
copy_filename_setting((char*)settings[i].setting,
|
copy_filename_setting((char*)setting->setting,
|
||||||
fs->max_len, value, fs);
|
fs->max_len, value, fs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
} /* if (!strcmp(name,settings[i].cfg_name)) */
|
|
||||||
} /* for(...) */
|
|
||||||
} /* while(...) */
|
} /* while(...) */
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -1145,7 +1145,7 @@ const struct settings_list* find_setting_by_cfgname(const char* name, int *id)
|
||||||
for (i=0; i<nb_settings; i++)
|
for (i=0; i<nb_settings; i++)
|
||||||
{
|
{
|
||||||
if (settings[i].cfg_name &&
|
if (settings[i].cfg_name &&
|
||||||
!strcmp(settings[i].cfg_name, name))
|
!strcasecmp(settings[i].cfg_name, name))
|
||||||
{
|
{
|
||||||
if (id) *id = i;
|
if (id) *id = i;
|
||||||
return &settings[i];
|
return &settings[i];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue