Changes: added notification for address resolution failure and no route; fixed issue...
[ptas] / zouba / src / location_p.cpp
1 #include <stdio.h>
2 #include "location_p.h"
3
4 #include <QXmlStreamReader>
5 #include <QByteArray>
6 #include <QDebug>
7 #include <QMaemo5InformationBox>
8
9 LocationPrivate::LocationPrivate( const QString &x, const QString &y, const QString &label ) :
10   m_label(label),
11   m_address(),
12   m_x(x),
13   m_y(y),
14   m_valid(true)
15 {
16 }
17
18 LocationPrivate::LocationPrivate( const QString &label ) :
19   m_label(label),
20   m_address(),
21   m_x(0),
22   m_y(0),
23   m_valid(false)
24 {
25 }
26
27 LocationPrivate::~LocationPrivate()
28 {
29   m_label="deleted";
30   m_address="";
31   m_x="";
32   m_y="";
33   m_valid=false;
34 }
35
36 void LocationPrivate::parseReply( const QByteArray &reply )
37 {
38   qDebug() << "parsing";
39   QXmlStreamReader xml( reply );
40   bool responseHasError = false;
41
42   while ( !xml.atEnd() ) {
43     xml.readNext();
44
45     if ( xml.isStartElement() ) {
46       QString xmlName( xml.name().toString() );
47
48       if ( xmlName == "LOC" ) {
49         QXmlStreamAttributes attributes( xml.attributes() );
50         QStringRef xAttribute( attributes.value("x") );
51         QStringRef yAttribute( attributes.value("y") );
52         QString newX( xAttribute.toString() );
53         QString newY( yAttribute.toString() );
54
55         m_x = newX;
56         m_y = newY;
57       }
58
59       if ( xmlName == "ERROR" ) {
60         responseHasError = true;
61       }
62
63     }
64   }
65
66   if ( xml.hasError() || responseHasError ) {
67     QMaemo5InformationBox::information( 0, "address resolution error - please check address" );
68     qDebug() << "xml error";
69     m_valid = false;
70   } else {
71     qDebug() << "(" << m_x << "," << m_y << ")";
72     if ( m_x.isEmpty() ||  m_y.isEmpty() ) {
73       qDebug() << "is NOT valid";
74       m_valid = false;
75     } else {
76       qDebug() << "is now valid";
77       m_valid = true;
78     }
79   }
80 }
81
82 void LocationPrivate::setLabel( const QString &label)
83 {
84   m_label = label;
85 }
86
87 QString LocationPrivate::label() const
88 {
89   return m_label;
90 }
91
92 void LocationPrivate::setAddress( const QString &address)
93 {
94   m_address = address;
95 }
96
97 QString LocationPrivate::address() const
98 {
99   return m_address;
100 }
101
102 void LocationPrivate::setX( uint x )
103 {
104   m_x = QString( "%1" ).arg( x );
105 }
106
107 void LocationPrivate::setX( const QString &x )
108 {
109   m_x = x;
110 }
111
112 QString LocationPrivate::x() const
113 {
114   return m_x;
115 }
116
117 void LocationPrivate::setY( uint y )
118 {
119   m_y = QString( "%1" ).arg( y );
120 }
121
122 void LocationPrivate::setY( const QString &y )
123 {
124   m_y = y;
125 }
126
127 QString LocationPrivate::y() const
128 {
129   return m_y;
130 }
131
132 void LocationPrivate::setValid( bool valid )
133 {
134   m_valid = valid;
135 }
136
137 bool LocationPrivate::isValid() const
138 {
139   return m_valid;
140 }