comparison src/core/config.cc @ 280:9b6e12c14a1e

chore: merge
author Paper <paper@paper.us.eu.org>
date Mon, 06 May 2024 17:23:30 -0400
parents ec0a2b5493f8
children 53e3c015a973
comparison
equal deleted inserted replaced
279:657fda1b9cac 280:9b6e12c14a1e
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::GetIniString(ini, "General", "Service", "None"));
43 43
44 anime_list.score_format = 44 anime_list.score_format =
45 Translate::ToScoreFormat(INI::GetIniValue<std::string>(ini, "Anime List", "Score format", "POINT_100")); 45 Translate::ToScoreFormat(INI::GetIniString(ini, "Anime List", "Score format", "POINT_100"));
46 anime_list.language = 46 anime_list.language =
47 Translate::ToLanguage(INI::GetIniValue<std::string>(ini, "Anime List", "Title language", "Romaji")); 47 Translate::ToLanguage(INI::GetIniString(ini, "Anime List", "Title language", "Romaji"));
48 anime_list.display_aired_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only aired episodes", true); 48 anime_list.display_aired_episodes = INI::GetIniBool(ini, "Anime List", "Display only aired episodes", true);
49 anime_list.display_available_episodes = 49 anime_list.display_available_episodes =
50 INI::GetIniValue<bool>(ini, "Anime List", "Display only available episodes in library", true); 50 INI::GetIniBool(ini, "Anime List", "Display only available episodes in library", true);
51 anime_list.highlight_anime_if_available = 51 anime_list.highlight_anime_if_available =
52 INI::GetIniValue<bool>(ini, "Anime List", "Highlight anime if available", true); 52 INI::GetIniBool(ini, "Anime List", "Highlight anime if available", true);
53 53
54 if (anime_list.highlight_anime_if_available) // sanity check 54 if (anime_list.highlight_anime_if_available) // sanity check
55 anime_list.highlighted_anime_above_others = 55 anime_list.highlighted_anime_above_others =
56 INI::GetIniValue<bool>(ini, "Anime List", "Display highlighted anime above others", false); 56 INI::GetIniBool(ini, "Anime List", "Display highlighted anime above others", false);
57 else 57 else
58 anime_list.highlighted_anime_above_others = false; 58 anime_list.highlighted_anime_above_others = false;
59 59
60 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", ""); 60 auth.anilist.auth_token = INI::GetIniString(ini, "Authentication/AniList", "Auth Token", "");
61 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); 61 auth.anilist.user_id = INI::GetIniInteger<int>(ini, "Authentication/AniList", "User ID", 0);
62 62
63 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", 63 torrents.feed_link = INI::GetIniString(ini, "Torrents", "RSS feed",
64 "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); 64 "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0");
65 65
66 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); 66 recognition.detect_media_players = INI::GetIniBool(ini, "Recognition", "Detect media players", true);
67 67
68 /* lots of dumb logic to import the player data */ 68 /* lots of dumb logic to import the player data */
69 { 69 {
70 /* load the player data */ 70 /* load the player data */
71 QFile f(":/players.anisthesia"); 71 QFile f(":/players.anisthesia");
87 87
88 for (auto& [enabled, player] : recognition.players) { 88 for (auto& [enabled, player] : recognition.players) {
89 switch (player.type) { 89 switch (player.type) {
90 default: 90 default:
91 case animone::PlayerType::Default: 91 case animone::PlayerType::Default:
92 enabled = INI::GetIniValue<bool>(ini, "Recognition/Players", player.name, true); 92 enabled = INI::GetIniBool(ini, "Recognition/Players", player.name, true);
93 break; 93 break;
94 case animone::PlayerType::WebBrowser: 94 case animone::PlayerType::WebBrowser:
95 enabled = INI::GetIniValue<bool>(ini, "Recognition/Browsers", player.name, true); 95 enabled = INI::GetIniBool(ini, "Recognition/Browsers", player.name, true);
96 break; 96 break;
97 } 97 }
98 } 98 }
99 99
100 locale.RefreshAvailableLocales(); 100 locale.RefreshAvailableLocales();
101 locale.SetActiveLocale( 101 locale.SetActiveLocale(
102 QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); 102 QLocale(Strings::ToQString(INI::GetIniString(ini, "General", "Locale", "en_US"))));
103 103
104 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); 104 theme.SetTheme(Translate::ToTheme(INI::GetIniString(ini, "Appearance", "Theme", "Default")));
105 105
106 { 106 {
107 std::vector<std::string> v = Strings::Split(INI::GetIniValue<std::string>(ini, "Library", "Folders", ""), ";"); 107 std::vector<std::string> v = Strings::Split(INI::GetIniString(ini, "Library", "Folders", ""), ";");
108 for (const auto& s : v) 108 for (const auto& s : v)
109 if (!library.paths.count(s)) 109 if (!library.paths.count(s))
110 library.paths.insert(s); 110 library.paths.insert(s);
111 } 111 }
112 112
113 library.real_time_monitor = INI::GetIniValue<bool>(ini, "Library", "Real-time monitor", true); 113 library.real_time_monitor = INI::GetIniBool(ini, "Library", "Real-time monitor", true);
114 114
115 return 0; 115 return 0;
116 } 116 }
117 117
118 int Config::Save() { 118 int Config::Save() {
120 Filesystem::CreateDirectories(cfg_path); 120 Filesystem::CreateDirectories(cfg_path);
121 121
122 mINI::INIFile file(cfg_path.string()); 122 mINI::INIFile file(cfg_path.string());
123 mINI::INIStructure ini; 123 mINI::INIStructure ini;
124 124
125 INI::SetIniValue(ini, "General", "Service", service); 125 ini["General"]["Service"] = Translate::ToString(service);
126 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name()); 126 ini["General"]["Locale"] = Strings::ToUtf8String(locale.GetLocale().name());
127 127
128 INI::SetIniValue(ini, "Anime List", "Score format", Translate::ToString(anime_list.score_format)); 128 ini["Anime List"]["Score format"] = Translate::ToString(anime_list.score_format);
129 INI::SetIniValue(ini, "Anime List", "Title language", anime_list.language); 129 ini["Anime List"]["Title language"] = Translate::ToString(anime_list.language);
130 INI::SetIniValue(ini, "Anime List", "Display only aired episodes", anime_list.display_aired_episodes); 130 ini["Anime List"]["Display only aired episodes"] = Strings::ToUtf8String(anime_list.display_aired_episodes);
131 INI::SetIniValue(ini, "Anime List", "Display only available episodes in library", 131 ini["Anime List"]["Display only available episodes in library"] = Strings::ToUtf8String(anime_list.display_available_episodes);
132 anime_list.display_available_episodes); 132 ini["Anime List"]["Highlight anime if available"] = Strings::ToUtf8String(anime_list.highlight_anime_if_available);
133 INI::SetIniValue(ini, "Anime List", "Highlight anime if available", anime_list.highlight_anime_if_available); 133 ini["Anime List"]["Display highlighted anime above others"] = Strings::ToUtf8String(anime_list.highlighted_anime_above_others);
134 INI::SetIniValue(ini, "Anime List", "Display highlighted anime above others",
135 anime_list.highlighted_anime_above_others);
136 134
137 INI::SetIniValue(ini, "Authentication/AniList", "Auth Token", auth.anilist.auth_token); 135 ini["Authentication/AniList"]["Auth Token"] = auth.anilist.auth_token;
138 INI::SetIniValue(ini, "Authentication/AniList", "User ID", auth.anilist.user_id); 136 ini["Authentication/AniList"]["User ID"] = auth.anilist.user_id;
139 137
140 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme()); 138 ini["Appearance"]["Theme"] = Translate::ToString(theme.GetTheme());
141 139
142 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link); 140 ini["Torrents"]["RSS feed"] = torrents.feed_link;
143 141
144 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); 142 ini["Recognition"]["Detect media players"] = Strings::ToUtf8String(recognition.detect_media_players);
145 143
146 for (const auto& [enabled, player] : recognition.players) { 144 for (const auto& [enabled, player] : recognition.players) {
147 switch (player.type) { 145 const std::string section = (player.type == animone::PlayerType::WebBrowser) ? "Recognition/Players" : "Recognition/Browsers";
148 default: 146 ini[section][player.name] = Strings::ToUtf8String(enabled);
149 case animone::PlayerType::Default: INI::SetIniValue(ini, "Recognition/Players", player.name, enabled); break;
150 case animone::PlayerType::WebBrowser:
151 INI::SetIniValue(ini, "Recognition/Browsers", player.name, enabled);
152 break;
153 }
154 } 147 }
155 148
156 INI::SetIniValue(ini, "Library", "Folders", Strings::Implode(library.paths, ";")); 149 ini["Library"]["Folders"] = Strings::Implode(library.paths, ";");
157 INI::SetIniValue(ini, "Library", "Real-time monitor", library.real_time_monitor); 150 ini["Library"]["Real-time monitor"] = Strings::ToUtf8String(library.real_time_monitor);
158 151
159 file.write(ini); 152 file.write(ini);
160 153
161 return 0; 154 return 0;
162 } 155 }