Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

option_select.c clean-up option_screen

No functional changes

Change-Id: I0409b76258ce8af5aa9c2e68a2070b6e25927d1c

authored by

William Wilgus and committed by
William Wilgus
e8a17b12 27aa95af

+53 -49
+53 -49
apps/gui/option_select.c
··· 36 36 #include "menu.h" 37 37 #include "quickscreen.h" 38 38 39 + /* HASFLAG compares value to a (SINGLE) flag returns true if set, false otherwise */ 40 + #define HASFLAG(settings_list, flag) ((settings_list->flags & flag) == flag) 39 41 40 42 static int selection_to_val(const struct settings_list *setting, int selection); 41 43 int option_value_as_int(const struct settings_list *setting) ··· 65 67 intptr_t temp_var) 66 68 { 67 69 const char* str = buffer; 68 - if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 70 + if (HASFLAG(setting, F_BOOL_SETTING)) 69 71 { 70 72 bool val = (bool)temp_var; 71 73 strmemccpy(buffer, str(val? setting->bool_setting->lang_yes : 72 74 setting->bool_setting->lang_no), buf_len); 73 75 } 74 76 #if 0 /* probably dont need this one */ 75 - else if ((setting->flags & F_FILENAME) == F_FILENAME) 77 + else if (HASFLAG(setting, F_FILENAME)) 76 78 { 77 79 struct filename_setting *info = setting->filename_setting; 78 80 snprintf(buffer, buf_len, "%s%s%s", info->prefix, 79 81 (char*)temp_var, info->suffix); 80 82 } 81 83 #endif 82 - else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) || 83 - ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)) 84 + else if ((HASFLAG(setting, F_INT_SETTING)) || 85 + HASFLAG(setting, F_TABLE_SETTING)) 84 86 { 85 87 const struct int_setting *int_info = setting->int_setting; 86 88 const struct table_setting *tbl_info = setting->table_setting; 87 89 int info_unit; 88 90 const char *str_unit; 89 91 const char* (*formatter)(char*, size_t, int, const char*); 90 - if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 92 + if (HASFLAG(setting, F_INT_SETTING)) 91 93 { 92 94 formatter = int_info->formatter; 93 95 info_unit = int_info->unit; ··· 98 100 info_unit = tbl_info->unit; 99 101 } 100 102 101 - if ((setting->flags & F_TIME_SETTING) == F_TIME_SETTING) 103 + bool is_time_setting = HASFLAG(setting, F_TIME_SETTING); 104 + if (is_time_setting) 102 105 str = option_get_timestring(buffer, buf_len, (long)temp_var, info_unit); 103 106 104 107 str_unit = unit_strings_core[info_unit]; 108 + 105 109 if (formatter) 106 110 str = formatter(buffer, buf_len, (int)temp_var, str_unit); 107 - else if ((setting->flags & F_TIME_SETTING) != F_TIME_SETTING) 111 + else if (!is_time_setting) 108 112 snprintf(buffer, buf_len, "%d %s", (int)temp_var, str_unit?str_unit:""); 109 113 } 110 - else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 114 + else if (HASFLAG(setting, F_T_SOUND)) 111 115 { 112 116 format_sound_value(buffer, buf_len, 113 117 setting->sound_setting->setting, 114 118 temp_var); 115 119 } 116 - else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 120 + else if (HASFLAG(setting, F_CHOICE_SETTING)) 117 121 { 118 - if (setting->flags & F_CHOICETALKS) 122 + if (HASFLAG(setting, F_CHOICETALKS)) 119 123 { 120 124 const struct choice_setting *info = setting->choice_setting; 121 125 if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) ··· 138 142 } 139 143 void option_talk_value(const struct settings_list *setting, int value, bool enqueue) 140 144 { 141 - if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 145 + 146 + if (HASFLAG(setting, F_BOOL_SETTING)) 142 147 { 143 148 bool val = (value==1); 144 149 talk_id(val? setting->bool_setting->lang_yes : 145 150 setting->bool_setting->lang_no, enqueue); 146 151 } 147 152 #if 0 /* probably dont need this one */ 148 - else if ((setting->flags & F_FILENAME) == F_FILENAME) 153 + else if (HASFLAG(setting, F_FILENAME)) 149 154 { 150 155 } 151 156 #endif 152 - else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) || 153 - ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)) 157 + else if ((HASFLAG(setting, F_INT_SETTING)) || 158 + HASFLAG(setting, F_TABLE_SETTING)) 154 159 { 155 160 const struct int_setting *int_info = setting->int_setting; 156 161 const struct table_setting *tbl_info = setting->table_setting; 157 162 int unit; 158 163 int32_t (*get_talk_id)(int, int); 159 - if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 164 + if (HASFLAG(setting, F_INT_SETTING)) 160 165 { 161 166 unit = int_info->unit; 162 167 get_talk_id = int_info->get_talk_id; ··· 168 173 } 169 174 if (get_talk_id) 170 175 talk_id(get_talk_id(value, unit), enqueue); 171 - else if ((setting->flags & F_TIME_SETTING) == F_TIME_SETTING) 176 + else if (HASFLAG(setting, F_TIME_SETTING)) 172 177 talk_time_intervals(value, unit, enqueue); 173 178 else 174 179 talk_value(value, unit, enqueue); 175 180 } 176 - else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 181 + else if (HASFLAG(setting, F_T_SOUND)) 177 182 { 178 183 int talkunit = UNIT_INT; 179 184 int sound_setting = setting->sound_setting->setting; ··· 188 193 talkunit = UNIT_HERTZ; 189 194 talk_value_decimal(phys, talkunit, decimals, enqueue); 190 195 } 191 - else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 196 + else if (HASFLAG(setting, F_CHOICE_SETTING)) 192 197 { 193 - if (setting->flags & F_CHOICETALKS) 198 + if (HASFLAG(setting, F_CHOICETALKS)) 194 199 { 195 200 talk_id(setting->choice_setting->talks[value], enqueue); 196 201 } ··· 216 221 { 217 222 int val = 0; 218 223 int *value = setting->setting; 219 - if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 224 + if (HASFLAG(setting, F_BOOL_SETTING)) 220 225 { 221 226 *(bool*)value = !*(bool*)value; 222 227 if (apply && setting->bool_setting->option_callback) 223 228 setting->bool_setting->option_callback(*(bool*)value); 224 229 return; 225 230 } 226 - else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 231 + else if (HASFLAG(setting, F_INT_SETTING)) 227 232 { 228 233 struct int_setting *info = (struct int_setting *)setting->int_setting; 229 234 bool neg_step = (info->step < 0); ··· 243 248 if (apply && info->option_callback) 244 249 info->option_callback(val); 245 250 } 246 - else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 251 + else if (HASFLAG(setting, F_T_SOUND)) 247 252 { 248 253 int setting_id = setting->sound_setting->setting; 249 254 int steps = sound_steps(setting_id); ··· 265 270 if (apply) 266 271 sound_set(setting_id, val); 267 272 } 268 - else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 273 + else if (HASFLAG(setting, F_CHOICE_SETTING)) 269 274 { 270 275 struct choice_setting *info = (struct choice_setting *)setting->choice_setting; 271 276 if (!previous) ··· 284 289 if (apply && info->option_callback) 285 290 info->option_callback(val); 286 291 } 287 - else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) 292 + else if (HASFLAG(setting, F_TABLE_SETTING)) 288 293 { 289 294 const struct table_setting *tbl_info = setting->table_setting; 290 295 int i, add; ··· 312 317 int min = 0; 313 318 */ 314 319 int max = 0, step = 1; 315 - if (((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) || 316 - ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)) 320 + if ((HASFLAG(setting, F_BOOL_SETTING)) || 321 + HASFLAG(setting, F_CHOICE_SETTING)) 322 + { 317 323 return selection; 318 - else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) 324 + } 325 + else if (HASFLAG(setting, F_TABLE_SETTING)) 319 326 { 320 327 const struct table_setting *info = setting->table_setting; 321 - if (setting->flags&F_ALLOW_ARBITRARY_VALS && 328 + if (HASFLAG(setting, F_ALLOW_ARBITRARY_VALS) && 322 329 table_setting_array_position != -1 && 323 330 (selection >= table_setting_array_position)) 324 331 { ··· 329 336 else 330 337 return info->values[selection]; 331 338 } 332 - else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 339 + else if (HASFLAG(setting, F_T_SOUND)) 333 340 { 334 341 int setting_id = setting->sound_setting->setting; 335 342 if(global_settings.list_order == LIST_ORDER_DESCENDING) ··· 346 353 max = sound_min(setting_id); 347 354 } 348 355 } 349 - else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 356 + else if (HASFLAG(setting, F_INT_SETTING)) 350 357 { 351 358 const struct int_setting *info = setting->int_setting; 352 359 if(global_settings.list_order == LIST_ORDER_DESCENDING) ··· 392 399 /* set the number of items and current selection */ 393 400 if (var_type == F_T_INT || var_type == F_T_UINT) 394 401 { 395 - if (setting->flags&F_CHOICE_SETTING) 402 + if (HASFLAG(setting, F_CHOICE_SETTING)) 396 403 { 397 404 *nb_items = setting->choice_setting->count; 398 405 *selected = oldvalue; 399 406 *function = setting->choice_setting->option_callback; 400 407 } 401 - else if (setting->flags&F_TABLE_SETTING) 408 + else if (HASFLAG(setting, F_TABLE_SETTING)) 402 409 { 403 410 const struct table_setting *info = setting->table_setting; 404 411 int i; ··· 407 414 table_setting_array_position = -1; 408 415 for (i=0;*selected==-1 && i<*nb_items;i++) 409 416 { 410 - if (setting->flags&F_ALLOW_ARBITRARY_VALS && 417 + if (HASFLAG(setting, F_ALLOW_ARBITRARY_VALS) && 411 418 (oldvalue < info->values[i])) 412 419 { 413 420 table_setting_oldval = oldvalue; ··· 420 427 } 421 428 *function = info->option_callback; 422 429 } 423 - else if (setting->flags&F_T_SOUND) 430 + else if (HASFLAG(setting, F_T_SOUND)) 424 431 { 425 432 int setting_id = setting->sound_setting->setting; 426 433 int steps = sound_steps(setting_id); ··· 468 475 struct gui_synclist lists; 469 476 int oldvalue, nb_items = 0, selected = 0, temp_var; 470 477 int *variable; 471 - bool allow_wrap = setting->flags & F_NO_WRAP ? false : true; 472 - bool cb_on_select_only = 473 - ((setting->flags & F_CB_ON_SELECT_ONLY) == F_CB_ON_SELECT_ONLY); 474 - bool cb_on_changed = 475 - ((setting->flags & F_CB_ONLY_IF_CHANGED) == F_CB_ONLY_IF_CHANGED); 478 + bool allow_wrap = (!HASFLAG(setting, F_NO_WRAP)); 479 + bool cb_on_select_only = HASFLAG(setting, F_CB_ON_SELECT_ONLY); 480 + bool cb_on_changed = HASFLAG(setting, F_CB_ONLY_IF_CHANGED); 476 481 477 482 int var_type = setting->flags&F_T_MASK; 478 483 void (*function)(int) = NULL; ··· 564 569 } 565 570 settings_save(); 566 571 done = true; 567 - 568 - if (cb_on_select_only && function) 569 - { 570 - if (!cb_on_changed || (*variable != oldvalue)) 571 - function(*variable); 572 - } 572 + cb_on_select_only = false; /* unset the flag so callback can be called */ 573 573 } 574 574 else if(default_event_handler(action) == SYS_USB_CONNECTED) 575 575 { 576 576 pop_current_activity(); 577 577 return true; 578 578 } 579 + 579 580 /* callback */ 580 - if (function && !cb_on_select_only) 581 + if (!cb_on_select_only && function) 581 582 { 582 583 if (!cb_on_changed || (*variable != oldvalue)) 584 + { 583 585 function(*variable); 586 + /* if the volume is changing we need to let the skins know */ 587 + if (function == sound_get_fn(SOUND_VOLUME)) 588 + global_status.last_volume_change = current_tick; 589 + } 584 590 } 585 - /* if the volume is changing we need to let the skins know */ 586 - if (function == sound_get_fn(SOUND_VOLUME)) 587 - global_status.last_volume_change = current_tick; 591 + 588 592 } 589 593 pop_current_activity(); 590 594 return false;