#include "configuration.h" #include "iniparser/src/iniparser.h" #include "iniparser/src/dictionary.h" #include "extString.h" #include #include #include #include dictionary * load_config(void) { char *xdg_config = getenv ("XDG_CONFIG_HOME"); char *home = getenv ("HOME"); if (home == NULL) return NULL; if (xdg_config == NULL) { xdg_config = malloc (strlen(home)*sizeof(char)+strlen("/.config")*sizeof(char)+1); sprintf (xdg_config, "%s/.config", home); } char *config_path = malloc(strlen(xdg_config)*sizeof(char)+strlen("/autodarkmode/config.ini")*sizeof(char)+1); sprintf (config_path, "%s/autodarkmode/config.ini", xdg_config); free (xdg_config); if (access(config_path, F_OK) != 0) { g_printerr ("Config file not found. Using default values.\n"); free (config_path); return NULL; } g_print ("Loading config file %s\n", config_path); dictionary *dict = iniparser_load (config_path); free (config_path); return dict; } enum LocationType config_get_location_type(dictionary *d) { if (d == NULL) return GCLUE; char *loctype = iniparser_getstring (d, "main:locationtype", "gclue"); if (strcmp(strlwr(loctype), "gclue") == 0) { return GCLUE; } else if (strcmp(strlwr(loctype), "manual") == 0) { return MANUAL; } else { g_printerr("Invalid Location type %s. Defaulting to GeoClue\n", loctype); return GCLUE; } return GCLUE; } float config_get_latitude (dictionary *d) { if (d == NULL) return 0; return iniparser_getdouble (d, "manual:latitude", 0); } float config_get_longitude (dictionary *d) { if (d == NULL) return 0; return iniparser_getdouble (d, "manual:longitude", 0); }