summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2008-11-03 10:43:37 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2008-11-03 10:43:37 +0000
commit5395957549c9b04fefa87a0aedb6bc15bf360739 (patch)
treef80721fe66ef078c92a1b0180c4d108c505c5289
parentee0111a53986ab309e3ae1a819d55318a950e99a (diff)
downloadrockbox-5395957549c9b04fefa87a0aedb6bc15bf360739.zip
rockbox-5395957549c9b04fefa87a0aedb6bc15bf360739.tar.gz
rockbox-5395957549c9b04fefa87a0aedb6bc15bf360739.tar.bz2
rockbox-5395957549c9b04fefa87a0aedb6bc15bf360739.tar.xz
Add a setting type which is completly user-defined. This setting type cannot be used by the regular menu macros (e.g MENUITEM_SETTING() macro) so if you are goign to use this type remember to implement the setting screen seperately (using option_select() if you can)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18983 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/settings.c15
-rw-r--r--apps/settings_list.c8
-rw-r--r--apps/settings_list.h32
3 files changed, 55 insertions, 0 deletions
diff --git a/apps/settings.c b/apps/settings.c
index e15bfc8..bdfaba2 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -282,6 +282,9 @@ bool settings_load_config(const char* file, bool apply)
{
switch (settings[i].flags&F_T_MASK)
{
+ case F_T_CUSTOM:
+ settings[i].custom_setting->load_from_cfg(settings[i].setting, value);
+ break;
case F_T_INT:
case F_T_UINT:
#ifdef HAVE_LCD_COLOR
@@ -419,6 +422,10 @@ static bool is_changed(int setting_id)
const struct settings_list *setting = &settings[setting_id];
switch (setting->flags&F_T_MASK)
{
+ case F_T_CUSTOM:
+ return setting->custom_setting->is_changed(setting->setting,
+ setting->default_val.custom);
+ break;
case F_T_INT:
case F_T_UINT:
if (setting->flags&F_DEF_ISFUNC)
@@ -498,6 +505,10 @@ static bool settings_write_config(const char* filename, int options)
}
switch (settings[i].flags&F_T_MASK)
{
+ case F_T_CUSTOM:
+ settings[i].custom_setting->write_to_cfg(settings[i].setting,
+ value, MAX_PATH);
+ break;
case F_T_INT:
case F_T_UINT:
#ifdef HAVE_LCD_COLOR
@@ -952,6 +963,10 @@ void reset_setting(const struct settings_list *setting, void *var)
{
switch (setting->flags&F_T_MASK)
{
+ case F_T_CUSTOM:
+ setting->custom_setting->set_default(setting->setting,
+ setting->default_val.custom);
+ break;
case F_T_INT:
case F_T_UINT:
if (setting->flags&F_DEF_ISFUNC)
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 3eeeffd..99a4601 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -165,6 +165,14 @@
{cb, formatter, get_talk_id, unit, count, \
(const int[]){__VA_ARGS__}}}}}
+#define CUSTOM_SETTING(flags, var, lang_id, default, name, \
+ load_from_cfg, write_to_cfg, \
+ is_change, set_default) \
+ {flags|F_CUSTOM_SETTING|F_T_CUSTOM|F_BANFROMQS, \
+ &global_settings.var, lang_id, \
+ {.custom = (void*)default}, name, NULL, \
+ {.custom_setting = (struct custom_setting[]){ \
+ {load_from_cfg, write_to_cfg, is_change, set_default}}}}
/* some sets of values which are used more than once, to save memory */
static const char off_on[] = "off,on";
static const char off_on_ask[] = "off,on,ask";
diff --git a/apps/settings_list.h b/apps/settings_list.h
index 326effd..60e3f7f 100644
--- a/apps/settings_list.h
+++ b/apps/settings_list.h
@@ -35,6 +35,7 @@ union storage_type {
char *charptr;
unsigned char *ucharptr;
_isfunc_type func;
+ void* custom;
};
/* the variable type for the setting */
#define F_T_INT 1
@@ -42,6 +43,7 @@ union storage_type {
#define F_T_BOOL 3
#define F_T_CHARPTR 4
#define F_T_UCHARPTR 5
+#define F_T_CUSTOM 6 /* MUST use struct custom_setting below */
#define F_T_MASK 0x7
struct sound_setting {
@@ -104,6 +106,35 @@ struct table_setting {
#define F_MAX_ISFUNC 0x200000 /* max(above) is function pointer to above type */
#define F_DEF_ISFUNC 0x400000 /* default_val is function pointer to above type */
+/* The next stuff is used when none of the other types work.
+ Should really only be used if the value you want to store in global_settings
+ is very different to the string you want to use in the config. */
+#define F_CUSTOM_SETTING 0x8000
+struct custom_setting {
+ /* load the saved value from the .cfg
+ setting: pointer into global_settings
+ value: the text from the .cfg
+ */
+ void (*load_from_cfg)(void* setting, char*value);
+ /* store the value into a .cfg
+ setting: pointer into global_settings
+ buf/buf_len: buffer and length to write the string into.
+ Returns the string.
+ */
+ char* (*write_to_cfg)(void* setting, char*buf, int buf_len);
+ /* Check if the setting has been changed from the default.
+ setting: pointer into global_settings
+ defaultval: the value given in the settings_list.c macro
+ Return true if the setting was changed
+ */
+ bool (*is_changed)(void* setting, void* defaultval);
+ /* Set the setting back to its default value.
+ setting: pointer into global_settings
+ defaultval: the value given in the settings_list.c macro
+ */
+ void (*set_default)(void* setting, void* defaultval);
+};
+
#define F_THEMESETTING 0x0800000
#define F_RECSETTING 0x1000000
#define F_EQSETTING 0x2000000
@@ -137,6 +168,7 @@ struct settings_list {
const struct int_setting *int_setting; /* use F_INT_SETTING */
const struct choice_setting *choice_setting; /* F_CHOICE_SETTING */
const struct table_setting *table_setting; /* F_TABLE_SETTING */
+ const struct custom_setting *custom_setting; /* F_CUSTOM_SETTING */
};
};
const struct settings_list* get_settings_list(int*count);