diff options
Diffstat (limited to 'apps/plugins/puzzles/rockbox.c')
-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) | |||
805 | } | 805 | } |
806 | } | 806 | } |
807 | 807 | ||
808 | static void do_configure_item(config_item *cfg) | 808 | #define CONFIGMENU_FREEDSTR 1 |
809 | #define CONFIGMENU_SUCCESS 2 | ||
810 | static int do_configure_item(config_item *cfg) | ||
809 | { | 811 | { |
812 | int rc = 0; | ||
810 | switch(cfg->type) | 813 | switch(cfg->type) |
811 | { | 814 | { |
812 | case C_STRING: | 815 | case C_STRING: |
@@ -819,34 +822,46 @@ static void do_configure_item(config_item *cfg) | |||
819 | if(rb->kbd_input(newstr, MAX_STRLEN) < 0) | 822 | if(rb->kbd_input(newstr, MAX_STRLEN) < 0) |
820 | { | 823 | { |
821 | sfree(newstr); | 824 | sfree(newstr); |
822 | break; | 825 | return rc; |
823 | } | 826 | } |
827 | if(strcmp(newstr, cfg->sval)) | ||
828 | rc |= CONFIGMENU_SUCCESS; | ||
824 | sfree(cfg->sval); | 829 | sfree(cfg->sval); |
825 | cfg->sval = newstr; | 830 | cfg->sval = newstr; |
826 | break; | 831 | rc |= CONFIGMENU_FREEDSTR; |
832 | return rc; | ||
827 | } | 833 | } |
828 | case C_BOOLEAN: | 834 | case C_BOOLEAN: |
829 | { | 835 | { |
830 | bool res = cfg->ival != 0; | 836 | bool res = cfg->ival != 0; |
837 | bool orig = res; | ||
831 | rb->set_bool(cfg->name, &res); | 838 | rb->set_bool(cfg->name, &res); |
832 | 839 | ||
833 | /* seems to reset backdrop */ | 840 | /* seems to reset backdrop */ |
834 | rb->lcd_set_backdrop(NULL); | 841 | rb->lcd_set_backdrop(NULL); |
835 | 842 | ||
836 | cfg->ival = res; | 843 | cfg->ival = res; |
844 | if(cfg->ival != orig) | ||
845 | rc |= CONFIGMENU_SUCCESS; | ||
837 | break; | 846 | break; |
838 | } | 847 | } |
839 | case C_CHOICES: | 848 | case C_CHOICES: |
840 | { | 849 | { |
850 | int old = cfg->ival; | ||
841 | int sel = list_choose(cfg->sval, cfg->name); | 851 | int sel = list_choose(cfg->sval, cfg->name); |
842 | if(sel >= 0) | 852 | if(sel >= 0) |
853 | { | ||
843 | cfg->ival = sel; | 854 | cfg->ival = sel; |
855 | } | ||
856 | if(cfg->ival != old) | ||
857 | rc |= CONFIGMENU_SUCCESS; | ||
844 | break; | 858 | break; |
845 | } | 859 | } |
846 | default: | 860 | default: |
847 | fatal("bad type"); | 861 | fatal("bad type"); |
848 | break; | 862 | break; |
849 | } | 863 | } |
864 | return rc; | ||
850 | } | 865 | } |
851 | 866 | ||
852 | const char *config_formatter(int sel, void *data, char *buf, size_t len) | 867 | const char *config_formatter(int sel, void *data, char *buf, size_t len) |
@@ -904,14 +919,24 @@ static bool config_menu(void) | |||
904 | config_item old; | 919 | config_item old; |
905 | int pos = rb->gui_synclist_get_sel_pos(&list); | 920 | int pos = rb->gui_synclist_get_sel_pos(&list); |
906 | memcpy(&old, config + pos, sizeof(old)); | 921 | memcpy(&old, config + pos, sizeof(old)); |
907 | do_configure_item(config + pos); | 922 | char *old_str; |
923 | if(old.type == C_STRING) | ||
924 | old_str = dupstr(old.sval); | ||
925 | int rc = do_configure_item(config + pos); | ||
908 | char *err = midend_set_config(me, CFG_SETTINGS, config); | 926 | char *err = midend_set_config(me, CFG_SETTINGS, config); |
909 | if(err) | 927 | if(err) |
910 | { | 928 | { |
911 | rb->splash(HZ, err); | 929 | rb->splash(HZ, err); |
912 | memcpy(config + pos, &old, sizeof(old)); | 930 | memcpy(config + pos, &old, sizeof(old)); |
931 | if(rc & CONFIGMENU_FREEDSTR) | ||
932 | config[pos].sval = old_str; | ||
913 | } | 933 | } |
914 | else | 934 | else if(old.type == C_STRING) |
935 | { | ||
936 | /* success, and we duplicated the old string, so free it */ | ||
937 | sfree(old_str); | ||
938 | } | ||
939 | if(!err && (rc & CONFIGMENU_SUCCESS)) | ||
915 | { | 940 | { |
916 | success = true; | 941 | success = true; |
917 | } | 942 | } |