Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/phononwidget.cpp
Show All 13 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | 17 | 02110-1301, USA. | ||
18 | 18 | | |||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "phononwidget.h" | 21 | #include "phononwidget.h" | ||
22 | #include "dolphin_generalsettings.h" | ||||
22 | 23 | | |||
23 | #include <KIconLoader> | 24 | #include <KIconLoader> | ||
24 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
25 | #include <Phonon/AudioOutput> | 26 | #include <Phonon/AudioOutput> | ||
26 | #include <Phonon/MediaObject> | 27 | #include <Phonon/MediaObject> | ||
27 | #include <Phonon/SeekSlider> | 28 | #include <Phonon/SeekSlider> | ||
28 | #include <Phonon/VideoWidget> | 29 | #include <Phonon/VideoWidget> | ||
29 | 30 | | |||
30 | #include <QShowEvent> | 31 | #include <QShowEvent> | ||
31 | #include <QToolButton> | 32 | #include <QToolButton> | ||
32 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
34 | #include <QTimer> | ||||
33 | 35 | | |||
34 | class EmbeddedVideoPlayer : public Phonon::VideoWidget | 36 | class EmbeddedVideoPlayer : public Phonon::VideoWidget | ||
35 | { | 37 | { | ||
36 | Q_OBJECT | 38 | Q_OBJECT | ||
37 | 39 | | |||
38 | public: | 40 | public: | ||
39 | EmbeddedVideoPlayer(QWidget *parent = nullptr) : | 41 | EmbeddedVideoPlayer(QWidget *parent = nullptr) : | ||
40 | Phonon::VideoWidget(parent) | 42 | Phonon::VideoWidget(parent) | ||
Show All 21 Lines | 61 | PhononWidget::PhononWidget(QWidget *parent) | |||
62 | m_playButton(nullptr), | 64 | m_playButton(nullptr), | ||
63 | m_stopButton(nullptr), | 65 | m_stopButton(nullptr), | ||
64 | m_topLayout(nullptr), | 66 | m_topLayout(nullptr), | ||
65 | m_media(nullptr), | 67 | m_media(nullptr), | ||
66 | m_seekSlider(nullptr), | 68 | m_seekSlider(nullptr), | ||
67 | m_audioOutput(nullptr), | 69 | m_audioOutput(nullptr), | ||
68 | m_videoPlayer(nullptr) | 70 | m_videoPlayer(nullptr) | ||
69 | { | 71 | { | ||
72 | // timer to start/stop the auto play | ||||
73 | m_autoPlayTimer = new QTimer(this); | ||||
74 | m_autoPlayTimer->setSingleShot(true); | ||||
75 | connect(m_autoPlayTimer, &QTimer::timeout, [this](){ | ||||
broulik: Add a context `this` or else it will crash when timer fires with the widget being gone:
```… | |||||
meven: Thanks I thought I could not use this as context in a connect. | |||||
76 | play(); | ||||
77 | }); | ||||
70 | } | 78 | } | ||
71 | 79 | | |||
72 | void PhononWidget::setUrl(const QUrl &url) | 80 | void PhononWidget::setUrl(const QUrl &url) | ||
73 | { | 81 | { | ||
74 | if (m_url != url) { | 82 | if (m_url != url) { | ||
75 | stop(); // emits playingStopped() signal | 83 | stop(); // emits playingStopped() signal | ||
76 | m_url = url; | 84 | m_url = url; | ||
85 | | ||||
86 | if (GeneralSettings::autoPlayMediaFiles()) { | ||||
87 | // TODO move the 1000 ms to a constant or a setting | ||||
88 | m_autoPlayTimer->start(1000); | ||||
89 | } | ||||
77 | } | 90 | } | ||
78 | } | 91 | } | ||
79 | 92 | | |||
80 | QUrl PhononWidget::url() const | 93 | QUrl PhononWidget::url() const | ||
81 | { | 94 | { | ||
82 | return m_url; | 95 | return m_url; | ||
83 | } | 96 | } | ||
84 | 97 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 118 | if (!m_topLayout) { | |||
143 | // interface gets noticeable blocked, the creation is delayed until | 156 | // interface gets noticeable blocked, the creation is delayed until | ||
144 | // the play button has been pressed (see PhononWidget::play()). | 157 | // the play button has been pressed (see PhononWidget::play()). | ||
145 | } | 158 | } | ||
146 | } | 159 | } | ||
147 | 160 | | |||
148 | void PhononWidget::hideEvent(QHideEvent *event) | 161 | void PhononWidget::hideEvent(QHideEvent *event) | ||
149 | { | 162 | { | ||
150 | QWidget::hideEvent(event); | 163 | QWidget::hideEvent(event); | ||
151 | if (!event->spontaneous()) { | 164 | if (!event->spontaneous()) { | ||
152 | stop(); | 165 | stop(); | ||
153 | } | 166 | } | ||
154 | } | 167 | } | ||
155 | 168 | | |||
156 | void PhononWidget::stateChanged(Phonon::State newstate) | 169 | void PhononWidget::stateChanged(Phonon::State newstate) | ||
157 | { | 170 | { | ||
158 | setUpdatesEnabled(false); | 171 | setUpdatesEnabled(false); | ||
159 | switch (newstate) { | 172 | switch (newstate) { | ||
160 | case Phonon::PlayingState: | 173 | case Phonon::PlayingState: | ||
161 | case Phonon::BufferingState: | 174 | case Phonon::BufferingState: | ||
162 | m_stopButton->show(); | 175 | m_stopButton->show(); | ||
163 | m_playButton->hide(); | 176 | m_playButton->hide(); | ||
164 | break; | 177 | break; | ||
elvisangelaccio: Maybe an if-else would be nicer here. | |||||
165 | case Phonon::StoppedState: | 178 | case Phonon::StoppedState: | ||
166 | if (m_videoPlayer) { | 179 | if (m_videoPlayer) { | ||
167 | m_videoPlayer->hide(); | 180 | m_videoPlayer->hide(); | ||
168 | } | 181 | } | ||
169 | emit hasVideoChanged(false); | 182 | emit hasVideoChanged(false); | ||
170 | Q_FALLTHROUGH(); | 183 | Q_FALLTHROUGH(); | ||
171 | default: | 184 | default: | ||
172 | m_stopButton->hide(); | 185 | m_stopButton->hide(); | ||
Show All 33 Lines | 193 | { | |||
206 | m_media->play(); | 219 | m_media->play(); | ||
207 | } | 220 | } | ||
208 | 221 | | |||
209 | void PhononWidget::stop() | 222 | void PhononWidget::stop() | ||
210 | { | 223 | { | ||
211 | if (m_media) { | 224 | if (m_media) { | ||
212 | m_media->stop(); | 225 | m_media->stop(); | ||
213 | } | 226 | } | ||
227 | if (m_autoPlayTimer->isActive()) { | ||||
228 | m_autoPlayTimer->stop(); | ||||
229 | } | ||||
214 | } | 230 | } | ||
215 | 231 | | |||
216 | void PhononWidget::slotHasVideoChanged(bool hasVideo) | 232 | void PhononWidget::slotHasVideoChanged(bool hasVideo) | ||
217 | { | 233 | { | ||
218 | emit hasVideoChanged(hasVideo); | 234 | emit hasVideoChanged(hasVideo); | ||
219 | 235 | | |||
220 | if (hasVideo) { | 236 | if (hasVideo) { | ||
221 | m_videoPlayer->show(); | 237 | m_videoPlayer->show(); | ||
Show All 11 Lines |
Add a context this or else it will crash when timer fires with the widget being gone:
You can also probably just connect to &PhononWidget::play directly without a lambda