static const QString INVALID_LOGIN_STRING = "Invalid login details";
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 YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\">(.*)</td>|<td class=\"hTd2\">(.*)<span class=\"bold\"\\}>(.*)</td>";
+ 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_)
+ // We must use full search instead of wap page because wap search is currently not
+ // working for persons
+ if(loggedIn_ && type == PERSONS && site_ == FI && getMaxResults() > 1)
+ {
+ what = "wp";
+ }
+ else if(loggedIn_ || site_ != FI)
{
switch(type)
{
default:
what = "moball";
+ break;
}
}
http_.setHost(url.host(), url.port(80));
int id = http_.get(url.encodedPath() + '?' + url.encodedQuery());
+ //qDebug() << "Url: " << url.host() << url.encodedPath() << "?" << url.encodedQuery();
+
QVector <Source::Result> results;
// Store search data for later identification
if((searchIt = pendingSearches_.find(id)) !=
pendingSearches_.end())
{
+ if(data.isEmpty())
+ {
+ setError(CONNECTION_FAILURE, "Server returned empty data");
+ emitRequestFinished(id, searchIt.value(), true);
+ return;
+ }
+
// Load results from html data
loadResults(id, data);
}
else if((numberIt = pendingNumberRequests_.find(id)) !=
pendingNumberRequests_.end())
{
+ if(data.isEmpty())
+ {
+ setError(CONNECTION_FAILURE, "Server returned empty data");
+ emitRequestFinished(id, searchIt.value(), true);
+ return;
+ }
+
// Load number from html data
loadNumber(id, data);
}
pendingLoginRequests_.end())
{
emit loginStatus(false);
-
}
}
void Eniro::loadResults(int id, QString const& httpData)
{
searchMap::iterator it = pendingSearches_.find(id);
- QString expr;
- switch(it.value()->details.type)
+ // Finnish person search is not working in wap mode so we have to use different type of loading
+ if(getMaxResults() > 1 && loggedIn_ && site_ == FI && it.value()->details.type == PERSONS)
{
- case YELLOW_PAGES:
- expr = YELLOW_REGEXP;
- break;
- case PERSONS:
- expr = PERSON_REGEXP;
- break;
- default:
+ loadFinnishPersonResults(id, httpData);
return;
}
- QRegExp rx(expr);
+ QRegExp rx("((" + YELLOW_REGEXP + ")|(" + PERSON_REGEXP + ")|(" + SINGLE_REGEXP + "))");
rx.setMinimal(true);
bool requestsPending = false;
{
pos += rx.matchedLength();
- data = rx.cap(2);
+ data = rx.cap(1);
+
data = stripTags(data);
+
QStringList rows = data.split('\n');
for(int i = 0; i < rows.size(); i++)
Result result;
+ switch(site_)
+ {
+ case FI:
+ result.country = "Finland";
+ break;
+ case SE:
+ result.country = "Sweden";
+ break;
+ case DK:
+ result.country = "Denmark";
+ break;
+ }
+
int size = rows.size();
switch(size)
break;
case 3:
- result.name = rows[0];
- result.street = rows[1];
- result.city = rows[2];
+ if(isPhoneNumber(rows[1]))
+ {
+ result.name = rows[0];
+ result.number = cleanUpNumber(rows[1]);
+ result.city = rows[2];
+ }
+ else
+ {
+ result.name = rows[0];
+ result.street = rows[1];
+ result.city = rows[2];
+ }
break;
case 4:
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;
}
}
+void Eniro::loadFinnishPersonResults(int id, QString const& httpData)
+{
+ searchMap::iterator it = pendingSearches_.find(id);
+
+ static QRegExp rx("<div id=\"hit_(.*)<p class=\"adLinks\">");
+ static QRegExp name("<a class=\"fn expand\" href=\"#\">(.*)</a>");
+ static QRegExp number("<!-- sphoneid(.*)-->(.*)<!--");
+ static QRegExp street("<span class=\"street-address\">(.*)</span>");
+ static QRegExp zipCode("<span class=\"postal-code\">(.*)</span>");
+ static QRegExp city("<span class=\"locality\">(.*)</span>");
+ rx.setMinimal(true);
+ name.setMinimal(true);
+ number.setMinimal(true);
+ street.setMinimal(true);
+ zipCode.setMinimal(true);
+ city.setMinimal(true);
+
+ int pos = 0;
+
+ unsigned int maxResults = getMaxResults();
+ unsigned int foundResults = 0;
+
+ while((pos = rx.indexIn(httpData, pos)) != -1)
+ {
+ pos += rx.matchedLength();
+
+ QString data = rx.cap(0);
+
+ Result result;
+
+ if(name.indexIn(data) != -1)
+ {
+ result.name = name.cap(1);
+ }
+ else
+ {
+ continue;
+ }
+
+ if(number.indexIn(data) != -1)
+ {
+ result.number = number.cap(2);
+ }
+
+ if(street.indexIn(data) != -1)
+ {
+ result.street = street.cap(1);
+ }
+
+ QString cityStr;
+
+ if(zipCode.indexIn(data) != -1)
+ {
+ cityStr = zipCode.cap(1) + " ";
+ }
+
+ if(city.indexIn(data) != -1)
+ {
+ cityStr += city.cap(1);
+ }
+
+ result.city = cityStr;
+
+ result.name = cleanUpString(result.name);
+ result.street = cleanUpString(result.street);
+ result.number = cleanUpNumber(result.number);
+ result.city = cleanUpString(result.city);
+ result.country = "Finland";
+
+ it.value()->results.push_back(result);
+ emit resultAvailable(result, it.value()->details);
+
+ foundResults++;
+
+ if(foundResults >= maxResults)
+ {
+ break;
+ }
+
+ }
+
+ emitRequestFinished(it.key(), it.value(), false);
+
+}
+
+QString& Eniro::cleanUpString(QString& str)
+{
+ str = htmlEntityDecode(str);
+ str = str.toLower();
+ str = str.trimmed();
+ static QRegExp cleaner("(\r\n|\n|\t| )+");
+ str = str.replace(cleaner, " ");
+ str = ucFirst(str);
+ return str;
+}
+
// Loads phone number from html source
void Eniro::loadNumber(int id, QString const& result)
{
{
url.addQueryItem("hpp", QString::number(maxResults));
}
- if(loggedIn_)
+ if(loggedIn_ && site_ == FI)
{
url.addQueryItem("login_name", username_);
url.addQueryItem("login_password", password_);
QMap <Eniro::Site, Eniro::SiteDetails> Eniro::getSites()
{
QMap <Site, SiteDetails> sites;
- SiteDetails details;
for(int i = 0; i < SITE_COUNT; i++)
{
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;
+}