From 5056dfd8cdef3df4aaa56ed63ec2c8a36f04b324 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Fri, 31 May 2013 17:23:14 +0000 Subject: [PATCH] Fix case when no response is receveid from wikipedia or last.fm --- context/metaengine.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/context/metaengine.cpp b/context/metaengine.cpp index c4b3d0412..83637b360 100644 --- a/context/metaengine.cpp +++ b/context/metaengine.cpp @@ -24,6 +24,13 @@ #include "metaengine.h" #include "wikipediaengine.h" #include "lastfmengine.h" +#include + +//#define DBUG qWarning() << "MetaEngine" + +#ifndef DBUG +#define DBUG qDebug() +#endif static const QLatin1String constBlankResp("-"); @@ -55,6 +62,7 @@ QString MetaEngine::translateLinks(QString text) const void MetaEngine::search(const QStringList &query, Mode mode) { + DBUG << __FUNCTION__ << query << (int)mode; responses.clear(); wiki->cancel(); lastfm->cancel(); @@ -64,21 +72,26 @@ void MetaEngine::search(const QStringList &query, Mode mode) void MetaEngine::wikiResponse(const QString &html, const QString &lang) { + DBUG << __FUNCTION__ << html.isEmpty() << lang.isEmpty(); if (!html.isEmpty()) { // Got a wikipedia reponse, use it! + DBUG << __FUNCTION__ << "Got wiki response!"; lastfm->cancel(); emit searchResult(html, lang); responses.clear(); } else if (responses[LastFm].html.isEmpty()) { + DBUG << __FUNCTION__ << "Wiki empty, but not received last.fm"; // Wikipedia response is empty, but have not received last.fm reply yet. // So, indicate that Wikipedia was empty - and wait for last.fm responses[Wiki]=Response(constBlankResp, lang); } else if (constBlankResp==responses[LastFm].html) { - // Last.fmn is empty as well :-( + DBUG << __FUNCTION__ << "Both responses empty"; + // Last.fm is empty as well :-( emit searchResult(QString(), QString()); responses.clear(); } else { // Got a last.fm response, use that! + DBUG << __FUNCTION__ << "Wiki empty, last.fm not - so use last.fm"; emit searchResult(responses[LastFm].html, responses[LastFm].lang); responses.clear(); } @@ -86,12 +99,15 @@ void MetaEngine::wikiResponse(const QString &html, const QString &lang) void MetaEngine::lastFmResponse(const QString &html, const QString &lang) { + DBUG << __FUNCTION__ << html.isEmpty() << lang.isEmpty(); if (constBlankResp==responses[Wiki].html) { // Wikipedia failed, so use last.fm response... + DBUG << __FUNCTION__ << "Wiki failed, so use last.fm"; emit searchResult(html, lang); responses.clear(); } else if (responses[Wiki].html.isEmpty()) { // No Wikipedia response yet, so save last.fm response... - responses[Wiki]=Response(html.isEmpty() ? constBlankResp : html, lang); + DBUG << __FUNCTION__ << "No wiki response, save last.fm"; + responses[LastFm]=Response(html.isEmpty() ? constBlankResp : html, lang); } }