# HG changeset patch # User Paper # Date 1701715242 18000 # Node ID 01d259b9c89fb11b042486db4a8bc31af236108b # Parent c413e475f496dc9e3a8791a4d613a791924230b1 pages/torrents.cc: parse feed descriptions separately services/anilist.cc: use constexpr STL string_view for HTTP queries diff -r c413e475f496 -r 01d259b9c89f include/gui/pages/torrents.h --- a/include/gui/pages/torrents.h Mon Dec 04 13:19:54 2023 -0500 +++ b/include/gui/pages/torrents.h Mon Dec 04 13:40:42 2023 -0500 @@ -46,6 +46,7 @@ Qt::ItemFlags flags(const QModelIndex& index) const override; QByteArray DownloadTorrentList(); + void ParseFeedDescription(const std::string& description, Torrent& torrent); void ParseTorrentList(const QByteArray& ba); void RefreshTorrentList(); diff -r c413e475f496 -r 01d259b9c89f src/core/anime.cc --- a/src/core/anime.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/core/anime.cc Mon Dec 04 13:40:42 2023 -0500 @@ -206,6 +206,7 @@ } std::string Anime::GetServiceUrl() const { + /* todo: add support for other services... */ return "https://anilist.co/anime/" + std::to_string(GetId()); } diff -r c413e475f496 -r 01d259b9c89f src/core/config.cc --- a/src/core/config.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/core/config.cc Mon Dec 04 13:40:42 2023 -0500 @@ -39,7 +39,11 @@ anime_list.display_aired_episodes = INI::GetIniValue(ini, "Anime List", "Display only aired episodes", true); anime_list.display_available_episodes = INI::GetIniValue(ini, "Anime List", "Display only available episodes in library", true); anime_list.highlight_anime_if_available = INI::GetIniValue(ini, "Anime List", "Highlight anime if available", true); - anime_list.highlighted_anime_above_others = INI::GetIniValue(ini, "Anime List", "Display highlighted anime above others", false); + + if (anime_list.highlight_anime_if_available) // sanity check + anime_list.highlighted_anime_above_others = INI::GetIniValue(ini, "Anime List", "Display highlighted anime above others", false); + else + anime_list.highlighted_anime_above_others = false; auth.anilist.auth_token = INI::GetIniValue(ini, "Authentication/AniList", "Auth Token", ""); auth.anilist.user_id = INI::GetIniValue(ini, "Authentication/AniList", "User ID", 0); diff -r c413e475f496 -r 01d259b9c89f src/gui/pages/torrents.cc --- a/src/gui/pages/torrents.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/gui/pages/torrents.cc Mon Dec 04 13:40:42 2023 -0500 @@ -54,6 +54,41 @@ return HTTP::Get(session.config.torrents.feed_link); } +void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) { + /* Parse description... */ + enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT }; + + const std::unordered_map KeyMap = { + {"Size", Keys::SIZE}, + {"Authorized", Keys::AUTHORIZED}, + {"Submitter", Keys::SUBMITTER}, + {"Comment", Keys::COMMENT} + }; + + /* Parse size from description */ + std::istringstream descstream(description); + + for (std::string line; std::getline(descstream, line);) { + const size_t pos = line.find_first_of(':', 0); + if (pos == std::string::npos) + continue; + + const std::string key = line.substr(0, pos); + const std::string value = line.substr(line.find_first_not_of(": ", pos)); + + switch (KeyMap.at(key)) { + case Keys::COMMENT: + torrent.SetDescription(value); + break; + case Keys::SIZE: + torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); + break; + default: + break; + } + } +} + void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { std::istringstream stdstream(Strings::ToUtf8String(ba)); @@ -86,43 +121,9 @@ torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup))); torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution))); } - torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description"))); - { - /* Parse description... */ - enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT }; - - const std::unordered_map KeyMap = { - {"Size", Keys::SIZE}, - {"Authorized", Keys::AUTHORIZED}, - {"Submitter", Keys::SUBMITTER}, - {"Comment", Keys::COMMENT} - }; - - const std::string description = Strings::TextifySynopsis(item.child_value("description")); - - /* Parse size from description */ - std::istringstream descstream(description); - for (std::string line; std::getline(descstream, line);) { - const size_t pos = line.find_first_of(':', 0); - if (pos == std::string::npos) - continue; - - const std::string key = line.substr(0, pos); - const std::string value = line.substr(line.find_first_not_of(": ", pos)); + ParseFeedDescription(Strings::TextifySynopsis(item.child_value("description")), torrent); - switch (KeyMap.at(key)) { - case Keys::COMMENT: - torrent.SetDescription(value); - break; - case Keys::SIZE: - torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); - break; - default: - break; - } - } - } torrent.SetLink(item.child_value("link")); torrent.SetGuid(item.child_value("guid")); { diff -r c413e475f496 -r 01d259b9c89f src/gui/theme.cc --- a/src/gui/theme.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/gui/theme.cc Mon Dec 04 13:40:42 2023 -0500 @@ -17,7 +17,7 @@ 3. I don't want to use the Fusion style on every single platform 4. Windows dark mode support in Qt 6.5 (with Fusion) is completely unavoidable (not a joke btw, it's retarded) - These three already make it really hard, but along with that, I don't even remember if + These four already make it really difficult, but along with that, I don't even remember if OS X dark mode support even works still; I remember the background of some of the widgets would refuse to update for whatever reason. */ diff -r c413e475f496 -r 01d259b9c89f src/gui/widgets/text.cc --- a/src/gui/widgets/text.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/gui/widgets/text.cc Mon Dec 04 13:40:42 2023 -0500 @@ -14,9 +14,12 @@ static_text_title = new QLabel(title, this); static_text_title->setTextFormat(Qt::PlainText); - QFont font = static_text_title->font(); - font.setWeight(QFont::Bold); - static_text_title->setFont(font); + + { + QFont font = static_text_title->font(); + font.setWeight(QFont::Bold); + static_text_title->setFont(font); + } static_text_line = new QFrame(this); static_text_line->setFrameShape(QFrame::HLine); diff -r c413e475f496 -r 01d259b9c89f src/services/anilist.cc --- a/src/services/anilist.cc Mon Dec 04 13:19:54 2023 -0500 +++ b/src/services/anilist.cc Mon Dec 04 13:40:42 2023 -0500 @@ -177,8 +177,8 @@ return 0; } - /* NOTE: these should be in the qrc file */ - const std::string query = "query ($id: Int) {\n" + /* NOTE: these really ought to be in the qrc file */ + constexpr std::string_view query = "query ($id: Int) {\n" " MediaListCollection (userId: $id, type: ANIME) {\n" " lists {\n" " name\n" @@ -265,7 +265,7 @@ * Date completedAt **/ Anime::Anime& anime = Anime::db.items[id]; - const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, " + constexpr std::string_view query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, " "$notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput) {\n" " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, " "scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp) {\n" @@ -313,7 +313,7 @@ account.SetAuthToken(Strings::ToUtf8String(token)); - const std::string query = "query {\n" + constexpr std::string_view query = "query {\n" " Viewer {\n" " id\n" " name\n"