#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)
{
setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowTitle(tr("Search results"));
list_->clear();
}
- Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source"));
+ show();
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+
+ if(!connectionManager_)
+ {
+ connectionManager_ = new ConnectionManager();
+ }
+
+ connectionManager_->connect();
+
+ Source::SourceId id = Source::stringToId(Settings::instance()->get("source"));
- if(!source_)
+ if(!source_ || id != sourceId_)
{
- source_ = Source::getSource(sourceId);
+ sourceId_ = id;
+
+ if(source_)
+ {
+ delete source_;
+ source_ = 0;
+ }
+
+ source_ = Source::getSource(sourceId_);
Q_ASSERT(source_ != 0);
source_->setTimeout(REQUEST_TIMEOUT);
Source::SearchDetails const&, bool)));
}
- SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId);
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId_);
Q_ASSERT(config != 0);
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;
+ source_->search(Source::SearchDetails(details.name, details.location, details.type));
}
void ResultWindow::resultAvailable(Source::Result const& result,
Source::SearchDetails const& details)
{
+ if(!list_)
+ {
+ return;
+ }
+
Q_UNUSED(details);
if(!result.number.isEmpty())
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));
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+ if(timer_)
+ {
+ killTimer(timer_);
+ }
+
+ timer_ = startTimer(SEARCH_INTERVAL);
+ searching_ = false;
+
}
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;
+}