diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-13 23:18:20 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-01-13 23:22:51 -0500 |
commit | 823f726f834932534fc21ba6227b5169fc707a20 (patch) | |
tree | dd34f9004150a55dbf8beeb1151cb37352089ecd | |
parent | 8e4429853d1ac024ac2b8069636cc210cf5bab1b (diff) |
puzzles: fix configuration menu (again!)
Change-Id: I440f3cea1bbeb3e7bda4aebefaaece3e8f3d44fd
-rw-r--r-- | apps/plugins/puzzles/rockbox.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c index 2884e4e775..c3921a80b6 100644 --- a/apps/plugins/puzzles/rockbox.c +++ b/apps/plugins/puzzles/rockbox.c @@ -805,8 +805,11 @@ static int list_choose(const char *list_str, const char *title) } } -static void do_configure_item(config_item *cfg) +#define CONFIGMENU_FREEDSTR 1 +#define CONFIGMENU_SUCCESS 2 +static int do_configure_item(config_item *cfg) { + int rc = 0; switch(cfg->type) { case C_STRING: @@ -819,34 +822,46 @@ static void do_configure_item(config_item *cfg) if(rb->kbd_input(newstr, MAX_STRLEN) < 0) { sfree(newstr); - break; + return rc; } + if(strcmp(newstr, cfg->sval)) + rc |= CONFIGMENU_SUCCESS; sfree(cfg->sval); cfg->sval = newstr; - break; + rc |= CONFIGMENU_FREEDSTR; + return rc; } case C_BOOLEAN: { bool res = cfg->ival != 0; + bool orig = res; rb->set_bool(cfg->name, &res); /* seems to reset backdrop */ rb->lcd_set_backdrop(NULL); cfg->ival = res; + if(cfg->ival != orig) + rc |= CONFIGMENU_SUCCESS; break; } case C_CHOICES: { + int old = cfg->ival; int sel = list_choose(cfg->sval, cfg->name); if(sel >= 0) + { cfg->ival = sel; + } + if(cfg->ival != old) + rc |= CONFIGMENU_SUCCESS; break; } default: fatal("bad type"); break; } + return rc; } const char *config_formatter(int sel, void *data, char *buf, size_t len) @@ -904,14 +919,24 @@ static bool config_menu(void) config_item old; int pos = rb->gui_synclist_get_sel_pos(&list); memcpy(&old, config + pos, sizeof(old)); - do_configure_item(config + pos); + char *old_str; + if(old.type == C_STRING) + old_str = dupstr(old.sval); + int rc = do_configure_item(config + pos); char *err = midend_set_config(me, CFG_SETTINGS, config); if(err) { rb->splash(HZ, err); memcpy(config + pos, &old, sizeof(old)); + if(rc & CONFIGMENU_FREEDSTR) + config[pos].sval = old_str; } - else + else if(old.type == C_STRING) + { + /* success, and we duplicated the old string, so free it */ + sfree(old_str); + } + if(!err && (rc & CONFIGMENU_SUCCESS)) { success = true; } |