X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=blobdiff_plain;f=src%2Fgui%2Fresultwindow.cpp;h=1bd7cb4684c1fcb0bfe627c80b79197b05310f75;hp=07349ff67e86aeca7b357aa995a5216e5a74acdf;hb=40f8e10e1efc5019011df940328cdc734576143d;hpb=a1c81fc3e2fd0b22b1897214a20c498110369fd9 diff --git a/src/gui/resultwindow.cpp b/src/gui/resultwindow.cpp index 07349ff..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), -sourceId_(Source::SOURCE_NONE), source_(0), list_(0), connectionManager_(0) +source_(0), list_(0), connectionManager_(0), timer_(0), searching_(false), retries_(0) { setAttribute(Qt::WA_Maemo5StackedWindow); setWindowTitle(tr("Search results")); @@ -56,6 +56,16 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) list_->clear(); } + show(); + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); + + if(!connectionManager_) + { + connectionManager_ = new ConnectionManager(); + } + + connectionManager_->connect(); + Source::SourceId id = Source::stringToId(Settings::instance()->get("source")); if(!source_ || id != sourceId_) @@ -90,39 +100,33 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) config->apply(source_); delete config; - Source::SearchType type; - - switch(details.type) + if(searching_) { - case 0: - type = Source::PERSONS; - break; - case 1: - type = Source::YELLOW_PAGES; - break; - default: - qDebug() << "Unknown search type: " << details.type; - return; + source_->abort(); + timer_ = startTimer(SEARCH_INTERVAL); } - show(); - setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); - - if(!connectionManager_) + while(timer_) { - connectionManager_ = new ConnectionManager(); + QApplication::processEvents(QEventLoop::WaitForMoreEvents); } - connectionManager_->connect(); - - source_->abort(); - source_->search(Source::SearchDetails(details.name, details.location, type)); + list_->clear(); + searching_ = true; + retries_ = 0; + currentSearch_ = Source::SearchDetails(details.name, details.location, details.type); + source_->search(currentSearch_); } void ResultWindow::resultAvailable(Source::Result const& result, Source::SearchDetails const& details) { + if(!list_) + { + return; + } + Q_UNUSED(details); if(!result.number.isEmpty()) @@ -148,6 +152,7 @@ void ResultWindow::resultAvailable(Source::Result const& result, data["street"] = QVariant(result.street); data["city"] = QVariant(result.city); data["number"] = QVariant(result.number); + data["country"] = QVariant(result.country); item->setData(Qt::UserRole, QVariant(data)); @@ -162,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(); @@ -194,6 +208,8 @@ void ResultWindow::requestFinished(QVector const& results, setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); + searching_ = false; + } void ResultWindow::itemClicked(QListWidgetItem* item) @@ -204,21 +220,27 @@ void ResultWindow::itemClicked(QListWidgetItem* item) details.street = data["street"].toString(); details.city = data["city"].toString(); details.number = data["number"].toString(); + details.country = data["country"].toString(); emit itemSelected(details); } void ResultWindow::setVisible(bool visible) { - QMainWindow::setVisible(visible); - if(!visible && source_) { source_->abort(); - - } + + QMainWindow::setVisible(visible); } +void ResultWindow::timerEvent(QTimerEvent* event) +{ + Q_UNUSED(event); + + killTimer(timer_); + timer_ = 0; +}