From c90c0a261d929485e50693f21db70d1a4703cd2f Mon Sep 17 00:00:00 2001 From: Alejandro Wainzinger Date: Tue, 9 Aug 2011 02:31:54 -0700 Subject: [PATCH] Initial skeleton for MPRIS support. --- src/libtomahawk/CMakeLists.txt | 4 + .../infoplugins/unix/mprisplugin.cpp | 185 ++++++++++++++++++ .../infosystem/infoplugins/unix/mprisplugin.h | 87 ++++++++ .../unix/mprispluginrootadaptor.cpp | 130 ++++++++++++ .../infoplugins/unix/mprispluginrootadaptor.h | 73 +++++++ .../infosystem/infosystemworker.cpp | 4 + 6 files changed, 483 insertions(+) create mode 100644 src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp create mode 100644 src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h create mode 100644 src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.cpp create mode 100644 src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 574c29ad5..3c42d2c06 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -411,10 +411,14 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/. IF( UNIX AND NOT APPLE ) SET( libSources ${libSources} + infosystem/infoplugins/unix/mprispluginrootadaptor.cpp + infosystem/infoplugins/unix/mprisplugin.cpp infosystem/infoplugins/unix/fdonotifyplugin.cpp infosystem/infoplugins/unix/imageconverter.cpp ) SET( libHeaders ${libHeaders} + infosystem/infoplugins/unix/mprispluginrootadaptor.h + infosystem/infoplugins/unix/mprisplugin.h infosystem/infoplugins/unix/fdonotifyplugin.h ) ENDIF( UNIX AND NOT APPLE ) diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp new file mode 100644 index 000000000..52903c614 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp @@ -0,0 +1,185 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include + +#include "infosystem/infosystemworker.h" +#include "artist.h" +#include "result.h" +#include "tomahawksettings.h" +#include "globalactionmanager.h" +#include "utils/logger.h" + +#include "mprisplugin.h" +#include "mprispluginrootadaptor.h" + +using namespace Tomahawk::InfoSystem; + +MprisPlugin::MprisPlugin() + : InfoPlugin() +{ + qDebug() << Q_FUNC_INFO; + + m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped; + + new MprisPluginRootAdaptor( this ); + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/org/mpris/MediaPlayer2", this); + dbus.registerService("org.mpris.MediaPlayer2.tomahawk"); + +} + + +MprisPlugin::~MprisPlugin() +{ + qDebug() << Q_FUNC_INFO; +} + +// org.mpris.MediaPlayer2 + +bool +MprisPlugin::canQuit() +{ + qDebug() << Q_FUNC_INFO; + return true; +} + +bool +MprisPlugin::canRaise() +{ + return false; +} + +bool +MprisPlugin::hasTrackList() +{ + return false; +} +QString +MprisPlugin::identity() +{ + return QString("Tomahawk Music Player"); +} + +QString +MprisPlugin::desktopEntry() +{ + return QString("tomahawk"); +} + +QStringList +MprisPlugin::supportedUriSchemes() +{ + return QStringList(); +} + +QStringList +MprisPlugin::supportedMimeTypes() +{ + return QStringList(); +} + +void +MprisPlugin::raise() +{ +} + +void +MprisPlugin::quit() +{ +} + +// InfoPlugin Methods + +void +MprisPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + qDebug() << Q_FUNC_INFO; + + return; +} + +void +MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ) +{ + qDebug() << Q_FUNC_INFO; + + switch ( type ) + { + case InfoNowPlaying: + audioStarted( input ); + break; + case InfoNowPaused: + audioPaused(); + return; + case InfoNowResumed: + audioResumed( input ); + break; + case InfoNowStopped: + audioStopped(); + break; + + default: + return; + } + +} + +/** Audio state slots */ +void +MprisPlugin::audioStarted( const QVariant &input ) +{ + qDebug() << Q_FUNC_INFO; + + if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) + return; + + InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + if ( !hash.contains( "title" ) || !hash.contains( "artist" ) ) + return; + + //hash["artist"]; + //hash["title"]; + QString nowPlaying = ""; + qDebug() << "nowPlaying: " << nowPlaying; +} + +void +MprisPlugin::audioFinished( const QVariant &input ) +{ + //qDebug() << Q_FUNC_INFO; +} + +void +MprisPlugin::audioStopped() +{ + qDebug() << Q_FUNC_INFO; +} + +void +MprisPlugin::audioPaused() +{ + qDebug() << Q_FUNC_INFO; +} + +void +MprisPlugin::audioResumed( const QVariant &input ) +{ + qDebug() << Q_FUNC_INFO; + audioStarted( input ); +} diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h new file mode 100644 index 000000000..7d2885271 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h @@ -0,0 +1,87 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef MPRISPLUGIN_H +#define MPRISPLUGIN_H + +#include "infosystem/infosystem.h" + +#include +#include + +namespace Tomahawk { + +namespace InfoSystem { + +class MprisPlugin : public InfoPlugin +{ + Q_OBJECT + +public: + MprisPlugin(); + virtual ~MprisPlugin(); + +protected slots: + void getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); + void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); + +public slots: + // MPRIS DBus Methods + + // org.mpris.MediaPlayer2 + bool canQuit(); + bool canRaise(); + bool hasTrackList(); + QString identity(); + QString desktopEntry(); + QStringList supportedUriSchemes(); + QStringList supportedMimeTypes(); + + void raise(); + void quit(); + + // org.mpris.MediaPlayer2.player + // TODO: player methods/properties + + void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused + + virtual void notInCacheSlot( uint requestId, const Tomahawk::InfoSystem::InfoCriteriaHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) + { + Q_UNUSED( requestId ); + Q_UNUSED( criteria ); + Q_UNUSED( requestData ); + } + +private: + // Get Info + + // Push Info + void audioStarted( const QVariant &input ); + void audioFinished( const QVariant &input ); + void audioStopped(); + void audioPaused(); + void audioResumed( const QVariant &input ); + +}; + +}; + + +} + +#endif // MPRISPLUGIN_H diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.cpp b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.cpp new file mode 100644 index 000000000..c1ceaf019 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.cpp @@ -0,0 +1,130 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "mprispluginrootadaptor.h" + +MprisPluginRootAdaptor::MprisPluginRootAdaptor( QObject *parent ) + : QDBusAbstractAdaptor( parent ) +{ +} + +MprisPluginRootAdaptor::~MprisPluginRootAdaptor() +{ +} + +// Properties + +bool +MprisPluginRootAdaptor::canQuit() +{ + qDebug() << Q_FUNC_INFO; + bool retVal; + QMetaObject::invokeMethod(parent() + , "canQuit" + , Qt::DirectConnection + , Q_RETURN_ARG( bool, retVal ) ); + return retVal; +} + +bool +MprisPluginRootAdaptor::canRaise() +{ + qDebug() << Q_FUNC_INFO; + bool retVal; + QMetaObject::invokeMethod(parent() + , "canRaise" + , Qt::DirectConnection + , Q_RETURN_ARG( bool, retVal ) ); + return retVal; +} + +bool +MprisPluginRootAdaptor::hasTrackList() +{ + qDebug() << Q_FUNC_INFO; + bool retVal; + QMetaObject::invokeMethod(parent() + , "hasTrackList" + , Qt::DirectConnection + , Q_RETURN_ARG( bool, retVal ) ); + return retVal; +} + +QString +MprisPluginRootAdaptor::identity() +{ + qDebug() << Q_FUNC_INFO; + QString retVal; + QMetaObject::invokeMethod(parent() + , "identity" + , Qt::DirectConnection + , Q_RETURN_ARG( QString, retVal ) ); + return retVal; +} + +QString +MprisPluginRootAdaptor::desktopEntry() +{ + qDebug() << Q_FUNC_INFO; + QString retVal; + QMetaObject::invokeMethod(parent() + , "desktopEntry" + , Qt::DirectConnection + , Q_RETURN_ARG( QString, retVal ) ); + return retVal; +} + +QStringList +MprisPluginRootAdaptor::supportedUriSchemes() +{ + qDebug() << Q_FUNC_INFO; + QStringList retVal; + QMetaObject::invokeMethod(parent() + , "supportedUriSchemes" + , Qt::DirectConnection + , Q_RETURN_ARG( QStringList, retVal ) ); + return retVal; +} + +QStringList +MprisPluginRootAdaptor::supportedMimeTypes() +{ + qDebug() << Q_FUNC_INFO; + QStringList retVal; + QMetaObject::invokeMethod(parent() + , "supportedMimeTypes" + , Qt::DirectConnection + , Q_RETURN_ARG( QStringList, retVal ) ); + return retVal; +} + +// Methods + +void +MprisPluginRootAdaptor::Raise() +{ + qDebug() << Q_FUNC_INFO; + QMetaObject::invokeMethod(parent(), "raise"); +} + +void +MprisPluginRootAdaptor::Quit() +{ + qDebug() << Q_FUNC_INFO; + QMetaObject::invokeMethod(parent(), "quit"); +} diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.h b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.h new file mode 100644 index 000000000..d0bc8ed72 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginrootadaptor.h @@ -0,0 +1,73 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef MPRIS_PLUGIN_ROOT_ADAPTOR +#define MPRIS_PLUGIN_ROOT_ADAPTOR + +#include +#include + +#include + +class MprisPluginRootAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2") + Q_CLASSINFO("D-Bus Introspection", "" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "") + Q_PROPERTY( bool CanQuit READ canQuit ) + Q_PROPERTY( bool CanRaise READ canRaise ) + Q_PROPERTY( bool HasTrackList READ hasTrackList ) + Q_PROPERTY( QString Identity READ identity ) + Q_PROPERTY( QString DesktopEntry READ desktopEntry ) + Q_PROPERTY( QStringList SupportedUriSchemes READ supportedUriSchemes ) + Q_PROPERTY( QStringList SupportedMimeTypes READ supportedMimeTypes ) + + +public: + MprisPluginRootAdaptor( QObject *parent ); + virtual ~MprisPluginRootAdaptor(); + + bool canQuit(); + bool canRaise(); + bool hasTrackList(); + QString identity(); + QString desktopEntry(); + QStringList supportedUriSchemes(); + QStringList supportedMimeTypes(); + + +public slots: + Q_NOREPLY void Raise(); + Q_NOREPLY void Quit(); + +}; + + +#endif diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index eea9a27ea..7b11ded1f 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -35,6 +35,7 @@ #endif #ifdef Q_WS_X11 #include "infoplugins/unix/fdonotifyplugin.h" +#include "infoplugins/unix/mprisplugin.h" #endif #include "lastfm/NetworkAccessManager" @@ -97,6 +98,9 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac InfoPluginPtr fdonotifyptr( new FdoNotifyPlugin() ); m_plugins.append( fdonotifyptr ); registerInfoTypes( fdonotifyptr, fdonotifyptr.data()->supportedGetTypes(), fdonotifyptr.data()->supportedPushTypes() ); + InfoPluginPtr mprisptr( new MprisPlugin() ); + m_plugins.append( mprisptr ); + registerInfoTypes( mprisptr, mprisptr.data()->supportedGetTypes(), mprisptr.data()->supportedPushTypes() ); #endif Q_FOREACH( InfoPluginPtr plugin, m_plugins )