From: eshe Date: Mon, 14 Jun 2010 15:48:03 +0000 (+0100) Subject: Fixed problems with special html characters and entities in Norwegian version. X-Git-Url: http://vcs.maemo.org/git/?p=jenirok;a=commitdiff_plain;h=a1c81fc3e2fd0b22b1897214a20c498110369fd9 Fixed problems with special html characters and entities in Norwegian version. --- diff --git a/src/common/contactmanager.cpp b/src/common/contactmanager.cpp index e674a4b..114c2d3 100644 --- a/src/common/contactmanager.cpp +++ b/src/common/contactmanager.cpp @@ -21,7 +21,7 @@ namespace { - const int COUNTRY_CODES[] = {358, 45, 46, 47}; + const int COUNTRY_CODES[] = {358, 45, 46, 47, 354}; const int NUM_OF_CODES = 4; } @@ -31,6 +31,10 @@ ContactManager::ContactManager(): book_(0) ContactManager::~ContactManager() { + if(book_) + { + g_object_unref(book_); + } } bool ContactManager::numberExists(QString const& number) diff --git a/src/common/eniro.cpp b/src/common/eniro.cpp index 0958893..d20c441 100644 --- a/src/common/eniro.cpp +++ b/src/common/eniro.cpp @@ -190,9 +190,8 @@ void Eniro::search(SearchDetails const& details) } -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; @@ -200,7 +199,6 @@ void Eniro::handleHttpData(int id, QString const& data) if((searchIt = pendingSearches_.find(id)) != pendingSearches_.end()) { - qDebug() << "Load results"; // Load results from html data loadResults(id, data); } diff --git a/src/common/eniro.h b/src/common/eniro.h index bbec9fe..5000be2 100644 --- a/src/common/eniro.h +++ b/src/common/eniro.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ private: 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); diff --git a/src/common/mobil1881.cpp b/src/common/mobil1881.cpp index ba1907a..37b070e 100644 --- a/src/common/mobil1881.cpp +++ b/src/common/mobil1881.cpp @@ -57,15 +57,16 @@ void Mobil1881::search(Source::SearchDetails const& details) 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; } } @@ -219,16 +220,19 @@ bool Mobil1881::formatResult(QString& name, QString& number, 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; } diff --git a/src/common/mobil1881.h b/src/common/mobil1881.h index 1444e32..ef376c8 100644 --- a/src/common/mobil1881.h +++ b/src/common/mobil1881.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "source.h" class Mobil1881 : public Source @@ -33,7 +34,7 @@ private: QList 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); }; diff --git a/src/common/source.cpp b/src/common/source.cpp index 4fc513e..49fc999 100644 --- a/src/common/source.cpp +++ b/src/common/source.cpp @@ -181,7 +181,7 @@ void Source::httpReady(int id, bool error) } else { - QString result(http_.readAll()); + QByteArray result = http_.readAll(); handleHttpData(id, result); } } @@ -213,6 +213,162 @@ QString& Source::stripTags(QString& string) 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"); diff --git a/src/common/source.h b/src/common/source.h index 34cd356..7e0765c 100644 --- a/src/common/source.h +++ b/src/common/source.h @@ -23,6 +23,7 @@ #include #include #include +#include #include class Source : public QObject @@ -54,7 +55,7 @@ public: 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 @@ -91,9 +92,10 @@ signals: 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_; @@ -102,7 +104,7 @@ private slots: 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_; diff --git a/src/gui/resultwindow.cpp b/src/gui/resultwindow.cpp index 2640bbe..07349ff 100644 --- a/src/gui/resultwindow.cpp +++ b/src/gui/resultwindow.cpp @@ -30,7 +30,7 @@ #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")); @@ -56,11 +56,19 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) 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); @@ -75,7 +83,7 @@ void ResultWindow::search(SearchDialog::SearchDetails& details) Source::SearchDetails const&, bool))); } - SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId); + SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId_); Q_ASSERT(config != 0); @@ -207,6 +215,8 @@ void ResultWindow::setVisible(bool visible) if(!visible && source_) { source_->abort(); + + } } diff --git a/src/gui/resultwindow.h b/src/gui/resultwindow.h index 76b1a1b..1fff79a 100644 --- a/src/gui/resultwindow.h +++ b/src/gui/resultwindow.h @@ -49,6 +49,7 @@ private slots: void itemClicked(QListWidgetItem* item); private: + Source::SourceId sourceId_; Source* source_; QListWidget* list_; ConnectionManager* connectionManager_; diff --git a/www/index.html b/www/index.html index 7360c0a..df939bf 100644 --- a/www/index.html +++ b/www/index.html @@ -57,7 +57,8 @@

Compilation on scratchbox is pretty straightforward when you have the required dependencies:

fakeroot apt-get install libqt4-dev libebook-dev icd2-dev

And the compilation:

-
make
+
qmake
+make
 fakeroot make install