namespace
{
- static const QString SITE_URLS[] =
+ static const QString SITE_URLS[Eniro::SITE_COUNT] =
{
"http://wap.eniro.fi/",
"http://wap.eniro.se/",
"http://wap.eniro.dk/"
};
- const QString INVALID_LOGIN_STRING = "Invalid login details";
- const QString PERSON_REGEXP = "<td class=\"hTd2\">(.*)<b>(.*)</td>";
- const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\"\\}>(.*)</td>";
- const QString NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
- const QString LOGIN_CHECK = "<input class=\"inpTxt\" id=\"loginformUsername\"";
+ static const QString SITE_NAMES[Eniro::SITE_COUNT] =
+ {
+ "finnish",
+ "swedish",
+ "danish"
+ };
+
+ static const QString SITE_IDS[Eniro::SITE_COUNT] =
+ {
+ "fi",
+ "se",
+ "dk"
+ };
+
+ static const QString INVALID_LOGIN_STRING = QObject::tr("Invalid login details");
+ static const QString TIMEOUT_STRING = QObject::tr("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 NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
+ static const QString LOGIN_CHECK = "<input class=\"inpTxt\" id=\"loginformUsername\"";
}
// Regexp used to remove numbers from string
Eniro::Eniro(Site site, QObject *parent): QObject(parent), site_(site),
username_(""), password_(""), loggedIn_(false), error_(NO_ERROR),
-errorString_(""), maxResults_(10), findNumber_(true),
-pendingSearches_(), pendingNumberRequests_()
+errorString_(""), maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0),
+findNumber_(true), pendingSearches_(), pendingNumberRequests_()
{
connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
}
site_ = site;
}
+void Eniro::setTimeout(unsigned int ms)
+{
+ timeout_ = ms;
+ resetTimeout();
+}
+
+void Eniro::resetTimeout()
+{
+ if(timerId_)
+ {
+ killTimer(timerId_);
+ }
+ if(timeout_)
+ {
+ timerId_ = startTimer(timeout_);
+ }
+}
+
+void Eniro::timerEvent(QTimerEvent* t)
+{
+ if(t->timerId() == timerId_)
+ {
+ int currentId = http_.currentId();
+
+ if(currentId)
+ {
+ searchMap::const_iterator it = pendingSearches_.find(currentId);
+
+ if(it != pendingSearches_.end())
+ {
+ QVector <Eniro::Result> results = it.value()->results;
+ SearchDetails details = it.value()->details;
+
+ abort();
+
+ error_ = TIMEOUT;
+ errorString_ = TIMEOUT_STRING;
+
+ emit requestFinished(results, details, true);
+ }
+ }
+
+ }
+}
+
void Eniro::login(QString const& username,
QString const& password)
{
bool Eniro::search(SearchDetails const& details)
{
+ resetTimeout();
+
SearchType type = details.type;
// Only logged in users can use other than person search
}
}
- // If number there were no results or no phone numbers needed to
+ // If there were no results or no phone numbers needed to
// be fetched, the whole request is ready
if(it.value()->numbersTotal == 0 || !requestsPending)
{
{
QMap <Site, SiteDetails> sites;
SiteDetails details;
- details.name = tr("Finnish");
- details.id = "fi";
- sites[FI] = details;
-
- details.name = tr("Swedish");
- details.id = "se";
- sites[SE] = details;
- details.name = tr("Danish");
- details.id = "dk";
- sites[DK] = details;
+ for(int i = 0; i < SITE_COUNT; i++)
+ {
+ SiteDetails details;
+ details.name = SITE_NAMES[i];
+ details.id = SITE_IDS[i];
+ sites[static_cast<Site>(i)] = details;
+ }
return sites;
}
Eniro::Site Eniro::stringToSite(QString const& str)
{
Site site = FI;
-
QString lower = str.toLower();
- if(lower == "se" || lower == "swedish")
- {
- site = SE;
- }
- else if(lower == "dk" || lower == "danish")
+ for(int i = 0; i < SITE_COUNT; i++)
{
- site = DK;
+ if(lower == SITE_NAMES[i] || lower == SITE_IDS[i])
+ {
+ site = static_cast <Site> (i);
+ }
}
return site;