changeset 375:abd956418fe9 default tip

gui/pages/now_playing: automatically update progress when the episode is "finished"
author Paper <paper@tflc.us>
date Fri, 25 Jul 2025 11:22:55 -0400
parents f7bb2978de48
children
files include/gui/pages/now_playing.h src/gui/pages/now_playing.cc
diffstat 2 files changed, 44 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 <QFrame>
 #include <QStackedWidget>
+#include <QTimer>
 
 #include <memory>
 #include <unordered_map>
@@ -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_;
--- 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 <QHBoxLayout>
 #include <QLabel>
@@ -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<int>(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<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();
 }
+
+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());
+	}
+}