Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 382:0265e125f680 | 383:27c462bc7815 |
|---|---|
| 3 #include "core/strings.h" | 3 #include "core/strings.h" |
| 4 #include "gui/widgets/anime_info.h" | 4 #include "gui/widgets/anime_info.h" |
| 5 #include "gui/widgets/poster.h" | 5 #include "gui/widgets/poster.h" |
| 6 #include "gui/widgets/text.h" | 6 #include "gui/widgets/text.h" |
| 7 #include "services/services.h" | 7 #include "services/services.h" |
| 8 #include "core/session.h" | |
| 8 | 9 |
| 9 #include <QHBoxLayout> | 10 #include <QHBoxLayout> |
| 10 #include <QLabel> | 11 #include <QLabel> |
| 11 #include <QStackedWidget> | 12 #include <QStackedWidget> |
| 12 #include <QVBoxLayout> | 13 #include <QVBoxLayout> |
| 13 #include <QWidget> | 14 #include <QWidget> |
| 14 | 15 |
| 16 #include <iostream> | |
| 17 | |
| 15 #include "anitomy/anitomy.h" | 18 #include "anitomy/anitomy.h" |
| 16 | 19 |
| 17 namespace NowPlayingPages { | 20 namespace NowPlayingPages { |
| 21 // TODO the "now playing" logic should NOT be located here; this should | |
| 22 // only be a frontent. THAT logic should at the very least be in the | |
| 23 // "core" subdirectory | |
| 18 | 24 |
| 19 Default::Default(QWidget *parent) : QWidget(parent) | 25 Default::Default(QWidget *parent) : QWidget(parent) |
| 20 { | 26 { |
| 21 QVBoxLayout *layout = new QVBoxLayout(this); | 27 QVBoxLayout *layout = new QVBoxLayout(this); |
| 22 layout->setContentsMargins(0, 0, 0, 0); | 28 layout->setContentsMargins(0, 0, 0, 0); |
| 92 setAutoFillBackground(true); | 98 setAutoFillBackground(true); |
| 93 | 99 |
| 94 stack_.addWidget(&default_); | 100 stack_.addWidget(&default_); |
| 95 stack_.addWidget(&playing_); | 101 stack_.addWidget(&playing_); |
| 96 layout->addWidget(&stack_); | 102 layout->addWidget(&stack_); |
| 97 timer_.setSingleShot(true); | |
| 98 | |
| 99 QObject::connect(&timer_, &QTimer::timeout, this, &NowPlayingPage::TimerDone); | |
| 100 | 103 |
| 101 SetDefault(); | 104 SetDefault(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void NowPlayingPage::SetDefault() | 107 void NowPlayingPage::SetDefault() |
| 105 { | 108 { |
| 106 /* stop any timer */ | 109 /* 'timer_' is the time elapsed since we were set to the 'playing' |
| 107 timer_.stop(); | 110 * mode. Otherwise it is -1. */ |
| 111 if (timer_ != -1) { | |
| 112 std::int64_t elapsed = session.uptime() - timer_; | |
| 113 | |
| 114 /* FIXME hardcoding the interval length is a hack at best | |
| 115 * (18 * 60 * 1000), is 18 minutes. */ | |
| 116 if (elapsed > (18ll * 60ll * 1000ll)) { | |
| 117 /* Episode has finished playing */ | |
| 118 TimerDone(); | |
| 119 } | |
| 120 | |
| 121 /* Reset the timer */ | |
| 122 timer_ = -1; | |
| 123 } | |
| 108 | 124 |
| 109 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); | 125 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); |
| 110 } | 126 } |
| 111 | 127 |
| 112 int NowPlayingPage::GetPlayingId() | 128 int NowPlayingPage::GetPlayingId() |
| 114 return playing_.GetPlayingAnime(); | 130 return playing_.GetPlayingAnime(); |
| 115 } | 131 } |
| 116 | 132 |
| 117 void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) | 133 void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) |
| 118 { | 134 { |
| 119 /* ok */ | |
| 120 timer_.stop(); | |
| 121 | |
| 122 playing_.SetPlayingAnime(anime, info); | 135 playing_.SetPlayingAnime(anime, info); |
| 123 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); | 136 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); |
| 124 updateGeometry(); | 137 updateGeometry(); |
| 125 | 138 |
| 126 /* now, start the timer | 139 timer_ = session.uptime(); |
| 127 * FIXME hardcoding the interval length is a hack at best | |
| 128 * (12 * 60 * 1000) == 720000 msec, which is 12 minutes. */ | |
| 129 timer_.setInterval(12 * 60 * 1000); | |
| 130 timer_.start(); | |
| 131 } | 140 } |
| 132 | 141 |
| 133 void NowPlayingPage::TimerDone(void) | 142 void NowPlayingPage::TimerDone(void) |
| 134 { | 143 { |
| 135 Anime::Anime &anime = Anime::db.items[playing_.GetPlayingAnime()]; | 144 Anime::Anime &anime = Anime::db.items[playing_.GetPlayingAnime()]; |
