void RadioTuner::onTuneReturn() { if ( !d->m_retuneStation.url().isEmpty() ) { d->m_station = d->m_retuneStation; d->m_retuneStation = RadioStation(); } XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { qDebug() << lfm; d->m_station.setTitle( lfm["station"]["name"].text() ); d->m_station.setUrl( lfm["station"]["url"].text() ); emit title( lfm["station"]["name"].text() ); emit supportsDisco( lfm["station"]["supportsdiscovery"].text() == "1" ); d->fetchFiveMoreTracks(); } else { emit error( lfm.parseError().enumValue(), lfm.parseError().message() ); } }
void TrackWidget::onGotBuyLinks() { if ( !ui->buy->menu() ) { // make sure we don't process this again if the button was clicked twice XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { bool thingsToBuy = false; QMenu* menu = new QMenu( this ); menu->addAction( tr("Downloads") )->setEnabled( false ); // USD EUR GBP foreach ( const XmlQuery& affiliation, lfm["affiliations"]["downloads"].children( "affiliation" ) ) { bool isSearch = affiliation["isSearch"].text() == "1"; QAction* buyAction = 0; if ( isSearch ) buyAction = menu->addAction( tr("Search on %1").arg( affiliation["supplierName"].text() ) ); else buyAction = menu->addAction( tr("Buy on %1 %2").arg( affiliation["supplierName"].text(), unicorn::Label::price( affiliation["price"]["amount"].text(), affiliation["price"]["currency"].text() ) ) ); buyAction->setData( affiliation["buyLink"].text() ); thingsToBuy = true; } menu->addSeparator(); menu->addAction( tr("Physical") )->setEnabled( false ); foreach ( const XmlQuery& affiliation, lfm["affiliations"]["physicals"].children( "affiliation" ) ) { bool isSearch = affiliation["isSearch"].text() == "1"; QAction* buyAction = 0; if ( isSearch ) buyAction = menu->addAction( tr("Search on %1").arg( affiliation["supplierName"].text() ) ); else buyAction = menu->addAction( tr("Buy on %1 %2").arg( affiliation["supplierName"].text(), unicorn::Label::price( affiliation["price"]["amount"].text(), affiliation["price"]["currency"].text() ) ) ); buyAction->setData( affiliation["buyLink"].text() ); thingsToBuy = true; } ui->buy->setMenu( menu ); connect( menu, SIGNAL(triggered(QAction*)), SLOT(onBuyActionTriggered(QAction*)) ); ui->buy->click(); }
bool TrackImageFetcher::downloadImage( QNetworkReply* reply, const QString& root_node ) { XmlQuery lfm; if ( reply && lfm.parse( reply->readAll() ) ) { // cache all the sizes if ( root_node == "album" ) { m_track.album().setImageUrl( Track::MegaImage, lfm[root_node]["image size=mega"].text() ); m_track.album().setImageUrl( Track::ExtraLargeImage, lfm[root_node]["image size=extralarge"].text() ); m_track.album().setImageUrl( Track::LargeImage, lfm[root_node]["image size=large"].text() ); m_track.album().setImageUrl( Track::MediumImage, lfm[root_node]["image size=medium"].text() ); m_track.album().setImageUrl( Track::SmallImage, lfm[root_node]["image size=small"].text() ); } else if ( root_node == "artist" ) { m_track.artist().setImageUrl( Track::MegaImage, lfm[root_node]["image size=mega"].text() ); m_track.artist().setImageUrl( Track::ExtraLargeImage, lfm[root_node]["image size=extralarge"].text() ); m_track.artist().setImageUrl( Track::LargeImage, lfm[root_node]["image size=large"].text() ); m_track.artist().setImageUrl( Track::MediumImage, lfm[root_node]["image size=medium"].text() ); m_track.artist().setImageUrl( Track::SmallImage, lfm[root_node]["image size=small"].text() ); } } else { qWarning() << lfm.parseError().message(); } QUrl imageUrl = url( root_node ); qWarning() << root_node << imageUrl; if ( imageUrl.isValid() ) { QNetworkReply* get = lastfm::nam()->get( QNetworkRequest( imageUrl ) ); if ( root_node == "album" ) connect( get, SIGNAL(finished()), SLOT(onAlbumImageDownloaded()) ); else if ( root_node == "track" ) connect( get, SIGNAL(finished()), SLOT(onTrackImageDownloaded()) ); else connect( get, SIGNAL(finished()), SLOT(onArtistImageDownloaded()) ); return true; } return false; }
void RadioTuner::onGetPlaylistReturn() { // We shouldn't request another playlist for 2 seconds because we'll get the same one // in a different order. This QTimer will block until it has finished. If one or more // playlists have been requested in the meantime, it will fetch one on timeout d->m_twoSecondTimer->start( 2000 ); // This will block us fetching two playlists at once d->m_fetchingPlaylist = false; XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { qDebug() << lfm; d->m_station.setTitle( lfm["playlist"]["title"].text() ); // we don't get the radio url in the playlist //d->m_station.setUrl( lfm["station"]["url"].text() ); emit title( lfm["playlist"]["title"].text() ); Xspf* xspf = new Xspf( lfm["playlist"], this ); if ( xspf->isEmpty() ) { // give up after too many empty playlists :( if (!d->tryAgain()) emit error( ws::NotEnoughContent, "Not enough content" ); } else { d->m_retry_counter = 0; d->m_playlist << xspf->tracks(); emit trackAvailable(); } delete xspf; } else { qDebug() << lfm.parseError().message() << lfm.parseError().enumValue(); emit error( lfm.parseError().enumValue(), lfm.parseError().message() ); } }
void ShareDialog::onShared() { XmlQuery lfm; if ( lfm.parse( qobject_cast<QNetworkReply*>(sender()) ) ) { if ( lfm.attribute( "status" ) == "ok" ) close(); else { // TODO: display some kind of error message setEnabled( true ); } } else { // TODO: display some kind of error message setEnabled( true ); } }
void TrackImageFetcher::onTrackGotInfo( const QByteArray& data ) { XmlQuery lfm; if ( lfm.parse( data ) ) { lastfm::MutableTrack track( m_track ); track.setImageUrl( Track::MegaImage, lfm["track"]["image size=mega"].text() ); track.setImageUrl( Track::ExtraLargeImage, lfm["track"]["image size=extralarge"].text() ); track.setImageUrl( Track::LargeImage, lfm["track"]["image size=large"].text() ); track.setImageUrl( Track::MediumImage, lfm["track"]["image size=medium"].text() ); track.setImageUrl( Track::SmallImage, lfm["track"]["image size=small"].text() ); if (!downloadImage( 0, "track" )) startArtist(); } else { qWarning() << lfm.parseError().message(); } }
QMap<int, QString> //static Tag::list( QNetworkReply* r ) { QMap<int, QString> tags; XmlQuery lfm; if ( lfm.parse( r ) ) { foreach ( XmlQuery xq, lfm.children("tag") ) // we toLower always as otherwise it is ugly mixed case, as first // ever tag decides case, and Last.fm is case insensitive about it // anyway tags.insertMulti( xq["count"].text().toInt(), xq["name"].text().toLower() ); } else { qDebug() << lfm.parseError().message() << lfm.parseError().enumValue(); } return tags; }
void MetadataWidget::onArtistGotInfo() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); XmlQuery lfm; if ( lfm.parse( reply ) ) { m_globalArtistScrobbles = lfm["artist"]["stats"]["playcount"].text().toInt(); m_artistListeners = lfm["artist"]["stats"]["listeners"].text().toInt(); m_userArtistScrobbles = lfm["artist"]["stats"]["userplaycount"].text().toInt(); ui->artistPlays->setText( tr( "%L1" ).arg( m_globalArtistScrobbles ) ); ui->artistUserPlays->setText( tr( "%L1" ).arg( m_userArtistScrobbles ) ); ui->artistListeners->setText( tr( "%L1" ).arg( m_artistListeners ) ); ui->artistPlaysLabel->setText( tr( "Play(s)", "", m_globalArtistScrobbles ) ); ui->artistUserPlaysLabel->setText( tr( "Play(s) in your library", "", m_userArtistScrobbles ) ); ui->artistListenersLabel->setText( tr( "Listener(s)", "", m_artistListeners ) ); // Update the context now that we have the user track listens ui->context->setText( contextString( m_track ) ); { // Similar artists! QList<XmlQuery> artists = lfm["artist"]["similar"].children("artist").mid( 0, 4 ); if ( artists.count() != 0 ) { ui->similarArtistFrame->show(); ui->similarArtists->show(); QList<SimilarArtistWidget*> widgets; widgets << ui->artist1 << ui->artist2 << ui->artist3 << ui->artist4; QRegExp re( "/serve/(\\d*)s?/" ); for ( int i = 0 ; i < artists.count() ; ++i ) { widgets[i]->setArtist( artists[i]["name"].text() ); widgets[i]->setToolTip( artists[i]["name"].text() ); widgets[i]->loadUrl( artists[i]["image size=medium"].text().replace( re, "/serve/\\1s/" ), HttpImageWidget::ScaleNone ); widgets[i]->setHref( artists[i]["url"].text() ); } // "With yeah, blah and more." if ( artists.count() == 1 ) ui->radio->setDescription( tr( "With %1 and more." ).arg( artists[0]["name"].text() ) ); else if ( artists.count() >= 2 ) ui->radio->setDescription( tr( "With %1, %2 and more.").arg( artists[0]["name"].text(), artists[1]["name"].text() ) ); } } QList<XmlQuery> tags = lfm["artist"]["tags"].children("tag"); if ( tags.count() == 0 ) ui->artistTagsFrame->hide(); else { QString tagString = tr( "Popular tags:" ); for ( int i = 0 ; i < tags.count() ; ++i ) { if ( i == 0 ) tagString.append( QString( " %1" ).arg( Label::anchor( tags.at(i)["url"].text(), tags.at(i)["name"].text() ) ) ); else tagString.append( QString( " %1 %2" ).arg( QString::fromUtf8( "ยท" ), Label::anchor( tags.at(i)["url"].text(), tags.at(i)["name"].text() ) ) ); } ui->artistPopTags->setText( tagString ); } //TODO if empty suggest they edit it QString bio; { QStringList bioList = lfm["artist"]["bio"]["summary"].text().trimmed().split( "\r" ); foreach( const QString& p, bioList ) { QString pTrimmed = p.trimmed(); if( pTrimmed.isEmpty()) continue; bio += "<p>" + pTrimmed + "</p>"; } }