*/
#include <QtCore/QDebug>
+#include <QtNetwork/QHttpResponseHeader>
#include "source.h"
#include "eniro.h"
#include "mobil1881.h"
+#include "dastelefonbuch.h"
namespace
{
static const QString SOURCE_NAMES[Source::SOURCE_COUNT] =
{
"Eniro (FI, SE, DK)",
- "1881 Mobil (NO)"
+ "1881 Mobil (NO)",
+ "Das Telefonbuch (DE)"
};
static const QString SOURCE_IDS[Source::SOURCE_COUNT] =
{
"eniro",
- "1881mobil"
+ "1881mobil",
+ "dastelefonbuch"
};
}
case MOBIL1881:
return new Mobil1881(parent);
break;
+ case DASTELEFONBUCH:
+ return new DasTelefonbuch(parent);
+ break;
default:
qDebug() << "Unknown source:" << id;
}
}
Source::Source(QObject* parent): QObject(parent),
-maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(false),
+maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(true),
error_(NO_ERROR), loggedIn_(false)
{
connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
return maxResults_;
}
+void Source::getSearchTypes(QList<SearchType>& types) const
+{
+ types.clear();
+ types.push_back(PERSONS);
+ types.push_back(YELLOW_PAGES);
+}
+
void Source::setTimeout(unsigned int timeout)
{
timeout_ = timeout;
void Source::httpReady(int id, bool error)
{
+ QByteArray result = http_.readAll();
if(error)
{
}
else
{
- QByteArray result = http_.readAll();
handleHttpData(id, result);
}
}
38,
60,
62,
- 160,
+ 32,
192,
193,
194,
string = string.replace("&" + entities[i] + ";", QChar(entityValues[i]));
}
+ static QRegExp entityCleaner("&#([0-9]{1,3});");
+ entityCleaner.setMinimal(true);
+
+ int pos = 0;
+
+ while((pos = entityCleaner.indexIn(string, pos)) != -1)
+ {
+ QString match = entityCleaner.cap(1);
+
+ int value = match.toInt();
+
+ if(value >= 1 && value <= 255)
+ {
+ string = string.replace(pos, match.length() + 3, QChar(value));
+ }
+
+ pos += entityCleaner.matchedLength();
+ }
+
+
return string;
}
url.setEncodedQuery(path);
}
+bool Source::isPhoneNumber(QString const& string)
+{
+ static QRegExp check("^([0-9 -]{7,25})$");
+ return check.exactMatch(string);
+}
+
Source::SearchDetails::SearchDetails(QString const& q,
QString const& loc,
SearchType t)