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.tar.gz
rockbox-5395957549c9b04fefa87a0aedb6bc15bf360739.zip
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 e15bfc8638..bdfaba2f44 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -282,6 +282,9 @@ bool settings_load_config(const char* file, bool apply)
282 { 282 {
283 switch (settings[i].flags&F_T_MASK) 283 switch (settings[i].flags&F_T_MASK)
284 { 284 {
285 case F_T_CUSTOM:
286 settings[i].custom_setting->load_from_cfg(settings[i].setting, value);
287 break;
285 case F_T_INT: 288 case F_T_INT:
286 case F_T_UINT: 289 case F_T_UINT:
287#ifdef HAVE_LCD_COLOR 290#ifdef HAVE_LCD_COLOR
@@ -419,6 +422,10 @@ static bool is_changed(int setting_id)
419 const struct settings_list *setting = &settings[setting_id]; 422 const struct settings_list *setting = &settings[setting_id];
420 switch (setting->flags&F_T_MASK) 423 switch (setting->flags&F_T_MASK)
421 { 424 {
425 case F_T_CUSTOM:
426 return setting->custom_setting->is_changed(setting->setting,
427 setting->default_val.custom);
428 break;
422 case F_T_INT: 429 case F_T_INT:
423 case F_T_UINT: 430 case F_T_UINT:
424 if (setting->flags&F_DEF_ISFUNC) 431 if (setting->flags&F_DEF_ISFUNC)
@@ -498,6 +505,10 @@ static bool settings_write_config(const char* filename, int options)
498 } 505 }
499 switch (settings[i].flags&F_T_MASK) 506 switch (settings[i].flags&F_T_MASK)
500 { 507 {
508 case F_T_CUSTOM:
509 settings[i].custom_setting->write_to_cfg(settings[i].setting,
510 value, MAX_PATH);
511 break;
501 case F_T_INT: 512 case F_T_INT:
502 case F_T_UINT: 513 case F_T_UINT:
503#ifdef HAVE_LCD_COLOR 514#ifdef HAVE_LCD_COLOR
@@ -952,6 +963,10 @@ void reset_setting(const struct settings_list *setting, void *var)
952{ 963{
953 switch (setting->flags&F_T_MASK) 964 switch (setting->flags&F_T_MASK)
954 { 965 {
966 case F_T_CUSTOM:
967 setting->custom_setting->set_default(setting->setting,
968 setting->default_val.custom);
969 break;
955 case F_T_INT: 970 case F_T_INT:
956 case F_T_UINT: 971 case F_T_UINT:
957 if (setting->flags&F_DEF_ISFUNC) 972 if (setting->flags&F_DEF_ISFUNC)
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 3eeeffd8fd..99a4601a3f 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -165,6 +165,14 @@
165 {cb, formatter, get_talk_id, unit, count, \ 165 {cb, formatter, get_talk_id, unit, count, \
166 (const int[]){__VA_ARGS__}}}}} 166 (const int[]){__VA_ARGS__}}}}}
167 167
168#define CUSTOM_SETTING(flags, var, lang_id, default, name, \
169 load_from_cfg, write_to_cfg, \
170 is_change, set_default) \
171 {flags|F_CUSTOM_SETTING|F_T_CUSTOM|F_BANFROMQS, \
172 &global_settings.var, lang_id, \
173 {.custom = (void*)default}, name, NULL, \
174 {.custom_setting = (struct custom_setting[]){ \
175 {load_from_cfg, write_to_cfg, is_change, set_default}}}}
168/* some sets of values which are used more than once, to save memory */ 176/* some sets of values which are used more than once, to save memory */
169static const char off_on[] = "off,on"; 177static const char off_on[] = "off,on";
170static const char off_on_ask[] = "off,on,ask"; 178static const char off_on_ask[] = "off,on,ask";
diff --git a/apps/settings_list.h b/apps/settings_list.h
index 326effdc40..60e3f7f0c7 100644
--- a/apps/settings_list.h
+++ b/apps/settings_list.h
@@ -35,6 +35,7 @@ union storage_type {
35 char *charptr; 35 char *charptr;
36 unsigned char *ucharptr; 36 unsigned char *ucharptr;
37 _isfunc_type func; 37 _isfunc_type func;
38 void* custom;
38}; 39};
39/* the variable type for the setting */ 40/* the variable type for the setting */
40#define F_T_INT 1 41#define F_T_INT 1
@@ -42,6 +43,7 @@ union storage_type {
42#define F_T_BOOL 3 43#define F_T_BOOL 3
43#define F_T_CHARPTR 4 44#define F_T_CHARPTR 4
44#define F_T_UCHARPTR 5 45#define F_T_UCHARPTR 5
46#define F_T_CUSTOM 6 /* MUST use struct custom_setting below */
45#define F_T_MASK 0x7 47#define F_T_MASK 0x7
46 48
47struct sound_setting { 49struct sound_setting {
@@ -104,6 +106,35 @@ struct table_setting {
104#define F_MAX_ISFUNC 0x200000 /* max(above) is function pointer to above type */ 106#define F_MAX_ISFUNC 0x200000 /* max(above) is function pointer to above type */
105#define F_DEF_ISFUNC 0x400000 /* default_val is function pointer to above type */ 107#define F_DEF_ISFUNC 0x400000 /* default_val is function pointer to above type */
106 108
109/* The next stuff is used when none of the other types work.
110 Should really only be used if the value you want to store in global_settings
111 is very different to the string you want to use in the config. */
112#define F_CUSTOM_SETTING 0x8000
113struct custom_setting {
114 /* load the saved value from the .cfg
115 setting: pointer into global_settings
116 value: the text from the .cfg
117 */
118 void (*load_from_cfg)(void* setting, char*value);
119 /* store the value into a .cfg
120 setting: pointer into global_settings
121 buf/buf_len: buffer and length to write the string into.
122 Returns the string.
123 */
124 char* (*write_to_cfg)(void* setting, char*buf, int buf_len);
125 /* Check if the setting has been changed from the default.
126 setting: pointer into global_settings
127 defaultval: the value given in the settings_list.c macro
128 Return true if the setting was changed
129 */
130 bool (*is_changed)(void* setting, void* defaultval);
131 /* Set the setting back to its default value.
132 setting: pointer into global_settings
133 defaultval: the value given in the settings_list.c macro
134 */
135 void (*set_default)(void* setting, void* defaultval);
136};
137
107#define F_THEMESETTING 0x0800000 138#define F_THEMESETTING 0x0800000
108#define F_RECSETTING 0x1000000 139#define F_RECSETTING 0x1000000
109#define F_EQSETTING 0x2000000 140#define F_EQSETTING 0x2000000
@@ -137,6 +168,7 @@ struct settings_list {
137 const struct int_setting *int_setting; /* use F_INT_SETTING */ 168 const struct int_setting *int_setting; /* use F_INT_SETTING */
138 const struct choice_setting *choice_setting; /* F_CHOICE_SETTING */ 169 const struct choice_setting *choice_setting; /* F_CHOICE_SETTING */
139 const struct table_setting *table_setting; /* F_TABLE_SETTING */ 170 const struct table_setting *table_setting; /* F_TABLE_SETTING */
171 const struct custom_setting *custom_setting; /* F_CUSTOM_SETTING */
140 }; 172 };
141}; 173};
142const struct settings_list* get_settings_list(int*count); 174const struct settings_list* get_settings_list(int*count);