Mercurial > minori
comparison src/gui/pages/now_playing.cc @ 375:abd956418fe9
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 | ea3a74ed2ef9 |
children |
comparison
equal
deleted
inserted
replaced
374:f7bb2978de48 | 375:abd956418fe9 |
---|---|
2 #include "core/anime_db.h" | 2 #include "core/anime_db.h" |
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 | 8 |
8 #include <QHBoxLayout> | 9 #include <QHBoxLayout> |
9 #include <QLabel> | 10 #include <QLabel> |
10 #include <QStackedWidget> | 11 #include <QStackedWidget> |
11 #include <QVBoxLayout> | 12 #include <QVBoxLayout> |
58 int Playing::GetPlayingAnime() | 59 int Playing::GetPlayingAnime() |
59 { | 60 { |
60 return _id; | 61 return _id; |
61 } | 62 } |
62 | 63 |
64 int Playing::GetPlayingEpisode() | |
65 { | |
66 return _episode; | |
67 } | |
68 | |
63 void Playing::SetPlayingAnime(const Anime::Anime &anime, const anitomy::Elements &info) | 69 void Playing::SetPlayingAnime(const Anime::Anime &anime, const anitomy::Elements &info) |
64 { | 70 { |
65 if (_id == anime.GetId() && | 71 if (_id == anime.GetId() && |
66 _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) | 72 _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) |
67 return; | 73 return; |
86 setAutoFillBackground(true); | 92 setAutoFillBackground(true); |
87 | 93 |
88 stack_.addWidget(&default_); | 94 stack_.addWidget(&default_); |
89 stack_.addWidget(&playing_); | 95 stack_.addWidget(&playing_); |
90 layout->addWidget(&stack_); | 96 layout->addWidget(&stack_); |
97 timer_.setSingleShot(true); | |
98 | |
99 QObject::connect(&timer_, &QTimer::timeout, this, &NowPlayingPage::TimerDone); | |
91 | 100 |
92 SetDefault(); | 101 SetDefault(); |
93 } | 102 } |
94 | 103 |
95 void NowPlayingPage::SetDefault() | 104 void NowPlayingPage::SetDefault() |
96 { | 105 { |
106 /* stop any timer */ | |
107 timer_.stop(); | |
108 | |
97 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); | 109 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); |
98 } | 110 } |
99 | 111 |
100 int NowPlayingPage::GetPlayingId() | 112 int NowPlayingPage::GetPlayingId() |
101 { | 113 { |
102 return playing_.GetPlayingAnime(); | 114 return playing_.GetPlayingAnime(); |
103 } | 115 } |
104 | 116 |
105 void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) | 117 void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) |
106 { | 118 { |
119 /* ok */ | |
120 timer_.stop(); | |
121 | |
107 playing_.SetPlayingAnime(anime, info); | 122 playing_.SetPlayingAnime(anime, info); |
108 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); | 123 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); |
109 updateGeometry(); | 124 updateGeometry(); |
125 | |
126 /* now, start the timer | |
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(); | |
110 } | 131 } |
132 | |
133 void NowPlayingPage::TimerDone(void) | |
134 { | |
135 Anime::Anime &anime = Anime::db.items[playing_.GetPlayingAnime()]; | |
136 | |
137 if (!anime.IsInUserList()) | |
138 anime.AddToUserList(); | |
139 | |
140 const int progress = anime.GetUserProgress(); | |
141 const int playing_ep = playing_.GetPlayingEpisode(); | |
142 | |
143 if (progress > playing_ep) { | |
144 anime.SetUserProgress(playing_ep); | |
145 Services::UpdateAnimeEntry(anime.GetId()); | |
146 } | |
147 } |