static const QString TIMEOUT_STRING = "Request timed out";
static const QString PERSON_REGEXP = "<td class=\"hTd2\">(.*)<b>(.*)</td>";
static const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\">(.*)</td>";
- static const QString SINGLE_REGEXP = "<div class=\"header\">(.*)</div>(.*)<div class=\"callRow\">(.*)</div>";
+ static const QString SINGLE_REGEXP = "<div class=\"header\">(.*)</div>(.*)<div class=\"callRow\">(.*)(<div class=\"block\">|</p>(.*)<br/>|</p>(.*)<br />)";
static const QString NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
static const QString LOGIN_CHECK = "<input class=\"inpTxt\" id=\"loginformUsername\"";
}
SearchType type = details.type;
// Only logged in users can use other than person search
- if(!loggedIn_)
+ if(!loggedIn_ && site_ == FI)
{
type = PERSONS;
}
QUrl url = createUrl(details.query, details.location);
QString what;
- if(loggedIn_)
+ if(loggedIn_ || site_ != FI)
{
switch(type)
{
data = rx.cap(1);
data = stripTags(data);
+
QStringList rows = data.split('\n');
for(int i = 0; i < rows.size(); i++)
break;
default:
+ bool ok = false;
+
+ for(int a = 0; a < size && a < 8; a++)
+ {
+ if(isPhoneNumber(rows[a]))
+ {
+ result.name = rows[0];
+ result.number = cleanUpNumber(rows[a]);
+
+ for(int i = a + 1; i < size && i < 8; i++)
+ {
+ if(!isPhoneNumber(rows[i]) && size > i + 1 && isStreet(rows[i]))
+ {
+ result.street = rows[i];
+ result.city = rows[i+1];
+ ok = true;
+ break;
+ }
+ }
+
+ }
+
+ }
+
+ if(ok)
+ {
+ break;
+ }
+
continue;
}
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;
{
url.addQueryItem("hpp", QString::number(maxResults));
}
- if(loggedIn_)
+ if(loggedIn_ && site_ == FI)
{
url.addQueryItem("login_name", username_);
url.addQueryItem("login_password", password_);
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;
+}
#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 <Eniro::Site, Eniro::SiteDetails> sites = Eniro::getSites();
siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
- QString site = getSite();
int i = 0;
QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
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());
}
#define ENIROGUICONFIG_H
#include <QtGui/QLineEdit>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QLabel>
#include "buttonselector.h"
#include "enirocoreconfig.h"
#include "sourceguiconfig.h"
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_;
};