diff --git a/src/conky.cc b/src/conky.cc index b924c854..c5bd4f56 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -3022,14 +3022,6 @@ char load_config_file(const char *f) } } #endif - CONF("temperature_unit") { - if (!value) { - NORM_ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'"); - } else if (set_temp_output_unit(value)) { - NORM_ERR("temperature_unit: incorrect argument"); - } - } - #ifdef BUILD_LUA CONF("lua_load") { if (value) { diff --git a/src/temphelper.cc b/src/temphelper.cc index d6fa1f27..00bde02f 100644 --- a/src/temphelper.cc +++ b/src/temphelper.cc @@ -30,8 +30,14 @@ #include "temphelper.h" #include "conky.h" -/* default to output in celsius */ -static enum TEMP_UNIT output_unit = TEMP_CELSIUS; +template<> +conky::lua_traits::Map conky::lua_traits::map = { + { "celsius", TEMP_CELSIUS }, + { "fahrenheit", TEMP_FAHRENHEIT } +}; + +static conky::simple_config_setting output_unit("temperature_unit", + TEMP_CELSIUS, true); static double fahrenheit_to_celsius(double n) { @@ -43,35 +49,12 @@ static double celsius_to_fahrenheit(double n) return ((n * 9 / 5) + 32); } -int set_temp_output_unit(const char *name) -{ - long i; - int rc = 0; - char *buf; - - if (!name) - return 1; - - buf = strdup(name); - for (i = 0; i < (long)strlen(name); i++) - buf[i] = tolower(name[i]); - - if (!strcmp(buf, "celsius")) - output_unit = TEMP_CELSIUS; - else if (!strcmp(buf, "fahrenheit")) - output_unit = TEMP_FAHRENHEIT; - else - rc = 1; - free(buf); - return rc; -} - static double convert_temp_output(double n, enum TEMP_UNIT input_unit) { - if (input_unit == output_unit) + if (input_unit == output_unit.get(*state)) return n; - switch(output_unit) { + switch(output_unit.get(*state)) { case TEMP_CELSIUS: return fahrenheit_to_celsius(n); case TEMP_FAHRENHEIT: diff --git a/src/temphelper.h b/src/temphelper.h index d0cdf767..f8039542 100644 --- a/src/temphelper.h +++ b/src/temphelper.h @@ -30,7 +30,6 @@ enum TEMP_UNIT { TEMP_FAHRENHEIT }; -int set_temp_output_unit(const char *); int temp_print(char *, size_t, double, enum TEMP_UNIT); #endif /* TEMPHELPER_H */