Mercurial > minori
diff src/gui/pages/now_playing.cc @ 383:27c462bc7815
make the "Now Playing" page actually work
| author | Paper <paper@tflc.us> |
|---|---|
| date | Thu, 06 Nov 2025 07:10:58 -0500 |
| parents | abd956418fe9 |
| children | e89901683d72 |
line wrap: on
line diff
--- a/src/gui/pages/now_playing.cc Thu Nov 06 03:16:55 2025 -0500 +++ b/src/gui/pages/now_playing.cc Thu Nov 06 07:10:58 2025 -0500 @@ -5,6 +5,7 @@ #include "gui/widgets/poster.h" #include "gui/widgets/text.h" #include "services/services.h" +#include "core/session.h" #include <QHBoxLayout> #include <QLabel> @@ -12,9 +13,14 @@ #include <QVBoxLayout> #include <QWidget> +#include <iostream> + #include "anitomy/anitomy.h" namespace NowPlayingPages { +// TODO the "now playing" logic should NOT be located here; this should +// only be a frontent. THAT logic should at the very least be in the +// "core" subdirectory Default::Default(QWidget *parent) : QWidget(parent) { @@ -94,17 +100,27 @@ 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(); + /* 'timer_' is the time elapsed since we were set to the 'playing' + * mode. Otherwise it is -1. */ + if (timer_ != -1) { + std::int64_t elapsed = session.uptime() - timer_; + + /* FIXME hardcoding the interval length is a hack at best + * (18 * 60 * 1000), is 18 minutes. */ + if (elapsed > (18ll * 60ll * 1000ll)) { + /* Episode has finished playing */ + TimerDone(); + } + + /* Reset the timer */ + timer_ = -1; + } stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); } @@ -116,18 +132,11 @@ void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) { - /* ok */ - timer_.stop(); - playing_.SetPlayingAnime(anime, info); stack_.setCurrentIndex(static_cast<int>(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(); + timer_ = session.uptime(); } void NowPlayingPage::TimerDone(void)
