Fix case when no response is receveid from wikipedia or last.fm

This commit is contained in:
craig.p.drummond
2013-05-31 17:23:14 +00:00
committed by craig.p.drummond
parent 63ee2e6f38
commit 5056dfd8cd

View File

@@ -24,6 +24,13 @@
#include "metaengine.h"
#include "wikipediaengine.h"
#include "lastfmengine.h"
#include <QDebug>
//#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);
}
}