]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/phononwidget.cpp
disable rating, comments and tags if no meta data is available
[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_url(),
35 m_playButton(0),
36 m_stopButton(0),
37 m_media(0),
38 m_seekSlider(0)
39 {
40 QHBoxLayout *innerLayout = new QHBoxLayout(this);
41 innerLayout->setMargin(0);
42 innerLayout->setSpacing(0);
43 m_playButton = new QToolButton(this);
44 m_stopButton = new QToolButton(this);
45 m_seekSlider = new Phonon::SeekSlider(this);
46 innerLayout->addWidget(m_playButton);
47 innerLayout->addWidget(m_stopButton);
48 innerLayout->addWidget(m_seekSlider);
49
50 m_playButton->setToolTip(i18n("play"));
51 m_playButton->setIconSize(QSize(16, 16));
52 m_playButton->setIcon(KIcon("media-playback-start"));
53 connect(m_playButton, SIGNAL(clicked()), this, SLOT(play()));
54
55 m_stopButton->setToolTip(i18n("stop"));
56 m_stopButton->setIconSize(QSize(16, 16));
57 m_stopButton->setIcon(KIcon("media-playback-stop"));
58 m_stopButton->hide();
59 connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stop()));
60
61 m_seekSlider->setIconVisible(false);
62 }
63
64 void PhononWidget::setUrl(const KUrl &url)
65 {
66 m_url = url;
67 if (m_media) {
68 m_media->setCurrentSource(url);
69 }
70 }
71
72 void PhononWidget::stateChanged(Phonon::State newstate)
73 {
74 setUpdatesEnabled(false);
75 switch (newstate) {
76 case Phonon::PlayingState:
77 case Phonon::BufferingState:
78 m_stopButton->show();
79 m_playButton->hide();
80 break;
81 default:
82 m_stopButton->hide();
83 m_playButton->show();
84 break;
85 }
86 setUpdatesEnabled(true);
87 }
88
89 void PhononWidget::play()
90 {
91 requestMedia();
92 m_media->play();
93 }
94
95 void PhononWidget::stop()
96 {
97 requestMedia();
98 m_media->stop();
99 }
100
101 void PhononWidget::requestMedia()
102 {
103 if (!m_media) {
104 m_media = Phonon::createPlayer(Phonon::MusicCategory, m_url);
105 m_media->setParent(this);
106 connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State)));
107 m_seekSlider->setMediaObject(m_media);
108 }
109 }
110