diff src/core/config.cc @ 120:275da698697d

config: template-ify INI now it's... slightly less ugly :')
author Paper <mrpapersonic@gmail.com>
date Wed, 08 Nov 2023 18:13:37 -0500
parents 39521c47c7a3
children 0a458cb26ff4
line wrap: on
line diff
--- a/src/core/config.cc	Wed Nov 08 13:50:00 2023 -0500
+++ b/src/core/config.cc	Wed Nov 08 18:13:37 2023 -0500
@@ -17,6 +17,9 @@
 #include <fstream>
 #include <limits.h>
 
+/* I'll use an INI-based config file instead of using an
+   XML file like Taiga. */
+
 int Config::Load() {
 	Filesystem::Path cfg_path = Filesystem::GetConfigPath();
 
@@ -24,22 +27,23 @@
 	mINI::INIStructure ini;
 	file.read(ini);
 
-	service = Translate::ToService(INI::GetIniString(ini, "General", "Service", "None"));
-	/* ew */
-	locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniString(ini, "General", "Locale", "en_US"))));
+	service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None"));
+
+	anime_list.language = Translate::ToLanguage(INI::GetIniValue<std::string>(ini, "Anime List", "Title language", "Romaji"));
+	anime_list.display_aired_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only aired episodes", true);
+	anime_list.display_available_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only available episodes in library", true);
+	anime_list.highlight_anime_if_available = INI::GetIniValue<bool>(ini, "Anime List", "Highlight anime if available", true);
+	anime_list.highlighted_anime_above_others = INI::GetIniValue<bool>(ini, "Anime List", "Display highlighted anime above others", false);
 
-	anime_list.language = Translate::ToLanguage(INI::GetIniString(ini, "Anime List", "Title language", "Romaji"));
-	anime_list.display_aired_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only aired episodes", ""), true);
-	anime_list.display_available_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only available episodes in library", ""), true);
-	anime_list.highlight_anime_if_available = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Highlight anime if available", ""), true);
-	anime_list.highlighted_anime_above_others = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display highlighted anime above others", ""), false);
+	auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", "");
+	auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0);
+
+	torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0");
 
-	anilist.auth_token = INI::GetIniString(ini, "AniList", "Auth Token", "");
-	anilist.user_id = Strings::ToInt(INI::GetIniString(ini, "AniList", "User ID", ""), 0);
+	/* ew */
+	locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US"))));
 
-	torrents.feed_link = INI::GetIniString(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0");
-
-	theme.SetTheme(Translate::ToTheme(INI::GetIniString(ini, "Appearance", "Theme", "Default")));
+	theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default")));
 
 	return 0;
 }
@@ -52,17 +56,24 @@
 	mINI::INIFile file(cfg_path.GetPath());
 	mINI::INIStructure ini;
 
-	ini["General"]["Service"] = Translate::ToString(service);
-	ini["General"]["Locale"] = Strings::ToUtf8String(locale.GetLocale().name());
-	ini["Anime List"]["Title language"] = Translate::ToString(anime_list.language);
-	ini["Anime List"]["Display only aired episodes"] = Strings::ToUtf8String(anime_list.display_aired_episodes);
-	ini["Anime List"]["Display only available episodes in library"] = Strings::ToUtf8String(anime_list.display_available_episodes);
-	ini["Anime List"]["Highlight anime if available"] = Strings::ToUtf8String(anime_list.highlight_anime_if_available);
-	ini["Anime List"]["Display highlighted anime above others"] = Strings::ToUtf8String(anime_list.highlighted_anime_above_others);
-	ini["AniList"]["Auth Token"] = anilist.auth_token;
-	ini["AniList"]["User ID"] = std::to_string(anilist.user_id);
-	ini["Appearance"]["Theme"] = Translate::ToString(theme.GetTheme());
-	ini["Torrents"]["RSS feed"] = torrents.feed_link;
+	INI::SetIniValue(ini, "General", "Service", service);
+	INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name());
+
+	INI::SetIniValue(ini, "Anime List", "Title language", anime_list.language);
+	INI::SetIniValue(ini, "Anime List", "Display only aired episodes", anime_list.display_aired_episodes);
+	INI::SetIniValue(ini, "Anime List", "Display only available episodes in library", anime_list.display_available_episodes);
+	INI::SetIniValue(ini, "Anime List", "Highlight anime if available", anime_list.highlight_anime_if_available);
+	INI::SetIniValue(ini, "Anime List", "Display highlighted anime above others", anime_list.highlighted_anime_above_others);
+
+	INI::SetIniValue(ini, "Authentication/AniList", "Auth Token", auth.anilist.auth_token);
+	INI::SetIniValue(ini, "Authentication/AniList", "User ID", auth.anilist.user_id);
+
+	INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme());
+
+	INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link);
+
+	INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players);
+	//ini["Recognition"]["Detect streaming media"] = Strings::ToUtf8String(recognition.detect_streaming_media);
 
 	file.write(ini);