summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c75
1 files changed, 56 insertions, 19 deletions
diff --git a/apps/settings.c b/apps/settings.c
index a538543960..6f1fe86f8e 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1464,18 +1464,28 @@ void settings_reset(void) {
1464bool set_bool(char* string, bool* variable ) 1464bool set_bool(char* string, bool* variable )
1465{ 1465{
1466 return set_bool_options(string, variable, str(LANG_SET_BOOL_YES), 1466 return set_bool_options(string, variable, str(LANG_SET_BOOL_YES),
1467 str(LANG_SET_BOOL_NO)); 1467 str(LANG_SET_BOOL_NO), NULL);
1468}
1469
1470/* wrapper to convert from int param to bool param in set_option */
1471static void (*boolfunction)(bool);
1472void bool_funcwrapper(int value)
1473{
1474 if (value)
1475 boolfunction(true);
1476 else
1477 boolfunction(false);
1468} 1478}
1469 1479
1470bool set_bool_options(char* string, bool* variable, 1480bool set_bool_options(char* string, bool* variable,
1471 char* yes_str, char* no_str ) 1481 char* yes_str, char* no_str, void (*function)(bool))
1472{ 1482{
1473 char* names[] = { no_str, yes_str }; 1483 char* names[] = { no_str, yes_str };
1474 int value = *variable;
1475 bool result; 1484 bool result;
1476 1485
1477 result = set_option(string, &value, names, 2, NULL); 1486 boolfunction = function;
1478 *variable = value; 1487 result = set_option(string, variable, BOOL, names, 2,
1488 function ? bool_funcwrapper : NULL);
1479 return result; 1489 return result;
1480} 1490}
1481 1491
@@ -1576,12 +1586,23 @@ bool set_int(char* string,
1576 return false; 1586 return false;
1577} 1587}
1578 1588
1579bool set_option(char* string, int* variable, char* options[], 1589/* NOTE: the 'type' parameter specifies the actual type of the variable
1580 int numoptions, void (*function)(int)) 1590 that 'variable' points to. not the value within. Only variables with
1591 type 'bool' should use parameter BOOL.
1592
1593 The type separation is nececssary since int and bool are fundamentally
1594 different and bit-incompatible types and can not share the same access
1595 code. */
1596
1597bool set_option(char* string, void* variable, enum optiontype type,
1598 char* options[], int numoptions, void (*function)(int))
1581{ 1599{
1582 bool done = false; 1600 bool done = false;
1583 int button; 1601 int button;
1584 int org_value=*variable; 1602 int* intvar = (int*)variable;
1603 bool* boolvar = (bool*)variable;
1604 int orgint=*intvar;
1605 bool orgbool=*boolvar;
1585 1606
1586#ifdef HAVE_LCD_BITMAP 1607#ifdef HAVE_LCD_BITMAP
1587 if(global_settings.statusbar) 1608 if(global_settings.statusbar)
@@ -1594,7 +1615,7 @@ bool set_option(char* string, int* variable, char* options[],
1594 lcd_puts_scroll(0, 0, string); 1615 lcd_puts_scroll(0, 0, string);
1595 1616
1596 while ( !done ) { 1617 while ( !done ) {
1597 lcd_puts(0, 1, options[*variable]); 1618 lcd_puts(0, 1, options[type==INT ? *intvar : (int)*boolvar]);
1598#ifdef HAVE_LCD_BITMAP 1619#ifdef HAVE_LCD_BITMAP
1599 status_draw(true); 1620 status_draw(true);
1600#endif 1621#endif
@@ -1609,10 +1630,14 @@ bool set_option(char* string, int* variable, char* options[],
1609 case BUTTON_RIGHT: 1630 case BUTTON_RIGHT:
1610 case BUTTON_RIGHT | BUTTON_REPEAT: 1631 case BUTTON_RIGHT | BUTTON_REPEAT:
1611#endif 1632#endif
1612 if ( *variable < (numoptions-1) ) 1633 if (type == INT) {
1613 (*variable)++; 1634 if ( *intvar < (numoptions-1) )
1635 (*intvar)++;
1636 else
1637 (*intvar) -= (numoptions-1);
1638 }
1614 else 1639 else
1615 (*variable) -= (numoptions-1); 1640 *boolvar = !*boolvar;
1616 break; 1641 break;
1617 1642
1618#ifdef HAVE_RECORDER_KEYPAD 1643#ifdef HAVE_RECORDER_KEYPAD
@@ -1622,10 +1647,14 @@ bool set_option(char* string, int* variable, char* options[],
1622 case BUTTON_LEFT: 1647 case BUTTON_LEFT:
1623 case BUTTON_LEFT | BUTTON_REPEAT: 1648 case BUTTON_LEFT | BUTTON_REPEAT:
1624#endif 1649#endif
1625 if ( *variable > 0 ) 1650 if (type == INT) {
1626 (*variable)--; 1651 if ( *intvar > 0 )
1652 (*intvar)--;
1653 else
1654 (*intvar) += (numoptions-1);
1655 }
1627 else 1656 else
1628 (*variable) += (numoptions-1); 1657 *boolvar = !*boolvar;
1629 break; 1658 break;
1630 1659
1631#ifdef HAVE_RECORDER_KEYPAD 1660#ifdef HAVE_RECORDER_KEYPAD
@@ -1643,8 +1672,12 @@ bool set_option(char* string, int* variable, char* options[],
1643 case BUTTON_STOP: 1672 case BUTTON_STOP:
1644 case BUTTON_MENU: 1673 case BUTTON_MENU:
1645#endif 1674#endif
1646 if (*variable != org_value) { 1675 if (((type==INT) && (*intvar != orgint)) ||
1647 *variable=org_value; 1676 ((type==BOOL) && (*boolvar != orgbool))) {
1677 if (type==INT)
1678 *intvar=orgint;
1679 else
1680 *boolvar=orgbool;
1648 lcd_stop_scroll(); 1681 lcd_stop_scroll();
1649 lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL)); 1682 lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL));
1650 lcd_update(); 1683 lcd_update();
@@ -1658,8 +1691,12 @@ bool set_option(char* string, int* variable, char* options[],
1658 return true; 1691 return true;
1659 } 1692 }
1660 1693
1661 if ( function && button != BUTTON_NONE) 1694 if ( function && button != BUTTON_NONE) {
1662 function(*variable); 1695 if (type == INT)
1696 function(*intvar);
1697 else
1698 function(*boolvar);
1699 }
1663 } 1700 }
1664 lcd_stop_scroll(); 1701 lcd_stop_scroll();
1665 return false; 1702 return false;