diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 9bcc0a141..41f5eab41 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -115,6 +115,7 @@ set( libGuiSources utils/BinaryInstallerHelper.cpp utils/BinaryExtractWorker.cpp utils/SharedTimeLine.cpp + utils/WebResultHintChecker.cpp widgets/AnimatedCounterLabel.cpp widgets/Breadcrumb.cpp diff --git a/src/libtomahawk/Playlist.cpp b/src/libtomahawk/Playlist.cpp index 8966f8484..9550d20ea 100644 --- a/src/libtomahawk/Playlist.cpp +++ b/src/libtomahawk/Playlist.cpp @@ -524,8 +524,8 @@ Playlist::setRevision( const QString& rev, foreach( const plentry_ptr& entry, m_entries ) { - connect( entry->query().data(), SIGNAL( resultsAdded( QList ) ), - SLOT( onResultsFound( QList ) ), Qt::UniqueConnection ); + connect( entry->query().data(), SIGNAL( resultsChanged() ), + SLOT( onResultsChanged() ), Qt::UniqueConnection ); } setBusy( false ); @@ -620,9 +620,8 @@ Playlist::resolve() void -Playlist::onResultsFound( const QList& results ) +Playlist::onResultsChanged() { - Q_UNUSED( results ); m_locallyChanged = true; } diff --git a/src/libtomahawk/Playlist.h b/src/libtomahawk/Playlist.h index 23129a23f..bb4368f3c 100644 --- a/src/libtomahawk/Playlist.h +++ b/src/libtomahawk/Playlist.h @@ -293,7 +293,7 @@ protected: private slots: - void onResultsFound( const QList& results ); + void onResultsChanged(); void onResolvingFinished(); void onDeleteResult( SourceTreePopupDialog* ); diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 1ae0593b7..9b8c8e391 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -36,6 +36,7 @@ #include "audio/AudioEngine.h" #include "utils/Logger.h" +#include "utils/WebResultHintChecker.h" using namespace Tomahawk; @@ -772,6 +773,16 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co } +void +Query::setSaveHTTPResultHint( bool saveResultHint ) +{ + m_saveResultHint = saveResultHint; + + // Make sure it's a valid url + new WebResultHintChecker( m_ownRef.toStrongRef() ); +} + + #ifndef ENABLE_HEADLESS QPixmap Query::cover( const QSize& size, bool forceLoad ) const diff --git a/src/libtomahawk/Query.h b/src/libtomahawk/Query.h index 8216445ac..dc9899ed2 100644 --- a/src/libtomahawk/Query.h +++ b/src/libtomahawk/Query.h @@ -164,7 +164,7 @@ public: void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions ); QString socialActionDescription( const QString& action, DescriptionMode mode ) const; - void setSaveHTTPResultHint( bool saveResultHint ) { m_saveResultHint = saveResultHint; } + void setSaveHTTPResultHint( bool saveResultHint ); bool saveHTTPResultHint() const { return m_saveResultHint; } QList similarTracks() const; diff --git a/src/libtomahawk/utils/SoundcloudParser.cpp b/src/libtomahawk/utils/SoundcloudParser.cpp index 22f984859..75241364a 100644 --- a/src/libtomahawk/utils/SoundcloudParser.cpp +++ b/src/libtomahawk/utils/SoundcloudParser.cpp @@ -103,9 +103,9 @@ SoundcloudParser::parseTrack( const QVariantMap& res ) if ( !q.isNull() ) { - tLog() << "Setting resulthint to " << res.value( "stream_url" ); - q->setResultHint( res.value( "trackuri" ).toString() + "&client_id=TiNg2DRYhBnp01DA3zNag" ); - q->setProperty( "annotation", res.value( "trackuri" ).toString() + "&client_id=TiNg2DRYhBnp01DA3zNag" ); + tLog() << "Setting resulthint to " << res.value( "stream_url" ) << res; + q->setResultHint( res.value( "stream_url" ).toString() + "?client_id=TiNg2DRYhBnp01DA3zNag" ); + q->setSaveHTTPResultHint( true ); m_tracks << q; } diff --git a/src/libtomahawk/utils/WebResultHintChecker.cpp b/src/libtomahawk/utils/WebResultHintChecker.cpp new file mode 100644 index 000000000..0ae06f08f --- /dev/null +++ b/src/libtomahawk/utils/WebResultHintChecker.cpp @@ -0,0 +1,79 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ +#include "WebResultHintChecker.h" + +#include "Query.h" +#include "Result.h" +#include "Source.h" +#include "utils/Closure.h" +#include "utils/Logger.h" + +#include +#include + +using namespace Tomahawk; + +WebResultHintChecker::WebResultHintChecker( const query_ptr& q ) + : QObject( 0 ) + , m_query( q ) +{ + m_url = q->resultHint(); + + foreach ( const result_ptr& result, q->results() ) + { + if ( result->url() == m_url ) + { + m_result = result; + break; + } + } + + // Nothing to do + if ( m_url.isEmpty() || !m_url.startsWith( "http" ) ) + { + deleteLater(); + return; + } + + QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( m_url ) ) ); + NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ) ); +} + +WebResultHintChecker::~WebResultHintChecker() +{ + +} + + +void +WebResultHintChecker::headFinished( QNetworkReply* reply ) +{ + if ( reply->error() != QNetworkReply::NoError ) + { + // Error getting headers for the http resulthint, remove it from the result + // as it's definitely not playable + tLog() << "Removing HTTP result from query since HEAD request failed to verify it was a valid url:" << m_url; + if ( !m_result.isNull() ) + m_query->removeResult( m_result ); + if ( m_query->resultHint() == m_url ) + m_query->setResultHint( QString() ); + } + + reply->deleteLater(); + deleteLater(); +} diff --git a/src/libtomahawk/utils/WebResultHintChecker.h b/src/libtomahawk/utils/WebResultHintChecker.h new file mode 100644 index 000000000..593d33fa3 --- /dev/null +++ b/src/libtomahawk/utils/WebResultHintChecker.h @@ -0,0 +1,47 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ +#ifndef WEB_RESULT_HINT_CHECKER_H +#define WEB_RESULT_HINT_CHECKER_H + +#include "Typedefs.h" + +#include + +class QNetworkReply; + +namespace Tomahawk { + +class WebResultHintChecker : public QObject +{ + Q_OBJECT +public: + WebResultHintChecker( const query_ptr& q ); + virtual ~WebResultHintChecker(); + +private slots: + void headFinished( QNetworkReply* reply ); + +private: + query_ptr m_query; + result_ptr m_result; + QString m_url; +}; + +} + +#endif