lots of stuff

This commit is contained in:
Mars 2024-05-31 22:59:00 -04:00
parent e8fb8ec19f
commit 791e237470
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
224 changed files with 19811 additions and 129 deletions

21
src/config/config.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "config.h"
#include <fmt/core.h>
#include <toml++/toml.h>
#include <unistd.h>
Weather make_weather(toml::node_view<toml::node> location,
const char* api_key,
const char* units) {
return location.is_string()
? Weather(location.value_or(""), api_key, units)
: Weather(std::make_tuple(location["lat"].value_or(0.0),
location["lon"].value_or(0.0)),
api_key, units);
}
Config::Config(toml::table toml)
: m_general(toml["general"]["name"].value_or(getlogin())),
m_now_playing(toml["now_playing"]["enable"].value_or(false)),
m_weather(make_weather(toml["weather"]["location"],
toml["weather"]["api_key"].value_or(""),
toml["weather"]["units"].value_or("metric"))) {}

63
src/config/config.h Normal file
View file

@ -0,0 +1,63 @@
#pragma once
#include <toml++/toml.h>
#include <string>
using std::string;
typedef std::tuple<double, double> Coords;
typedef std::variant<string, Coords> Location;
class Weather {
private:
Location m_location;
string m_api_key;
string m_units;
public:
Weather(string city, string api_key, string units)
: m_location(city), m_api_key(api_key), m_units(units) {}
Weather(Coords coords, string api_key, string units)
: m_location(coords), m_api_key(api_key), m_units(units) {}
inline Location get_location() { return m_location; }
inline string get_api_key() { return m_api_key; }
inline string get_units() { return m_units; }
};
class General {
private:
string m_name;
public:
General(string name) { this->m_name = name; }
inline string get_name() { return m_name; }
};
class NowPlaying {
private:
bool m_enable;
public:
NowPlaying(bool enable) { this->m_enable = enable; }
inline bool get_enabled() { return m_enable; }
};
class Config {
private:
General m_general;
NowPlaying m_now_playing;
Weather m_weather;
public:
Config(toml::table toml);
~Config();
inline Weather get_weather() { return m_weather; }
inline General get_general() { return m_general; }
inline NowPlaying get_now_playing() { return m_now_playing; }
};