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)),
49
setData("players", QStringList());
51
connect(dbusWatcher, SIGNAL(newPlayer(Player::Ptr)),
52
this, SLOT(addPlayer(Player::Ptr)));
53
connect(dbusWatcher, SIGNAL(playerDisappeared(Player::Ptr)),
54
this, SLOT(removePlayer(Player::Ptr)));
56
dbusWatcher->addFactory(new MprisFactory(dbusWatcher));
57
dbusWatcher->addFactory(new JukFactory(dbusWatcher));
60
pollingWatcher = new PollingWatcher(this);
61
connect(pollingWatcher, SIGNAL(newPlayer(Player::Ptr)),
62
this, SLOT(addPlayer(Player::Ptr)));
63
connect(pollingWatcher, SIGNAL(playerDisappeared(Player::Ptr)),
64
this, SLOT(removePlayer(Player::Ptr)));
65
pollingWatcher->addFactory(new XmmsFactory(pollingWatcher));
69
Plasma::Service* NowPlayingEngine::serviceForSource(const QString& source)
71
PlayerContainer* container = qobject_cast<PlayerContainer*>(containerForSource(source));
73
return container->service(this);
75
return DataEngine::serviceForSource(source);
80
bool NowPlayingEngine::sourceRequestEvent(const QString& source)
82
kDebug() << "Source" << source << "was requested";
83
if (source == "help") {
84
setData(source, "Use 'players' to get a list of players.\n"
85
"Use 'properties' to get a list of all properties that may be returned."
88
} else if (source == "properties") {
89
setData(source, "State", "QString - playing|paused|stopped");
90
setData(source, "Artist", "QString - the artist metadata for the\n"
91
" current track, if available");
92
setData(source, "Album", "QString - the album metadata for the\n"
93
" current track, if available");
94
setData(source, "Title", "QString - the title metadata for the\n"
95
" current track, if available");
96
setData(source, "Track number", "int - the album/collection track number\n"
97
" (eg: on a CD) if known, 0 otherwise");
98
setData(source, "Comment", "QString - the comment metadata for the\n"
99
" current track, if available");
100
setData(source, "Genre", "QString - the comment metadata for the\n"
101
" current track, if available");
102
setData(source, "Length", "int - the length of the current track\n"
103
" in seconds, 0 if unknown");
104
setData(source, "Position", "int - the position of the current track\n"
105
" in seconds, 0 if unknown");
106
setData(source, "Volume", "float - the volume, given as a float\n"
107
" between 0 and 1, or -1 if unknown");
108
setData(source, "Artwork", "QPixmap - the album artwork, if available");
109
setData(source, "Lyrics", "QString - song lyrics, if available");
116
void NowPlayingEngine::addPlayer(Player::Ptr player)
118
kDebug() << "Adding player" << player->name();
119
Plasma::DataContainer *container = containerForSource("players");
122
players = container->data()["players"].toStringList();
125
players << player->name();
126
setData("players", players);
128
addSource(new PlayerContainer(player, this));
131
void NowPlayingEngine::removePlayer(Player::Ptr player)
133
kDebug() << "Player" << player->name() << "disappeared";
134
Plasma::DataContainer *container = containerForSource("players");
136
QStringList players = container->data()["players"].toStringList();
137
players.removeAll(player->name());
138
setData("players", players);
141
removeSource(player->name());
144
#include "nowplayingengine.moc"