Added facility to restore and save locations, and set existing location in home and...
[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( const QString &x, const QString &y, const QString &label ) :
9   m_label(label),
10   m_address(),
11   m_x(x),
12   m_y(y),
13   m_valid(true)
14 {
15 }
16
17 LocationPrivate::LocationPrivate( const QString &label ) :
18   m_label(label),
19   m_address(),
20   m_x(0),
21   m_y(0),
22   m_valid(false)
23 {
24 }
25
26 LocationPrivate::~LocationPrivate()
27 {
28 }
29
30 void LocationPrivate::parseReply( const QByteArray &reply )
31 {
32   qDebug() << "parsing";
33   QXmlStreamReader xml( reply );
34
35   while ( !xml.atEnd() ) {
36     xml.readNext();
37     if ( xml.isStartElement() && xml.name() == "LOC" ) {
38       QXmlStreamAttributes attributes( xml.attributes() );
39       QStringRef xAttribute( attributes.value("x") );
40       QStringRef yAttribute( attributes.value("y") );
41       QString newX( xAttribute.toString() );
42       QString newY( yAttribute.toString() );
43
44       m_x = newX;
45       m_y = newY;
46     }
47   }
48
49   if ( xml.hasError() ) {
50     qDebug() << "xml error";
51     m_valid = false;
52   } else {
53     qDebug() << "(" << m_x << "," << m_y << ")";
54     qDebug() << "is now valid";
55     m_valid = true;
56   }
57 }
58
59 void LocationPrivate::setLabel( const QString &label)
60 {
61   m_label = label;
62 }
63
64 QString LocationPrivate::label() const
65 {
66   return m_label;
67 }
68
69 void LocationPrivate::setAddress( const QString &address)
70 {
71   m_address = address;
72 }
73
74 QString LocationPrivate::address() const
75 {
76   return m_address;
77 }
78
79 void LocationPrivate::setX( uint x )
80 {
81   m_x = QString( "%1" ).arg( x );
82 }
83
84 void LocationPrivate::setX( const QString &x )
85 {
86   m_x = x;
87 }
88
89 QString LocationPrivate::x() const
90 {
91   return m_x;
92 }
93
94 void LocationPrivate::setY( uint y )
95 {
96   m_y = QString( "%1" ).arg( y );
97 }
98
99 void LocationPrivate::setY( const QString &y )
100 {
101   m_y = y;
102 }
103
104 QString LocationPrivate::y() const
105 {
106   return m_y;
107 }
108
109 void LocationPrivate::setValid( bool valid )
110 {
111   m_valid = valid;
112 }
113
114 bool LocationPrivate::isValid() const
115 {
116   return m_valid;
117 }