# HG changeset patch # User Paper # Date 1718257758 14400 # Node ID b5d6c27c308fd03fe830864361617c8a0478f954 # Parent 10096c5489e3aeed57de4db2bb21979c530c0aee anime: refactor Anime::SeriesSeason to Season class ToLocalString has also been altered to take in both season and year because lots of locales actually treat formatting seasons differently! most notably is Russian which adds a suffix at the end to notate seasons(??) diff -r 10096c5489e3 -r b5d6c27c308f include/core/anime.h --- a/include/core/anime.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/core/anime.h Thu Jun 13 01:49:18 2024 -0400 @@ -1,7 +1,9 @@ #ifndef MINORI_CORE_ANIME_H_ #define MINORI_CORE_ANIME_H_ +#include "core/anime_season.h" #include "core/date.h" + #include #include #include @@ -63,19 +65,6 @@ SeriesFormat::Music }; -enum class SeriesSeason { - Unknown = 0, - Winter, - Spring, - Summer, - Fall -}; - -constexpr std::array SeriesSeasons{ - SeriesSeason::Winter, SeriesSeason::Spring, - SeriesSeason::Summer, SeriesSeason::Fall -}; - enum class TitleLanguage { Romaji, Native, @@ -182,7 +171,7 @@ std::vector GetGenres() const; std::vector GetProducers() const; SeriesFormat GetFormat() const; - SeriesSeason GetSeason() const; + Season GetSeason() const; double GetAudienceScore() const; std::string GetSynopsis() const; int GetDuration() const; diff -r 10096c5489e3 -r b5d6c27c308f include/core/anime_db.h --- a/include/core/anime_db.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/core/anime_db.h Thu Jun 13 01:49:18 2024 -0400 @@ -35,7 +35,7 @@ /* when syncing we don't want to keep deleted anime */ void RemoveAllUserData(); - std::vector GetAllAnimeForSeason(SeriesSeason season, Date::Year year); + std::vector GetAllAnimeForSeason(Season season); }; extern Database db; diff -r 10096c5489e3 -r b5d6c27c308f include/core/anime_season.h --- a/include/core/anime_season.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/core/anime_season.h Thu Jun 13 01:49:18 2024 -0400 @@ -1,13 +1,45 @@ #ifndef MINORI_CORE_ANIME_SEASON_H_ #define MINORI_CORE_ANIME_SEASON_H_ -#include "core/anime.h" /* Anime::SeriesSeason */ #include "core/date.h" /* Date::Month */ +#include + namespace Anime { -SeriesSeason GetSeasonForMonth(Date::Month month); +class Season final { +public: + enum class Name { + Unknown, + Winter, + Spring, + Summer, + Autumn, + }; + + static constexpr std::array Names{ + Name::Winter, + Name::Spring, + Name::Summer, + Name::Autumn + }; -} + Season() = default; + Season(Name s, Date::Year y); + explicit Season(const Date& date); + + bool operator==(const Season& o) const; + bool operator!=(const Season& o) const; + + bool operator<(const Season& o) const; + bool operator>(const Season& o) const; + bool operator<=(const Season& o) const; + bool operator>=(const Season& o) const; + + Name season = Name::Unknown; + Date::Year year = 0; +}; + +} // namespace Anime #endif // MINORI_CORE_ANIME_SEASON_H_ diff -r 10096c5489e3 -r b5d6c27c308f include/core/date.h --- a/include/core/date.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/core/date.h Thu Jun 13 01:49:18 2024 -0400 @@ -40,13 +40,17 @@ Date(const QDate& date); Date(const nlohmann::json& json); Date(Time::Timestamp timestamp); + bool IsValid() const; + void SetYear(Year y); void SetMonth(Month m); void SetDay(Day d); + void VoidYear(); void VoidMonth(); void VoidDay(); + std::optional GetYear() const; std::optional GetMonth() const; std::optional GetDay() const; diff -r 10096c5489e3 -r b5d6c27c308f include/gui/pages/seasons.h --- a/include/gui/pages/seasons.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/gui/pages/seasons.h Thu Jun 13 01:49:18 2024 -0400 @@ -13,30 +13,24 @@ class QListWidget; class QToolButton; -Q_DECLARE_METATYPE(Anime::SeriesSeason); -Q_DECLARE_METATYPE(Date::Year); +Q_DECLARE_METATYPE(Anime::Season); class SeasonsPageSearchThread : public QThread { Q_OBJECT public: SeasonsPageSearchThread(QObject* parent = nullptr); - void AddToQueue(Anime::SeriesSeason season, Date::Year year); + void AddToQueue(Anime::Season season); protected: void run() override; private: - struct Season { - Anime::SeriesSeason season; - Date::Year year; - }; - - std::queue queue_; + std::queue queue_; std::mutex queue_mutex_; signals: - void ReceivedSeason(Anime::SeriesSeason season, Date::Year year); + void ReceivedSeason(Anime::Season season); }; class SeasonsPage final : public QFrame { @@ -44,15 +38,14 @@ public: SeasonsPage(QWidget* parent = nullptr); - void SetSeason(Anime::SeriesSeason season, Date::Year year); + void SetSeason(Anime::Season season); void Refresh(); protected: QListWidget* buttons = nullptr; QToolButton* season_button = nullptr; - Anime::SeriesSeason season_; - Date::Year year_; + Anime::Season season_; }; #endif // MINORI_GUI_PAGES_SEASONS_H_ diff -r 10096c5489e3 -r b5d6c27c308f include/gui/translate/anilist.h --- a/include/gui/translate/anilist.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/gui/translate/anilist.h Thu Jun 13 01:49:18 2024 -0400 @@ -7,9 +7,9 @@ namespace AniList { Anime::SeriesStatus ToSeriesStatus(const std::string& status); -Anime::SeriesSeason ToSeriesSeason(const std::string& season); +Anime::Season::Name ToSeriesSeason(const std::string& season); Anime::SeriesFormat ToSeriesFormat(const std::string& format); -std::string ToString(Anime::SeriesSeason season); +std::string ToString(Anime::Season::Name season); } // namespace AniList } // namespace Translate diff -r 10096c5489e3 -r b5d6c27c308f include/gui/translate/anime.h --- a/include/gui/translate/anime.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/gui/translate/anime.h Thu Jun 13 01:49:18 2024 -0400 @@ -7,7 +7,7 @@ std::string ToString(const Anime::ListStatus status); std::string ToString(const Anime::SeriesFormat format); -std::string ToString(const Anime::SeriesSeason season); +std::string ToString(const Anime::Season::Name season); std::string ToString(const Anime::SeriesStatus status); std::string ToString(const Anime::Service service); std::string ToString(const Anime::TitleLanguage language); @@ -15,7 +15,7 @@ std::string ToLocalString(const Anime::ListStatus status); std::string ToLocalString(const Anime::SeriesFormat format); -std::string ToLocalString(const Anime::SeriesSeason season); +std::string ToLocalString(const Anime::Season& season); std::string ToLocalString(const Anime::SeriesStatus status); std::string ToLocalString(const Anime::Service service); std::string ToLocalString(const Anime::TitleLanguage language); @@ -23,7 +23,7 @@ Anime::ListStatus ToListStatus(const std::string& str); Anime::SeriesFormat ToSeriesFormat(const std::string& str); -Anime::SeriesSeason ToSeriesSeason(const std::string& str); +Anime::Season::Name ToSeriesSeason(const std::string& str); Anime::SeriesStatus ToSeriesStatus(const std::string& str); Anime::Service ToService(const std::string& str); Anime::TitleLanguage ToLanguage(const std::string& str); diff -r 10096c5489e3 -r b5d6c27c308f include/services/anilist.h --- a/include/services/anilist.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/services/anilist.h Thu Jun 13 01:49:18 2024 -0400 @@ -17,7 +17,7 @@ /* Search query */ std::vector Search(const std::string& search); -bool GetSeason(Anime::SeriesSeason season, Date::Year year); +bool GetSeason(Anime::Season season); /* Write queries (mutations) */ int UpdateAnimeEntry(int id); diff -r 10096c5489e3 -r b5d6c27c308f include/services/kitsu.h --- a/include/services/kitsu.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/services/kitsu.h Thu Jun 13 01:49:18 2024 -0400 @@ -17,7 +17,7 @@ int GetAnimeList(); std::vector Search(const std::string& search); -bool GetSeason(Anime::SeriesSeason season, Date::Year year); +bool GetSeason(Anime::Season season); int UpdateAnimeEntry(int id); } // namespace Kitsu diff -r 10096c5489e3 -r b5d6c27c308f include/services/services.h --- a/include/services/services.h Thu Jun 13 00:42:00 2024 -0400 +++ b/include/services/services.h Thu Jun 13 01:49:18 2024 -0400 @@ -17,7 +17,7 @@ bool RetrieveAnimeMetadata(int id); std::vector Search(const std::string& search); -bool GetSeason(Anime::SeriesSeason season, Date::Year year); +bool GetSeason(Anime::Season season); void UpdateAnimeEntry(int id); }; // namespace Services diff -r 10096c5489e3 -r b5d6c27c308f src/core/anime.cc --- a/src/core/anime.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/core/anime.cc Thu Jun 13 01:49:18 2024 -0400 @@ -244,9 +244,8 @@ return info_.format; } -SeriesSeason Anime::GetSeason() const { - std::optional month = info_.started.GetMonth(); - return (month.has_value() ? GetSeasonForMonth(month.value()) : SeriesSeason::Unknown); +Season Anime::GetSeason() const { + return Season(info_.started); } double Anime::GetAudienceScore() const { diff -r 10096c5489e3 -r b5d6c27c308f src/core/anime_db.cc --- a/src/core/anime_db.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/core/anime_db.cc Thu Jun 13 01:49:18 2024 -0400 @@ -347,11 +347,11 @@ } } -std::vector Database::GetAllAnimeForSeason(SeriesSeason season, Date::Year year) { +std::vector Database::GetAllAnimeForSeason(Season season) { std::vector res; for (const auto& [id, anime] : items) { - if (anime.GetSeason() == season && anime.GetStartedDate().GetYear() == year) + if (anime.GetSeason() == season) res.push_back(id); } diff -r 10096c5489e3 -r b5d6c27c308f src/core/anime_season.cc --- a/src/core/anime_season.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/core/anime_season.cc Thu Jun 13 01:49:18 2024 -0400 @@ -1,19 +1,82 @@ #include "core/anime_season.h" +#include "core/session.h" namespace Anime { -SeriesSeason GetSeasonForMonth(Date::Month month) { - switch (month) { - case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: - default: - return SeriesSeason::Winter; - case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: - return SeriesSeason::Spring; - case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep: - return SeriesSeason::Summer; - case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec: - return SeriesSeason::Fall; +static bool WinterStartsInDecember() { + switch (session.config.service) { + case Service::MyAnimeList: + return false; + default: + return true; + } +} + +static Season::Name GetSeasonForMonth(Date::Month month) { + if (WinterStartsInDecember()) { + switch (month) { + case Date::Month::Dec: case Date::Month::Jan: case Date::Month::Feb: + return Season::Name::Winter; + case Date::Month::Mar: case Date::Month::Apr: case Date::Month::May: + return Season::Name::Spring; + case Date::Month::Jun: case Date::Month::Jul: case Date::Month::Aug: + return Season::Name::Summer; + case Date::Month::Sep: case Date::Month::Oct: case Date::Month::Nov: + return Season::Name::Autumn; + default: return Season::Name::Unknown; + } + } else { + switch (month) { + case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: + return Season::Name::Winter; + case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: + return Season::Name::Spring; + case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep: + return Season::Name::Summer; + case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec: + return Season::Name::Autumn; + default: return Season::Name::Unknown; + } } } +Season::Season(Season::Name s, Date::Year y) { + season = s; + year = y; } + +Season::Season(const Date& date) { + std::optional month = date.GetMonth(); + if (month) + season = GetSeasonForMonth(month.value()); + + std::optional y = date.GetYear(); + if (y) + year = y.value(); +} + +bool Season::operator==(const Season& o) const { + return (season == o.season && year == o.year); +} + +bool Season::operator!=(const Season& o) const { + return !(*this == o); +} + +bool Season::operator<(const Season& o) const { + return std::tie(season, year) < std::tie(o.season, o.year); +} + +bool Season::operator>(const Season& o) const { + return (o < *this); +} + +bool Season::operator<=(const Season& o) const { + return !(o > *this); +} + +bool Season::operator>=(const Season& o) const { + return !(*this < o); +} + +} diff -r 10096c5489e3 -r b5d6c27c308f src/gui/pages/anime_list.cc --- a/src/gui/pages/anime_list.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/pages/anime_list.cc Thu Jun 13 01:49:18 2024 -0400 @@ -142,13 +142,7 @@ case AL_EPISODES: return list[index.row()].GetEpisodes(); case AL_SCORE: return Strings::ToQString(list[index.row()].GetUserPresentableScore()); case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); - case AL_SEASON: { - std::optional year = list[index.row()].GetStartedDate().GetYear(); - if (!year) - return tr("Unknown Unknown"); - return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason()) + " " + - Strings::ToUtf8String(year.value())); - } + case AL_SEASON: return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason())); case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%"; case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate(); case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate(); diff -r 10096c5489e3 -r b5d6c27c308f src/gui/pages/search.cc --- a/src/gui/pages/search.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/pages/search.cc Thu Jun 13 01:49:18 2024 -0400 @@ -126,9 +126,7 @@ case SR_TYPE: return Strings::ToQString(Translate::ToLocalString(anime.GetFormat())); case SR_EPISODES: return anime.GetEpisodes(); case SR_SCORE: return QString::number(anime.GetAudienceScore()) + "%"; - case SR_SEASON: - return Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) + " " + - QString::number(anime.GetStartedDate().GetYear().value_or(2000)); + case SR_SEASON: return Strings::ToQString(Translate::ToLocalString(anime.GetSeason())); default: return {}; } break; diff -r 10096c5489e3 -r b5d6c27c308f src/gui/pages/seasons.cc --- a/src/gui/pages/seasons.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/pages/seasons.cc Thu Jun 13 01:49:18 2024 -0400 @@ -18,9 +18,9 @@ SeasonsPageSearchThread::SeasonsPageSearchThread(QObject* parent) : QThread(parent) { } -void SeasonsPageSearchThread::AddToQueue(Anime::SeriesSeason season, Date::Year year) { +void SeasonsPageSearchThread::AddToQueue(Anime::Season season) { queue_mutex_.lock(); - queue_.push({season, year}); + queue_.push(season); queue_mutex_.unlock(); } @@ -28,14 +28,14 @@ queue_mutex_.lock(); while (!queue_.empty() && !isInterruptionRequested()) { - Season season = queue_.front(); + Anime::Season season = queue_.front(); /* unlock the mutex for a long blocking operation, so items * can be added without worry */ queue_mutex_.unlock(); - if (Services::GetSeason(season.season, season.year)) - emit ReceivedSeason(season.season, season.year); + if (Services::GetSeason(season)) + emit ReceivedSeason(season); queue_mutex_.lock(); @@ -61,7 +61,7 @@ buttons->clear(); - for (const auto& id : Anime::db.GetAllAnimeForSeason(season_, year_)) { + for (const auto& id : Anime::db.GetAllAnimeForSeason(season_)) { QListWidgetItem* item = new QListWidgetItem; AnimeButton* button = new AnimeButton(this); button->SetAnime(Anime::db.items[id]); @@ -70,14 +70,13 @@ buttons->setItemWidget(item, button); } - season_button->setText(Strings::ToQString(Translate::ToLocalString(season_)) + " " + QString::number(year_)); + season_button->setText(Strings::ToQString(Translate::ToLocalString(season_))); setUpdatesEnabled(true); } -void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { +void SeasonsPage::SetSeason(Anime::Season season) { season_ = season; - year_ = year; Refresh(); } @@ -97,16 +96,17 @@ toolbar->setMovable(false); { + /* currently this is VERY hardcoded to en_US */ static constexpr Date::Year last_year = 1960; auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ const QString year_s = QString::number(year); QMenu* menu = new QMenu(year_s, parent); - for (const auto& season : Anime::SeriesSeasons) { - QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); + for (const auto& season : Anime::Season::Names) { + QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(Anime::Season(season, year)))); connect(action, &QAction::triggered, this, [this, season, year] { - SetSeason(season, year); + SetSeason({season, year}); }); } parent_menu->addMenu(menu); @@ -143,7 +143,7 @@ { toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data"), [this]{ - search_thread_.AddToQueue(season_, year_); + search_thread_.AddToQueue(season_); if (!search_thread_.isRunning()) search_thread_.start(); }); @@ -234,11 +234,11 @@ full_layout->setContentsMargins(0, 0, 0, 0); full_layout->setSpacing(0); - connect(&search_thread_, &SeasonsPageSearchThread::ReceivedSeason, this, [this](Anime::SeriesSeason season, Date::Year year) { - if (season == season_ && year == year_) + connect(&search_thread_, &SeasonsPageSearchThread::ReceivedSeason, this, [this](Anime::Season season) { + if (season == season_) Refresh(); }); /* Do NOT move this up in this function, buttons HAS to be initialized */ - SetSeason(Anime::SeriesSeason::Summer, 2011U); + SetSeason({Anime::Season::Name::Summer, 2011U}); } diff -r 10096c5489e3 -r b5d6c27c308f src/gui/translate/anilist.cc --- a/src/gui/translate/anilist.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/translate/anilist.cc Thu Jun 13 01:49:18 2024 -0400 @@ -18,16 +18,16 @@ return map.at(status); } -Anime::SeriesSeason ToSeriesSeason(const std::string& season) { - static const std::unordered_map map = { - {"WINTER", Anime::SeriesSeason::Winter}, - {"SPRING", Anime::SeriesSeason::Spring}, - {"SUMMER", Anime::SeriesSeason::Summer}, - {"FALL", Anime::SeriesSeason::Fall } +Anime::Season::Name ToSeriesSeason(const std::string& season) { + static const std::unordered_map map = { + {"WINTER", Anime::Season::Name::Winter}, + {"SPRING", Anime::Season::Name::Spring}, + {"SUMMER", Anime::Season::Name::Summer}, + {"FALL", Anime::Season::Name::Autumn} }; if (map.find(season) == map.end()) - return Anime::SeriesSeason::Unknown; + return Anime::Season::Name::Unknown; return map.at(season); } @@ -47,13 +47,13 @@ return map.at(format); } -std::string ToString(Anime::SeriesSeason season) { +std::string ToString(Anime::Season::Name season) { switch (season) { default: - case Anime::SeriesSeason::Winter: return "WINTER"; - case Anime::SeriesSeason::Fall: return "FALL"; - case Anime::SeriesSeason::Summer: return "SUMMER"; - case Anime::SeriesSeason::Spring: return "SPRING"; + case Anime::Season::Name::Winter: return "WINTER"; + case Anime::Season::Name::Autumn: return "FALL"; + case Anime::Season::Name::Summer: return "SUMMER"; + case Anime::Season::Name::Spring: return "SPRING"; } } diff -r 10096c5489e3 -r b5d6c27c308f src/gui/translate/anime.cc --- a/src/gui/translate/anime.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/translate/anime.cc Thu Jun 13 01:49:18 2024 -0400 @@ -34,14 +34,14 @@ } } -std::string ToString(const Anime::SeriesSeason season) { +std::string ToString(const Anime::Season::Name season) { switch (season) { - case Anime::SeriesSeason::Winter: return "Winter"; - case Anime::SeriesSeason::Summer: return "Summer"; - case Anime::SeriesSeason::Fall: return "Fall"; - case Anime::SeriesSeason::Spring: return "Spring"; + case Anime::Season::Name::Winter: return "Winter"; + case Anime::Season::Name::Summer: return "Summer"; + case Anime::Season::Name::Autumn: return "Autumn"; + case Anime::Season::Name::Spring: return "Spring"; default: - case Anime::SeriesSeason::Unknown: return "Unknown"; + case Anime::Season::Name::Unknown: return "Unknown"; } } @@ -89,83 +89,96 @@ Anime::ListStatus ToListStatus(const std::string& str) { static const std::unordered_map map = { - {"Currently watching", Anime::ListStatus::Current }, - {"Plan to watch", Anime::ListStatus::Planning }, - {"Completed", Anime::ListStatus::Completed}, - {"Dropped", Anime::ListStatus::Dropped }, - {"On hold", Anime::ListStatus::Paused } - }; + {"currently watching", Anime::ListStatus::Current }, + {"plan to watch", Anime::ListStatus::Planning }, + {"completed", Anime::ListStatus::Completed}, + {"dropped", Anime::ListStatus::Dropped }, + {"on hold", Anime::ListStatus::Paused } + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::ListStatus::NotInList; - return map.at(str); + return map.at(lower); } Anime::SeriesStatus ToSeriesStatus(const std::string& str) { static const std::unordered_map map = { - {"Currently airing", Anime::SeriesStatus::Releasing }, - {"Finished airing", Anime::SeriesStatus::Finished }, - {"Not yet aired", Anime::SeriesStatus::NotYetReleased}, - {"Cancelled", Anime::SeriesStatus::Cancelled }, - {"On hiatus", Anime::SeriesStatus::Hiatus } - }; + {"currently airing", Anime::SeriesStatus::Releasing }, + {"finished airing", Anime::SeriesStatus::Finished }, + {"not yet aired", Anime::SeriesStatus::NotYetReleased}, + {"cancelled", Anime::SeriesStatus::Cancelled }, + {"on hiatus", Anime::SeriesStatus::Hiatus } + }; + + std::string lower = Strings::ToLower(str); if (map.find(str) == map.end()) return Anime::SeriesStatus::Unknown; return map.at(str); } -Anime::SeriesSeason ToSeriesSeason(const std::string& str) { - static const std::unordered_map map = { - {"Winter", Anime::SeriesSeason::Winter}, - {"Summer", Anime::SeriesSeason::Summer}, - {"Fall", Anime::SeriesSeason::Fall }, - {"Spring", Anime::SeriesSeason::Spring} - }; +Anime::Season::Name ToSeriesSeason(const std::string& str) { + static const std::unordered_map map = { + {"winter", Anime::Season::Name::Winter}, + {"summer", Anime::Season::Name::Summer}, + {"fall", Anime::Season::Name::Autumn}, + {"autumn", Anime::Season::Name::Autumn}, + {"spring", Anime::Season::Name::Spring}, + }; - if (map.find(str) == map.end()) - return Anime::SeriesSeason::Unknown; - return map.at(str); + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) + return Anime::Season::Name::Unknown; + return map.at(lower); } Anime::SeriesFormat ToSeriesFormat(const std::string& str) { static const std::unordered_map map = { - {"TV", Anime::SeriesFormat::Tv }, - {"TV short", Anime::SeriesFormat::TvShort}, - {"OVA", Anime::SeriesFormat::Ova }, - {"Movie", Anime::SeriesFormat::Movie }, - {"Special", Anime::SeriesFormat::Special }, - {"ONA", Anime::SeriesFormat::Ona }, - {"Music", Anime::SeriesFormat::Music } - }; + {"tv", Anime::SeriesFormat::Tv }, + {"tv short", Anime::SeriesFormat::TvShort}, + {"ova", Anime::SeriesFormat::Ova }, + {"movie", Anime::SeriesFormat::Movie }, + {"special", Anime::SeriesFormat::Special }, + {"ona", Anime::SeriesFormat::Ona }, + {"music", Anime::SeriesFormat::Music } + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::SeriesFormat::Unknown; - return map.at(str); + return map.at(lower); } Anime::Service ToService(const std::string& str) { static const std::unordered_map map = { - {"AniList", Anime::Service::AniList}, - {"MyAnimeList", Anime::Service::MyAnimeList}, - {"Kitsu", Anime::Service::Kitsu} - }; + {"anilist", Anime::Service::AniList}, + {"myanimelist", Anime::Service::MyAnimeList}, + {"kitsu", Anime::Service::Kitsu} + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::Service::None; - return map.at(str); + return map.at(lower); } Anime::TitleLanguage ToLanguage(const std::string& str) { static const std::unordered_map map = { - {"Romaji", Anime::TitleLanguage::Romaji }, - {"Native", Anime::TitleLanguage::Native }, - {"English", Anime::TitleLanguage::English} - }; + {"romaji", Anime::TitleLanguage::Romaji }, + {"native", Anime::TitleLanguage::Native }, + {"english", Anime::TitleLanguage::English} + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::TitleLanguage::Romaji; - return map.at(str); + return map.at(lower); } Anime::ScoreFormat ToScoreFormat(const std::string& str) { @@ -173,19 +186,21 @@ {"3-point", Anime::ScoreFormat::Point3}, {"5-point", Anime::ScoreFormat::Point5}, {"10-point", Anime::ScoreFormat::Point10 }, - {"10-point Decimal", Anime::ScoreFormat::Point10Decimal}, + {"10-point decimal", Anime::ScoreFormat::Point10Decimal}, {"100-point", Anime::ScoreFormat::Point100 }, /* old values, provided for compatibility */ - {"POINT_3", Anime::ScoreFormat::Point3 }, - {"POINT_5", Anime::ScoreFormat::Point5 }, - {"POINT_10", Anime::ScoreFormat::Point10 }, - {"POINT_10_DECIMAL", Anime::ScoreFormat::Point10Decimal}, - {"POINT_100", Anime::ScoreFormat::Point100 } - }; + {"point_3", Anime::ScoreFormat::Point3 }, + {"point_5", Anime::ScoreFormat::Point5 }, + {"point_10", Anime::ScoreFormat::Point10 }, + {"point_10_decimal", Anime::ScoreFormat::Point10Decimal}, + {"point_100", Anime::ScoreFormat::Point100 }, + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::ScoreFormat::Point100; - return map.at(str); + return map.at(lower); } /* Localized versions of ToString() functions. Meant for display to the user. */ @@ -216,17 +231,23 @@ } } -std::string ToLocalString(const Anime::SeriesSeason season) { +std::string ToLocalString(const Anime::Season::Name season) { switch (season) { - case Anime::SeriesSeason::Winter: return Strings::Translate("Winter"); - case Anime::SeriesSeason::Summer: return Strings::Translate("Summer"); - case Anime::SeriesSeason::Fall: return Strings::Translate("Fall"); - case Anime::SeriesSeason::Spring: return Strings::Translate("Spring"); + case Anime::Season::Name::Winter: return Strings::Translate("Winter"); + case Anime::Season::Name::Summer: return Strings::Translate("Summer"); + case Anime::Season::Name::Autumn: return Strings::Translate("Autumn"); + case Anime::Season::Name::Spring: return Strings::Translate("Spring"); default: - case Anime::SeriesSeason::Unknown: return Strings::Translate("Unknown"); + case Anime::Season::Name::Unknown: return Strings::Translate("Unknown"); } } +std::string ToLocalString(const Anime::Season& season) { + std::string year = (season.year) ? Strings::ToUtf8String(season.year) : Strings::Translate("Unknown"); + + return ToLocalString(season.season) + " " + year; +} + std::string ToLocalString(const Anime::SeriesStatus status) { switch (status) { case Anime::SeriesStatus::Releasing: return Strings::Translate("Currently airing"); diff -r 10096c5489e3 -r b5d6c27c308f src/gui/widgets/anime_info.cc --- a/src/gui/widgets/anime_info.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/widgets/anime_info.cc Thu Jun 13 01:49:18 2024 -0400 @@ -97,8 +97,7 @@ details_data_s << Strings::ToQString(Translate::ToLocalString(anime.GetFormat())) << "\n" << anime.GetEpisodes() << "\n" << Strings::ToQString(Translate::ToLocalString(anime.GetAiringStatus())) << "\n" - << Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) << " " - << anime.GetStartedDate().GetYear().value_or(2000) << "\n" + << Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) << "\n" << Strings::ToQString((genres.size() > 1) ? Strings::Implode(genres, ", ") : "-") << "\n" << Strings::ToQString((producers.size() > 1) ? Strings::Implode(producers, ", ") : "-") << "\n" << anime.GetAudienceScore() << "%"; diff -r 10096c5489e3 -r b5d6c27c308f src/main.cc --- a/src/main.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/main.cc Thu Jun 13 01:49:18 2024 -0400 @@ -22,8 +22,7 @@ qRegisterMetaType>(); /* window.cc */ qRegisterMetaType>(); /* search.cc */ qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType("Date::Year"); + qRegisterMetaType(); session.config.Load(); Anime::db.LoadDatabaseFromDisk(); diff -r 10096c5489e3 -r b5d6c27c308f src/services/anilist.cc --- a/src/services/anilist.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/services/anilist.cc Thu Jun 13 01:49:18 2024 -0400 @@ -357,7 +357,7 @@ return ret; } -bool GetSeason(Anime::SeriesSeason season, Date::Year year) { +bool GetSeason(Anime::Season season) { static constexpr std::string_view query = "query ($season: MediaSeason!, $season_year: Int!, $page: Int) {\n" " Page(page: $page) {\n" @@ -381,8 +381,8 @@ nlohmann::json json = { {"query", query}, {"variables", { - {"season", Translate::AniList::ToString(season)}, - {"season_year", Strings::ToUtf8String(year)}, + {"season", Translate::AniList::ToString(season.season)}, + {"season_year", Strings::ToUtf8String(season.year)}, {"page", page}, }}, }; diff -r 10096c5489e3 -r b5d6c27c308f src/services/kitsu.cc --- a/src/services/kitsu.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/services/kitsu.cc Thu Jun 13 01:49:18 2024 -0400 @@ -548,7 +548,7 @@ return {}; } -bool GetSeason(Anime::SeriesSeason season, Date::Year year) { +bool GetSeason(Anime::Season season) { return false; } diff -r 10096c5489e3 -r b5d6c27c308f src/services/services.cc --- a/src/services/services.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/services/services.cc Thu Jun 13 01:49:18 2024 -0400 @@ -33,12 +33,12 @@ } } -bool GetSeason(Anime::SeriesSeason season, Date::Year year) { +bool GetSeason(Anime::Season season) { session.SetStatusBar(Translate::ToString(session.config.service) + ": Retrieving anime season data..."); switch (session.config.service) { - case Anime::Service::AniList: return AniList::GetSeason(season, year); - case Anime::Service::Kitsu: return Kitsu::GetSeason(season, year); + case Anime::Service::AniList: return AniList::GetSeason(season); + case Anime::Service::Kitsu: return Kitsu::GetSeason(season); default: return {}; } }