diff --git a/src/accounts/lastfm/LastFmPlugin.cpp b/src/accounts/lastfm/LastFmPlugin.cpp index 5b6e0e384..f9ecc5a72 100644 --- a/src/accounts/lastfm/LastFmPlugin.cpp +++ b/src/accounts/lastfm/LastFmPlugin.cpp @@ -206,13 +206,13 @@ LastFmPlugin::sendLoveSong( const InfoType type, QVariant input ) { qDebug() << Q_FUNC_INFO; - if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) + if ( !input.toMap().contains( "trackinfo" ) || !input.toMap()[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { tLog() << "LastFmPlugin::nowPlaying cannot convert input!"; return; } - InfoStringHash hash = input.value< Tomahawk::InfoSystem::InfoStringHash >(); + InfoStringHash hash = input.toMap()[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; diff --git a/src/accounts/twitter/TwitterInfoPlugin.cpp b/src/accounts/twitter/TwitterInfoPlugin.cpp index ef37dd1f8..89d8da763 100644 --- a/src/accounts/twitter/TwitterInfoPlugin.cpp +++ b/src/accounts/twitter/TwitterInfoPlugin.cpp @@ -37,7 +37,7 @@ namespace InfoSystem TwitterInfoPlugin::TwitterInfoPlugin( Tomahawk::Accounts::TwitterAccount* account ) : m_account( account ) { - //m_supportedPushTypes << InfoLove; + m_supportedPushTypes << InfoShareTrack << InfoLove; } @@ -122,21 +122,47 @@ TwitterInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) } Tomahawk::InfoSystem::PushInfoPair pushInfoPair = pushData.infoPair; - - if ( !pushInfoPair.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) + + if ( !pushInfoPair.second.canConvert< QVariantMap >() ) { - tDebug() << Q_FUNC_INFO << "Cannot convert input into an info string hash"; + tLog() << Q_FUNC_INFO << "Failed to find QVariantMap!"; + return; + } + + QVariantMap map = pushInfoPair.second.toMap(); + + if ( !map.contains( "accountlist" ) || !map[ "accountlist" ].canConvert< QStringList >() ) + { + tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Cowardly failing to send out a message without an account list present"; return; } - Tomahawk::InfoSystem::InfoStringHash info = pushInfoPair.second.value< Tomahawk::InfoSystem::InfoStringHash >(); - - QString msg = tr( "Listening to \"%1\" by %2 and loving it! %3" ) - .arg( info[ "title" ] ) - .arg( info[ "artist" ] ) - .arg( pushInfoPair.first.contains( "shorturl" ) ? - pushInfoPair.first[ "shorturl" ].toUrl().toString() : - GlobalActionManager::instance()->openLink( info[ "title" ], info[ "artist" ], info[ "album" ] ).toString() ); + if ( !map[ "accountlist" ].toStringList().contains( m_account->accountId() ) ) + { + tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Our account not in the list, not tweeting out"; + return; + } + + if ( !map.contains( "message" ) && ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) ) + { + tLog() << Q_FUNC_INFO << "Failed to find message or trackinfo"; + return; + } + + Tomahawk::InfoSystem::InfoStringHash info; + QString msg; + if ( !map.contains( "message" ) ) + { + info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); + msg = tr( "Listening to \"%1\" by %2 and loving it! %3" ) + .arg( info[ "title" ] ) + .arg( info[ "artist" ] ) + .arg( pushInfoPair.first.contains( "shorturl" ) ? + pushInfoPair.first[ "shorturl" ].toUrl().toString() : + GlobalActionManager::instance()->openLink( info[ "title" ], info[ "artist" ], info[ "album" ] ).toString() ); + } + else + msg = map[ "message" ].toString(); QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( m_twitterAuth.data(), this ); connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postLovedStatusUpdateReply(const QTweetStatus &) ) ); diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 38f3a1c89..58c6ffa0f 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -582,14 +582,17 @@ Query::setLoved( bool loved ) { m_currentSocialActions[ "Love" ] = loved; + QVariantMap loveInfo; Tomahawk::InfoSystem::InfoStringHash trackInfo; trackInfo["title"] = track(); trackInfo["artist"] = artist(); trackInfo["album"] = album(); + loveInfo[ "trackinfo" ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ); + Tomahawk::InfoSystem::InfoPushData pushData ( id(), ( loved ? Tomahawk::InfoSystem::InfoLove : Tomahawk::InfoSystem::InfoUnLove ), - QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ), + loveInfo, Tomahawk::InfoSystem::PushShortUrlFlag ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData ); diff --git a/src/libtomahawk/infosystem/InfoSystem.h b/src/libtomahawk/infosystem/InfoSystem.h index d70d9da88..8298c8166 100644 --- a/src/libtomahawk/infosystem/InfoSystem.h +++ b/src/libtomahawk/infosystem/InfoSystem.h @@ -129,6 +129,7 @@ enum InfoType { // as items are saved in cache, mark them here to not change the InfoLove = 90, InfoUnLove = 91, + InfoShareTrack = 92, InfoNotifyUser = 100,