Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
115:c72b907b9bef | 116:254b1d2b7096 |
---|---|
15 #include <cstring> | 15 #include <cstring> |
16 #include <filesystem> | 16 #include <filesystem> |
17 #include <fstream> | 17 #include <fstream> |
18 #include <limits.h> | 18 #include <limits.h> |
19 | 19 |
20 /* Move these to strings.cc or the translation stuff, please. */ | |
21 static bool string_to_bool(const std::string& s, bool def = false) { | |
22 if (s.length() < 4) | |
23 return def; | |
24 std::string l = Strings::ToLower(s); | |
25 if (Strings::BeginningMatchesSubstring(l, "true")) | |
26 return true; | |
27 else if (Strings::BeginningMatchesSubstring(l, "false")) | |
28 return false; | |
29 return def; | |
30 } | |
31 | |
32 static std::string bool_to_string(bool b) { | |
33 return b ? "true" : "false"; | |
34 } | |
35 | |
36 int Config::Load() { | 20 int Config::Load() { |
37 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); | 21 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); |
38 | 22 |
39 mINI::INIFile file(cfg_path.GetPath()); | 23 mINI::INIFile file(cfg_path.GetPath()); |
40 mINI::INIStructure ini; | 24 mINI::INIStructure ini; |
41 file.read(ini); | 25 file.read(ini); |
42 | 26 |
43 service = Translate::ToService(ini.get("General").get("Service")); | 27 service = Translate::ToService(INI::GetIniString(ini, "General", "Service", "None")); |
44 locale.SetActiveLocale(QLocale(Strings::ToQString(ini.get("General").get("Locale")))); | 28 /* ew */ |
45 anime_list.language = Translate::ToLanguage(ini.get("Anime List").get("Title language")); | 29 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniString(ini, "General", "Locale", "en_US")))); |
46 anime_list.display_aired_episodes = string_to_bool(ini.get("Anime List").get("Display only aired episodes"), true); | 30 |
47 anime_list.display_available_episodes = string_to_bool(ini.get("Anime List").get("Display only available episodes in library"), true); | 31 anime_list.language = Translate::ToLanguage(INI::GetIniString(ini, "Anime List", "Title language", "Romaji")); |
48 anime_list.highlight_anime_if_available = string_to_bool(ini.get("Anime List").get("Highlight anime if available"), true); | 32 anime_list.display_aired_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only aired episodes", ""), true); |
49 anime_list.highlighted_anime_above_others = string_to_bool(ini.get("Anime List").get("Display highlighted anime above others")); | 33 anime_list.display_available_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only available episodes in library", ""), true); |
50 anilist.auth_token = ini.get("AniList").get("Auth Token"); | 34 anime_list.highlight_anime_if_available = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Highlight anime if available", ""), true); |
51 anilist.user_id = Strings::ToInt(ini.get("AniList").get("User ID")); | 35 anime_list.highlighted_anime_above_others = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display highlighted anime above others", ""), false); |
52 theme.SetTheme(Translate::ToTheme(ini.get("Appearance").get("Theme"))); | 36 |
37 anilist.auth_token = INI::GetIniString(ini, "AniList", "Auth Token", ""); | |
38 anilist.user_id = Strings::ToInt(INI::GetIniString(ini, "AniList", "User ID", ""), 0); | |
39 | |
40 torrents.feed_link = INI::GetIniString(ini, "Torrents", "RSS Feed Link", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | |
41 | |
42 theme.SetTheme(Translate::ToTheme(INI::GetIniString(ini, "Appearance", "Theme", "Default"))); | |
53 | 43 |
54 return 0; | 44 return 0; |
55 } | 45 } |
56 | 46 |
57 int Config::Save() { | 47 int Config::Save() { |
63 mINI::INIStructure ini; | 53 mINI::INIStructure ini; |
64 | 54 |
65 ini["General"]["Service"] = Translate::ToString(service); | 55 ini["General"]["Service"] = Translate::ToString(service); |
66 ini["General"]["Locale"] = Strings::ToUtf8String(locale.GetLocale().name()); | 56 ini["General"]["Locale"] = Strings::ToUtf8String(locale.GetLocale().name()); |
67 ini["Anime List"]["Title language"] = Translate::ToString(anime_list.language); | 57 ini["Anime List"]["Title language"] = Translate::ToString(anime_list.language); |
68 ini["Anime List"]["Display only aired episodes"] = bool_to_string(anime_list.display_aired_episodes); | 58 ini["Anime List"]["Display only aired episodes"] = Strings::ToUtf8String(anime_list.display_aired_episodes); |
69 ini["Anime List"]["Display only available episodes in library"] = bool_to_string(anime_list.display_available_episodes); | 59 ini["Anime List"]["Display only available episodes in library"] = Strings::ToUtf8String(anime_list.display_available_episodes); |
70 ini["Anime List"]["Highlight anime if available"] = bool_to_string(anime_list.highlight_anime_if_available); | 60 ini["Anime List"]["Highlight anime if available"] = Strings::ToUtf8String(anime_list.highlight_anime_if_available); |
71 ini["Anime List"]["Display highlighted anime above others"] = bool_to_string(anime_list.highlighted_anime_above_others); | 61 ini["Anime List"]["Display highlighted anime above others"] = Strings::ToUtf8String(anime_list.highlighted_anime_above_others); |
72 ini["AniList"]["Auth Token"] = anilist.auth_token; | 62 ini["AniList"]["Auth Token"] = anilist.auth_token; |
73 ini["AniList"]["User ID"] = std::to_string(anilist.user_id); | 63 ini["AniList"]["User ID"] = std::to_string(anilist.user_id); |
74 ini["Appearance"]["Theme"] = Translate::ToString(theme.GetTheme()); | 64 ini["Appearance"]["Theme"] = Translate::ToString(theme.GetTheme()); |
65 ini["Torrents"]["RSS Feed Link"] = torrents.feed_link; | |
75 | 66 |
76 file.write(ini); | 67 file.write(ini); |
77 | 68 |
78 return 0; | 69 return 0; |
79 } | 70 } |