00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "nowplayingengine.h"
00020
00021 #include <config-nowplaying.h>
00022
00023 #include <QStringList>
00024
00025 #include <KDebug>
00026 #include <KLocale>
00027
00028 #include "playerinterface/player.h"
00029 #include "playerinterface/playerfactory.h"
00030 #include "playerinterface/dbuswatcher.h"
00031 #include "playerinterface/pollingwatcher.h"
00032 #include "playerinterface/mpris/mpris.h"
00033 #include "playerinterface/juk.h"
00034 #ifdef XMMS_FOUND
00035 #include "playerinterface/xmms.h"
00036 #endif // XMMS_FOUND
00037
00038 #include "playercontrol.h"
00039 #include "playercontainer.h"
00040
00041 NowPlayingEngine::NowPlayingEngine(QObject* parent,
00042 const QVariantList& args)
00043 : Plasma::DataEngine(parent),
00044 dbusWatcher(new DBusWatcher(this)),
00045 pollingWatcher(new PollingWatcher(this))
00046 {
00047 Q_UNUSED(args)
00048
00049 connect(dbusWatcher, SIGNAL(newPlayer(Player::Ptr)),
00050 this, SLOT(addPlayer(Player::Ptr)));
00051 connect(dbusWatcher, SIGNAL(playerDisappeared(Player::Ptr)),
00052 this, SLOT(removePlayer(Player::Ptr)));
00053 connect(pollingWatcher, SIGNAL(newPlayer(Player::Ptr)),
00054 this, SLOT(addPlayer(Player::Ptr)));
00055 connect(pollingWatcher, SIGNAL(playerDisappeared(Player::Ptr)),
00056 this, SLOT(removePlayer(Player::Ptr)));
00057
00058 dbusWatcher->addFactory(new MprisFactory(dbusWatcher));
00059 dbusWatcher->addFactory(new JukFactory(dbusWatcher));
00060 #ifdef XMMS_FOUND
00061 pollingWatcher->addFactory(new XmmsFactory(pollingWatcher));
00062 #endif
00063 }
00064
00065 Plasma::Service* NowPlayingEngine::serviceForSource(const QString& source)
00066 {
00067 PlayerContainer* container = qobject_cast<PlayerContainer*>(containerForSource(source));
00068 if (container) {
00069 return container->service(this);
00070 } else {
00071 return DataEngine::serviceForSource(source);
00072 }
00073 }
00074
00075
00076 bool NowPlayingEngine::sourceRequestEvent(const QString& source)
00077 {
00078 kDebug() << "Source" << source << "was requested";
00079 QString lowerSource = source.toLower();
00080 if (lowerSource == "help") {
00081 setData(source, "Use 'players' to get a list of players.\n"
00082 "Use 'properties' to get a list of all properties that may be returned."
00083 );
00084 return true;
00085 } else if (lowerSource == "properties") {
00086 setData(source, "State", "QString - playing|paused|stopped");
00087 setData(source, "Artist", "QString - the artist metadata for the\n"
00088 " current track, if available");
00089 setData(source, "Album", "QString - the album metadata for the\n"
00090 " current track, if available");
00091 setData(source, "Title", "QString - the title metadata for the\n"
00092 " current track, if available");
00093 setData(source, "Track number", "int - the album/collection track number\n"
00094 " (eg: on a CD) if known, 0 otherwise");
00095 setData(source, "Comment", "QString - the comment metadata for the\n"
00096 " current track, if available");
00097 setData(source, "Genre", "QString - the comment metadata for the\n"
00098 " current track, if available");
00099 setData(source, "Length", "int - the length of the current track\n"
00100 " in seconds, 0 if unknown");
00101 setData(source, "Position", "int - the position of the current track\n"
00102 " in seconds, 0 if unknown");
00103 setData(source, "Volume", "float - the volume, given as a float\n"
00104 " between 0 and 1, or -1 if unknown");
00105 setData(source, "Artwork", "QPixmap - the album artwork, if available");
00106 return true;
00107 } else if (lowerSource == "players") {
00108 setData(source, sources());
00109 return true;
00110 }
00111
00112 return false;
00113 }
00114
00115 bool NowPlayingEngine::updateSourceEvent(const QString& source)
00116 {
00117 QString lowerSource = source.toLower();
00118 if (lowerSource == "help" || lowerSource == "properties") {
00119
00120 return true;
00121 }
00122 return false;
00123 }
00124
00125 void NowPlayingEngine::addPlayer(Player::Ptr player)
00126 {
00127 kDebug() << "Adding player" << player->name();
00128 addSource(new PlayerContainer(player, this));
00129 }
00130
00131 void NowPlayingEngine::removePlayer(Player::Ptr player)
00132 {
00133 kDebug() << "Player" << player->name() << "disappeared";
00134 removeSource(player->name());
00135 }
00136
00137 #include "nowplayingengine.moc"