9
9
** $QT_BEGIN_LICENSE:LGPL$
10
10
** Commercial Usage
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Solutions Commercial License Agreement provided
13
** with the Software or, alternatively, in accordance with the terms
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Commercial License Agreement provided with
13
** the Software or, alternatively, in accordance with the terms
14
14
** contained in a written agreement between you and Nokia.
16
16
** GNU Lesser General Public License Usage
33
33
** ensure the GNU General Public License version 3.0 requirements will be
34
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** Please note Third Party Software included with Qt Solutions may impose
37
** additional restrictions and it is the user's responsibility to ensure
38
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
** Solutions Commercial license and the relevant license of the Third
40
** Party Software they are using.
42
36
** If you are unsure which license is appropriate for your use, please
43
37
** contact the sales department at qt-sales@nokia.com.
44
38
** $QT_END_LICENSE$
46
** This file is part of the Ovi services plugin for the Maps and
47
** Navigation API. The use of these services, whether by use of the
48
** plugin or by other means, is governed by the terms and conditions
49
** described by the file OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
50
** this package, located in the directory containing the Ovi services
40
** This file is part of the Ovi services plugin for the Maps and
41
** Navigation API. The use of these services, whether by use of the
42
** plugin or by other means, is governed by the terms and conditions
43
** described by the file OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
44
** this package, located in the directory containing the Ovi services
51
45
** plugin source code.
53
47
****************************************************************************/
55
49
#include "qgeosearchmanagerengine_nokia.h"
56
50
#include "qgeosearchreply_nokia.h"
51
#include "marclanguagecodes.h"
58
53
#include <qgeoaddress.h>
59
54
#include <qgeocoordinate.h>
63
58
QGeoSearchManagerEngineNokia::QGeoSearchManagerEngineNokia(const QMap<QString, QVariant> ¶meters, QGeoServiceProvider::Error *error, QString *errorString)
64
59
: QGeoSearchManagerEngine(parameters),
65
60
m_host("loc.desktop.maps.svc.ovi.com"),
66
m_referer("localhost")
61
m_token(QGeoServiceProviderFactoryNokia::defaultToken),
62
m_referer(QGeoServiceProviderFactoryNokia::defaultReferer)
68
64
m_networkManager = new QNetworkAccessManager(this);
70
QList<QString> keys = parameters.keys();
72
if (keys.contains("places.proxy")) {
66
if (parameters.contains("places.proxy")) {
73
67
QString proxy = parameters.value("places.proxy").toString();
74
68
if (!proxy.isEmpty())
75
69
m_networkManager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxy, 8080));
78
if (keys.contains("places.host")) {
72
if (parameters.contains("places.host")) {
79
73
QString host = parameters.value("places.host").toString();
80
74
if (!host.isEmpty())
84
if (keys.contains("places.referer")) {
85
QString referer = parameters.value("places.referer").toString();
86
if (!referer.isEmpty())
90
if (keys.contains("places.token")) {
91
QString token = parameters.value("places.token").toString();
78
if (parameters.contains("places.referer")) {
79
m_referer = parameters.value("places.referer").toString();
82
if (parameters.contains("places.token")) {
83
m_token = parameters.value("places.token").toString();
85
else if (parameters.contains("token")) {
86
m_token = parameters.value("token").toString();
96
90
setSupportsGeocoding(true);
97
91
setSupportsReverseGeocoding(true);
112
106
QGeoSearchReply* QGeoSearchManagerEngineNokia::geocode(const QGeoAddress &address,
113
107
QGeoBoundingArea *bounds)
117
109
if (!supportsGeocoding()) {
118
110
QGeoSearchReply *reply = new QGeoSearchReply(QGeoSearchReply::UnsupportedOptionError, "Geocoding is not supported by this service provider.", this);
119
111
emit error(reply, reply->error(), reply->errorString());
127
119
if (!m_token.isNull())
128
120
requestString += "&token=" + m_token;
130
// TODO locale / language handling
131
//requestString += "&lg=";
132
//requestString += request->locale().language();
122
requestString += "&lg=";
123
requestString += languageToMarc(locale().language());
134
125
requestString += "&country=";
135
126
requestString += address.country();
144
135
requestString += address.city();
147
if (!address.postCode().isEmpty()) {
138
if (!address.postcode().isEmpty()) {
148
139
requestString += "&zip=";
149
requestString += address.postCode();
140
requestString += address.postcode();
152
143
if (!address.street().isEmpty()) {
154
145
requestString += address.street();
157
if (!address.streetNumber().isEmpty()) {
158
requestString += "&number=";
159
requestString += address.streetNumber();
162
return search(requestString);
149
// street number has been removed from QGeoAddress
150
// do we need to try to split it out from QGeoAddress::street
151
// in order to geocode properly
154
// if (!address.streetNumber().isEmpty()) {
155
// requestString += "&number=";
156
// requestString += address.streetNumber();
159
return search(requestString, bounds);
165
162
QGeoSearchReply* QGeoSearchManagerEngineNokia::reverseGeocode(const QGeoCoordinate &coordinate,
166
163
QGeoBoundingArea *bounds)
170
165
if (!supportsReverseGeocoding()) {
171
166
QGeoSearchReply *reply = new QGeoSearchReply(QGeoSearchReply::UnsupportedOptionError, "Reverse geocoding is not supported by this service provider.", this);
172
167
emit error(reply, reply->error(), reply->errorString());
183
178
requestString += "&lat=";
184
179
requestString += trimDouble(coordinate.latitude());
186
// TODO locale / language handling
187
//requestString += "&lg=";
188
//requestString += request->locale().language();
181
requestString += "&lg=";
182
requestString += languageToMarc(locale().language());
190
return search(requestString);
184
return search(requestString, bounds);
193
187
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(const QString &searchString,
197
191
QGeoBoundingArea *bounds)
201
193
// NOTE this will eventually replaced by a much improved implementation
202
194
// which will make use of the additionLandmarkManagers()
203
195
if ((searchTypes != QGeoSearchManager::SearchTypes(QGeoSearchManager::SearchAll))
215
207
if (!m_token.isNull())
216
208
requestString += "&token=" + m_token;
218
// TODO locale / language handling
219
//requestString += "&lg=";
220
//requestString += request->locale().language();
210
requestString += "&lg=";
211
requestString += languageToMarc(locale().language());
222
213
requestString += "&obloc=";
223
214
requestString += searchString;
226
217
requestString += "&total=";
227
218
requestString += QString::number(limit);
231
222
requestString += "&offset=";
232
223
requestString += QString::number(offset);
235
return search(requestString);
226
return search(requestString, bounds, limit, offset);
238
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(QString requestString)
229
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(QString requestString,
230
QGeoBoundingArea *bounds,
240
234
QNetworkReply *networkReply = m_networkManager->get(QNetworkRequest(QUrl(requestString)));
241
QGeoSearchReplyNokia *reply = new QGeoSearchReplyNokia(networkReply, this);
235
QGeoSearchReplyNokia *reply = new QGeoSearchReplyNokia(networkReply, limit, offset, bounds, this);
244
238
SIGNAL(finished()),
295
289
emit this->error(reply, error, errorString);
292
QString QGeoSearchManagerEngineNokia::languageToMarc(QLocale::Language language)
294
uint offset = 3 * (uint(language));
295
if (language == QLocale::C || offset + 2 > sizeof(marc_language_code_list))
296
return QLatin1String("eng");
298
const unsigned char *c = marc_language_code_list + offset;
300
return QLatin1String("eng");
302
QString code(3, Qt::Uninitialized);
303
code[0] = ushort(c[0]);
304
code[1] = ushort(c[1]);
305
code[2] = ushort(c[2]);