mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Fixed TWK-641: don't write empty album covers in InfoSystem.
This commit is contained in:
@@ -42,8 +42,6 @@ MprisPlugin::MprisPlugin()
|
|||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_coverTempFile( 0 )
|
, m_coverTempFile( 0 )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
// init
|
// init
|
||||||
m_playbackStatus = "Stopped";
|
m_playbackStatus = "Stopped";
|
||||||
|
|
||||||
@@ -54,79 +52,84 @@ MprisPlugin::MprisPlugin()
|
|||||||
new MprisPluginRootAdaptor( this );
|
new MprisPluginRootAdaptor( this );
|
||||||
new MprisPluginPlayerAdaptor( this );
|
new MprisPluginPlayerAdaptor( this );
|
||||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||||
dbus.registerObject("/org/mpris/MediaPlayer2", this);
|
dbus.registerObject( "/org/mpris/MediaPlayer2", this );
|
||||||
dbus.registerService("org.mpris.MediaPlayer2.tomahawk");
|
dbus.registerService( "org.mpris.MediaPlayer2.tomahawk" );
|
||||||
|
|
||||||
// Listen to volume changes
|
// Listen to volume changes
|
||||||
connect( AudioEngine::instance(), SIGNAL( volumeChanged( int ) ),
|
connect( AudioEngine::instance(), SIGNAL( volumeChanged( int ) ),
|
||||||
SLOT( onVolumeChanged( int ) ) );
|
SLOT( onVolumeChanged( int ) ) );
|
||||||
|
|
||||||
// When the playlist changes, signals for several properties are sent
|
// When the playlist changes, signals for several properties are sent
|
||||||
connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::playlistinterface_ptr ) ),
|
connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::playlistinterface_ptr ) ),
|
||||||
SLOT( onPlaylistChanged( Tomahawk::playlistinterface_ptr ) ) );
|
SLOT( onPlaylistChanged( Tomahawk::playlistinterface_ptr ) ) );
|
||||||
|
|
||||||
// When a track is added or removed, CanGoNext updated signal is sent
|
// When a track is added or removed, CanGoNext updated signal is sent
|
||||||
Tomahawk::playlistinterface_ptr playlist = AudioEngine::instance()->playlist();
|
Tomahawk::playlistinterface_ptr playlist = AudioEngine::instance()->playlist();
|
||||||
if( !playlist.isNull() )
|
if ( !playlist.isNull() )
|
||||||
|
{
|
||||||
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
|
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
|
||||||
SLOT( onTrackCountChanged( unsigned int ) ) );
|
SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to AudioEngine's seeked signal
|
// Connect to AudioEngine's seeked signal
|
||||||
connect( AudioEngine::instance(), SIGNAL( seeked( qint64 ) ),
|
connect( AudioEngine::instance(), SIGNAL( seeked( qint64 ) ),
|
||||||
SLOT( onSeeked( qint64 ) ) );
|
SLOT( onSeeked( qint64 ) ) );
|
||||||
|
|
||||||
// Connect to the InfoSystem (we need to get album covers via getInfo)
|
// Connect to the InfoSystem (we need to get album covers via getInfo)
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||||
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
|
|
||||||
|
|
||||||
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
|
SIGNAL( finished( QString ) ),
|
||||||
|
SLOT( infoSystemFinished( QString ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MprisPlugin::~MprisPlugin()
|
MprisPlugin::~MprisPlugin()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
delete m_coverTempFile;
|
delete m_coverTempFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// org.mpris.MediaPlayer2
|
// org.mpris.MediaPlayer2
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canQuit() const
|
MprisPlugin::canQuit() const
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canRaise() const
|
MprisPlugin::canRaise() const
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::hasTrackList() const
|
MprisPlugin::hasTrackList() const
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::identity() const
|
MprisPlugin::identity() const
|
||||||
{
|
{
|
||||||
return QString("Tomahawk");
|
return QString( "Tomahawk" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::desktopEntry() const
|
MprisPlugin::desktopEntry() const
|
||||||
{
|
{
|
||||||
return QString("tomahawk");
|
return QString( "tomahawk" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList
|
QStringList
|
||||||
MprisPlugin::supportedUriSchemes() const
|
MprisPlugin::supportedUriSchemes() const
|
||||||
{
|
{
|
||||||
@@ -135,23 +138,27 @@ MprisPlugin::supportedUriSchemes() const
|
|||||||
return uriSchemes;
|
return uriSchemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList
|
QStringList
|
||||||
MprisPlugin::supportedMimeTypes() const
|
MprisPlugin::supportedMimeTypes() const
|
||||||
{
|
{
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Raise()
|
MprisPlugin::Raise()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Quit()
|
MprisPlugin::Quit()
|
||||||
{
|
{
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// org.mpris.MediaPlayer2.Player
|
// org.mpris.MediaPlayer2.Player
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -160,24 +167,28 @@ MprisPlugin::canControl() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canGoNext() const
|
MprisPlugin::canGoNext() const
|
||||||
{
|
{
|
||||||
return AudioEngine::instance()->canGoNext();
|
return AudioEngine::instance()->canGoNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canGoPrevious() const
|
MprisPlugin::canGoPrevious() const
|
||||||
{
|
{
|
||||||
return AudioEngine::instance()->canGoPrevious();
|
return AudioEngine::instance()->canGoPrevious();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canPause() const
|
MprisPlugin::canPause() const
|
||||||
{
|
{
|
||||||
return AudioEngine::instance()->currentTrack();
|
return AudioEngine::instance()->currentTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canPlay() const
|
MprisPlugin::canPlay() const
|
||||||
{
|
{
|
||||||
@@ -186,6 +197,7 @@ MprisPlugin::canPlay() const
|
|||||||
return AudioEngine::instance()->currentTrack() || ( !p.isNull() && p->trackCount() );
|
return AudioEngine::instance()->currentTrack() || ( !p.isNull() && p->trackCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canSeek() const
|
MprisPlugin::canSeek() const
|
||||||
{
|
{
|
||||||
@@ -196,6 +208,7 @@ MprisPlugin::canSeek() const
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::loopStatus() const
|
MprisPlugin::loopStatus() const
|
||||||
{
|
{
|
||||||
@@ -215,39 +228,42 @@ MprisPlugin::loopStatus() const
|
|||||||
return "None";
|
return "None";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return QString("None");
|
return "None";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("None");
|
return QString( "None" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setLoopStatus( const QString &value )
|
MprisPlugin::setLoopStatus( const QString& value )
|
||||||
{
|
{
|
||||||
Tomahawk::playlistinterface_ptr p = AudioEngine::instance()->playlist();
|
Tomahawk::playlistinterface_ptr p = AudioEngine::instance()->playlist();
|
||||||
if ( p.isNull() )
|
if ( p.isNull() )
|
||||||
return;
|
return;
|
||||||
if( value == "Track")
|
if ( value == "Track" )
|
||||||
p->setRepeatMode( PlaylistInterface::RepeatOne );
|
p->setRepeatMode( PlaylistInterface::RepeatOne );
|
||||||
else if( value == "Playlist" )
|
else if ( value == "Playlist" )
|
||||||
p->setRepeatMode( PlaylistInterface::RepeatAll );
|
p->setRepeatMode( PlaylistInterface::RepeatAll );
|
||||||
else if( value == "None" )
|
else if ( value == "None" )
|
||||||
p->setRepeatMode( PlaylistInterface::NoRepeat );
|
p->setRepeatMode( PlaylistInterface::NoRepeat );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::maximumRate() const
|
MprisPlugin::maximumRate() const
|
||||||
{
|
{
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantMap
|
QVariantMap
|
||||||
MprisPlugin::metadata() const
|
MprisPlugin::metadata() const
|
||||||
{
|
{
|
||||||
QVariantMap metadataMap;
|
QVariantMap metadataMap;
|
||||||
Tomahawk::result_ptr track = AudioEngine::instance()->currentTrack();
|
Tomahawk::result_ptr track = AudioEngine::instance()->currentTrack();
|
||||||
if( track )
|
if ( track )
|
||||||
{
|
{
|
||||||
metadataMap.insert( "mpris:trackid", QString( "/track/" ) + track->id().replace( "-", "" ) );
|
metadataMap.insert( "mpris:trackid", QString( "/track/" ) + track->id().replace( "-", "" ) );
|
||||||
metadataMap.insert( "mpris:length", track->duration() );
|
metadataMap.insert( "mpris:length", track->duration() );
|
||||||
@@ -256,9 +272,11 @@ MprisPlugin::metadata() const
|
|||||||
metadataMap.insert( "xesam:title", track->track() );
|
metadataMap.insert( "xesam:title", track->track() );
|
||||||
|
|
||||||
// Only return art if tempfile exists, and if its name contains the same "artist_album_tomahawk_cover.png"
|
// Only return art if tempfile exists, and if its name contains the same "artist_album_tomahawk_cover.png"
|
||||||
if( m_coverTempFile && m_coverTempFile->exists() &&
|
if ( m_coverTempFile && m_coverTempFile->exists() &&
|
||||||
m_coverTempFile->fileName().contains( track->artist()->name() + "_" + track->album()->name() + "_tomahawk_cover.png" ) )
|
m_coverTempFile->fileName().contains( track->artist()->name() + "_" + track->album()->name() + "_tomahawk_cover.png" ) )
|
||||||
|
{
|
||||||
metadataMap.insert( "mpris:artUrl", QString( QUrl::fromLocalFile( QFileInfo( *m_coverTempFile ).absoluteFilePath() ).toEncoded() ) );
|
metadataMap.insert( "mpris:artUrl", QString( QUrl::fromLocalFile( QFileInfo( *m_coverTempFile ).absoluteFilePath() ).toEncoded() ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Need to fetch the album cover
|
// Need to fetch the album cover
|
||||||
@@ -280,18 +298,21 @@ MprisPlugin::metadata() const
|
|||||||
return metadataMap;
|
return metadataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::minimumRate() const
|
MprisPlugin::minimumRate() const
|
||||||
{
|
{
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::playbackStatus() const
|
MprisPlugin::playbackStatus() const
|
||||||
{
|
{
|
||||||
return m_playbackStatus;
|
return m_playbackStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qlonglong
|
qlonglong
|
||||||
MprisPlugin::position() const
|
MprisPlugin::position() const
|
||||||
{
|
{
|
||||||
@@ -299,18 +320,21 @@ MprisPlugin::position() const
|
|||||||
return (qlonglong) ( AudioEngine::instance()->currentTime() * 1000 );
|
return (qlonglong) ( AudioEngine::instance()->currentTime() * 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::rate() const
|
MprisPlugin::rate() const
|
||||||
{
|
{
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setRate( double value )
|
MprisPlugin::setRate( double value )
|
||||||
{
|
{
|
||||||
Q_UNUSED( value );
|
Q_UNUSED( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::shuffle() const
|
MprisPlugin::shuffle() const
|
||||||
{
|
{
|
||||||
@@ -320,6 +344,7 @@ MprisPlugin::shuffle() const
|
|||||||
return p->shuffled();
|
return p->shuffled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setShuffle( bool value )
|
MprisPlugin::setShuffle( bool value )
|
||||||
{
|
{
|
||||||
@@ -329,70 +354,76 @@ MprisPlugin::setShuffle( bool value )
|
|||||||
return p->setShuffled( value );
|
return p->setShuffled( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::volume() const
|
MprisPlugin::volume() const
|
||||||
{
|
{
|
||||||
return AudioEngine::instance()->volume();
|
return AudioEngine::instance()->volume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setVolume( double value )
|
MprisPlugin::setVolume( double value )
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->setVolume( value );
|
AudioEngine::instance()->setVolume( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Next()
|
MprisPlugin::Next()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->next();
|
AudioEngine::instance()->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::OpenUri( const QString &Uri )
|
MprisPlugin::OpenUri( const QString& Uri )
|
||||||
{
|
{
|
||||||
if( Uri.contains( "tomahawk://" ) )
|
if ( Uri.contains( "tomahawk://" ) )
|
||||||
GlobalActionManager::instance()->parseTomahawkLink( Uri );
|
GlobalActionManager::instance()->parseTomahawkLink( Uri );
|
||||||
else if( Uri.contains( "spotify:" ) )
|
else if ( Uri.contains( "spotify:" ) )
|
||||||
GlobalActionManager::instance()->openSpotifyLink( Uri );
|
GlobalActionManager::instance()->openSpotifyLink( Uri );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Pause()
|
MprisPlugin::Pause()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->pause();
|
AudioEngine::instance()->pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Play()
|
MprisPlugin::Play()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->play();
|
AudioEngine::instance()->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::PlayPause()
|
MprisPlugin::PlayPause()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->playPause();
|
AudioEngine::instance()->playPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Previous()
|
MprisPlugin::Previous()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->previous();
|
AudioEngine::instance()->previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Seek( qlonglong Offset )
|
MprisPlugin::Seek( qlonglong Offset )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
if ( !canSeek() )
|
||||||
|
|
||||||
if( !canSeek() )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qlonglong seekTime = position() + Offset;
|
qlonglong seekTime = position() + Offset;
|
||||||
qDebug() << "seekTime: " << seekTime;
|
if ( seekTime < 0 )
|
||||||
if( seekTime < 0 )
|
|
||||||
AudioEngine::instance()->seek( 0 );
|
AudioEngine::instance()->seek( 0 );
|
||||||
else if( seekTime > AudioEngine::instance()->currentTrackTotalTime()*1000 )
|
else if ( seekTime > AudioEngine::instance()->currentTrackTotalTime()*1000 )
|
||||||
Next();
|
Next();
|
||||||
// seekTime is in microseconds, but we work internally in milliseconds
|
// seekTime is in microseconds, but we work internally in milliseconds
|
||||||
else
|
else
|
||||||
@@ -400,50 +431,46 @@ MprisPlugin::Seek( qlonglong Offset )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::SetPosition( const QDBusObjectPath &TrackId, qlonglong Position )
|
MprisPlugin::SetPosition( const QDBusObjectPath& TrackId, qlonglong Position )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
if ( !canSeek() )
|
||||||
if( !canSeek() )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "path: " << TrackId.path();
|
if ( TrackId.path() != QString( "/track/" ) + AudioEngine::instance()->currentTrack()->id().replace( "-", "" ) )
|
||||||
qDebug() << "position: " << Position;
|
|
||||||
|
|
||||||
if( TrackId.path() != QString("/track/") + AudioEngine::instance()->currentTrack()->id().replace( "-", "" ) )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( ( Position < 0) || ( Position > AudioEngine::instance()->currentTrackTotalTime()*1000 ) )
|
if ( ( Position < 0) || ( Position > AudioEngine::instance()->currentTrackTotalTime()*1000 ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "seeking to: " << Position/1000 << "ms";
|
|
||||||
|
|
||||||
AudioEngine::instance()->seek( (qint64) (Position / 1000 ) );
|
AudioEngine::instance()->seek( (qint64) (Position / 1000 ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Stop()
|
MprisPlugin::Stop()
|
||||||
{
|
{
|
||||||
AudioEngine::instance()->stop();
|
AudioEngine::instance()->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InfoPlugin Methods
|
// InfoPlugin Methods
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
MprisPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
Q_UNUSED( requestData );
|
Q_UNUSED( requestData );
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
|
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
|
||||||
{
|
{
|
||||||
Q_UNUSED( caller );
|
Q_UNUSED( caller );
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
bool isPlayingInfo = false;
|
bool isPlayingInfo = false;
|
||||||
|
|
||||||
switch ( type )
|
switch ( type )
|
||||||
@@ -469,11 +496,11 @@ MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( isPlayingInfo )
|
if ( isPlayingInfo )
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "PlaybackStatus");
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "PlaybackStatus" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
|
MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
|
||||||
{
|
{
|
||||||
@@ -481,12 +508,11 @@ MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
|
|||||||
Q_UNUSED( oldState );
|
Q_UNUSED( oldState );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Audio state slots */
|
/** Audio state slots */
|
||||||
void
|
void
|
||||||
MprisPlugin::audioStarted( const QVariant &input )
|
MprisPlugin::audioStarted( const QVariant& input )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -495,64 +521,55 @@ MprisPlugin::audioStarted( const QVariant &input )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_playbackStatus = "Playing";
|
m_playbackStatus = "Playing";
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata");
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
|
|
||||||
//hash["artist"];
|
|
||||||
//hash["title"];
|
|
||||||
//QString nowPlaying = "";
|
|
||||||
//qDebug() << "nowPlaying: " << nowPlaying;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::audioFinished( const QVariant &input )
|
MprisPlugin::audioFinished( const QVariant& input )
|
||||||
{
|
{
|
||||||
Q_UNUSED( input );
|
Q_UNUSED( input );
|
||||||
//qDebug() << Q_FUNC_INFO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::audioStopped()
|
MprisPlugin::audioStopped()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
m_playbackStatus = "Stopped";
|
m_playbackStatus = "Stopped";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::audioPaused()
|
MprisPlugin::audioPaused()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
m_playbackStatus = "Paused";
|
m_playbackStatus = "Paused";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::audioResumed( const QVariant &input )
|
MprisPlugin::audioResumed( const QVariant& input )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
audioStarted( input );
|
audioStarted( input );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::onVolumeChanged( int volume )
|
MprisPlugin::onVolumeChanged( int volume )
|
||||||
{
|
{
|
||||||
Q_UNUSED( volume );
|
Q_UNUSED( volume );
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Volume");
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Volume" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::onPlaylistChanged( Tomahawk::playlistinterface_ptr playlist )
|
MprisPlugin::onPlaylistChanged( Tomahawk::playlistinterface_ptr playlist )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
disconnect( this, SLOT( onTrackCountChanged( unsigned int ) ) );
|
disconnect( this, SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||||
qDebug() << "disconnected";
|
|
||||||
if( !playlist.isNull() )
|
|
||||||
qDebug() << "playlist not null";
|
|
||||||
|
|
||||||
if( !playlist.isNull() )
|
if ( !playlist.isNull() )
|
||||||
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
|
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
|
||||||
SLOT( onTrackCountChanged( unsigned int ) ) );
|
SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||||
|
|
||||||
qDebug() << "connected new playlist";
|
|
||||||
|
|
||||||
// Notify relevant changes
|
// Notify relevant changes
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "LoopStatus" );
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "LoopStatus" );
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Shuffle" );
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Shuffle" );
|
||||||
@@ -560,6 +577,7 @@ MprisPlugin::onPlaylistChanged( Tomahawk::playlistinterface_ptr playlist )
|
|||||||
onTrackCountChanged( 0 );
|
onTrackCountChanged( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::onTrackCountChanged( unsigned int tracks )
|
MprisPlugin::onTrackCountChanged( unsigned int tracks )
|
||||||
{
|
{
|
||||||
@@ -569,12 +587,14 @@ MprisPlugin::onTrackCountChanged( unsigned int tracks )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
MprisPlugin::onSeeked( qint64 ms )
|
void
|
||||||
{
|
MprisPlugin::onSeeked( qint64 ms )
|
||||||
|
{
|
||||||
qlonglong us = (qlonglong) ( ms*1000 );
|
qlonglong us = (qlonglong) ( ms*1000 );
|
||||||
emit Seeked( us );
|
emit Seeked( us );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||||
@@ -603,7 +623,7 @@ MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData,
|
|||||||
image.loadFromData( ba );
|
image.loadFromData( ba );
|
||||||
|
|
||||||
// Pull out request data for album+artist
|
// Pull out request data for album+artist
|
||||||
if( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||||
{
|
{
|
||||||
qDebug() << "Cannot convert metadata input to album cover retrieval";
|
qDebug() << "Cannot convert metadata input to album cover retrieval";
|
||||||
return;
|
return;
|
||||||
@@ -612,41 +632,33 @@ MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData,
|
|||||||
Tomahawk::InfoSystem::InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
|
Tomahawk::InfoSystem::InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
|
||||||
|
|
||||||
// delete the old tempfile and make new one, to avoid caching of filename by mpris clients
|
// delete the old tempfile and make new one, to avoid caching of filename by mpris clients
|
||||||
if( m_coverTempFile )
|
if ( m_coverTempFile )
|
||||||
|
{
|
||||||
delete m_coverTempFile;
|
delete m_coverTempFile;
|
||||||
m_coverTempFile = new QTemporaryFile( QDir::toNativeSeparators(
|
m_coverTempFile = 0;
|
||||||
QDir::tempPath() + "/" + hash["artist"] + "_" + hash["album"] + "_tomahawk_cover.png" ) );
|
}
|
||||||
if( !m_coverTempFile->open() )
|
|
||||||
|
if ( image.isNull() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_coverTempFile = new QTemporaryFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + hash["artist"] + "_" + hash["album"] + "_tomahawk_cover.png" ) );
|
||||||
|
if ( !m_coverTempFile->open() )
|
||||||
{
|
{
|
||||||
qDebug() << "WARNING: could not write temporary file for cover art!";
|
qDebug() << "WARNING: could not write temporary file for cover art!";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, save the image to the new temp file
|
// Finally, save the image to the new temp file
|
||||||
//if( image.save( QFileInfo( *m_coverTempFile ).absoluteFilePath(), "PNG" ) )
|
if ( image.save( m_coverTempFile, "PNG" ) )
|
||||||
if( image.save( m_coverTempFile, "PNG") )
|
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Image saving successful, notifying";
|
qDebug() << "Saving cover image to:" << QFileInfo( *m_coverTempFile ).absoluteFilePath();
|
||||||
qDebug() << "Saving to: " << QFileInfo( *m_coverTempFile ).absoluteFilePath();
|
|
||||||
m_coverTempFile->close();
|
m_coverTempFile->close();
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << " failed to save image!";
|
tDebug() << Q_FUNC_INFO << "failed to save cover image!";
|
||||||
m_coverTempFile->close();
|
m_coverTempFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if( m_coverTempFile->open() )
|
|
||||||
{
|
|
||||||
QTextStream out( m_coverTempFile );
|
|
||||||
out << ba;
|
|
||||||
m_coverTempFile->close();
|
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,14 +669,14 @@ MprisPlugin::infoSystemFinished( QString target )
|
|||||||
Q_UNUSED( target );
|
Q_UNUSED( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::notifyPropertyChanged( const QString& interface,
|
MprisPlugin::notifyPropertyChanged( const QString& interface, const QString& propertyName )
|
||||||
const QString& propertyName )
|
|
||||||
{
|
{
|
||||||
QDBusMessage signal = QDBusMessage::createSignal(
|
QDBusMessage signal = QDBusMessage::createSignal(
|
||||||
"/org/mpris/MediaPlayer2",
|
"/org/mpris/MediaPlayer2",
|
||||||
"org.freedesktop.DBus.Properties",
|
"org.freedesktop.DBus.Properties",
|
||||||
"PropertiesChanged");
|
"PropertiesChanged" );
|
||||||
signal << interface;
|
signal << interface;
|
||||||
QVariantMap changedProps;
|
QVariantMap changedProps;
|
||||||
changedProps.insert(propertyName, property(propertyName.toAscii()));
|
changedProps.insert(propertyName, property(propertyName.toAscii()));
|
||||||
|
@@ -87,7 +87,7 @@ public:
|
|||||||
|
|
||||||
Q_PROPERTY( QString LoopStatus READ loopStatus WRITE setLoopStatus )
|
Q_PROPERTY( QString LoopStatus READ loopStatus WRITE setLoopStatus )
|
||||||
QString loopStatus() const;
|
QString loopStatus() const;
|
||||||
void setLoopStatus( const QString &value );
|
void setLoopStatus( const QString& value );
|
||||||
|
|
||||||
Q_PROPERTY( double MaximumRate READ maximumRate )
|
Q_PROPERTY( double MaximumRate READ maximumRate )
|
||||||
double maximumRate() const;
|
double maximumRate() const;
|
||||||
@@ -129,16 +129,15 @@ public slots:
|
|||||||
|
|
||||||
// org.mpris.MediaPlayer2.Player
|
// org.mpris.MediaPlayer2.Player
|
||||||
void Next();
|
void Next();
|
||||||
void OpenUri( const QString &Uri );
|
void OpenUri( const QString& Uri );
|
||||||
void Pause();
|
void Pause();
|
||||||
void Play();
|
void Play();
|
||||||
void PlayPause();
|
void PlayPause();
|
||||||
void Previous();
|
void Previous();
|
||||||
void Seek( qlonglong Offset );
|
void Seek( qlonglong Offset );
|
||||||
void SetPosition( const QDBusObjectPath &TrackId, qlonglong Position );
|
void SetPosition( const QDBusObjectPath& TrackId, qlonglong Position );
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
|
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||||
@@ -160,16 +159,16 @@ private:
|
|||||||
// Get Info
|
// Get Info
|
||||||
|
|
||||||
// Push Info
|
// Push Info
|
||||||
void audioStarted( const QVariant &input );
|
void audioStarted( const QVariant& input );
|
||||||
void audioFinished( const QVariant &input );
|
void audioFinished( const QVariant& input );
|
||||||
void audioStopped();
|
void audioStopped();
|
||||||
void audioPaused();
|
void audioPaused();
|
||||||
void audioResumed( const QVariant &input );
|
void audioResumed( const QVariant& input );
|
||||||
|
|
||||||
// DBus
|
// DBus
|
||||||
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
|
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
|
||||||
QString m_playbackStatus;
|
QString m_playbackStatus;
|
||||||
QTemporaryFile *m_coverTempFile;
|
QTemporaryFile* m_coverTempFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user