e5b4287a8c182154f15bd888156ac468b3973e5c
[ptas] / src / location_p.cpp
1 #include <stdio.h>
2 #include "location_p.h"
3
4 #include "xmlparser.h"
5
6 #include <QXmlStreamReader>
7 #include <QByteArray>
8 #include <QDebug>
9 #include <QMaemo5InformationBox>
10
11 LocationPrivate::LocationPrivate(const QString &longitude, const QString &latitude, const QString &label) :
12     m_label(label),
13     m_address(),
14     m_longitude(longitude),
15     m_latitude(latitude),
16     m_valid(true)
17 {
18 }
19
20 LocationPrivate::LocationPrivate(const QString &label) :
21     m_label(label),
22     m_address(),
23     m_longitude(QString()),
24     m_latitude(QString()),
25     m_valid(false)
26 {
27 }
28
29 LocationPrivate::~LocationPrivate()
30 {
31     m_label="deleted";
32     m_address="";
33     m_longitude="";
34     m_latitude="";
35     m_valid=false;
36 }
37
38 void LocationPrivate::parseReply(const QByteArray &reply)
39 {
40     qDebug() << "parsing/" << reply;
41
42     XmlParser parser;
43     QPair<QString,QString> parsedReply = parser.parseGeocode(reply);
44
45     m_longitude = parsedReply.first;
46     m_latitude  = parsedReply.second;
47
48     qDebug() << "DONE parsing";
49
50     if (parser.error()) {
51         QMaemo5InformationBox::information(0, "address resolution error - please check address");
52         m_valid = false;
53     } else {
54         qDebug() << "(" << m_longitude << "," << m_latitude << ")";
55         if (m_longitude.isEmpty() ||  m_latitude.isEmpty()) {
56             qDebug() << "is NOT valid";
57             m_valid = false;
58         } else {
59             qDebug() << "is now valid";
60             m_valid = true;
61         }
62     }
63 }
64
65 void LocationPrivate::setLabel(const QString &label)
66 {
67     m_label = label;
68 }
69
70 QString LocationPrivate::label() const
71 {
72     return m_label;
73 }
74
75 void LocationPrivate::setAddress(const QString &address)
76 {
77     m_address = address;
78 }
79
80 QString LocationPrivate::address() const
81 {
82     return m_address;
83 }
84
85 void LocationPrivate::setLongitude(double longitude)
86 {
87     m_longitude = QString("%1").arg(longitude);
88 }
89
90 void LocationPrivate::setLongitude(const QString &longitude)
91 {
92     m_longitude = longitude;
93 }
94
95 QString LocationPrivate::longitude() const
96 {
97     return m_longitude;
98 }
99
100 void LocationPrivate::setlatitude(double latitude)
101 {
102     m_latitude = QString("%1").arg(latitude);
103 }
104
105 void LocationPrivate::setlatitude(const QString &latitude)
106 {
107     m_latitude = latitude;
108 }
109
110 QString LocationPrivate::latitude() const
111 {
112     return m_latitude;
113 }
114
115 void LocationPrivate::setValid(bool valid)
116 {
117     qDebug() << Q_FUNC_INFO << "/valid/" << valid;
118     m_valid = valid;
119 }
120
121 bool LocationPrivate::isValid() const
122 {
123     return m_valid;
124 }