From 3637f101f5223d24de435c5edaa44d9d5cc8dd1f Mon Sep 17 00:00:00 2001 From: eshe Date: Mon, 28 Jun 2010 16:59:44 +0100 Subject: [PATCH] Various fixes to Eniro search in SE and DK sites. --- src/common/eniro.cpp | 56 +++++++++++++++++++--- src/common/eniro.h | 1 + src/common/enirocoreconfig.cpp | 5 ++ src/gui/eniroguiconfig.cpp | 100 +++++++++++++++++++++++++++++----------- src/gui/eniroguiconfig.h | 9 ++++ 5 files changed, 138 insertions(+), 33 deletions(-) diff --git a/src/common/eniro.cpp b/src/common/eniro.cpp index d3ebf5b..8e2503a 100644 --- a/src/common/eniro.cpp +++ b/src/common/eniro.cpp @@ -46,7 +46,7 @@ namespace static const QString TIMEOUT_STRING = "Request timed out"; static const QString PERSON_REGEXP = "(.*)(.*)"; static const QString YELLOW_REGEXP = "(.*)(.*)"; - static const QString SINGLE_REGEXP = "
(.*)
(.*)
(.*)
"; + static const QString SINGLE_REGEXP = "
(.*)
(.*)
(.*)(
|

(.*)
|

(.*)
)"; static const QString NUMBER_REGEXP = "
(.*)
"; static const QString LOGIN_CHECK = " i + 1 && isStreet(rows[i])) + { + result.street = rows[i]; + result.city = rows[i+1]; + ok = true; + break; + } + } + + } + + } + + if(ok) + { + break; + } + continue; } @@ -348,9 +378,9 @@ void Eniro::loadResults(int id, QString const& httpData) unsigned int foundResults = ++(it.value()->numbersTotal); - // If phone number searh is enabled, we have to make another + // If phone number search is enabled, we have to make another // request to find it out - if(getFindNumber() && size < 4 && loggedIn_ && + if(getFindNumber() && size < 4 && (loggedIn_ || site_ != FI) && it.value()->details.type != YELLOW_PAGES) { requestsPending = true; @@ -473,7 +503,7 @@ QUrl Eniro::createUrl(QString const& query, QString const& location) { url.addQueryItem("hpp", QString::number(maxResults)); } - if(loggedIn_) + if(loggedIn_ && site_ == FI) { url.addQueryItem("login_name", username_); url.addQueryItem("login_password", password_); @@ -540,3 +570,17 @@ Eniro::Site Eniro::stringToSite(QString const& str) return site; } + +bool Eniro::isStreet(QString const& str) +{ + static QRegExp number("([0-9]+)"); + int a = number.indexIn(str); + int b = str.indexOf(" "); + + if((a == -1 && b == -1) || (a != -1 && b != -1)) + { + return true; + } + + return false; +} diff --git a/src/common/eniro.h b/src/common/eniro.h index 5000be2..fbba9f4 100644 --- a/src/common/eniro.h +++ b/src/common/eniro.h @@ -85,6 +85,7 @@ private: void getNumberForResult(int id, int index, SearchDetails const& details); void emitRequestFinished(int key, SearchData* data, bool error); void timerEvent(QTimerEvent *t); + bool isStreet(QString const& str); Site site_; bool loggedIn_; diff --git a/src/common/enirocoreconfig.cpp b/src/common/enirocoreconfig.cpp index 86af526..8c09152 100644 --- a/src/common/enirocoreconfig.cpp +++ b/src/common/enirocoreconfig.cpp @@ -90,6 +90,11 @@ bool EniroCoreConfig::readyToSearch() { load(); + if(config_[SITE_COLUMN] != "fi") + { + return true; + } + return !config_[USERNAME_COLUMN].isEmpty() && !config_[PASSWORD_COLUMN].isEmpty(); } diff --git a/src/gui/eniroguiconfig.cpp b/src/gui/eniroguiconfig.cpp index 126d059..be41339 100644 --- a/src/gui/eniroguiconfig.cpp +++ b/src/gui/eniroguiconfig.cpp @@ -24,26 +24,59 @@ #include "eniro.h" EniroGuiConfig::EniroGuiConfig(QWidget* parent): -SourceGuiConfig(parent), EniroCoreConfig() +SourceGuiConfig(parent), EniroCoreConfig(), layout_(0), usernameInput_(0), +passwordInput_(0), siteSelector_(0), usernameLabel_(0), passwordLabel_(0) { load(); + loadLayout(getSite()); +} + +EniroGuiConfig::~EniroGuiConfig() +{ +} + +void EniroGuiConfig::save() +{ + if(usernameInput_ && passwordInput_) + { + setUsername(usernameInput_->text()); + setPassword(passwordInput_->text()); + } + + setSite(siteSelector_->value().toString()); + + store(); +} + +void EniroGuiConfig::loadLayout(QString const& site) +{ + if(layout()) + { + siteSelector_->hide(); + siteSelector_ = 0; - QVBoxLayout* layout = new QVBoxLayout; + if(usernameLabel_ && passwordLabel_) + { + usernameLabel_->hide(); + usernameLabel_ = 0; + usernameInput_->hide(); + usernameInput_ = 0; + passwordLabel_->hide(); + passwordLabel_ = 0; + passwordInput_->hide(); + passwordInput_ = 0; + } - QHBoxLayout* username = new QHBoxLayout; - QHBoxLayout* password = new QHBoxLayout; + delete layout(); + layout_ = 0; - QLabel* usernameLabel = new QLabel(tr("Eniro username")); - usernameInput_ = new QLineEdit(getUsername()); + } - QLabel* passwordLabel = new QLabel(tr("Eniro password")); - passwordInput_ = new QLineEdit(getPassword()); - passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit); + layout_ = new QVBoxLayout; QMap sites = Eniro::getSites(); siteSelector_ = new ButtonSelector(tr("Eniro site"), this); - QString site = getSite(); int i = 0; QMap ::const_iterator it; @@ -77,27 +110,40 @@ SourceGuiConfig(parent), EniroCoreConfig() i++; } - username->addWidget(usernameLabel); - username->addWidget(usernameInput_); - password->addWidget(passwordLabel); - password->addWidget(passwordInput_); + connect(siteSelector_, SIGNAL(selected(unsigned int, QString const&, QVariant const&)), + this, SLOT(siteChanged(unsigned int, QString const&, QVariant const&))); - layout->addLayout(username); - layout->addLayout(password); - layout->addWidget(siteSelector_); + layout_->addWidget(siteSelector_); - setLayout(layout); -} + if(site == "fi") + { + QHBoxLayout* username = new QHBoxLayout; + QHBoxLayout* password = new QHBoxLayout; -EniroGuiConfig::~EniroGuiConfig() -{ + usernameLabel_ = new QLabel(tr("Eniro username")); + usernameInput_ = new QLineEdit(getUsername()); + + passwordLabel_ = new QLabel(tr("Eniro password")); + passwordInput_ = new QLineEdit(getPassword()); + passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit); + + username->addWidget(usernameLabel_); + username->addWidget(usernameInput_); + password->addWidget(passwordLabel_); + password->addWidget(passwordInput_); + + layout_->addLayout(username); + layout_->addLayout(password); + } + + setLayout(layout_); } -void EniroGuiConfig::save() +void EniroGuiConfig::siteChanged(unsigned int index, + QString const& text, + QVariant const& value) { - setUsername(usernameInput_->text()); - setPassword(passwordInput_->text()); - setSite(siteSelector_->value().toString()); - - store(); + Q_UNUSED(index); + Q_UNUSED(text); + loadLayout(value.toString()); } diff --git a/src/gui/eniroguiconfig.h b/src/gui/eniroguiconfig.h index d8cab97..4108bdd 100644 --- a/src/gui/eniroguiconfig.h +++ b/src/gui/eniroguiconfig.h @@ -20,6 +20,8 @@ #define ENIROGUICONFIG_H #include +#include +#include #include "buttonselector.h" #include "enirocoreconfig.h" #include "sourceguiconfig.h" @@ -34,10 +36,17 @@ public: virtual ~EniroGuiConfig(); virtual void save(); +private slots: + void siteChanged(unsigned int index, QString const& text, QVariant const& value); + private: + void loadLayout(QString const& site); + QVBoxLayout* layout_; QLineEdit* usernameInput_; QLineEdit* passwordInput_; ButtonSelector* siteSelector_; + QLabel* usernameLabel_; + QLabel* passwordLabel_; }; -- 1.7.9.5