|(.*)
|(.*)
)";
static const QString NUMBER_REGEXP = "
(.*)
";
static const QString LOGIN_CHECK = "
1)
+ {
+ what = "wp";
+ }
+ else if(loggedIn_ || site_ != FI)
{
switch(type)
{
@@ -163,6 +170,7 @@ void Eniro::search(SearchDetails const& details)
default:
what = "moball";
+ break;
}
}
@@ -176,6 +184,8 @@ void Eniro::search(SearchDetails const& details)
http_.setHost(url.host(), url.port(80));
int id = http_.get(url.encodedPath() + '?' + url.encodedQuery());
+ //qDebug() << "Url: " << url.host() << url.encodedPath() << "?" << url.encodedQuery();
+
QVector
results;
// Store search data for later identification
@@ -199,6 +209,13 @@ void Eniro::handleHttpData(int id, QByteArray const& data)
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);
}
@@ -207,6 +224,13 @@ void Eniro::handleHttpData(int id, QByteArray const& 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);
}
@@ -255,7 +279,6 @@ void Eniro::handleHttpError(int id)
pendingLoginRequests_.end())
{
emit loginStatus(false);
-
}
}
@@ -263,21 +286,15 @@ void Eniro::handleHttpError(int id)
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;
@@ -289,8 +306,10 @@ void Eniro::loadResults(int id, QString const& httpData)
{
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++)
@@ -313,6 +332,19 @@ void Eniro::loadResults(int id, QString const& httpData)
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)
@@ -327,9 +359,18 @@ void Eniro::loadResults(int id, QString const& httpData)
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:
@@ -341,6 +382,35 @@ void Eniro::loadResults(int id, QString const& httpData)
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;
}
@@ -349,9 +419,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;
@@ -388,6 +458,102 @@ void Eniro::loadResults(int id, QString const& httpData)
}
}
+void Eniro::loadFinnishPersonResults(int id, QString const& httpData)
+{
+ searchMap::iterator it = pendingSearches_.find(id);
+
+ static QRegExp rx("");
+ static QRegExp name("
(.*)");
+ static QRegExp number("(.*)