summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
authorSteve Bavin <pondlife@pondlife.me>2008-03-25 15:24:03 +0000
committerSteve Bavin <pondlife@pondlife.me>2008-03-25 15:24:03 +0000
commitcd88e2ad93881c9516c7c712b628b42450506f4f (patch)
tree90a5787cde4baddfdd6a6bb02285c7267671a855 /apps/settings.c
parent222994f180a7cc6582864df8d13d1fb456e1d4f0 (diff)
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
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c141
1 files changed, 100 insertions, 41 deletions
diff --git a/apps/settings.c b/apps/settings.c
index 449a38b96f..9374c2e372 100644
--- a/apps/settings.c
+++ b/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;
@@ -581,7 +584,7 @@ static void update_runtime(void)
global_status.topruntime = global_status.runtime;
}
-void status_save( void )
+void status_save(void)
{
update_runtime();
#ifdef HAVE_RTC_RAM
@@ -593,7 +596,7 @@ void status_save( void )
#endif
}
-int settings_save( void )
+int settings_save(void)
{
update_runtime();
#ifdef HAVE_RTC_RAM
@@ -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);
+}
+
+
+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;
+}
-/** extra stuff which is probably misplaced **/
-void set_file(char* filename, char* setting, int maxlen)
+void set_file(const char* filename, char* setting, const int maxlen)
{
char* fptr = strrchr(filename,'/');
int len;