]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/phononwidget.cpp
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
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
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "phononwidget.h"
23 #include <Phonon/Global>
24 #include <Phonon/MediaObject>
25 #include <Phonon/SeekSlider>
26 #include <Phonon/VideoPlayer>
27 #include <QtGui/QVBoxLayout>
28 #include <QtGui/QHBoxLayout>
29 #include <QtGui/QShowEvent>
30 #include <QtGui/QToolButton>
35 PhononWidget::PhononWidget(QWidget
*parent
)
48 void PhononWidget::setUrl(const KUrl
&url
)
51 stop(); // emits playingStopped() signal
56 KUrl
PhononWidget::url() const
61 void PhononWidget::setMode(Mode mode
)
64 stop(); // emits playingStopped() signal
69 PhononWidget::Mode
PhononWidget::mode() const
74 void PhononWidget::showEvent(QShowEvent
*event
)
76 if (event
->spontaneous()) {
77 QWidget::showEvent(event
);
81 if (m_playButton
== 0) {
82 QVBoxLayout
*topLayout
= new QVBoxLayout(this);
83 topLayout
->setMargin(0);
84 topLayout
->setSpacing(0);
85 QHBoxLayout
*controlsLayout
= new QHBoxLayout(this);
86 controlsLayout
->setMargin(0);
87 controlsLayout
->setSpacing(0);
89 m_playButton
= new QToolButton(this);
90 m_stopButton
= new QToolButton(this);
91 m_seekSlider
= new Phonon::SeekSlider(this);
92 m_videoPlayer
= new Phonon::VideoPlayer(Phonon::VideoCategory
, this);
93 m_videoPlayer
->hide();
95 controlsLayout
->addWidget(m_playButton
);
96 controlsLayout
->addWidget(m_stopButton
);
97 controlsLayout
->addWidget(m_seekSlider
);
99 topLayout
->addWidget(m_videoPlayer
);
100 topLayout
->addLayout(controlsLayout
);
102 m_playButton
->setToolTip(i18n("play"));
103 m_playButton
->setIconSize(QSize(16, 16));
104 m_playButton
->setIcon(KIcon("media-playback-start"));
105 connect(m_playButton
, SIGNAL(clicked()), this, SLOT(play()));
107 m_stopButton
->setToolTip(i18n("stop"));
108 m_stopButton
->setIconSize(QSize(16, 16));
109 m_stopButton
->setIcon(KIcon("media-playback-stop"));
110 m_stopButton
->hide();
111 connect(m_stopButton
, SIGNAL(clicked()), this, SLOT(stop()));
113 m_seekSlider
->setIconVisible(false);
117 void PhononWidget::hideEvent(QHideEvent
*event
)
119 QWidget::hideEvent(event
);
120 if (!event
->spontaneous()) {
125 void PhononWidget::stateChanged(Phonon::State newstate
)
127 setUpdatesEnabled(false);
129 case Phonon::PlayingState
:
130 case Phonon::BufferingState
:
131 m_stopButton
->show();
132 m_playButton
->hide();
135 m_stopButton
->hide();
136 m_playButton
->show();
139 setUpdatesEnabled(true);
142 void PhononWidget::play()
146 if (m_audioMedia
== 0) {
147 // Creating an audio player might take up to 2 seconds when doing
148 // it the first time. To prevent that the user interface gets
149 // noticable blocked, the creation is delayed until the play button
151 m_audioMedia
= Phonon::createPlayer(Phonon::MusicCategory
, m_url
);
152 m_audioMedia
->setParent(this);
154 m_media
= m_audioMedia
;
155 m_media
->setCurrentSource(m_url
);
159 m_videoPlayer
->show();
160 m_videoPlayer
->play(m_url
);
161 m_media
= m_videoPlayer
->mediaObject();
168 Q_ASSERT(m_media
!= 0);
169 connect(m_media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
170 this, SLOT(stateChanged(Phonon::State
)));
171 m_seekSlider
->setMediaObject(m_media
);
173 emit
playingStarted();
176 void PhononWidget::stop()
180 disconnect(m_media
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
181 this, SLOT(stateChanged(Phonon::State
)));
182 emit
playingStopped();
184 m_stopButton
->hide();
185 m_playButton
->show();
188 if (m_videoPlayer
!= 0) {
189 m_videoPlayer
->hide();