Mercurial > minori
comparison src/core/config.cc @ 147:6fdf0632c003
track: use a bit of a more sane way to manage recognition
it also works with the new animia API
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 14 Nov 2023 13:19:40 -0500 |
| parents | 0a458cb26ff4 |
| children | e41505d24733 |
comparison
equal
deleted
inserted
replaced
| 146:d8a61e7e2a36 | 147:6fdf0632c003 |
|---|---|
| 8 #include "core/ini.h" | 8 #include "core/ini.h" |
| 9 #include "core/filesystem.h" | 9 #include "core/filesystem.h" |
| 10 #include "core/json.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 | |
| 14 #include "animia/player.h" | |
| 15 | |
| 13 #include <algorithm> | 16 #include <algorithm> |
| 14 #include <cstdlib> | 17 #include <cstdlib> |
| 15 #include <cstring> | 18 #include <cstring> |
| 16 #include <filesystem> | 19 #include <filesystem> |
| 17 #include <fstream> | 20 #include <fstream> |
| 18 #include <limits.h> | 21 #include <limits.h> |
| 22 | |
| 23 #include <QFile> | |
| 24 #include <QTextStream> | |
| 19 | 25 |
| 20 /* I'll use an INI-based config file instead of using an | 26 /* I'll use an INI-based config file instead of using an |
| 21 XML file like Taiga. */ | 27 XML file like Taiga. */ |
| 22 | 28 |
| 23 int Config::Load() { | 29 int Config::Load() { |
| 39 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); | 45 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); |
| 40 | 46 |
| 41 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | 47 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); |
| 42 | 48 |
| 43 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); | 49 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); |
| 50 | |
| 51 /* lots of dumb logic to import the player data */ | |
| 52 { | |
| 53 /* load the player data */ | |
| 54 QFile f(":/players.anisthesia"); | |
| 55 if (!f.exists()) | |
| 56 return false; | |
| 57 | |
| 58 f.open(QFile::ReadOnly | QFile::Text); | |
| 59 QTextStream ts(&f); | |
| 60 | |
| 61 std::vector<animia::Player> players; | |
| 62 | |
| 63 if (!animia::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players)) | |
| 64 return false; | |
| 65 | |
| 66 recognition.players.reserve(players.size()); | |
| 67 for (const auto& player : players) | |
| 68 recognition.players.push_back({true, player}); | |
| 69 } | |
| 70 | |
| 71 for (auto& player : recognition.players) | |
| 72 player.first = INI::GetIniValue<bool>(ini, "Recognition/Players", player.second.name, true); | |
| 44 | 73 |
| 45 /* ew */ | 74 /* ew */ |
| 46 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); | 75 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); |
| 47 | 76 |
| 48 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); | 77 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); |
| 73 | 102 |
| 74 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link); | 103 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link); |
| 75 | 104 |
| 76 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); | 105 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); |
| 77 | 106 |
| 107 for (const auto& player : recognition.players) | |
| 108 INI::SetIniValue(ini, "Recognition/Players", player.second.name, player.first); | |
| 109 | |
| 78 file.write(ini); | 110 file.write(ini); |
| 79 | 111 |
| 80 return 0; | 112 return 0; |
| 81 } | 113 } |
