Changes: added GPS class and made app get from location from GPS
[ptas] / zouba / location_p.cpp
1 #include <stdio.h>
2 #include "location_p.h"
3
4 #include <QXmlStreamReader>
5 #include <QByteArray>
6 #include <QDebug>
7
8 LocationPrivate::LocationPrivate( QString x, QString y ) :
9   m_x(x),
10   m_y(y),
11   m_valid(true)
12 {
13 }
14
15 LocationPrivate::LocationPrivate() :
16   m_x(0),
17   m_y(0),
18   m_valid(false)
19 {
20 }
21
22 LocationPrivate::~LocationPrivate()
23 {
24 }
25
26 void LocationPrivate::parseReply( const QByteArray &reply )
27 {
28   QXmlStreamReader xml( reply );
29
30   while ( !xml.atEnd() ) {
31     xml.readNext();
32     if ( xml.isStartElement() && xml.name() == "LOC" ) {
33       QXmlStreamAttributes attributes( xml.attributes() );
34       QStringRef xAttribute( attributes.value("x") );
35       QStringRef yAttribute( attributes.value("y") );
36       QString newX( xAttribute.toString() );
37       QString newY( yAttribute.toString() );
38
39       m_x = newX;
40       m_y = newY;
41     }
42   }
43
44   if ( xml.hasError() ) {
45     qDebug() << "xml error";
46     m_valid = false;
47   } else {
48     m_valid = true;
49   }
50 }
51
52 void LocationPrivate::setX( uint x )
53 {
54   m_x = QString( "%1" ).arg( x );
55 }
56
57 void LocationPrivate::setX( QString x )
58 {
59   m_x = x;
60 }
61
62 QString LocationPrivate::x() const
63 {
64   return m_x;
65 }
66
67 void LocationPrivate::setY( uint y )
68 {
69   m_y = QString( "%1" ).arg( y );
70 }
71
72 void LocationPrivate::setY( QString y )
73 {
74   m_y = y;
75 }
76
77 QString LocationPrivate::y() const
78 {
79   return m_y;
80 }
81
82 void LocationPrivate::setValid( bool valid )
83 {
84   m_valid = valid;
85 }
86
87 bool LocationPrivate::isValid() const
88 {
89   return m_valid;
90 }