Incorporated changes from bus project.
[ptas] / src / location_p.cpp
index fe9d555..e5b4287 100644 (file)
 #include <stdio.h>
 #include "location_p.h"
 
+#include "xmlparser.h"
+
 #include <QXmlStreamReader>
 #include <QByteArray>
 #include <QDebug>
 #include <QMaemo5InformationBox>
 
-LocationPrivate::LocationPrivate( const QString &x, const QString &y, const QString &label ) :
-  m_label(label),
-  m_address(),
-  m_x(x),
-  m_y(y),
-  m_valid(true)
+LocationPrivate::LocationPrivate(const QString &longitude, const QString &latitude, const QString &label) :
+    m_label(label),
+    m_address(),
+    m_longitude(longitude),
+    m_latitude(latitude),
+    m_valid(true)
 {
 }
 
-LocationPrivate::LocationPrivate( const QString &label ) :
-  m_label(label),
-  m_address(),
-  m_x(0),
-  m_y(0),
-  m_valid(false)
+LocationPrivate::LocationPrivate(const QString &label) :
+    m_label(label),
+    m_address(),
+    m_longitude(QString()),
+    m_latitude(QString()),
+    m_valid(false)
 {
 }
 
 LocationPrivate::~LocationPrivate()
 {
-  m_label="deleted";
-  m_address="";
-  m_x="";
-  m_y="";
-  m_valid=false;
+    m_label="deleted";
+    m_address="";
+    m_longitude="";
+    m_latitude="";
+    m_valid=false;
 }
 
-void LocationPrivate::parseReply( const QByteArray &reply )
+void LocationPrivate::parseReply(const QByteArray &reply)
 {
-  qDebug() << "parsing";
-  QXmlStreamReader xml( reply );
-  bool responseHasError = false;
-
-  while ( !xml.atEnd() ) {
-    xml.readNext();
+    qDebug() << "parsing/" << reply;
 
-    if ( xml.isStartElement() ) {
-      QString xmlName( xml.name().toString() );
+    XmlParser parser;
+    QPair<QString,QString> parsedReply = parser.parseGeocode(reply);
 
-      if ( xmlName == "LOC" ) {
-        QXmlStreamAttributes attributes( xml.attributes() );
-        QStringRef xAttribute( attributes.value("x") );
-        QStringRef yAttribute( attributes.value("y") );
-        QString newX( xAttribute.toString() );
-        QString newY( yAttribute.toString() );
+    m_longitude = parsedReply.first;
+    m_latitude  = parsedReply.second;
 
-        m_x = newX;
-        m_y = newY;
-      }
+    qDebug() << "DONE parsing";
 
-      if ( xmlName == "ERROR" ) {
-        responseHasError = true;
-      }
-
-    }
-  }
-
-  if ( xml.hasError() || responseHasError ) {
-    QMaemo5InformationBox::information( 0, "address resolution error - please check address" );
-    qDebug() << "xml error";
-    m_valid = false;
-  } else {
-    qDebug() << "(" << m_x << "," << m_y << ")";
-    if ( m_x.isEmpty() ||  m_y.isEmpty() ) {
-      qDebug() << "is NOT valid";
-      m_valid = false;
+    if (parser.error()) {
+        QMaemo5InformationBox::information(0, "address resolution error - please check address");
+        m_valid = false;
     } else {
-      qDebug() << "is now valid";
-      m_valid = true;
+        qDebug() << "(" << m_longitude << "," << m_latitude << ")";
+        if (m_longitude.isEmpty() ||  m_latitude.isEmpty()) {
+            qDebug() << "is NOT valid";
+            m_valid = false;
+        } else {
+            qDebug() << "is now valid";
+            m_valid = true;
+        }
     }
-  }
 }
 
-void LocationPrivate::setLabel( const QString &label)
+void LocationPrivate::setLabel(const QString &label)
 {
-  m_label = label;
+    m_label = label;
 }
 
 QString LocationPrivate::label() const
 {
-  return m_label;
+    return m_label;
 }
 
-void LocationPrivate::setAddress( const QString &address)
+void LocationPrivate::setAddress(const QString &address)
 {
-  m_address = address;
+    m_address = address;
 }
 
 QString LocationPrivate::address() const
 {
-  return m_address;
+    return m_address;
 }
 
-void LocationPrivate::setX( uint x )
+void LocationPrivate::setLongitude(double longitude)
 {
-  m_x = QString( "%1" ).arg( x );
+    m_longitude = QString("%1").arg(longitude);
 }
 
-void LocationPrivate::setX( const QString &x )
+void LocationPrivate::setLongitude(const QString &longitude)
 {
-  m_x = x;
+    m_longitude = longitude;
 }
 
-QString LocationPrivate::x() const
+QString LocationPrivate::longitude() const
 {
-  return m_x;
+    return m_longitude;
 }
 
-void LocationPrivate::setY( uint y )
+void LocationPrivate::setlatitude(double latitude)
 {
-  m_y = QString( "%1" ).arg( y );
+    m_latitude = QString("%1").arg(latitude);
 }
 
-void LocationPrivate::setY( const QString &y )
+void LocationPrivate::setlatitude(const QString &latitude)
 {
-  m_y = y;
+    m_latitude = latitude;
 }
 
-QString LocationPrivate::y() const
+QString LocationPrivate::latitude() const
 {
-  return m_y;
+    return m_latitude;
 }
 
-void LocationPrivate::setValid( bool valid )
+void LocationPrivate::setValid(bool valid)
 {
-  m_valid = valid;
+    qDebug() << Q_FUNC_INFO << "/valid/" << valid;
+    m_valid = valid;
 }
 
 bool LocationPrivate::isValid() const
 {
-  return m_valid;
+    return m_valid;
 }