1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

Make temperature_unit a lua setting

This commit is contained in:
Pavel Labath 2010-08-25 21:26:14 +02:00
parent 0085402d08
commit b6ed33b82a
3 changed files with 10 additions and 36 deletions

View File

@ -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) {

View File

@ -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<TEMP_UNIT>::Map conky::lua_traits<TEMP_UNIT>::map = {
{ "celsius", TEMP_CELSIUS },
{ "fahrenheit", TEMP_FAHRENHEIT }
};
static conky::simple_config_setting<TEMP_UNIT> 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:

View File

@ -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 */