Mercurial > minori
annotate src/gui/pages/now_playing.cc @ 376:5d716acb2774
gui/dialog/dialog: fix win32 build
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 12:28:38 -0400 |
parents | abd956418fe9 |
children |
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" |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
8 |
258 | 9 #include <QHBoxLayout> |
64 | 10 #include <QLabel> |
11 #include <QStackedWidget> | |
12 #include <QVBoxLayout> | |
13 #include <QWidget> | |
14 | |
154 | 15 #include "anitomy/anitomy.h" |
16 | |
64 | 17 namespace NowPlayingPages { |
18 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
19 Default::Default(QWidget *parent) : QWidget(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
20 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
21 QVBoxLayout *layout = new QVBoxLayout(this); |
64 | 22 layout->setContentsMargins(0, 0, 0, 0); |
2 | 23 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
24 title_.SetText(Strings::Translate("Now Playing")); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
25 layout->addWidget(&title_); |
80 | 26 |
64 | 27 layout->addStretch(); |
28 } | |
29 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
30 Playing::Playing(QWidget *parent) : QWidget(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
31 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
32 QHBoxLayout *layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
33 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
34 _main.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
83 | 35 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
36 QVBoxLayout *main_layout = new QVBoxLayout(&_main); |
83 | 37 main_layout->setContentsMargins(0, 0, 0, 0); |
38 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
39 main_layout->addWidget(&_title); |
83 | 40 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
41 _info.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
42 _info.layout()->setContentsMargins(0, 0, 0, 0); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
43 main_layout->addWidget(&_info); |
80 | 44 |
83 | 45 /* "sidebar", includes... just the anime image :) */ |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
46 QVBoxLayout *sidebar_layout = new QVBoxLayout(&_sidebar); |
83 | 47 sidebar_layout->setContentsMargins(0, 0, 0, 0); |
80 | 48 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
49 sidebar_layout->addWidget(&_poster); |
83 | 50 |
51 sidebar_layout->addStretch(); | |
52 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
53 layout->addWidget(&_sidebar); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
54 layout->addWidget(&_main); |
83 | 55 layout->setSpacing(10); |
64 | 56 layout->setContentsMargins(0, 0, 0, 0); |
57 } | |
58 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
59 int Playing::GetPlayingAnime() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
60 { |
69 | 61 return _id; |
62 } | |
63 | |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
64 int Playing::GetPlayingEpisode() |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
65 { |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
66 return _episode; |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
67 } |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
68 |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
69 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
|
70 { |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
71 if (_id == anime.GetId() && |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
72 _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) |
79 | 73 return; |
83 | 74 _id = anime.GetId(); |
154 | 75 _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
|
76 _title.SetText(anime.GetUserPreferredTitle()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
77 _info.SetAnime(anime); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
78 _poster.SetAnime(anime); |
83 | 79 |
80 updateGeometry(); | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
81 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
82 |
64 | 83 } // namespace NowPlayingPages |
84 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
85 NowPlayingPage::NowPlayingPage(QWidget *parent) : QFrame(parent) |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
86 { |
295 | 87 setBackgroundRole(QPalette::Base); |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
88 QVBoxLayout *layout = new QVBoxLayout(this); |
64 | 89 |
90 setFrameShape(QFrame::Box); | |
91 setFrameShadow(QFrame::Sunken); | |
92 setAutoFillBackground(true); | |
93 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
94 stack_.addWidget(&default_); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
95 stack_.addWidget(&playing_); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
96 layout->addWidget(&stack_); |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
97 timer_.setSingleShot(true); |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
98 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
99 QObject::connect(&timer_, &QTimer::timeout, this, &NowPlayingPage::TimerDone); |
64 | 100 |
101 SetDefault(); | |
102 } | |
103 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
104 void NowPlayingPage::SetDefault() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
105 { |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
106 /* stop any timer */ |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
107 timer_.stop(); |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
108 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
109 stack_.setCurrentIndex(static_cast<int>(Subpages::Default)); |
64 | 110 } |
111 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
112 int NowPlayingPage::GetPlayingId() |
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
113 { |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
114 return playing_.GetPlayingAnime(); |
69 | 115 } |
116 | |
370
ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
Paper <paper@tflc.us>
parents:
348
diff
changeset
|
117 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
|
118 { |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
119 /* ok */ |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
120 timer_.stop(); |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
121 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
122 playing_.SetPlayingAnime(anime, info); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
123 stack_.setCurrentIndex(static_cast<int>(Subpages::Playing)); |
83 | 124 updateGeometry(); |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
125 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
126 /* now, start the timer |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
127 * FIXME hardcoding the interval length is a hack at best |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
128 * (12 * 60 * 1000) == 720000 msec, which is 12 minutes. */ |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
129 timer_.setInterval(12 * 60 * 1000); |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
130 timer_.start(); |
2 | 131 } |
375
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
132 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
133 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
|
134 { |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
135 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
|
136 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
137 if (!anime.IsInUserList()) |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
138 anime.AddToUserList(); |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
139 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
140 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
|
141 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
|
142 |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 } |
abd956418fe9
gui/pages/now_playing: automatically update progress when the episode is "finished"
Paper <paper@tflc.us>
parents:
370
diff
changeset
|
147 } |