diff src/core/config.cc @ 116:254b1d2b7096

settings: add torrents page, make rss feed configurable
author Paper <mrpapersonic@gmail.com>
date Tue, 07 Nov 2023 13:52:13 -0500
parents 2004b41d4a59
children 39521c47c7a3
line wrap: on
line diff
--- a/src/core/config.cc	Tue Nov 07 12:04:51 2023 -0500
+++ b/src/core/config.cc	Tue Nov 07 13:52:13 2023 -0500
@@ -17,22 +17,6 @@
 #include <fstream>
 #include <limits.h>
 
-/* Move these to strings.cc or the translation stuff, please. */
-static bool string_to_bool(const std::string& s, bool def = false) {
-	if (s.length() < 4)
-		return def;
-	std::string l = Strings::ToLower(s);
-	if (Strings::BeginningMatchesSubstring(l, "true"))
-		return true;
-	else if (Strings::BeginningMatchesSubstring(l, "false"))
-		return false;
-	return def;
-}
-
-static std::string bool_to_string(bool b) {
-	return b ? "true" : "false";
-}
-
 int Config::Load() {
 	Filesystem::Path cfg_path = Filesystem::GetConfigPath();
 
@@ -40,16 +24,22 @@
 	mINI::INIStructure ini;
 	file.read(ini);
 
-	service = Translate::ToService(ini.get("General").get("Service"));
-	locale.SetActiveLocale(QLocale(Strings::ToQString(ini.get("General").get("Locale"))));
-	anime_list.language = Translate::ToLanguage(ini.get("Anime List").get("Title language"));
-	anime_list.display_aired_episodes = string_to_bool(ini.get("Anime List").get("Display only aired episodes"), true);
-	anime_list.display_available_episodes = string_to_bool(ini.get("Anime List").get("Display only available episodes in library"), true);
-	anime_list.highlight_anime_if_available = string_to_bool(ini.get("Anime List").get("Highlight anime if available"), true);
-	anime_list.highlighted_anime_above_others = string_to_bool(ini.get("Anime List").get("Display highlighted anime above others"));
-	anilist.auth_token = ini.get("AniList").get("Auth Token");
-	anilist.user_id = Strings::ToInt(ini.get("AniList").get("User ID"));
-	theme.SetTheme(Translate::ToTheme(ini.get("Appearance").get("Theme")));
+	service = Translate::ToService(INI::GetIniString(ini, "General", "Service", "None"));
+	/* ew */
+	locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniString(ini, "General", "Locale", "en_US"))));
+
+	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);
+
+	anilist.auth_token = INI::GetIniString(ini, "AniList", "Auth Token", "");
+	anilist.user_id = Strings::ToInt(INI::GetIniString(ini, "AniList", "User ID", ""), 0);
+
+	torrents.feed_link = INI::GetIniString(ini, "Torrents", "RSS Feed Link", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0");
+
+	theme.SetTheme(Translate::ToTheme(INI::GetIniString(ini, "Appearance", "Theme", "Default")));
 
 	return 0;
 }
@@ -65,13 +55,14 @@
 	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"] = bool_to_string(anime_list.display_aired_episodes);
-	ini["Anime List"]["Display only available episodes in library"] = bool_to_string(anime_list.display_available_episodes);
-	ini["Anime List"]["Highlight anime if available"] = bool_to_string(anime_list.highlight_anime_if_available);
-	ini["Anime List"]["Display highlighted anime above others"] = bool_to_string(anime_list.highlighted_anime_above_others);
+	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 Link"] = torrents.feed_link;
 
 	file.write(ini);