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, &PhononWidget::play); | ||||
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. | |||||
70 | } | 76 | } | ||
71 | 77 | | |||
72 | void PhononWidget::setUrl(const QUrl &url) | 78 | void PhononWidget::setUrl(const QUrl &url) | ||
73 | { | 79 | { | ||
74 | if (m_url != url) { | 80 | if (m_url != url) { | ||
75 | stop(); // emits playingStopped() signal | 81 | stop(); // emits playingStopped() signal | ||
76 | m_url = url; | 82 | m_url = url; | ||
83 | | ||||
84 | if (GeneralSettings::autoPlayMediaFiles()) { | ||||
85 | // TODO move the 1000 ms to a constant or a setting | ||||
86 | m_autoPlayTimer->start(1000); | ||||
87 | } | ||||
77 | } | 88 | } | ||
78 | } | 89 | } | ||
79 | 90 | | |||
80 | QUrl PhononWidget::url() const | 91 | QUrl PhononWidget::url() const | ||
81 | { | 92 | { | ||
82 | return m_url; | 93 | return m_url; | ||
83 | } | 94 | } | ||
84 | 95 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 116 | if (!m_topLayout) { | |||
143 | // interface gets noticeable blocked, the creation is delayed until | 154 | // interface gets noticeable blocked, the creation is delayed until | ||
144 | // the play button has been pressed (see PhononWidget::play()). | 155 | // the play button has been pressed (see PhononWidget::play()). | ||
145 | } | 156 | } | ||
146 | } | 157 | } | ||
147 | 158 | | |||
148 | void PhononWidget::hideEvent(QHideEvent *event) | 159 | void PhononWidget::hideEvent(QHideEvent *event) | ||
149 | { | 160 | { | ||
150 | QWidget::hideEvent(event); | 161 | QWidget::hideEvent(event); | ||
151 | if (!event->spontaneous()) { | 162 | if (!event->spontaneous()) { | ||
152 | stop(); | 163 | stop(); | ||
153 | } | 164 | } | ||
154 | } | 165 | } | ||
155 | 166 | | |||
156 | void PhononWidget::stateChanged(Phonon::State newstate) | 167 | void PhononWidget::stateChanged(Phonon::State newstate) | ||
157 | { | 168 | { | ||
158 | setUpdatesEnabled(false); | 169 | setUpdatesEnabled(false); | ||
159 | switch (newstate) { | 170 | switch (newstate) { | ||
160 | case Phonon::PlayingState: | 171 | case Phonon::PlayingState: | ||
161 | case Phonon::BufferingState: | 172 | case Phonon::BufferingState: | ||
162 | m_stopButton->show(); | 173 | m_stopButton->show(); | ||
163 | m_playButton->hide(); | 174 | m_playButton->hide(); | ||
164 | break; | 175 | break; | ||
elvisangelaccio: Maybe an if-else would be nicer here. | |||||
165 | case Phonon::StoppedState: | 176 | case Phonon::StoppedState: | ||
166 | if (m_videoPlayer) { | 177 | if (m_videoPlayer) { | ||
167 | m_videoPlayer->hide(); | 178 | m_videoPlayer->hide(); | ||
168 | } | 179 | } | ||
169 | emit hasVideoChanged(false); | 180 | emit hasVideoChanged(false); | ||
170 | Q_FALLTHROUGH(); | 181 | Q_FALLTHROUGH(); | ||
171 | default: | 182 | default: | ||
172 | m_stopButton->hide(); | 183 | m_stopButton->hide(); | ||
Show All 33 Lines | 191 | { | |||
206 | m_media->play(); | 217 | m_media->play(); | ||
207 | } | 218 | } | ||
208 | 219 | | |||
209 | void PhononWidget::stop() | 220 | void PhononWidget::stop() | ||
210 | { | 221 | { | ||
211 | if (m_media) { | 222 | if (m_media) { | ||
212 | m_media->stop(); | 223 | m_media->stop(); | ||
213 | } | 224 | } | ||
225 | if (m_autoPlayTimer->isActive()) { | ||||
226 | m_autoPlayTimer->stop(); | ||||
227 | } | ||||
214 | } | 228 | } | ||
215 | 229 | | |||
216 | void PhononWidget::slotHasVideoChanged(bool hasVideo) | 230 | void PhononWidget::slotHasVideoChanged(bool hasVideo) | ||
217 | { | 231 | { | ||
218 | emit hasVideoChanged(hasVideo); | 232 | emit hasVideoChanged(hasVideo); | ||
219 | 233 | | |||
220 | if (hasVideo) { | 234 | if (hasVideo) { | ||
221 | m_videoPlayer->show(); | 235 | 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