3 #include "location_p.h"
9 #include <QNetworkAccessManager>
11 #include <QNetworkRequest>
12 #include <QNetworkReply>
13 #include <QXmlStreamReader>
15 #include <QXmlStreamAttributes>
17 #include <QGeoPositionInfo>
21 Location::Location(const QString &x, const QString &y, const QString &label) :
22 q(new LocationPrivate(x, y, label)),
23 manager(new QNetworkAccessManager(this))
26 manager, SIGNAL(finished(QNetworkReply*)),
27 this, SLOT(replyFinished(QNetworkReply*))
31 Location::Location(const QGeoPositionInfo &positionInfo, const QString &label) :
32 q(new LocationPrivate(label)),
35 setLocation(positionInfo);
38 void Location::setLocation(const QGeoPositionInfo &positionInfo)
40 double latitude = positionInfo.coordinate().latitude();
41 double longitude = positionInfo.coordinate().longitude();
43 qDebug() << "GPS Location/" << longitude << latitude;
45 q->setLongitude(longitude);
46 q->setlatitude(latitude);
50 Location::Location(const Location &from) :
52 q(new LocationPrivate(from.label())),
55 q->setAddress(from.address());
56 q->setLongitude(from.longitude());
57 q->setlatitude(from.latitude());
58 q->setValid(from.isValid());
59 if (from.manager != 0) {
60 manager = new QNetworkAccessManager(this);
61 connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
65 Location::Location(const QString &label) :
66 q(new LocationPrivate(label)),
67 manager(new QNetworkAccessManager(this))
69 connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
80 Location &Location::operator=(const Location &from)
82 q = new LocationPrivate(from.label());
83 q->setAddress(from.address());
84 q->setLongitude(from.longitude());
85 q->setlatitude(from.latitude());
86 q->setValid(from.isValid());
88 if (from.manager != 0) {
89 manager = new QNetworkAccessManager(this);
90 connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
98 void Location::resolveAddress(const QString &address)
100 qDebug() << "resolving address (" << address << ")";
102 q->setAddress(address);
105 QUrl fullUrl(Ytv::Url);
106 QByteArray encodedAddress = QUrl::toPercentEncoding(address);
107 qDebug() << "encodedAddress/" << encodedAddress;
109 fullUrl.addQueryItem("user", Ytv::Username);
110 fullUrl.addQueryItem("pass", Ytv::Password);
111 fullUrl.addEncodedQueryItem("key", encodedAddress);
112 fullUrl.addQueryItem("request", Ytv::Geocode);
113 fullUrl.addQueryItem("format", Ytv::Xml);
114 fullUrl.addQueryItem("language", Ytv::English);
115 fullUrl.addQueryItem("epsg_out", Ytv::WGS84);
117 qDebug() << "resolveAddress/" << address << "/" << fullUrl;
118 manager->get(QNetworkRequest(fullUrl));
119 qDebug() << "waiting for reply from Ytv";
123 void Location::replyFinished(QNetworkReply * reply)
125 qDebug() << "address resolved";
126 q->parseReply(reply->readAll());
129 qDebug() << label() << "becomeValid";
132 qDebug() << label() << "not valid";
133 emit becomeInValid();
139 QString Location::longitude() const
141 return q->longitude();
144 QString Location::latitude() const
146 return q->latitude();
149 void Location::setLabel(const QString &label) const
154 void Location::setValid(bool valid) const
159 QString Location::label() const
164 void Location::setAddress(const QString &address) const
166 qDebug() << "setting address to" << address;
167 q->setAddress(address);
170 QString Location::address() const
175 bool Location::isValid() const