namespace
{
- const int COUNTRY_CODES[] = {358, 45, 46, 47};
+ const int COUNTRY_CODES[] = {358, 45, 46, 47, 354};
const int NUM_OF_CODES = 4;
}
ContactManager::~ContactManager()
{
+ if(book_)
+ {
+ g_object_unref(book_);
+ }
}
bool ContactManager::numberExists(QString const& number)
}
-void Eniro::handleHttpData(int id, QString const& data)
+void Eniro::handleHttpData(int id, QByteArray const& data)
{
- qDebug() << "Handle:" << id;
searchMap::const_iterator searchIt;
numberMap::const_iterator numberIt;
if((searchIt = pendingSearches_.find(id)) !=
pendingSearches_.end())
{
- qDebug() << "Load results";
// Load results from html data
loadResults(id, data);
}
#include <QtCore/QObject>
#include <QtCore/QString>
+#include <QtCore/QByteArray>
#include <QtCore/QVector>
#include <QtCore/QSet>
#include <QtCore/QRegExp>
unsigned int numbersTotal;
};
- virtual void handleHttpData(int id, QString const& data);
+ virtual void handleHttpData(int id, QByteArray const& data);
virtual void handleHttpError(int id);
QUrl createUrl(QString const& query, QString const& location);
void loadResults(int id, QString const& data);
pendingSearches_.push_back(newData);
}
-void Mobil1881::handleHttpData(int id, QString const& data)
+void Mobil1881::handleHttpData(int id, QByteArray const& data)
{
+ QString decoded = QString::fromUtf8(data.data());
+
for(int i = 0; i < pendingSearches_.size(); i++)
{
if(pendingSearches_.at(i) && pendingSearches_.at(i)->searchIds.find(id) !=
pendingSearches_.at(i)->searchIds.end())
{
-
- addNumbers(pendingSearches_.at(i), data, i);
+ addNumbers(pendingSearches_.at(i), decoded, i);
break;
}
}
Source::Result& result)
{
name = stripTags(name);
+ name = htmlEntityDecode(name);
result.name = name.trimmed();
number = stripTags(number);
number = cleanUpNumber(number);
result.number = number.trimmed();
street = stripTags(street);
+ street = htmlEntityDecode(street);
city = stripTags(city);
+ city = htmlEntityDecode(city);
result.street = street.trimmed();
result.city = city.trimmed();
- if(!result.name.isEmpty() && !result.number.isEmpty())
+ if(!result.name.isEmpty() && (!getFindNumber() || !result.number.isEmpty()))
{
return true;
}
#include <QtCore/QList>
#include <QtCore/QSet>
#include <QtCore/QVector>
+#include <QtCore/QByteArray>
#include "source.h"
class Mobil1881 : public Source
QList<SearchData*> pendingSearches_;
Q_DISABLE_COPY(Mobil1881);
- virtual void handleHttpData(int id, QString const& data);
+ virtual void handleHttpData(int id, QByteArray const& data);
virtual void handleHttpError(int id);
};
}
else
{
- QString result(http_.readAll());
+ QByteArray result = http_.readAll();
handleHttpData(id, result);
}
}
return string.replace(tagStripper_, "");
}
+QString& Source::htmlEntityDecode(QString& string)
+{
+ static const QString entities[] =
+ {
+ "quot",
+ "apos",
+ "amp",
+ "lt",
+ "gt",
+ "nbsp",
+ "Agrave",
+ "Aacute",
+ "Acirc",
+ "Atilde",
+ "Auml",
+ "Aring",
+ "AElig",
+ "Ccedil",
+ "Egrave",
+ "Eacute",
+ "Ecirc",
+ "Euml",
+ "Igrave",
+ "Iacute",
+ "Icirc",
+ "Iuml",
+ "ETH",
+ "Ntilde",
+ "Ograve",
+ "Oacute",
+ "Ocirc",
+ "Otilde",
+ "Ouml",
+ "Oslash",
+ "Ugrave",
+ "Uacute",
+ "Ucirc",
+ "Uuml",
+ "Yacute",
+ "THORN",
+ "szlig",
+ "agrave",
+ "aacute",
+ "acirc",
+ "atilde",
+ "auml",
+ "aring",
+ "aelig",
+ "ccedil",
+ "egrave",
+ "eacute",
+ "ecirc",
+ "euml",
+ "igrave",
+ "iacute",
+ "icirc",
+ "iuml",
+ "eth",
+ "ntilde",
+ "ograve",
+ "oacute",
+ "ocirc",
+ "otilde",
+ "ouml",
+ "oslash",
+ "ugrave",
+ "uacute",
+ "ucirc",
+ "uuml",
+ "yacute",
+ "thorn",
+ "yuml"
+ };
+
+ static const int entityValues[] =
+ {
+ 34,
+ 39,
+ 38,
+ 60,
+ 62,
+ 160,
+ 192,
+ 193,
+ 194,
+ 195,
+ 196,
+ 197,
+ 198,
+ 199,
+ 200,
+ 201,
+ 202,
+ 203,
+ 204,
+ 205,
+ 206,
+ 207,
+ 208,
+ 209,
+ 210,
+ 211,
+ 212,
+ 213,
+ 214,
+ 216,
+ 217,
+ 218,
+ 219,
+ 220,
+ 221,
+ 222,
+ 223,
+ 224,
+ 225,
+ 226,
+ 227,
+ 228,
+ 229,
+ 230,
+ 231,
+ 232,
+ 233,
+ 234,
+ 235,
+ 236,
+ 237,
+ 238,
+ 239,
+ 240,
+ 241,
+ 242,
+ 243,
+ 244,
+ 245,
+ 246,
+ 248,
+ 249,
+ 250,
+ 251,
+ 252,
+ 253,
+ 254,
+ 255
+ };
+
+ static int const COUNT = sizeof(entityValues) / sizeof(entityValues[0]);
+
+ for(int i = 0; i < COUNT; i++)
+ {
+ string = string.replace("&" + entities[i] + ";", QChar(entityValues[i]));
+ }
+
+ return string;
+}
+
void Source::fixUrl(QUrl& url)
{
QByteArray path = url.encodedQuery().replace('+', "%2B");
#include <QtCore/QString>
#include <QtCore/QTimerEvent>
#include <QtCore/QUrl>
+#include <QtCore/QByteArray>
#include <QtNetwork/QHttp>
class Source : public QObject
enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
- enum SourceId {ENIRO, MOBIL1881};
+ enum SourceId {SOURCE_NONE, ENIRO, MOBIL1881};
static int const SOURCE_COUNT = 2;
struct SourceDetails
protected:
void setError(Error error, QString const& errorString = "");
virtual void timerEvent(QTimerEvent *te);
- QString ucFirst(QString& string);
- QString& cleanUpNumber(QString& number);
- QString& stripTags(QString& string);
+ static QString ucFirst(QString& string);
+ static QString& cleanUpNumber(QString& number);
+ static QString& stripTags(QString& string);
+ static QString& htmlEntityDecode(QString& string);
void fixUrl(QUrl& url);
QHttp http_;
private:
Q_DISABLE_COPY(Source);
- virtual void handleHttpData(int id, QString const& data) = 0;
+ virtual void handleHttpData(int id, QByteArray const& data) = 0;
virtual void handleHttpError(int id) = 0;
unsigned int maxResults_;
unsigned int timeout_;
#include "sourcecoreconfig.h"
ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent),
-source_(0), list_(0), connectionManager_(0)
+sourceId_(Source::SOURCE_NONE), source_(0), list_(0), connectionManager_(0)
{
setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowTitle(tr("Search results"));
list_->clear();
}
- Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source"));
+ Source::SourceId id = Source::stringToId(Settings::instance()->get("source"));
- if(!source_)
+ if(!source_ || id != sourceId_)
{
- source_ = Source::getSource(sourceId);
+ sourceId_ = id;
+
+ if(source_)
+ {
+ delete source_;
+ source_ = 0;
+ }
+
+ source_ = Source::getSource(sourceId_);
Q_ASSERT(source_ != 0);
source_->setTimeout(REQUEST_TIMEOUT);
Source::SearchDetails const&, bool)));
}
- SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId);
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId_);
Q_ASSERT(config != 0);
if(!visible && source_)
{
source_->abort();
+
+
}
}
void itemClicked(QListWidgetItem* item);
private:
+ Source::SourceId sourceId_;
Source* source_;
QListWidget* list_;
ConnectionManager* connectionManager_;
<p>Compilation on scratchbox is pretty straightforward when you have the required dependencies:</p>
<pre>fakeroot apt-get install libqt4-dev libebook-dev icd2-dev</pre>
<p>And the compilation:</p>
-<pre>make
+<pre>qmake
+make
fakeroot make install</pre>
<hr/>