Mercurial > minori
annotate 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 |
| rev | line source |
|---|---|
| 9 | 1 #include "gui/pages/now_playing.h" |
| 64 | 2 #include "core/anime_db.h" |
|
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
3 #include "core/strings.h" |
| 64 | 4 #include "gui/widgets/anime_info.h" |
| 258 | 5 #include "gui/widgets/poster.h" |
| 64 | 6 #include "gui/widgets/text.h" |
|
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
7 #include "services/services.h" |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
8 #include "core/session.h" |
|
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
9 |
| 258 | 10 #include <QHBoxLayout> |
| 64 | 11 #include <QLabel> |
| 12 #include <QStackedWidget> | |
| 13 #include <QVBoxLayout> | |
| 14 #include <QWidget> | |
| 15 | |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
16 #include <iostream> |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
17 |
| 154 | 18 #include "anitomy/anitomy.h" |
| 19 | |
| 64 | 20 namespace NowPlayingPages { |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
21 // TODO the "now playing" logic should NOT be located here; this should |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
22 // only be a frontent. THAT logic should at the very least be in the |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
23 // "core" subdirectory |
| 64 | 24 |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
25 Default::Default(QWidget *parent) : QWidget(parent) |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
26 { |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
27 QVBoxLayout *layout = new QVBoxLayout(this); |
| 64 | 28 layout->setContentsMargins(0, 0, 0, 0); |
| 2 | 29 |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
30 title_.SetText(Strings::Translate("Now Playing")); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
31 layout->addWidget(&title_); |
| 80 | 32 |
| 64 | 33 layout->addStretch(); |
| 34 } | |
| 35 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
36 Playing::Playing(QWidget *parent) : QWidget(parent) |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
37 { |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
38 QHBoxLayout *layout = new QHBoxLayout(this); |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
39 |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
40 _main.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
| 83 | 41 |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
42 QVBoxLayout *main_layout = new QVBoxLayout(&_main); |
| 83 | 43 main_layout->setContentsMargins(0, 0, 0, 0); |
| 44 | |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
45 main_layout->addWidget(&_title); |
| 83 | 46 |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
47 _info.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
48 _info.layout()->setContentsMargins(0, 0, 0, 0); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
49 main_layout->addWidget(&_info); |
| 80 | 50 |
| 83 | 51 /* "sidebar", includes... just the anime image :) */ |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
52 QVBoxLayout *sidebar_layout = new QVBoxLayout(&_sidebar); |
| 83 | 53 sidebar_layout->setContentsMargins(0, 0, 0, 0); |
| 80 | 54 |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
55 sidebar_layout->addWidget(&_poster); |
| 83 | 56 |
| 57 sidebar_layout->addStretch(); | |
| 58 | |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
59 layout->addWidget(&_sidebar); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
60 layout->addWidget(&_main); |
| 83 | 61 layout->setSpacing(10); |
| 64 | 62 layout->setContentsMargins(0, 0, 0, 0); |
| 63 } | |
| 64 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
65 int Playing::GetPlayingAnime() |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
66 { |
| 69 | 67 return _id; |
| 68 } | |
| 69 | |
|
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
70 int Playing::GetPlayingEpisode() |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
71 { |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
72 return _episode; |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
73 } |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
74 |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
75 void Playing::SetPlayingAnime(const Anime::Anime &anime, const anitomy::Elements &info) |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
76 { |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
77 if (_id == anime.GetId() && |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
78 _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) |
| 79 | 79 return; |
| 83 | 80 _id = anime.GetId(); |
| 154 | 81 _episode = Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber))); |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
82 _title.SetText(anime.GetUserPreferredTitle()); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
83 _info.SetAnime(anime); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
84 _poster.SetAnime(anime); |
| 83 | 85 |
| 86 updateGeometry(); | |
|
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
87 } |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
88 |
| 64 | 89 } // namespace NowPlayingPages |
| 90 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
91 NowPlayingPage::NowPlayingPage(QWidget *parent) : QFrame(parent) |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
92 { |
| 295 | 93 setBackgroundRole(QPalette::Base); |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
94 QVBoxLayout *layout = new QVBoxLayout(this); |
| 64 | 95 |
| 96 setFrameShape(QFrame::Box); | |
| 97 setFrameShadow(QFrame::Sunken); | |
| 98 setAutoFillBackground(true); | |
| 99 | |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
100 stack_.addWidget(&default_); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
101 stack_.addWidget(&playing_); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
102 layout->addWidget(&stack_); |
| 64 | 103 |
| 104 SetDefault(); | |
| 105 } | |
| 106 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
107 void NowPlayingPage::SetDefault() |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
108 { |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
109 /* 'timer_' is the time elapsed since we were set to the 'playing' |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
110 * mode. Otherwise it is -1. */ |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
111 if (timer_ != -1) { |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
112 std::int64_t elapsed = session.uptime() - timer_; |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
113 |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
114 /* FIXME hardcoding the interval length is a hack at best |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
115 * (18 * 60 * 1000), is 18 minutes. */ |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
116 if (elapsed > (18ll * 60ll * 1000ll)) { |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
117 /* Episode has finished playing */ |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
118 TimerDone(); |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
119 } |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
120 |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
121 /* Reset the timer */ |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
122 timer_ = -1; |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
123 } |
|
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
124 |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
125 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); |
| 64 | 126 } |
| 127 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
128 int NowPlayingPage::GetPlayingId() |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
129 { |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
130 return playing_.GetPlayingAnime(); |
| 69 | 131 } |
| 132 | |
|
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
133 void NowPlayingPage::SetPlaying(const Anime::Anime &anime, const anitomy::Elements &info) |
|
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
134 { |
|
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
135 playing_.SetPlayingAnime(anime, info); |
|
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
136 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); |
| 83 | 137 updateGeometry(); |
|
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
138 |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
375
diff
changeset
|
139 timer_ = session.uptime(); |
| 2 | 140 } |
|
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
141 |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
142 void NowPlayingPage::TimerDone(void) |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
143 { |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
144 Anime::Anime &anime = Anime::db.items[playing_.GetPlayingAnime()]; |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
145 |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
146 if (!anime.IsInUserList()) |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
147 anime.AddToUserList(); |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
148 |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
149 const int progress = anime.GetUserProgress(); |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
150 const int playing_ep = playing_.GetPlayingEpisode(); |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
151 |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
152 if (progress > playing_ep) { |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
153 anime.SetUserProgress(playing_ep); |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
154 Services::UpdateAnimeEntry(anime.GetId()); |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
155 } |
|
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
156 } |
