From f0d2861fc58a81ad6dc520279c42710b1d02e20a Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 1 Feb 2007 13:57:14 +0000 Subject: when saving config.cfg, only save settings which are not the same as default, hopefully will give a small boost to saving and loading times. Doing a manual save from "manage settings" > "write config" will save every setting. Adds an option to save a cfg file from only the settings needed in a theme .cfg (I may have missed some so let me know). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12172 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 14 ++++++++++++++ apps/settings.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- apps/settings.h | 6 +++++- apps/settings_list.c | 21 +++++++++++++-------- apps/settings_list.h | 4 ++-- apps/settings_menu.c | 11 ++++++++++- 6 files changed, 89 insertions(+), 16 deletions(-) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index e9c9f4c50c..83cbe0e98f 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -10473,3 +10473,17 @@ *: "Play Next" + + id: LANG_SAVE_THEME + desc: save a theme file + user: + + *: "Save Theme Settings" + + + *: "Save Theme Settings" + + + *: "Save Theme Settings" + + diff --git a/apps/settings.c b/apps/settings.c index faf1f92773..f0833a65c2 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -402,8 +402,41 @@ static bool cfg_int_to_string(int setting_id, int val, char* buf) } return true; } +static bool is_changed(int setting_id) +{ + const struct settings_list *setting = &settings[setting_id]; + switch (setting->flags&F_T_MASK) + { + case F_T_INT: + case F_T_UINT: + if (setting->flags&F_DEF_ISFUNC) + { + if (*(int*)setting->setting == setting->default_val.func()) + return false; + } + else if (setting->flags&F_T_SOUND) + { + if (*(int*)setting->setting == + sound_default(setting->sound_setting->setting)) + return false; + } + else if (*(int*)setting->setting == setting->default_val.int_) + return false; + break; + case F_T_BOOL: + if (*(bool*)setting->setting == setting->default_val.bool_) + return false; + break; + case F_T_CHARPTR: + case F_T_UCHARPTR: + if (!strcmp((char*)setting->setting, setting->default_val.charptr)) + return false; + break; + } + return true; +} -bool settings_write_config(char* filename) +static bool settings_write_config(char* filename, int options) { int i; int fd; @@ -418,6 +451,14 @@ bool settings_write_config(char* filename) if (settings[i].cfg_name == NULL) continue; value[0] = '\0'; + + if ((options == SETTINGS_SAVE_CHANGED) && + !is_changed(i)) + continue; + else if ((options == SETTINGS_SAVE_THEME) && + ((settings[i].flags&F_THEMESETTING) == 0)) + continue; + switch (settings[i].flags&F_T_MASK) { case F_T_INT: @@ -477,7 +518,7 @@ static bool flush_config_block_callback(void) { bool r1, r2; r1 = write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); - r2 = settings_write_config(CONFIGFILE); + r2 = settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED); return r1 || r2; } @@ -536,7 +577,7 @@ int settings_save( void ) } return 0; } -bool settings_save_config(void) +bool settings_save_config(int options) { char filename[MAX_PATH]; @@ -554,7 +595,7 @@ bool settings_save_config(void) } } - if (settings_write_config(filename)) + if (settings_write_config(filename, options)) gui_syncsplash(HZ, true, str(LANG_SETTINGS_SAVED)); else gui_syncsplash(HZ, true, str(LANG_FAILED)); return true; diff --git a/apps/settings.h b/apps/settings.h index e8db3289a1..ea3df8ef79 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -206,7 +206,11 @@ bool settings_load_config(const char* file, bool apply); void status_save( void ); int settings_save(void); -bool settings_save_config(void); +/* defines for the options paramater */ +#define SETTINGS_SAVE_CHANGED 0 +#define SETTINGS_SAVE_ALL 1 +#define SETTINGS_SAVE_THEME 2 +bool settings_save_config(int options); void settings_reset(void); void sound_settings_apply(void); diff --git a/apps/settings_list.c b/apps/settings_list.c index 6243607264..f9ef383f85 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -155,7 +155,7 @@ const struct settings_list settings[] = { /* display */ OFFON_SETTING(0,invert_cursor, LANG_INVERT_CURSOR, true,"invert cursor", NULL), - OFFON_SETTING(0,statusbar, LANG_STATUS_BAR, true,"statusbar", NULL), + OFFON_SETTING(F_THEMESETTING,statusbar, LANG_STATUS_BAR, true,"statusbar", NULL), OFFON_SETTING(0,scrollbar, LANG_SCROLL_BAR, true,"scrollbar", NULL), #if CONFIG_KEYPAD == RECORDER_PAD OFFON_SETTING(0,buttonbar, LANG_BUTTON_BAR ,true,"buttonbar", NULL), @@ -287,9 +287,9 @@ const struct settings_list settings[] = { OFFON_SETTING(0,scroll_paginated,LANG_SCROLL_PAGINATED, false,"scroll paginated",NULL), #ifdef HAVE_LCD_COLOR - {F_T_INT|F_RGB,GS(fg_color),-1,INT(LCD_DEFAULT_FG), + {F_T_INT|F_RGB|F_THEMESETTING ,GS(fg_color),-1,INT(LCD_DEFAULT_FG), "foreground color",NULL,UNUSED}, - {F_T_INT|F_RGB,GS(bg_color),-1,INT(LCD_DEFAULT_BG), + {F_T_INT|F_RGB|F_THEMESETTING ,GS(bg_color),-1,INT(LCD_DEFAULT_BG), "background color",NULL,UNUSED}, #endif /* more playback */ @@ -676,16 +676,21 @@ const struct settings_list settings[] = { /** settings not in the old config blocks **/ #ifdef CONFIG_TUNER - FILENAME_SETTING(0,fmr_file,"fmr","",FMPRESET_PATH "/",".fmr",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING, fmr_file, "fmr", + "", FMPRESET_PATH "/", ".fmr", MAX_FILENAME+1), #endif - FILENAME_SETTING(0,font_file,"font","",FONT_DIR "/",".fnt",MAX_FILENAME+1), - FILENAME_SETTING(0,wps_file, "wps","",WPS_DIR "/",".wps",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING, font_file, "font", + "", FONT_DIR "/", ".fnt", MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,wps_file, "wps", + "", WPS_DIR "/", ".wps", MAX_FILENAME+1), FILENAME_SETTING(0,lang_file,"lang","",LANG_DIR "/",".lng",MAX_FILENAME+1), #ifdef HAVE_REMOTE_LCD - FILENAME_SETTING(0,rwps_file,"rwps","",WPS_DIR "/",".rwps",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,rwps_file,"rwps", + "", WPS_DIR "/", ".rwps", MAX_FILENAME+1), #endif #if LCD_DEPTH > 1 - FILENAME_SETTING(0,backdrop_file,"backdrop","",BACKDROP_DIR "/",".bmp",MAX_FILENAME+1), + FILENAME_SETTING(F_THEMESETTING,backdrop_file,"backdrop", + "", BACKDROP_DIR "/", ".bmp", MAX_FILENAME+1), #endif #ifdef HAVE_LCD_BITMAP FILENAME_SETTING(0,kbd_file,"kbd","",ROCKBOX_DIR "/",".kbd",MAX_FILENAME+1), diff --git a/apps/settings_list.h b/apps/settings_list.h index 9e50b85f09..195703bfe3 100644 --- a/apps/settings_list.h +++ b/apps/settings_list.h @@ -83,10 +83,10 @@ struct int_setting { - number of bytes for a NVRAM setting is changed - a NVRAM setting is removed */ - +#define F_THEMESETTING 0x800000 struct settings_list { - uint32_t flags; /* ____ ____ _FFF ____ ____ NNN_ IFRB STTT */ + uint32_t flags; /* ____ ____ TFFF ____ ____ NNN_ IFRB STTT */ void *setting; int lang_id; /* -1 for none */ union storage_type default_val; diff --git a/apps/settings_menu.c b/apps/settings_menu.c index b1204e2c1a..8e6fbd02d7 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -2161,6 +2161,14 @@ static bool time_settings_menu(void) return result; } #endif +static bool manage_settings_write_config(void) +{ + return settings_save_config(SETTINGS_SAVE_ALL); +} +static bool manage_settings_write_theme(void) +{ + return settings_save_config(SETTINGS_SAVE_THEME); +} bool manage_settings_menu(void) { @@ -2170,7 +2178,8 @@ bool manage_settings_menu(void) static const struct menu_item items[] = { { ID2P(LANG_CUSTOM_CFG), custom_cfg_browse }, { ID2P(LANG_RESET), reset_settings }, - { ID2P(LANG_SAVE_SETTINGS), settings_save_config }, + { ID2P(LANG_SAVE_SETTINGS), manage_settings_write_config}, + { ID2P(LANG_SAVE_THEME), manage_settings_write_theme}, }; m=menu_init( items, sizeof(items) / sizeof(*items), NULL, -- cgit v1.2.3