From: eshe Date: Fri, 20 Aug 2010 19:19:04 +0000 (+0100) Subject: Changed search to retry automatically couple of times before failing. X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=commitdiff_plain;h=40f8e10e1efc5019011df940328cdc734576143d;hp=d93782e7a5ae0fc072d094fd645cf415a34a2244 Changed search to retry automatically couple of times before failing. --- diff --git a/src/common/connectionmanager.cpp b/src/common/connectionmanager.cpp index f7b0f32..baa6e2d 100644 --- a/src/common/connectionmanager.cpp +++ b/src/common/connectionmanager.cpp @@ -429,10 +429,10 @@ bool ConnectionManager::waitSignal(bool* ready) killTimer(timer_); - if(timeout_) + /*if(timeout_) { qDebug() << "Connection request timed out"; - } + }*/ return *ready || !timeout_; } diff --git a/src/common/dastelefonbuch.cpp b/src/common/dastelefonbuch.cpp index 7cb36ad..68352e1 100644 --- a/src/common/dastelefonbuch.cpp +++ b/src/common/dastelefonbuch.cpp @@ -106,6 +106,14 @@ void DasTelefonbuch::addNumbers(SearchData* searchData, QString const& data, int index) { + if(data.isEmpty()) + { + qDebug() << "Server returned no data"; + setError(CONNECTION_FAILURE, "Server returned no data"); + emitRequestFinished(searchData, true, index); + return; + } + if(data.indexOf("1 Gesamttreffer") > 0) { addOnlyNumber(searchData, data, index); diff --git a/src/common/eniro.cpp b/src/common/eniro.cpp index 46fda30..edffeed 100644 --- a/src/common/eniro.cpp +++ b/src/common/eniro.cpp @@ -201,6 +201,13 @@ void Eniro::handleHttpData(int id, QByteArray const& data) if((searchIt = pendingSearches_.find(id)) != pendingSearches_.end()) { + if(data.isEmpty()) + { + setError(CONNECTION_FAILURE, "Server returned empty data"); + emitRequestFinished(id, searchIt.value(), true); + return; + } + // Load results from html data loadResults(id, data); } @@ -209,6 +216,13 @@ void Eniro::handleHttpData(int id, QByteArray const& data) else if((numberIt = pendingNumberRequests_.find(id)) != pendingNumberRequests_.end()) { + if(data.isEmpty()) + { + setError(CONNECTION_FAILURE, "Server returned empty data"); + emitRequestFinished(id, searchIt.value(), true); + return; + } + // Load number from html data loadNumber(id, data); } diff --git a/src/common/mobil1881.cpp b/src/common/mobil1881.cpp index 69327b0..a51d293 100644 --- a/src/common/mobil1881.cpp +++ b/src/common/mobil1881.cpp @@ -109,7 +109,9 @@ void Mobil1881::addNumbers(SearchData* searchData, if(data.isEmpty()) { qDebug() << "Server returned no data"; - qDebug() << "Headers: " << http_.lastResponse().toString(); + setError(CONNECTION_FAILURE, "Server returned no data"); + emitRequestFinished(searchData, true, index); + return; } if(data.indexOf("Last ned vCard") > 0) diff --git a/src/gui/resultwindow.cpp b/src/gui/resultwindow.cpp index dc1509f..1bd7cb4 100644 --- a/src/gui/resultwindow.cpp +++ b/src/gui/resultwindow.cpp @@ -30,7 +30,7 @@ #include "sourcecoreconfig.h" ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent), -source_(0), list_(0), connectionManager_(0), timer_(0), searching_(false) +source_(0), list_(0), connectionManager_(0), timer_(0), searching_(false), retries_(0) { setAttribute(Qt::WA_Maemo5StackedWindow); setWindowTitle(tr("Search results")); @@ -113,7 +113,9 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) list_->clear(); searching_ = true; - source_->search(Source::SearchDetails(details.name, details.location, details.type)); + retries_ = 0; + currentSearch_ = Source::SearchDetails(details.name, details.location, details.type); + source_->search(currentSearch_); } @@ -165,6 +167,15 @@ void ResultWindow::requestFinished(QVector const& results, if(error) { + if(retries_ < RETRIES) + { + qDebug() << "Searching failed, retrying..."; + retries_++; + list_->clear(); + source_->search(currentSearch_); + return; + } + QString errorString; Source::Error error = source_->error(); @@ -197,12 +208,6 @@ void ResultWindow::requestFinished(QVector const& results, setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); - if(timer_) - { - killTimer(timer_); - } - - timer_ = startTimer(SEARCH_INTERVAL); searching_ = false; } diff --git a/src/gui/resultwindow.h b/src/gui/resultwindow.h index 3391f7d..dde6501 100644 --- a/src/gui/resultwindow.h +++ b/src/gui/resultwindow.h @@ -35,7 +35,8 @@ public: ResultWindow(QWidget* parent = 0); ~ResultWindow(); static const int REQUEST_TIMEOUT = 30000; - static const int SEARCH_INTERVAL = 2000; + static const int SEARCH_INTERVAL = 1000; + static const int RETRIES = 2; signals: void itemSelected(Source::Result const& result); @@ -59,6 +60,8 @@ private: ConnectionManager* connectionManager_; int timer_; bool searching_; + int retries_; + Source::SearchDetails currentSearch_; };