Mercurial > minori
changeset 80:825506f0e221
[UNFINISHED]: stuff
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 13 Oct 2023 13:15:19 -0400 |
parents | c489dd4434af |
children | 9b2b41f83a5e |
files | include/gui/pages/now_playing.h include/gui/widgets/anime_info.h include/track/media.h src/gui/pages/now_playing.cpp src/gui/widgets/anime_info.cpp src/gui/window.cpp src/track/media.cpp |
diffstat | 7 files changed, 76 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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 <QFrame> +#include <unordered_map> 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<std::string, std::string>& episodes); int GetPlayingId(); private:
--- 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<TextWidgets::OneLineSection> _title = nullptr; + std::shared_ptr<TextWidgets::LabelledSection> _details = nullptr; + std::shared_ptr<TextWidgets::SelectableSection> _synopsis = nullptr; }; #endif // __gui__widgets__anime_info_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 <unordered_map> namespace Track { namespace Media { Filesystem::Path GetCurrentPlaying(); -std::string GetFileTitle(Filesystem::Path path); +std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path); } // namespace Media } // namespace Track
--- 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 <QVBoxLayout> #include <QWidget> +/* 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<std::string, std::string>& info); int GetPlayingAnime(); private: int _id = 0; int _episode = 0; - std::unique_ptr<AnimeInfoWidget> info = nullptr; + std::unique_ptr<TextWidgets::Title> _title = nullptr; + std::unique_ptr<AnimeInfoWidget> _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<std::string, std::string>& 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<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); } -void NowPlayingPage::SetPlaying(int id, int episodes) { - reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, episodes); +void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { + reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); stack->setCurrentIndex(1); }
--- 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 <QHBoxLayout> #include <QTextStream> -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); }
--- 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<NowPlayingPage*>(stack->widget(static_cast<int>(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<std::string, std::string> 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);
--- 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 <string> #include <vector> +#include <unordered_map> #include <QDebug> namespace Track { @@ -27,13 +28,25 @@ return Filesystem::Path(); } -std::string GetFileTitle(Filesystem::Path path) { +std::unordered_map<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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