• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

nowplayingengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 Alex Merry <alex.merry@kdemail.net>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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         // help text doesn't change
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"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal