]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/phononwidget.cpp
Initial import of Matthias's draft patch for adding video and audio previewing (simil...
[dolphin.git] / src / panels / information / phononwidget.cpp
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3
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.
8
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.
13
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
17 02110-1301, USA.
18
19 */
20
21 #include "phononwidget.h"
22
23 #include <Phonon/Global>
24 #include <Phonon/MediaObject>
25 #include <Phonon/SeekSlider>
26 #include <QtGui/QHBoxLayout>
27 #include <QtGui/QToolButton>
28 #include <kicon.h>
29 #include <kurl.h>
30 #include <klocale.h>
31
32 PhononWidget::PhononWidget(QWidget *parent)
33 : QWidget(parent),
34 m_media(0)
35 {
36 QHBoxLayout *innerLayout = new QHBoxLayout(this);
37 innerLayout->setMargin(0);
38 innerLayout->setSpacing(0);
39 m_playButton = new QToolButton(this);
40 m_stopButton = new QToolButton(this);
41 m_seekSlider = new Phonon::SeekSlider(this);
42 innerLayout->addWidget(m_playButton);
43 innerLayout->addWidget(m_stopButton);
44 innerLayout->addWidget(m_seekSlider);
45
46 m_playButton->setToolTip(i18n("play"));
47 m_playButton->setIconSize(QSize(16, 16));
48 m_playButton->setIcon(KIcon("media-playback-start"));
49 m_stopButton->setToolTip(i18n("stop"));
50 m_stopButton->setIconSize(QSize(16, 16));
51 m_stopButton->setIcon(KIcon("media-playback-stop"));
52 m_stopButton->hide();
53 m_seekSlider->setIconVisible(false);
54 }
55
56 void PhononWidget::setUrl(const KUrl &url)
57 {
58 if (m_media) {
59 m_media->setCurrentSource(url);
60 } else {
61 m_media = Phonon::createPlayer(Phonon::MusicCategory, url);
62 m_media->setParent(this);
63 connect(m_playButton, SIGNAL(clicked()), m_media, SLOT(play()));
64 connect(m_stopButton, SIGNAL(clicked()), m_media, SLOT(stop()));
65 connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State)));
66 m_seekSlider->setMediaObject(m_media);
67 }
68 }
69
70 void PhononWidget::stateChanged(Phonon::State newstate)
71 {
72 setUpdatesEnabled(false);
73 switch (newstate) {
74 case Phonon::PlayingState:
75 case Phonon::BufferingState:
76 m_stopButton->show();
77 m_playButton->hide();
78 break;
79 default:
80 m_stopButton->hide();
81 m_playButton->show();
82 break;
83 }
84 setUpdatesEnabled(true);
85 }