From 7b89460aa1f9c9c5805f277502fc0870b36f4ca5 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 5 May 2012 10:10:25 -0400 Subject: [PATCH] Do not scrobble or show current track on Last.fm when listening privately --- src/Scrobbler.cpp | 9 +++++++-- src/accounts/lastfm/LastFmInfoPlugin.cpp | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Scrobbler.cpp b/src/Scrobbler.cpp index 5c2041565..dd2f41942 100644 --- a/src/Scrobbler.cpp +++ b/src/Scrobbler.cpp @@ -79,16 +79,21 @@ Scrobbler::trackStarted( const Tomahawk::result_ptr& track ) scrobble(); } + QVariantMap playInfo; + Tomahawk::InfoSystem::InfoStringHash trackInfo; - trackInfo["title"] = track->track(); trackInfo["artist"] = track->artist()->name(); trackInfo["album"] = track->album()->name(); trackInfo["duration"] = QString::number( track->duration() ); + trackInfo["albumpos"] = QString::number( track->albumpos() ); + + playInfo["trackinfo"] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ); + playInfo["private"] = TomahawkSettings::instance()->privateListeningMode(); Tomahawk::InfoSystem::InfoPushData pushData ( s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying, - QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ), + playInfo, Tomahawk::InfoSystem::PushNoFlag ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData ); diff --git a/src/accounts/lastfm/LastFmInfoPlugin.cpp b/src/accounts/lastfm/LastFmInfoPlugin.cpp index 5803ba6ee..7d3bcf79a 100644 --- a/src/accounts/lastfm/LastFmInfoPlugin.cpp +++ b/src/accounts/lastfm/LastFmInfoPlugin.cpp @@ -161,19 +161,30 @@ LastFmInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) void LastFmInfoPlugin::nowPlaying( const QVariant &input ) { - if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() || !m_scrobbler ) + m_track = lastfm::MutableTrack(); + if ( !input.canConvert< QVariantMap >() ) { - tLog() << "LastFmInfoPlugin::nowPlaying no m_scrobbler, or cannot convert input!"; - if ( !m_scrobbler ) - tLog() << "No scrobbler!"; + tDebug() << Q_FUNC_INFO << "Failed to convert data to a QVariantMap"; return; } - InfoStringHash hash = input.value< Tomahawk::InfoSystem::InfoStringHash >(); + QVariantMap map = input.toMap(); + if ( map.contains( "private" ) && map[ "private" ] == TomahawkSettings::FullyPrivate ) + return; + + if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() || !m_scrobbler ) + { + tLog() << Q_FUNC_INFO << "LastFmInfoPlugin::nowPlaying no m_scrobbler, or cannot convert input!"; + if ( !m_scrobbler ) + tLog() << Q_FUNC_INFO << "No scrobbler!"; + return; + } + + Tomahawk::InfoSystem::InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); + if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) ) return; - m_track = lastfm::MutableTrack(); m_track.stamp(); m_track.setTitle( hash["title"] );