From e968e84fa314603ebe9819cdec2a12aa1ebe5fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Mon, 3 Dec 2012 20:19:01 +0100 Subject: [PATCH] Revert "Resulthintcheck" This reverts commit c5dd1ebf2fb6ed1113e4f2b35160c5edbc5a4069. --- .../generic/charts/ChartsPlugin.cpp | 7 +- src/libtomahawk/CMakeLists.txt | 2 - src/libtomahawk/playlist/PlaylistModel.cpp | 4 +- .../utils/CustomResultHintChecker.cpp | 119 ----------- .../utils/CustomResultHintChecker.h | 53 ----- src/libtomahawk/utils/ResultHintChecker.cpp | 201 ------------------ src/libtomahawk/utils/ResultHintChecker.h | 66 ------ src/libtomahawk/utils/TomahawkUtils.cpp | 6 - src/libtomahawk/utils/TomahawkUtils.h | 1 - .../utils/WebResultHintChecker.cpp | 88 +++++++- src/libtomahawk/utils/WebResultHintChecker.h | 17 +- 11 files changed, 100 insertions(+), 464 deletions(-) delete mode 100644 src/libtomahawk/utils/CustomResultHintChecker.cpp delete mode 100644 src/libtomahawk/utils/CustomResultHintChecker.h delete mode 100644 src/libtomahawk/utils/ResultHintChecker.cpp delete mode 100644 src/libtomahawk/utils/ResultHintChecker.h diff --git a/src/infoplugins/generic/charts/ChartsPlugin.cpp b/src/infoplugins/generic/charts/ChartsPlugin.cpp index 7f64f1bc6..1092abdf4 100644 --- a/src/infoplugins/generic/charts/ChartsPlugin.cpp +++ b/src/infoplugins/generic/charts/ChartsPlugin.cpp @@ -37,8 +37,8 @@ #include "utils/TomahawkCache.h" #include "Source.h" -//#define CHART_URL "http://charts.tomahawk-player.org/" -#define CHART_URL "http://localhost:8080/" +#define CHART_URL "http://charts.tomahawk-player.org/" +//#define CHART_URL "http://localhost:8080/" #include #include @@ -665,11 +665,8 @@ ChartsPlugin::chartReturned() else setChartType( None ); - int count = 0; foreach ( const QVariant& chartR, chartResponse ) { - if( count++ >= 1) - break; QString title, artist, album, streamUrl; QVariantMap chartMap = chartR.toMap(); diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 4968dcd52..35d33e356 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -120,8 +120,6 @@ set( libGuiSources utils/BinaryInstallerHelper.cpp utils/BinaryExtractWorker.cpp utils/SharedTimeLine.cpp - utils/ResultHintChecker.cpp - utils/CustomResultHintChecker.cpp utils/WebResultHintChecker.cpp utils/NetworkReply.cpp diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index e5f99fffa..f470aa157 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -35,7 +35,7 @@ #include "PlayableItem.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" -#include +#include using namespace Tomahawk; @@ -281,7 +281,7 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); - ResultHintChecker::checkQuery( entry->query() ); + WebResultHintChecker::checkQuery( entry->query() ); } if ( !m_waitingForResolved.isEmpty() ) diff --git a/src/libtomahawk/utils/CustomResultHintChecker.cpp b/src/libtomahawk/utils/CustomResultHintChecker.cpp deleted file mode 100644 index bfab472ed..000000000 --- a/src/libtomahawk/utils/CustomResultHintChecker.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012, Hugo Lindström - * - * 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 "CustomResultHintChecker.h" -#include "ResultHintChecker.h" - -#include -#include -#include -#include "Query.h" -#include "utils/NetworkReply.h" -#include "utils/Closure.h" -using namespace Tomahawk; - - -CustomResultHintChecker::CustomResultHintChecker( const query_ptr& q ) - : ResultHintChecker( q ) - , m_query( q ) -{ - if( !isValid() ) - { - qDebug() << Q_FUNC_INFO << "invalid:" << url(); - return; - } - - qDebug() << Q_FUNC_INFO << url(); - - handleResultHint(); -} - -void -CustomResultHintChecker::handleResultHint() -{ - - if ( url().startsWith( "hnhh" ) ) - { - QUrl httpUrl = QUrl::fromUserInput( url() ); - httpUrl.setScheme( "http" ); - - NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( httpUrl ) ) ); - - connect( this, SIGNAL( result( result_ptr ) ), this, SLOT( handleHnhhResult( result_ptr ) ) ); - connect( reply, SIGNAL( finished() ), SLOT( hnhhFinished() ) ); - return; - } -} - -void -CustomResultHintChecker::handleHnhhResult( result_ptr result ) -{ - if( !result.isNull() ) - { - - qDebug() << Q_FUNC_INFO << "Setting expiration for hotnewhiphop" << result->toString(); - qDebug() << Q_FUNC_INFO << url() << resultHint(); - - } -} - -void -CustomResultHintChecker::hnhhFinished() -{ - NetworkReply* r = qobject_cast( sender() ); - r->deleteLater(); - - bool foundStreamable = false; - // Intentionally accepts unknown error - if ( r->reply()->error() != ( QNetworkReply::NoError | QNetworkReply::UnknownNetworkError ) ) - { - - QXmlStreamReader xmlStream( r->reply()->readAll() ); - - if ( xmlStream.error() != QXmlStreamReader::NoError ) - { - qDebug() << "XML ERROR!" << xmlStream.errorString(); - } - else - { - while (!xmlStream.atEnd() ) - { - xmlStream.readNext(); - if ( xmlStream.isStartElement() ) - { - if ( xmlStream.name().toString() == "song" ) - { - const QString streamUrl = QString( xmlStream.attributes().value("filename").toLatin1() ); - // Dont save this resulthint, it needs to revalidate - qDebug() << Q_FUNC_INFO << "GOT STREAMABLE " << streamUrl; - setResultHint( streamUrl, false ); - foundStreamable = true; - break; - } - } - } - } - } - - if ( !foundStreamable) - { - removeHint(); - } - - deleteLater(); -} diff --git a/src/libtomahawk/utils/CustomResultHintChecker.h b/src/libtomahawk/utils/CustomResultHintChecker.h deleted file mode 100644 index 179560e58..000000000 --- a/src/libtomahawk/utils/CustomResultHintChecker.h +++ /dev/null @@ -1,53 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012, Hugo Lindström - * - * 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 Custom_RESULT_HINT_CHECKER_H -#define Custom_RESULT_HINT_CHECKER_H - -#include "Typedefs.h" -#include -#include -#include "ResultHintChecker.h" - -namespace Tomahawk -{ - -/** - * @brief The CustomResultHintChecker class - * This class is to be used with custom protocol to retrieve - * streamable urls for resulthints. - */ -class CustomResultHintChecker : public ResultHintChecker -{ - Q_OBJECT -public: - CustomResultHintChecker( const query_ptr& q ); - virtual ~CustomResultHintChecker(){} -private slots: - /* HotNewHiphop specific */ - void hnhhFinished(); - void handleHnhhResult( result_ptr result ); -private: - void handleResultHint(); - QString m_streamUrl; - query_ptr m_query; -}; - - -} - -#endif diff --git a/src/libtomahawk/utils/ResultHintChecker.cpp b/src/libtomahawk/utils/ResultHintChecker.cpp deleted file mode 100644 index 975ad44f0..000000000 --- a/src/libtomahawk/utils/ResultHintChecker.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012, Leo Franchi - * Copyright 2012, Hugo Lindström - * - * 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 "CustomResultHintChecker.h" -#include -#include -#include -#include "Query.h" -#include "Result.h" -#include "Source.h" -#include "Pipeline.h" -#include "utils/NetworkReply.h" -#include "utils/Logger.h" - -using namespace Tomahawk; - -ResultHintChecker::ResultHintChecker( const query_ptr& q ) - : QObject( 0 ) - , m_query( q ) - , m_isValid( false ) -{ - Q_ASSERT( !m_query.isNull() ); - m_url = q->resultHint(); - - connect( m_query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( onResolvingFinished( bool ) ) ); - connect( m_query.data(), SIGNAL( resultsRemoved( const Tomahawk::result_ptr& ) ), this, SLOT( onResultsRemoved( const Tomahawk::result_ptr& ) ) ); - connect( m_query.data(), SIGNAL( resultsChanged() ), this, SLOT( onResultsChanged() ) ); - connect( m_query.data(), SIGNAL( updated() ), this, SLOT( onResultsChanged() ) ); - connect( m_query.data(), SIGNAL( resultsAdded( const QList& ) ), this, SLOT( onResultsAdded( const QList& ) ) ); - - check( m_url ); -} - - -ResultHintChecker::~ResultHintChecker() -{ -} - -/** - * @brief ResultHintChecker::checkQuery - * @param query - * Static function to initiate resulthint checkers - */ -void -ResultHintChecker::checkQuery( const query_ptr& query ) -{ - if ( !query->resultHint().isEmpty() && TomahawkUtils::whitelistedHttpResultHint( query->resultHint() ) ) - new WebResultHintChecker( query ); - - else if ( !query->resultHint().isEmpty() && TomahawkUtils::whitelistedCustomProtocolResultHint( query->resultHint() ) ) - new CustomResultHintChecker( query ); -} - - -void -ResultHintChecker::onResultsRemoved(const result_ptr &result) -{ - qDebug() << Q_FUNC_INFO << result->toString(); -} - -void -ResultHintChecker::onResultsChanged() -{ - foreach( const result_ptr& rp, m_query->results() ) - { - qDebug() << Q_FUNC_INFO << rp->toString(); - } -} - - -void -ResultHintChecker::checkQueries( const QList< query_ptr >& queries ) -{ - foreach ( const query_ptr& query, queries ) - checkQuery( query ); -} - -void -ResultHintChecker::onResolvingFinished( bool hasResults ) -{ - foreach ( const result_ptr& result, m_query->results() ) - { - qDebug() << Q_FUNC_INFO << "result url():" << result->url(); - } -} - -void -ResultHintChecker::onResultsAdded( const QList& results ) -{ - foreach( const result_ptr& result, results ) - { - qDebug() << Q_FUNC_INFO << "result url():" << result->url(); - } - -} - -QString -ResultHintChecker::resultHint() const -{ - return m_query->resultHint(); -} - -bool -ResultHintChecker::isValid() -{ - return m_isValid; -} - - -void -ResultHintChecker::check( const QUrl &url ) -{ - - qDebug() << Q_FUNC_INFO << url; - // Nothing to do - if ( url.isEmpty() || - ( !TomahawkUtils::whitelistedHttpResultHint( url.toString() ) && - !TomahawkUtils::whitelistedCustomProtocolResultHint( url.toString() ) - ) ) - { - if ( !url.isEmpty() || m_query->saveHTTPResultHint() ) - removeHint(); - - deleteLater(); - return; - } - - m_isValid = true; - -} - -result_ptr -ResultHintChecker::getResultPtr() -{ - result_ptr foundResult; - foreach ( const result_ptr& result, m_query->results() ) - { - if ( result->url() == m_url ) - { - foundResult = result; - break; - } - } - - return foundResult; -} - -void -ResultHintChecker::setResultHint(const QString &url, const bool saveHint) -{ - - qDebug() << Q_FUNC_INFO << "Setting new resulthint" << url << "save it? " << saveHint; - - result_ptr foundResult = getResultPtr(); - - if ( !foundResult.isNull() ) - { - qDebug() << Q_FUNC_INFO << "Removing old result " << foundResult->toString(); - m_query->removeResult( foundResult ); - } - - m_query->setResultHint( url ); - m_query->setSaveHTTPResultHint( saveHint ); - -} - - -void -ResultHintChecker::removeHint() -{ - tLog() << "Removing invalid resulthint from query:" << m_url; - - result_ptr foundResult = getResultPtr(); - - if ( !foundResult.isNull() ) - m_query->removeResult( foundResult ); - - if ( m_query->resultHint() == m_url ) - { - m_query->setResultHint( QString() ); - } - - m_query->setSaveHTTPResultHint( false ); -} diff --git a/src/libtomahawk/utils/ResultHintChecker.h b/src/libtomahawk/utils/ResultHintChecker.h deleted file mode 100644 index b35c3966f..000000000 --- a/src/libtomahawk/utils/ResultHintChecker.h +++ /dev/null @@ -1,66 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012, Leo Franchi - * Copyright 2012, Hugo Lindström - * - * 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 RESULT_HINT_CHECKER_H -#define RESULT_HINT_CHECKER_H - -#include "Typedefs.h" -#include - -namespace Tomahawk -{ - -class ResultHintChecker : public QObject -{ - Q_OBJECT -public: - explicit ResultHintChecker( const query_ptr& q ); - virtual ~ResultHintChecker(); - - static void checkQuery( const query_ptr& query ); - static void checkQueries( const QList< query_ptr >& queries ); - - bool isValid(); - - QString url() const { return m_url; } - QString resultHint() const; - - void setUrl( const QString& url ) { m_url = url; } - void setResultHint( const QString &url, const bool saveHint ); - void removeHint(); - -signals: - void result( result_ptr ); - -private slots: - void onResolvingFinished( bool hasResults ); - void onResultsAdded( const QList& results ); - void onResultsRemoved( const Tomahawk::result_ptr& result ); - void onResultsChanged(); - -private: - void check( const QUrl& url ); - result_ptr getResultPtr(); - query_ptr m_query; - QString m_url; - bool m_isValid; -}; - -} - -#endif diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 306fb2bcf..77a0ccb82 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -950,12 +950,6 @@ whitelistedHttpResultHint( const QString& url ) } -bool -whitelistedCustomProtocolResultHint( const QString& url ) -{ - return url.startsWith( "hnhh" ); -} - } // ns #include "TomahawkUtils.moc" diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index 7488c7929..65d52d6e9 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -129,7 +129,6 @@ namespace TomahawkUtils void copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver ); DLLEXPORT bool whitelistedHttpResultHint( const QString& url ); - DLLEXPORT bool whitelistedCustomProtocolResultHint( const QString& url ); /** * This helper is designed to help "update" an existing playlist with a newer revision of itself. diff --git a/src/libtomahawk/utils/WebResultHintChecker.cpp b/src/libtomahawk/utils/WebResultHintChecker.cpp index fb2537799..ddea82547 100644 --- a/src/libtomahawk/utils/WebResultHintChecker.cpp +++ b/src/libtomahawk/utils/WebResultHintChecker.cpp @@ -1,7 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012, Leo Franchi - * Copyright 2012, Hugo Lindström + * * 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 @@ -17,29 +17,107 @@ */ #include "WebResultHintChecker.h" -#include "ResultHintChecker.h" #include #include #include + #include "Query.h" +#include "Result.h" +#include "Source.h" +#include "Pipeline.h" #include "utils/NetworkReply.h" +#include "utils/Logger.h" using namespace Tomahawk; WebResultHintChecker::WebResultHintChecker( const query_ptr& q ) - : ResultHintChecker( q ) + : QObject( 0 ) + , m_query( q ) { - if( !isValid() ) + Q_ASSERT( !m_query.isNull() ); + + m_url = q->resultHint(); + + if ( Pipeline::instance()->isResolving( m_query ) ) + connect( m_query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( onResolvingFinished( bool ) ) ); + else + check( QUrl::fromUserInput( m_url ) ); +} + + +WebResultHintChecker::~WebResultHintChecker() +{ +} + + +void +WebResultHintChecker::checkQuery( const query_ptr& query ) +{ + if ( !query->resultHint().isEmpty() && query->resultHint().startsWith( "http" ) ) + new WebResultHintChecker( query ); +} + + +void +WebResultHintChecker::checkQueries( const QList< query_ptr >& queries ) +{ + foreach ( const query_ptr& query, queries ) + checkQuery( query ); +} + + +void +WebResultHintChecker::onResolvingFinished( bool hasResults ) +{ + Q_UNUSED( hasResults ); + + check( QUrl::fromUserInput( m_url ) ); +} + + +void +WebResultHintChecker::check( const QUrl &url ) +{ + // Nothing to do + if ( url.isEmpty() || !url.toString().startsWith( "http" ) ) { + if ( !url.isEmpty() || m_query->saveHTTPResultHint() ) + removeHint(); + + deleteLater(); return; } - NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->head( QNetworkRequest( QUrl::fromUserInput( url() ) ) ) ); + NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->head( QNetworkRequest( url ) ) ); connect( reply, SIGNAL( finished() ), SLOT( headFinished() ) ); } + +void +WebResultHintChecker::removeHint() +{ + tLog() << "Removing HTTP result from query since HEAD request failed to verify it was a valid url:" << m_url; + + result_ptr foundResult; + foreach ( const result_ptr& result, m_query->results() ) + { + if ( result->url() == m_url ) + { + foundResult = result; + break; + } + } + + if ( !foundResult.isNull() ) + m_query->removeResult( foundResult ); + if ( m_query->resultHint() == m_url ) + m_query->setResultHint( QString() ); + m_query->setSaveHTTPResultHint( false ); +} + + void WebResultHintChecker::headFinished() { diff --git a/src/libtomahawk/utils/WebResultHintChecker.h b/src/libtomahawk/utils/WebResultHintChecker.h index 469e2fb68..58dc79c95 100644 --- a/src/libtomahawk/utils/WebResultHintChecker.h +++ b/src/libtomahawk/utils/WebResultHintChecker.h @@ -1,7 +1,6 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012, Leo Franchi - * Copyright 2012, Hugo Lindström * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,21 +19,31 @@ #define WEB_RESULT_HINT_CHECKER_H #include "Typedefs.h" + #include -#include "ResultHintChecker.h" namespace Tomahawk { -class WebResultHintChecker : public ResultHintChecker +class WebResultHintChecker : public QObject { Q_OBJECT public: WebResultHintChecker( const query_ptr& q ); - virtual ~WebResultHintChecker(){} + virtual ~WebResultHintChecker(); + + static void checkQuery( const query_ptr& query ); + static void checkQueries( const QList< query_ptr >& queries ); + private slots: void headFinished(); + + void check( const QUrl& url ); + + void onResolvingFinished( bool hasResults ); private: + void removeHint(); + query_ptr m_query; QString m_url; };