Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
authoreshe <jessehakanen@gmail.com>
Mon, 14 Jun 2010 15:48:03 +0000 (16:48 +0100)
committereshe <jessehakanen@gmail.com>
Mon, 14 Jun 2010 15:48:03 +0000 (16:48 +0100)
src/common/contactmanager.cpp
src/common/eniro.cpp
src/common/eniro.h
src/common/mobil1881.cpp
src/common/mobil1881.h
src/common/source.cpp
src/common/source.h
src/gui/resultwindow.cpp
src/gui/resultwindow.h
www/index.html

index e674a4b..114c2d3 100644 (file)
@@ -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)
index 0958893..d20c441 100644 (file)
@@ -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);
     }
index bbec9fe..5000be2 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <QtCore/QObject>
 #include <QtCore/QString>
+#include <QtCore/QByteArray>
 #include <QtCore/QVector>
 #include <QtCore/QSet>
 #include <QtCore/QRegExp>
@@ -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);
index ba1907a..37b070e 100644 (file)
@@ -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;
     }
index 1444e32..ef376c8 100644 (file)
@@ -4,6 +4,7 @@
 #include <QtCore/QList>
 #include <QtCore/QSet>
 #include <QtCore/QVector>
+#include <QtCore/QByteArray>
 #include "source.h"
 
 class Mobil1881 : public Source
@@ -33,7 +34,7 @@ private:
     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);
 };
 
index 4fc513e..49fc999 100644 (file)
@@ -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");
index 34cd356..7e0765c 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtCore/QString>
 #include <QtCore/QTimerEvent>
 #include <QtCore/QUrl>
+#include <QtCore/QByteArray>
 #include <QtNetwork/QHttp>
 
 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_;
index 2640bbe..07349ff 100644 (file)
@@ -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();
+
+
     }
 }
 
index 76b1a1b..1fff79a 100644 (file)
@@ -49,6 +49,7 @@ private slots:
     void itemClicked(QListWidgetItem* item);
 
 private:
+    Source::SourceId sourceId_;
     Source* source_;
     QListWidget* list_;
     ConnectionManager* connectionManager_;
index 7360c0a..df939bf 100644 (file)
@@ -57,7 +57,8 @@
 <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/>

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment