delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / workspace / plasma / dataengines / nowplaying / playerinterface / juk.cpp
blobaf55e77797f53d915b372d3ba3b2ac36819cbe08
1 /*
2 * Copyright 2007 Alex Merry <alex.merry@kdemail.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "juk.h"
20 #include "juk_p.h"
21 #include <juk_interface.h>
23 #include <QtDBus>
26 JukFactory::JukFactory(QObject* parent)
27 : DBusPlayerFactory(parent)
29 setObjectName("JukFactory");
32 Player::Ptr JukFactory::create(const QVariantList& args)
34 Q_UNUSED(args);
36 Juk* player = new Juk(this);
37 if (!player->isRunning()) {
38 delete player;
39 player = 0;
41 return Player::Ptr(player);
44 bool JukFactory::matches(const QString& serviceName)
46 return serviceName == "org.kde.juk";
53 Juk::Juk(PlayerFactory* factory)
54 : Player(factory),
55 jukPlayer(new JukPlayer("org.kde.juk", "/Player",
56 QDBusConnection::sessionBus()))
58 setName("JuK");
61 Juk::~Juk()
63 delete jukPlayer;
66 bool Juk::isRunning()
68 if (!jukPlayer->isValid()) {
69 delete jukPlayer;
70 jukPlayer = new JukPlayer("org.kde.juk", "/Player",
71 QDBusConnection::sessionBus());
73 return jukPlayer->isValid();
76 Player::State Juk::state()
78 if (jukPlayer->isValid()) {
79 if (jukPlayer->playing()) {
80 return Playing;
82 if (jukPlayer->paused()) {
83 return Paused;
86 return Stopped;
89 QString Juk::artist()
91 if (jukPlayer->isValid()) {
92 return jukPlayer->trackProperty("Artist");
94 return QString();
97 QString Juk::album()
99 if (jukPlayer->isValid()) {
100 return jukPlayer->trackProperty("Album");
102 return QString();
105 QString Juk::title()
107 if (jukPlayer->isValid()) {
108 return jukPlayer->trackProperty("Title");
110 return QString();
113 int Juk::trackNumber()
115 if (jukPlayer->isValid()) {
116 return jukPlayer->trackProperty("Track").value().toInt();
118 return 0;
121 QString Juk::comment()
123 if (jukPlayer->isValid()) {
124 return jukPlayer->trackProperty("Comment");
126 return QString();
129 QString Juk::genre()
131 if (jukPlayer->isValid()) {
132 return jukPlayer->trackProperty("Genre");
134 return QString();
137 int Juk::length()
139 if (jukPlayer->isValid()) {
140 return jukPlayer->totalTime();
142 return 0;
145 int Juk::position()
147 if (jukPlayer->isValid()) {
148 return jukPlayer->currentTime();
150 return 0;
153 float Juk::volume()
155 if (jukPlayer->isValid()) {
156 return jukPlayer->volume();
158 return 0;
161 void Juk::play()
163 if (jukPlayer->isValid()) {
164 jukPlayer->play();
168 void Juk::pause()
170 if (jukPlayer->isValid()) {
171 jukPlayer->pause();
175 void Juk::stop()
177 if (jukPlayer->isValid()) {
178 jukPlayer->stop();
182 void Juk::previous()
184 if (jukPlayer->isValid()) {
185 jukPlayer->back();
189 void Juk::next()
191 if (jukPlayer->isValid()) {
192 jukPlayer->forward();
196 void Juk::setVolume(qreal volume) {
197 if (jukPlayer->isValid()) {
198 jukPlayer->setVolume(volume);
202 void Juk::seek(int time)
204 if (jukPlayer->isValid()) {
205 // jukPlayer->seek() wants milliseconds
206 jukPlayer->seek(time * 1000);
211 #include "juk.moc"