void SpotifyInfoPlugin::sendLoveSong( const InfoType type, QVariant input ) { if ( m_account.isNull() || !m_account.data()->loggedIn() ) return; if( !m_account.data()->loveSync() ) return; if ( !input.toMap().contains( "trackinfo" ) || !input.toMap()[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { tLog( LOGVERBOSE ) << "SpotifyInfoPlugin::sendLoveSong cannot convert input!"; return; } InfoStringHash hash = input.toMap()[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; if ( type == Tomahawk::InfoSystem::InfoLove ) { m_account.data()->starTrack( hash["artist"], hash["title"], true ); } else if ( type == Tomahawk::InfoSystem::InfoUnLove ) { m_account.data()->starTrack( hash["artist"], hash["title"], false ); } }
void SpotifyInfoPlugin::getInfo( InfoRequestData requestData ) { switch ( requestData.type ) { case InfoAlbumSongs: { if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { dataError( requestData ); return; } InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "album" ) ) { dataError( requestData ); return; } Tomahawk::InfoSystem::InfoStringHash criteria; criteria[ "album" ] = hash[ "album" ]; if ( hash.contains( "artist" ) ) criteria["artist"] = hash["artist"]; emit getCachedInfo( criteria, Q_INT64_C(2419200000), requestData ); return; } default: dataError( requestData ); } }
void ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) { if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { dataError( requestData ); return; } InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); Tomahawk::InfoSystem::InfoStringHash criteria; /// Each request needs to contain both a id and source if ( !hash.contains( "chart_id" ) && !hash.contains( "chart_source" ) ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required params!"; dataError( requestData ); return; } /// Set the criterias for current chart criteria["chart_id"] = hash["chart_id"]; criteria["chart_source"] = hash["chart_source"]; emit getCachedInfo( criteria, 86400000, requestData ); }
bool newReleaseSort( const InfoStringHash& left, const InfoStringHash& right ) { if ( !left.contains( "date" ) || !right.contains( "date" ) ) { return true; } const QDate lDate = QDate::fromString( left[ "date" ], "yyyy-MM-dd" ); const QDate rDate = QDate::fromString( right[ "date" ], "yyyy-MM-dd" ); return lDate > rDate; }
void MusicBrainzPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { emit info( requestData, QVariant() ); return; } InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "artist" ) ) { emit info( requestData, QVariant() ); return; } switch ( requestData.type ) { case InfoArtistReleases: { Tomahawk::InfoSystem::InfoStringHash criteria; criteria["artist"] = hash["artist"]; emit getCachedInfo( criteria, 2419200000, requestData ); break; } case InfoAlbumSongs: { Tomahawk::InfoSystem::InfoStringHash criteria; criteria["artist"] = hash["artist"]; criteria["album"] = hash["album"]; emit getCachedInfo( criteria, 2419200000, requestData ); break; } default: { Q_ASSERT( false ); break; } } }
void ChartsPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { //qDebug() << Q_FUNC_INFO << requestData.caller; //qDebug() << Q_FUNC_INFO << requestData.customData; InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); bool foundSource = false; switch ( requestData.type ) { case InfoChart: /// We need something to check if the request is actually ment to go to this plugin if ( !hash.contains( "chart_source" ) ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required param!"; dataError( requestData ); break; } else { foreach( QString resource, m_chartResources ) { if( resource == hash["chart_source"] ) { foundSource = true; } } if( !foundSource ) { dataError( requestData ); break; } } fetchChart( requestData ); break; case InfoChartCapabilities: fetchChartCapabilities( requestData ); break; default: dataError( requestData ); } }
void FdoNotifyPlugin::nowPlaying( const QVariant &input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; QString messageText = tr( "Tomahawk is playing \"%1\" by %2%3." ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( hash[ "album" ].isEmpty() ? QString() : QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ) ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << m_nowPlayingId; //notification_id arguments << QString(); //app_icon arguments << QString( "Tomahawk" ); //summary arguments << messageText.replace("&", "&"); //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) dict[ "image_data" ] = ImageConverter::variantForImage( QImage( map[ "coveruri" ].toString(), "PNG" ) ); else dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-128x128.png" ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); const QDBusMessage &reply = QDBusConnection::sessionBus().call( message ); const QVariantList &list = reply.arguments(); if ( list.count() > 0 ) m_nowPlayingId = list.at( 0 ).toInt(); }
void SnoreNotifyPlugin::nowPlaying( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; QString messageText; // If the window manager supports notification styling then use it. // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( "<br><i>%1</i> %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( hash[ "album" ].toHtmlEscaped() ); messageText = tr( "%1%4 %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing, %4 is the preposition used to link track and artist ('by' in english)" ) .arg( hash[ "title" ].toHtmlEscaped() ) .arg( hash[ "artist" ].toHtmlEscaped() ) .arg( album ) .arg( QString( "<br><i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) ); // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text messageText = QString( "<i></i>%1" ).arg( messageText ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; // If there is a cover availble use it, else use Tomahawk logo as default. Snore::Icon image = m_defaultIcon; if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() ) { image = Snore::Icon( QPixmap::fromImage( map[ "cover" ].value< QImage >() ) ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image; } notifyUser( InfoNowPlaying, messageText, image ); }
bool newReleaseSort( const InfoStringHash& left, const InfoStringHash& right ) { if ( left.contains( "rank" ) && right.contains( "rank" ) ) { const int lRank = left[ "rank" ].toInt(); const int rRank = right[ "rank" ].toInt(); return lRank < rRank; } if ( left.contains( "date" ) && right.contains( "date" ) ) { const QDate lDate = QDate::fromString( left[ "date" ], "yyyy-MM-dd" ); const QDate rDate = QDate::fromString( right[ "date" ], "yyyy-MM-dd" ); return lDate > rDate; } return true; }
void EchonestPlugin::getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { return; } InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "artist" ) ) { return; } Echonest::Artist artist( hash["artist"] ); QNetworkReply *reply = artist.fetchBiographies(); reply->setProperty( "artist", QVariant::fromValue< Echonest::Artist >( artist ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( getArtistBiographySlot() ) ); }
void RoviPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { emit info( requestData, QVariant() ); return; } InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "artist" ) || !hash.contains( "album" ) ) { emit info( requestData, QVariant() ); return; } Tomahawk::InfoSystem::InfoStringHash criteria; criteria["artist"] = hash["artist"]; criteria["album"] = hash["album"]; emit getCachedInfo( criteria, 0, requestData ); }
/** Audio state slots */ void MprisPlugin::audioStarted( const QVariant& input ) { if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; m_playbackStatus = "Playing"; if ( map.contains( "coveruri" ) ) m_coverTempFile = map[ "coveruri" ].toString(); notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" ); }
void SnoreNotifyPlugin::inboxReceived( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; if ( !map.contains( "sourceinfo" ) || !map[ "sourceinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) ) return; InfoStringHash src = map[ "sourceinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !src.contains( "friendlyname" ) ) return; QString messageText; // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. messageText = tr( "%1 sent you\n%2%4 %3.", "%1 is a nickname, %2 is a title, %3 is an artist, %4 is the preposition used to link track and artist ('by' in english)" ) .arg( src["friendlyname"].toHtmlEscaped() ) .arg( hash[ "title" ].toHtmlEscaped() ) .arg( hash[ "artist" ].toHtmlEscaped() ) .arg( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) ); // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text messageText = QString( "<i></i>%1" ).arg( messageText ); Snore::Icon icon( RESPATH "images/inbox-512x512.png" ); notifyUser( Tomahawk::InfoSystem::InfoInboxReceived, messageText, icon ); }
void FdoNotifyPlugin::nowPlaying( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; QString messageText; // If the window manager supports notification styling then use it. if ( m_wmSupportsBodyMarkup ) { // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. QString album; if ( !hash[ "album" ].isEmpty() ) album = tr( "<br /><i>on</i> %1", "%1 is an album name" ).arg( Qt::escape( hash[ "album" ] ) ); messageText = tr( "%1<br /><i>by</i> %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( Qt::escape( hash[ "title" ] ) ) .arg( Qt::escape( hash[ "artist" ] ) ) .arg( album ); } else { QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( " %1" ).arg( tr( "on \"%1\"", "%1 is an album name" ).arg( hash[ "album" ] ) ); messageText = tr( "\"%1\" by %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( album ); } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << m_nowPlayingId; //notification_id arguments << QString(); //app_icon arguments << QString( "Tomahawk - Now Playing" ); //summary arguments << messageText; //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); // If there is a cover availble use it, else use Tomahawk logo as default. QImage image; if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) image = QImage( map[ "coveruri" ].toString(), "PNG" ); else image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); // Convert image to QVariant and scale to a consistent size. dict[ "image_data" ] = ImageConverter::variantForImage( image.scaledToHeight( getNotificationIconHeight() ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); // Handle reply in a callback, so that this a non-blocking call QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) ); }
void FdoNotifyPlugin::nowPlaying( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; QString messageText; // If the window manager supports notification styling then use it. if ( m_wmSupportsBodyMarkup ) { // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( "\n<i>%1</i> %2" ) .arg( tr( "on", "'on' is followed by an album name" ) ) .arg( escapeHtml( hash[ "album" ] ) ); messageText = tr( "%1%4 %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing, %4 is the preposition used to link track and artist ('by' in english)" ) .arg( escapeHtml( hash[ "title" ] ) ) .arg( escapeHtml( hash[ "artist" ] ) ) .arg( album ) .arg( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) ); // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text messageText = QString( "<i></i>%1" ).arg( messageText ); } else { QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( " %1" ).arg( tr( "on \"%1\"", "%1 is an album name" ).arg( hash[ "album" ] ) ); messageText = tr( "\"%1\" by %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( album ); } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QVariantMap hints; hints["desktop-entry"] = QString( "tomahawk" ); // If there is a cover availble use it, else use Tomahawk logo as default. QImage image; if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) image = QImage( map[ "coveruri" ].toString(), "PNG" ); else image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); // Convert image to QVariant and scale to a consistent size. hints[ "image_data" ] = ImageConverter::variantForImage( image.scaledToHeight( getNotificationIconHeight() ) ); QDBusPendingReply<> reply = notifications_interface->Notify( TOMAHAWK_APPLICATION_NAME, // app_name m_nowPlayingId, // notification_id "", // app_icon tr( "Tomahawk - Now Playing" ), // summary messageText, // body QStringList(), // actions hints, // hints -1 // expire_timeout ); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this ); connect( watcher, SIGNAL( finished( QDBusPendingCallWatcher* ) ), SLOT( dbusPlayingReplyReceived( QDBusPendingCallWatcher* ) ) ); }
void FdoNotifyPlugin::inboxReceived( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) return; QVariantMap map = input.toMap(); if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; if ( !map.contains( "sourceinfo" ) || !map[ "sourceinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) return; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) ) return; InfoStringHash src = map[ "sourceinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !src.contains( "friendlyname" ) ) return; QString messageText; // If the window manager supports notification styling then use it. if ( m_wmSupportsBodyMarkup ) { // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. messageText = tr( "%1 sent you\n%2%4 %3.", "%1 is a nickname, %2 is a title, %3 is an artist, %4 is the preposition used to link track and artist ('by' in english)" ) .arg( escapeHtml( src["friendlyname"] ) ) .arg( escapeHtml( hash[ "title" ] ) ) .arg( escapeHtml( hash[ "artist" ] ) ) .arg( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) ); // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text messageText = QString( "<i></i>%1" ).arg( messageText ); } else { messageText = tr( "%1 sent you \"%2\" by %3.", "%1 is a nickname, %2 is a title, %3 is an artist" ) .arg( src["friendlyname"] ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ); } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QVariantMap hints; hints["desktop-entry"] = QString( "tomahawk" ); // Convert image to QVariant and scale to a consistent size. hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); notifications_interface->Notify( "Tomahawk", // app_name m_nowPlayingId, // notification_id "", // app_icon "Tomahawk - Track received", // summary messageText, // body QStringList(), // actions hints, // hints -1 // expire_timeout ); }