Added dialogs to change home and work locations.
[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     m_valid = true;
55   }
56 }
57
58 void LocationPrivate::setLabel( const QString &label)
59 {
60   m_label = label;
61 }
62
63 QString LocationPrivate::label() const
64 {
65   return m_label;
66 }
67
68 void LocationPrivate::setAddress( const QString &address)
69 {
70   m_address = address;
71 }
72
73 QString LocationPrivate::address() const
74 {
75   return m_address;
76 }
77
78 void LocationPrivate::setX( uint x )
79 {
80   m_x = QString( "%1" ).arg( x );
81 }
82
83 void LocationPrivate::setX( const QString &x )
84 {
85   m_x = x;
86 }
87
88 QString LocationPrivate::x() const
89 {
90   return m_x;
91 }
92
93 void LocationPrivate::setY( uint y )
94 {
95   m_y = QString( "%1" ).arg( y );
96 }
97
98 void LocationPrivate::setY( const QString &y )
99 {
100   m_y = y;
101 }
102
103 QString LocationPrivate::y() const
104 {
105   return m_y;
106 }
107
108 void LocationPrivate::setValid( bool valid )
109 {
110   m_valid = valid;
111 }
112
113 bool LocationPrivate::isValid() const
114 {
115   return m_valid;
116 }