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 | | |||
Show All 35 Lines | 60 | PhononWidget::PhononWidget(QWidget *parent) | |||
65 | m_media(nullptr), | 66 | m_media(nullptr), | ||
66 | m_seekSlider(nullptr), | 67 | m_seekSlider(nullptr), | ||
67 | m_audioOutput(nullptr), | 68 | m_audioOutput(nullptr), | ||
68 | m_videoPlayer(nullptr) | 69 | m_videoPlayer(nullptr) | ||
69 | { | 70 | { | ||
70 | } | 71 | } | ||
71 | 72 | | |||
72 | void PhononWidget::setUrl(const QUrl &url) | 73 | void PhononWidget::setUrl(const QUrl &url) | ||
73 | { | 74 | { | ||
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. | |||||
74 | if (m_url != url) { | 75 | if (m_url != url) { | ||
75 | stop(); // emits playingStopped() signal | 76 | stop(); // emits playingStopped() signal | ||
76 | m_url = url; | 77 | m_url = url; | ||
78 | | ||||
79 | if (m_autoPlay) { | ||||
80 | play(); | ||||
81 | } | ||||
82 | } | ||||
83 | } | ||||
84 | | ||||
85 | void PhononWidget::setAutoPlay(bool autoPlay) { | ||||
86 | m_autoPlay = autoPlay; | ||||
87 | if (m_media != nullptr && m_media->state() != Phonon::State::PlayingState && m_autoPlay) { | ||||
88 | play(); | ||||
77 | } | 89 | } | ||
78 | } | 90 | } | ||
79 | 91 | | |||
80 | QUrl PhononWidget::url() const | 92 | QUrl PhononWidget::url() const | ||
81 | { | 93 | { | ||
82 | return m_url; | 94 | return m_url; | ||
83 | } | 95 | } | ||
84 | 96 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 117 | if (!m_topLayout) { | |||
143 | // interface gets noticeable blocked, the creation is delayed until | 155 | // interface gets noticeable blocked, the creation is delayed until | ||
144 | // the play button has been pressed (see PhononWidget::play()). | 156 | // the play button has been pressed (see PhononWidget::play()). | ||
145 | } | 157 | } | ||
146 | } | 158 | } | ||
147 | 159 | | |||
148 | void PhononWidget::hideEvent(QHideEvent *event) | 160 | void PhononWidget::hideEvent(QHideEvent *event) | ||
149 | { | 161 | { | ||
150 | QWidget::hideEvent(event); | 162 | QWidget::hideEvent(event); | ||
151 | if (!event->spontaneous()) { | 163 | if (!event->spontaneous()) { | ||
152 | stop(); | 164 | stop(); | ||
153 | } | 165 | } | ||
154 | } | 166 | } | ||
155 | 167 | | |||
156 | void PhononWidget::stateChanged(Phonon::State newstate) | 168 | void PhononWidget::stateChanged(Phonon::State newstate) | ||
157 | { | 169 | { | ||
158 | setUpdatesEnabled(false); | 170 | setUpdatesEnabled(false); | ||
159 | switch (newstate) { | 171 | switch (newstate) { | ||
160 | case Phonon::PlayingState: | 172 | case Phonon::PlayingState: | ||
161 | case Phonon::BufferingState: | 173 | case Phonon::BufferingState: | ||
162 | m_stopButton->show(); | 174 | m_stopButton->show(); | ||
163 | m_playButton->hide(); | 175 | m_playButton->hide(); | ||
164 | break; | 176 | break; | ||
elvisangelaccio: Maybe an if-else would be nicer here. | |||||
165 | case Phonon::StoppedState: | 177 | case Phonon::StoppedState: | ||
166 | if (m_videoPlayer) { | 178 | if (m_videoPlayer) { | ||
167 | m_videoPlayer->hide(); | 179 | m_videoPlayer->hide(); | ||
168 | } | 180 | } | ||
169 | emit hasVideoChanged(false); | 181 | emit hasVideoChanged(false); | ||
170 | Q_FALLTHROUGH(); | 182 | Q_FALLTHROUGH(); | ||
171 | default: | 183 | default: | ||
172 | m_stopButton->hide(); | 184 | m_stopButton->hide(); | ||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 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