# HG changeset patch # User Paper # Date 1753456975 14400 # Node ID abd956418fe98a103da044f6f39d93e9a54c8b69 # Parent f7bb2978de481bc45e8efbe03c33054df343b20c gui/pages/now_playing: automatically update progress when the episode is "finished" diff -r f7bb2978de48 -r abd956418fe9 include/gui/pages/now_playing.h --- a/include/gui/pages/now_playing.h Fri Jul 25 11:03:34 2025 -0400 +++ b/include/gui/pages/now_playing.h Fri Jul 25 11:22:55 2025 -0400 @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -22,7 +23,7 @@ } /* -------------------------------------------------------------- */ -/* separate pages */ +/* this is kinda ugly. */ namespace NowPlayingPages { @@ -43,6 +44,7 @@ Playing(QWidget* parent = nullptr); void SetPlayingAnime(const Anime::Anime& anime, const anitomy::Elements& info); int GetPlayingAnime(); + int GetPlayingEpisode(); private: int _id = 0; @@ -70,6 +72,9 @@ void SetPlaying(const Anime::Anime& anime, const anitomy::Elements& episodes); int GetPlayingId(); +private slots: + void TimerDone(); + private: enum class Subpages { Default = 0, @@ -77,6 +82,7 @@ }; QStackedWidget stack_; + QTimer timer_; NowPlayingPages::Default default_; NowPlayingPages::Playing playing_; diff -r f7bb2978de48 -r abd956418fe9 src/gui/pages/now_playing.cc --- a/src/gui/pages/now_playing.cc Fri Jul 25 11:03:34 2025 -0400 +++ b/src/gui/pages/now_playing.cc Fri Jul 25 11:22:55 2025 -0400 @@ -4,6 +4,7 @@ #include "gui/widgets/anime_info.h" #include "gui/widgets/poster.h" #include "gui/widgets/text.h" +#include "services/services.h" #include #include @@ -60,6 +61,11 @@ return _id; } +int Playing::GetPlayingEpisode() +{ + return _episode; +} + void Playing::SetPlayingAnime(const Anime::Anime &anime, const anitomy::Elements &info) { if (_id == anime.GetId() && @@ -88,12 +94,18 @@ stack_.addWidget(&default_); stack_.addWidget(&playing_); layout->addWidget(&stack_); + timer_.setSingleShot(true); + + QObject::connect(&timer_, &QTimer::timeout, this, &NowPlayingPage::TimerDone); SetDefault(); } void NowPlayingPage::SetDefault() { + /* stop any timer */ + timer_.stop(); + stack_.setCurrentIndex(static_cast(Subpages::Default)); } @@ -104,7 +116,32 @@ void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) { + /* ok */ + timer_.stop(); + playing_.SetPlayingAnime(anime, info); stack_.setCurrentIndex(static_cast(Subpages::Playing)); updateGeometry(); + + /* now, start the timer + * FIXME hardcoding the interval length is a hack at best + * (12 * 60 * 1000) == 720000 msec, which is 12 minutes. */ + timer_.setInterval(12 * 60 * 1000); + timer_.start(); } + +void NowPlayingPage::TimerDone(void) +{ + Anime::Anime &anime = Anime::db.items[playing_.GetPlayingAnime()]; + + if (!anime.IsInUserList()) + anime.AddToUserList(); + + const int progress = anime.GetUserProgress(); + const int playing_ep = playing_.GetPlayingEpisode(); + + if (progress > playing_ep) { + anime.SetUserProgress(playing_ep); + Services::UpdateAnimeEntry(anime.GetId()); + } +}