X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=blobdiff_plain;f=src%2Fgui%2Fresultwindow.cpp;h=1bd7cb4684c1fcb0bfe627c80b79197b05310f75;hp=e9da90a8d5d625ced028b89ec3dadab9f1f1f2ea;hb=f99718e69b270a89094113a26b22c694b79382f0;hpb=d683b3ca259161ea7b5fb806b3bdab8fb1e96cb7 diff --git a/src/gui/resultwindow.cpp b/src/gui/resultwindow.cpp index e9da90a..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) +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,24 +100,33 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) config->apply(source_); delete config; - show(); - setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); - - if(!connectionManager_) + if(searching_) { - connectionManager_ = new ConnectionManager(); + source_->abort(); + timer_ = startTimer(SEARCH_INTERVAL); } - connectionManager_->connect(); + while(timer_) + { + QApplication::processEvents(QEventLoop::WaitForMoreEvents); + } - source_->abort(); - source_->search(Source::SearchDetails(details.name, details.location, details.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 +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(); @@ -180,6 +208,8 @@ void ResultWindow::requestFinished(QVector const& results, setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); + searching_ = false; + } void ResultWindow::itemClicked(QListWidgetItem* item) @@ -197,15 +227,20 @@ void ResultWindow::itemClicked(QListWidgetItem* item) 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; +}