Mercurial > minori
comparison src/core/config.cc @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 01 Apr 2024 02:43:44 -0400 |
parents | c130f47f6f48 |
children | ec0a2b5493f8 |
comparison
equal
deleted
inserted
replaced
257:699a20c57dc8 | 258:862d0d8619f6 |
---|---|
1 /** | 1 /** |
2 * config.cpp: | 2 * config.cpp: |
3 * parses the config... lol | 3 * parses the config... lol |
4 **/ | 4 **/ |
5 #include "core/config.h" | 5 #include "core/config.h" |
6 #include "core/anime.h" | |
7 #include "core/filesystem.h" | |
8 #include "core/ini.h" | |
9 #include "core/json.h" | |
6 #include "core/strings.h" | 10 #include "core/strings.h" |
7 #include "core/anime.h" | |
8 #include "core/ini.h" | |
9 #include "core/filesystem.h" | |
10 #include "core/json.h" | |
11 #include "gui/translate/anime.h" | 11 #include "gui/translate/anime.h" |
12 #include "gui/translate/config.h" | 12 #include "gui/translate/config.h" |
13 | 13 |
14 #include "animia/player.h" | 14 #include "animone/player.h" |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <cstdlib> | 17 #include <cstdlib> |
18 #include <cstring> | 18 #include <cstring> |
19 #include <filesystem> | 19 #include <filesystem> |
28 /* I'll use an INI-based config file instead of using an | 28 /* I'll use an INI-based config file instead of using an |
29 * XML file like Taiga. | 29 * XML file like Taiga. |
30 * | 30 * |
31 * It technically isn't to spec, because I'm making these case-sensitive. | 31 * It technically isn't to spec, because I'm making these case-sensitive. |
32 * Boohoo. | 32 * Boohoo. |
33 */ | 33 */ |
34 | 34 |
35 int Config::Load() { | 35 int Config::Load() { |
36 std::filesystem::path cfg_path = Filesystem::GetConfigPath(); | 36 std::filesystem::path cfg_path = Filesystem::GetConfigPath(); |
37 | 37 |
38 mINI::INIFile file(cfg_path.u8string()); | 38 mINI::INIFile file(cfg_path.u8string()); |
39 mINI::INIStructure ini; | 39 mINI::INIStructure ini; |
40 file.read(ini); | 40 file.read(ini); |
41 | 41 |
42 service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None")); | 42 service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None")); |
43 | 43 |
44 anime_list.score_format = Translate::ToScoreFormat(INI::GetIniValue<std::string>(ini, "Anime List", "Score format", "POINT_100")); | 44 anime_list.score_format = |
45 anime_list.language = Translate::ToLanguage(INI::GetIniValue<std::string>(ini, "Anime List", "Title language", "Romaji")); | 45 Translate::ToScoreFormat(INI::GetIniValue<std::string>(ini, "Anime List", "Score format", "POINT_100")); |
46 anime_list.language = | |
47 Translate::ToLanguage(INI::GetIniValue<std::string>(ini, "Anime List", "Title language", "Romaji")); | |
46 anime_list.display_aired_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only aired episodes", true); | 48 anime_list.display_aired_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only aired episodes", true); |
47 anime_list.display_available_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only available episodes in library", true); | 49 anime_list.display_available_episodes = |
48 anime_list.highlight_anime_if_available = INI::GetIniValue<bool>(ini, "Anime List", "Highlight anime if available", true); | 50 INI::GetIniValue<bool>(ini, "Anime List", "Display only available episodes in library", true); |
51 anime_list.highlight_anime_if_available = | |
52 INI::GetIniValue<bool>(ini, "Anime List", "Highlight anime if available", true); | |
49 | 53 |
50 if (anime_list.highlight_anime_if_available) // sanity check | 54 if (anime_list.highlight_anime_if_available) // sanity check |
51 anime_list.highlighted_anime_above_others = INI::GetIniValue<bool>(ini, "Anime List", "Display highlighted anime above others", false); | 55 anime_list.highlighted_anime_above_others = |
56 INI::GetIniValue<bool>(ini, "Anime List", "Display highlighted anime above others", false); | |
52 else | 57 else |
53 anime_list.highlighted_anime_above_others = false; | 58 anime_list.highlighted_anime_above_others = false; |
54 | 59 |
55 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", ""); | 60 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", ""); |
56 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); | 61 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); |
57 | 62 |
58 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | 63 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", |
64 "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | |
59 | 65 |
60 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); | 66 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); |
61 | 67 |
62 /* lots of dumb logic to import the player data */ | 68 /* lots of dumb logic to import the player data */ |
63 { | 69 { |
67 return false; | 73 return false; |
68 | 74 |
69 f.open(QFile::ReadOnly | QFile::Text); | 75 f.open(QFile::ReadOnly | QFile::Text); |
70 QTextStream ts(&f); | 76 QTextStream ts(&f); |
71 | 77 |
72 std::vector<animia::Player> players; | 78 std::vector<animone::Player> players; |
73 | 79 |
74 if (!animia::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players)) | 80 if (!animone::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players)) |
75 return false; | 81 return false; |
76 | 82 |
77 recognition.players.reserve(players.size()); | 83 recognition.players.reserve(players.size()); |
78 for (const auto& player : players) | 84 for (const auto& player : players) |
79 recognition.players.push_back({true, player}); | 85 recognition.players.push_back({true, player}); |
80 } | 86 } |
81 | 87 |
82 for (auto& [enabled, player] : recognition.players) { | 88 for (auto& [enabled, player] : recognition.players) { |
83 switch (player.type) { | 89 switch (player.type) { |
84 default: | 90 default: |
85 case animia::PlayerType::Default: | 91 case animone::PlayerType::Default: |
86 enabled = INI::GetIniValue<bool>(ini, "Recognition/Players", player.name, true); | 92 enabled = INI::GetIniValue<bool>(ini, "Recognition/Players", player.name, true); |
87 break; | 93 break; |
88 case animia::PlayerType::WebBrowser: | 94 case animone::PlayerType::WebBrowser: |
89 enabled = INI::GetIniValue<bool>(ini, "Recognition/Browsers", player.name, true); | 95 enabled = INI::GetIniValue<bool>(ini, "Recognition/Browsers", player.name, true); |
90 break; | 96 break; |
91 } | 97 } |
92 } | 98 } |
93 | 99 |
94 locale.RefreshAvailableLocales(); | 100 locale.RefreshAvailableLocales(); |
95 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); | 101 locale.SetActiveLocale( |
102 QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); | |
96 | 103 |
97 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); | 104 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); |
98 | 105 |
99 { | 106 { |
100 std::vector<std::string> v = Strings::Split(INI::GetIniValue<std::string>(ini, "Library", "Folders", ""), ";"); | 107 std::vector<std::string> v = Strings::Split(INI::GetIniValue<std::string>(ini, "Library", "Folders", ""), ";"); |
119 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name()); | 126 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name()); |
120 | 127 |
121 INI::SetIniValue(ini, "Anime List", "Score format", Translate::ToString(anime_list.score_format)); | 128 INI::SetIniValue(ini, "Anime List", "Score format", Translate::ToString(anime_list.score_format)); |
122 INI::SetIniValue(ini, "Anime List", "Title language", anime_list.language); | 129 INI::SetIniValue(ini, "Anime List", "Title language", anime_list.language); |
123 INI::SetIniValue(ini, "Anime List", "Display only aired episodes", anime_list.display_aired_episodes); | 130 INI::SetIniValue(ini, "Anime List", "Display only aired episodes", anime_list.display_aired_episodes); |
124 INI::SetIniValue(ini, "Anime List", "Display only available episodes in library", anime_list.display_available_episodes); | 131 INI::SetIniValue(ini, "Anime List", "Display only available episodes in library", |
132 anime_list.display_available_episodes); | |
125 INI::SetIniValue(ini, "Anime List", "Highlight anime if available", anime_list.highlight_anime_if_available); | 133 INI::SetIniValue(ini, "Anime List", "Highlight anime if available", anime_list.highlight_anime_if_available); |
126 INI::SetIniValue(ini, "Anime List", "Display highlighted anime above others", anime_list.highlighted_anime_above_others); | 134 INI::SetIniValue(ini, "Anime List", "Display highlighted anime above others", |
135 anime_list.highlighted_anime_above_others); | |
127 | 136 |
128 INI::SetIniValue(ini, "Authentication/AniList", "Auth Token", auth.anilist.auth_token); | 137 INI::SetIniValue(ini, "Authentication/AniList", "Auth Token", auth.anilist.auth_token); |
129 INI::SetIniValue(ini, "Authentication/AniList", "User ID", auth.anilist.user_id); | 138 INI::SetIniValue(ini, "Authentication/AniList", "User ID", auth.anilist.user_id); |
130 | 139 |
131 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme()); | 140 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme()); |
135 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); | 144 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); |
136 | 145 |
137 for (const auto& [enabled, player] : recognition.players) { | 146 for (const auto& [enabled, player] : recognition.players) { |
138 switch (player.type) { | 147 switch (player.type) { |
139 default: | 148 default: |
140 case animia::PlayerType::Default: | 149 case animone::PlayerType::Default: INI::SetIniValue(ini, "Recognition/Players", player.name, enabled); break; |
141 INI::SetIniValue(ini, "Recognition/Players", player.name, enabled); | 150 case animone::PlayerType::WebBrowser: |
142 break; | |
143 case animia::PlayerType::WebBrowser: | |
144 INI::SetIniValue(ini, "Recognition/Browsers", player.name, enabled); | 151 INI::SetIniValue(ini, "Recognition/Browsers", player.name, enabled); |
145 break; | 152 break; |
146 } | 153 } |
147 } | 154 } |
148 | 155 |