mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 00:24:12 +02:00
Initial skeleton for MPRIS support.
This commit is contained in:
@@ -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 )
|
||||
|
||||
|
185
src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp
Normal file
185
src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
#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 );
|
||||
}
|
87
src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h
Normal file
87
src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MPRISPLUGIN_H
|
||||
#define MPRISPLUGIN_H
|
||||
|
||||
#include "infosystem/infosystem.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
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
|
@@ -0,0 +1,130 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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");
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MPRIS_PLUGIN_ROOT_ADAPTOR
|
||||
#define MPRIS_PLUGIN_ROOT_ADAPTOR
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
class MprisPluginRootAdaptor: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"org.mpris.MediaPlayer2\">\n"
|
||||
" <method name=\"Raise\"/>\n"
|
||||
" <method name=\"Quit\"/>\n"
|
||||
" <property name=\"CanQuit\" type=\"b\" access=\"read\"/>\n"
|
||||
" <property name=\"CanRaise\" type=\"b\" access=\"read\"/>\n"
|
||||
" <property name=\"HasTrackList\" type=\"b\" access=\"read\"/>\n"
|
||||
" <property name=\"Identity\" type=\"s\" access=\"read\"/>\n"
|
||||
" <property name=\"DesktopEntry\" type=\"s\" access=\"read\"/>\n"
|
||||
" <property name=\"SupportedUriSchemes\" type=\"as\" access=\"read\"/>\n"
|
||||
" <property name=\"SupportedMimeTypes\" type=\"as\" access=\"read\"/>\n"
|
||||
" </interface>\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
|
@@ -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 )
|
||||
|
Reference in New Issue
Block a user