# HG changeset patch # User Paper # Date 1697217319 14400 # Node ID 825506f0e221e68ea7f519ddd3b4605e779d41ca # Parent c489dd4434af3cc2170f7d52ea3ca972556a8cab [UNFINISHED]: stuff diff -r c489dd4434af -r 825506f0e221 include/gui/pages/now_playing.h --- a/include/gui/pages/now_playing.h Thu Oct 12 11:31:39 2023 -0400 +++ b/include/gui/pages/now_playing.h Fri Oct 13 13:15:19 2023 -0400 @@ -1,6 +1,7 @@ #ifndef __gui__pages__now_playing_h #define __gui__pages__now_playing_h #include +#include class QStackedWidget; @@ -10,7 +11,7 @@ public: NowPlayingPage(QWidget* parent = nullptr); void SetDefault(); - void SetPlaying(int id, int episodes); + void SetPlaying(int id, const std::unordered_map& episodes); int GetPlayingId(); private: diff -r c489dd4434af -r 825506f0e221 include/gui/widgets/anime_info.h --- a/include/gui/widgets/anime_info.h Thu Oct 12 11:31:39 2023 -0400 +++ b/include/gui/widgets/anime_info.h Fri Oct 13 13:15:19 2023 -0400 @@ -10,7 +10,14 @@ Q_OBJECT public: + AnimeInfoWidget(QWidget* parent = nullptr); AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent = nullptr); + SetAnime(const Anime::Anime& anime); + + private: + std::shared_ptr _title = nullptr; + std::shared_ptr _details = nullptr; + std::shared_ptr _synopsis = nullptr; }; #endif // __gui__widgets__anime_info_h diff -r c489dd4434af -r 825506f0e221 include/track/media.h --- a/include/track/media.h Thu Oct 12 11:31:39 2023 -0400 +++ b/include/track/media.h Fri Oct 13 13:15:19 2023 -0400 @@ -1,12 +1,13 @@ #ifndef __track__media_h #define __track__media_h #include "core/filesystem.h" +#include namespace Track { namespace Media { Filesystem::Path GetCurrentPlaying(); -std::string GetFileTitle(Filesystem::Path path); +std::unordered_map GetFileElements(Filesystem::Path path); } // namespace Media } // namespace Track diff -r c489dd4434af -r 825506f0e221 src/gui/pages/now_playing.cpp --- a/src/gui/pages/now_playing.cpp Thu Oct 12 11:31:39 2023 -0400 +++ b/src/gui/pages/now_playing.cpp Fri Oct 13 13:15:19 2023 -0400 @@ -7,6 +7,10 @@ #include #include +/* This is here to make it easier to switch between the + "sub-pages", i.e., not playing and playing. + + TODO: find a way to do this more efficiently */ namespace NowPlayingPages { class Default : public QWidget { @@ -21,25 +25,35 @@ public: Playing(QWidget* parent = nullptr); - void SetPlayingAnime(int id, int episode); + void SetPlayingAnime(int id, const std::unordered_map& info); int GetPlayingAnime(); private: int _id = 0; int _episode = 0; - std::unique_ptr info = nullptr; + std::unique_ptr _title = nullptr; + std::unique_ptr _info = nullptr; }; Default::Default(QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); + TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); + layout->addWidget(title); + layout->addStretch(); } Playing::Playing(QWidget* parent) : QWidget(parent) { QHBoxLayout* layout = new QHBoxLayout(this); + _title.reset(new TextWidgets::Title("\n", this)); + layout->addWidget(_title.get()); + + _info.reset(new AnimeInfoWidget(this)); + layout->addWidget(_info.get()); + layout->setContentsMargins(0, 0, 0, 0); } @@ -47,14 +61,13 @@ return _id; } -void Playing::SetPlayingAnime(int id, int episodes) { - if (id == _id) +void Playing::SetPlayingAnime(int id, const std::unordered_map& info) { + if (id == _id || id <= 0) return; - if (info.get()) - layout()->removeWidget(info.get()); if (Anime::db.items.find(id) != Anime::db.items.end()) { - info.reset(new AnimeInfoWidget(Anime::db.items[_id = id])); - layout()->addWidget(info.get()); + const Anime::Anime& anime = Anime::db.items[_id = id]; + _title->setText(anime.GetUserPreferredTitle()); + _info->SetAnime(anime); } } @@ -71,9 +84,6 @@ setPalette(pal); setAutoFillBackground(true); - TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); - layout->addWidget(title); - stack = new QStackedWidget(this); stack->addWidget(new NowPlayingPages::Default(stack)); stack->addWidget(new NowPlayingPages::Playing(stack)); @@ -90,8 +100,8 @@ return reinterpret_cast(stack->widget(1))->GetPlayingAnime(); } -void NowPlayingPage::SetPlaying(int id, int episodes) { - reinterpret_cast(stack->widget(1))->SetPlayingAnime(id, episodes); +void NowPlayingPage::SetPlaying(int id, const std::unordered_map& info) { + reinterpret_cast(stack->widget(1))->SetPlayingAnime(id, info); stack->setCurrentIndex(1); } diff -r c489dd4434af -r 825506f0e221 src/gui/widgets/anime_info.cpp --- a/src/gui/widgets/anime_info.cpp Thu Oct 12 11:31:39 2023 -0400 +++ b/src/gui/widgets/anime_info.cpp Fri Oct 13 13:15:19 2023 -0400 @@ -6,13 +6,28 @@ #include #include -AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent) : QWidget(parent) { +AnimeInfoWidget::AnimeInfoWidget(QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); + _title.reset(new TextWidgets::OneLineSection(tr("Alternative titles"), "", this)); + layout->addWidget(_title.get()); + + _details.reset(new TextWidgets::LabelledSection(tr("Details"), new TextWidgets::LabelledSection( + tr("Details"), tr("Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:"), "", this), "", this)); + layout->addWidget(_details.get()); + + _synopsis.reset(new TextWidgets::LabelledSection(tr("Synopsis"), "", this)); + _synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + layout->addWidget(_synopsis.get()); +} + +AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent) : AnimeInfoWidget(parent) { + SetAnime(anime); +} + +AnimeInfoWidget::SetAnime(const Anime::Anime& anime) { /* alt titles */ - TextWidgets::OneLineSection* title = new TextWidgets::OneLineSection( - tr("Alternative titles"), Strings::ToQString(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), this); - layout->addWidget(title); + _title->GetParagraph()->SetText(Strings::ToQString(Strings::Implode(anime.GetTitleSynonyms(), ", "))); /* details */ QString details_data; @@ -23,14 +38,10 @@ << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() << "\n" << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n" << anime.GetAudienceScore() << "%"; - layout->addWidget(new TextWidgets::LabelledSection( - tr("Details"), tr("Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:"), details_data, this)); + _details->GetParagraph()->SetText(Strings::ToQString(Strings::Implode(anime.GetTitleSynonyms(), ", "))); + layout->addWidget(); - /* synopsis */ - TextWidgets::SelectableSection* synopsis = - new TextWidgets::SelectableSection(tr("Synopsis"), QString::fromUtf8(anime.GetSynopsis().c_str()), this); - - synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + _synopsis->GetParagraph()->SetText(Strings::ToQString(Strings::Implode(anime.GetTitleSynonyms(), ", "))); layout->addWidget(synopsis); } diff -r c489dd4434af -r 825506f0e221 src/gui/window.cpp --- a/src/gui/window.cpp Thu Oct 12 11:31:39 2023 -0400 +++ b/src/gui/window.cpp Fri Oct 13 13:15:19 2023 -0400 @@ -96,14 +96,14 @@ NowPlayingPage* page = reinterpret_cast(stack->widget(static_cast(Pages::NOW_PLAYING))); Filesystem::Path p = Track::Media::GetCurrentPlaying(); - std::string title = Track::Media::GetFileTitle(p); - int id = Anime::db.GetAnimeFromTitle(title); + std::unordered_map elements = Track::Media::GetFileElements(p); + int id = Anime::db.GetAnimeFromTitle(elements["title"]); if (id == 0) { page->SetDefault(); return; } - page->SetPlaying(id, -1); + page->SetPlaying(id, elements); }); timer->start(5000); diff -r c489dd4434af -r 825506f0e221 src/track/media.cpp --- a/src/track/media.cpp Thu Oct 12 11:31:39 2023 -0400 +++ b/src/track/media.cpp Fri Oct 13 13:15:19 2023 -0400 @@ -5,6 +5,7 @@ #include "core/strings.h" #include #include +#include #include namespace Track { @@ -27,13 +28,25 @@ return Filesystem::Path(); } -std::string GetFileTitle(Filesystem::Path path) { +std::unordered_map GetMapFromElements(const anitomy::Elements& elements) { + /* there are way more than this in anitomy, but we only need basic information + I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ + std::unordered_map ret; + + ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); + ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); + ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage)); + ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)); + ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); + + return ret; +} + +std::unordered_map GetFileElements(Filesystem::Path path) { anitomy::Anitomy anitomy; anitomy.Parse(Strings::ToWstring(path.Basename())); - const auto& elements = anitomy.elements(); - - return Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); + return GetMapFromElements(anitomy.elements()); } } // namespace Media