Port last.fm cover provider to closures.

This commit is contained in:
John Maguire 2012-10-12 13:49:09 +02:00
parent 16fe238d98
commit e8f4496fea
2 changed files with 9 additions and 12 deletions

View File

@ -15,13 +15,15 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "lastfmcoverprovider.h" #include "lastfmcoverprovider.h"
#include "internet/lastfmcompat.h"
#include <QNetworkReply> #include <QNetworkReply>
#include "albumcoverfetcher.h"
#include "coverprovider.h"
#include "core/closure.h"
#include "internet/lastfmcompat.h"
LastFmCoverProvider::LastFmCoverProvider(QObject* parent) LastFmCoverProvider::LastFmCoverProvider(QObject* parent)
: CoverProvider("last.fm", parent) : CoverProvider("last.fm", parent)
{ {
@ -33,18 +35,13 @@ bool LastFmCoverProvider::StartSearch(const QString& artist, const QString& albu
params["album"] = album + " " + artist; params["album"] = album + " " + artist;
QNetworkReply* reply = lastfm::ws::post(params); QNetworkReply* reply = lastfm::ws::post(params);
connect(reply, SIGNAL(finished()), SLOT(QueryFinished())); NewClosure(reply, SIGNAL(finished()), this,
pending_queries_[reply] = id; SLOT(QueryFinished(QNetworkReply*, int)), reply, id);
return true; return true;
} }
void LastFmCoverProvider::QueryFinished() { void LastFmCoverProvider::QueryFinished(QNetworkReply* reply, int id) {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (!reply || !pending_queries_.contains(reply))
return;
int id = pending_queries_.take(reply);
reply->deleteLater(); reply->deleteLater();
CoverSearchResults results; CoverSearchResults results;

View File

@ -36,7 +36,7 @@ public:
bool StartSearch(const QString& artist, const QString& album, int id); bool StartSearch(const QString& artist, const QString& album, int id);
private slots: private slots:
void QueryFinished(); void QueryFinished(QNetworkReply* reply, int id);
private: private:
QMap<QNetworkReply*, int> pending_queries_; QMap<QNetworkReply*, int> pending_queries_;