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 "nowplayingengine.h"
21 #include <config-nowplaying.h>
23 #include <QStringList>
28 #include "playerinterface/player.h"
29 #include "playerinterface/playerfactory.h"
30 #include "playerinterface/dbuswatcher.h"
31 #include "playerinterface/pollingwatcher.h"
32 #include "playerinterface/mpris/mpris.h"
33 #include "playerinterface/juk.h"
35 #include "playerinterface/xmms.h"
38 #include "playercontrol.h"
39 #include "playercontainer.h"
41 NowPlayingEngine::NowPlayingEngine(QObject
* parent
,
42 const QVariantList
& args
)
43 : Plasma::DataEngine(parent
),
44 dbusWatcher(new DBusWatcher(this)),
45 pollingWatcher(new PollingWatcher(this))
49 connect(dbusWatcher
, SIGNAL(newPlayer(Player::Ptr
)),
50 this, SLOT(addPlayer(Player::Ptr
)));
51 connect(dbusWatcher
, SIGNAL(playerDisappeared(Player::Ptr
)),
52 this, SLOT(removePlayer(Player::Ptr
)));
53 connect(pollingWatcher
, SIGNAL(newPlayer(Player::Ptr
)),
54 this, SLOT(addPlayer(Player::Ptr
)));
55 connect(pollingWatcher
, SIGNAL(playerDisappeared(Player::Ptr
)),
56 this, SLOT(removePlayer(Player::Ptr
)));
58 dbusWatcher
->addFactory(new MprisFactory(dbusWatcher
));
59 dbusWatcher
->addFactory(new JukFactory(dbusWatcher
));
61 pollingWatcher
->addFactory(new XmmsFactory(pollingWatcher
));
65 Plasma::Service
* NowPlayingEngine::serviceForSource(const QString
& source
)
67 PlayerContainer
* container
= qobject_cast
<PlayerContainer
*>(containerForSource(source
));
69 return container
->service(this);
71 return DataEngine::serviceForSource(source
);
76 bool NowPlayingEngine::sourceRequestEvent(const QString
& source
)
78 kDebug() << "Source" << source
<< "was requested";
79 QString lowerSource
= source
.toLower();
80 if (lowerSource
== "help") {
81 setData(source
, "Use 'players' to get a list of players.\n"
82 "Use 'properties' to get a list of all properties that may be returned."
85 } else if (lowerSource
== "properties") {
86 setData(source
, "State", "QString - playing|paused|stopped");
87 setData(source
, "Artist", "QString - the artist metadata for the\n"
88 " current track, if available");
89 setData(source
, "Album", "QString - the album metadata for the\n"
90 " current track, if available");
91 setData(source
, "Title", "QString - the title metadata for the\n"
92 " current track, if available");
93 setData(source
, "Track number", "int - the album/collection track number\n"
94 " (eg: on a CD) if known, 0 otherwise");
95 setData(source
, "Comment", "QString - the comment metadata for the\n"
96 " current track, if available");
97 setData(source
, "Genre", "QString - the comment metadata for the\n"
98 " current track, if available");
99 setData(source
, "Length", "int - the length of the current track\n"
100 " in seconds, 0 if unknown");
101 setData(source
, "Position", "int - the position of the current track\n"
102 " in seconds, 0 if unknown");
103 setData(source
, "Volume", "float - the volume, given as a float\n"
104 " between 0 and 1, or -1 if unknown");
105 setData(source
, "Artwork", "QPixmap - the album artwork, if available");
107 } else if (lowerSource
== "players") {
108 setData(source
, sources());
115 bool NowPlayingEngine::updateSourceEvent(const QString
& source
)
117 QString lowerSource
= source
.toLower();
118 if (lowerSource
== "help" || lowerSource
== "properties") {
119 // help text doesn't change
125 void NowPlayingEngine::addPlayer(Player::Ptr player
)
127 kDebug() << "Adding player" << player
->name();
128 addSource(new PlayerContainer(player
, this));
131 void NowPlayingEngine::removePlayer(Player::Ptr player
)
133 kDebug() << "Player" << player
->name() << "disappeared";
134 removeSource(player
->name());
137 #include "nowplayingengine.moc"