~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to plugins/geoservices/nokia/qgeosearchmanagerengine_nokia.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
**
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.
15
15
**
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.
35
35
**
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.
41
 
**
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$
45
39
**
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.
52
46
**
53
47
****************************************************************************/
54
48
 
55
49
#include "qgeosearchmanagerengine_nokia.h"
56
50
#include "qgeosearchreply_nokia.h"
 
51
#include "marclanguagecodes.h"
57
52
 
58
53
#include <qgeoaddress.h>
59
54
#include <qgeocoordinate.h>
63
58
QGeoSearchManagerEngineNokia::QGeoSearchManagerEngineNokia(const QMap<QString, QVariant> &parameters, 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)
67
63
{
68
64
    m_networkManager = new QNetworkAccessManager(this);
69
65
 
70
 
    QList<QString> keys = parameters.keys();
71
 
 
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));
76
70
    }
77
71
 
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())
81
75
            m_host = host;
82
76
    }
83
77
 
84
 
    if (keys.contains("places.referer")) {
85
 
        QString referer = parameters.value("places.referer").toString();
86
 
        if (!referer.isEmpty())
87
 
            m_referer = referer;
88
 
    }
89
 
 
90
 
    if (keys.contains("places.token")) {
91
 
        QString token = parameters.value("places.token").toString();
92
 
        if (!token.isEmpty())
93
 
            m_token = token;
94
 
    }
 
78
    if (parameters.contains("places.referer")) {
 
79
        m_referer = parameters.value("places.referer").toString();
 
80
    }
 
81
 
 
82
    if (parameters.contains("places.token")) {
 
83
        m_token = parameters.value("places.token").toString();
 
84
    }
 
85
    else if (parameters.contains("token")) {
 
86
        m_token = parameters.value("token").toString();
 
87
    }
 
88
 
95
89
 
96
90
    setSupportsGeocoding(true);
97
91
    setSupportsReverseGeocoding(true);
112
106
QGeoSearchReply* QGeoSearchManagerEngineNokia::geocode(const QGeoAddress &address,
113
107
        QGeoBoundingArea *bounds)
114
108
{
115
 
    Q_UNUSED(bounds)
116
 
 
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;
129
121
 
130
 
    // TODO locale / language handling
131
 
    //requestString += "&lg=";
132
 
    //requestString += request->locale().language();
 
122
    requestString += "&lg=";
 
123
    requestString += languageToMarc(locale().language());
133
124
 
134
125
    requestString += "&country=";
135
126
    requestString += address.country();
144
135
        requestString += address.city();
145
136
    }
146
137
 
147
 
    if (!address.postCode().isEmpty()) {
 
138
    if (!address.postcode().isEmpty()) {
148
139
        requestString += "&zip=";
149
 
        requestString += address.postCode();
 
140
        requestString += address.postcode();
150
141
    }
151
142
 
152
143
    if (!address.street().isEmpty()) {
154
145
        requestString += address.street();
155
146
    }
156
147
 
157
 
    if (!address.streetNumber().isEmpty()) {
158
 
        requestString += "&number=";
159
 
        requestString += address.streetNumber();
160
 
    }
161
 
 
162
 
    return search(requestString);
 
148
    // TODO?
 
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
 
152
 
 
153
    // Old code:
 
154
//    if (!address.streetNumber().isEmpty()) {
 
155
//        requestString += "&number=";
 
156
//        requestString += address.streetNumber();
 
157
//    }
 
158
 
 
159
    return search(requestString, bounds);
163
160
}
164
161
 
165
162
QGeoSearchReply* QGeoSearchManagerEngineNokia::reverseGeocode(const QGeoCoordinate &coordinate,
166
163
        QGeoBoundingArea *bounds)
167
164
{
168
 
    Q_UNUSED(bounds)
169
 
 
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());
185
180
 
186
 
    // TODO locale / language handling
187
 
    //requestString += "&lg=";
188
 
    //requestString += request->locale().language();
 
181
    requestString += "&lg=";
 
182
    requestString += languageToMarc(locale().language());
189
183
 
190
 
    return search(requestString);
 
184
    return search(requestString, bounds);
191
185
}
192
186
 
193
187
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(const QString &searchString,
196
190
        int offset,
197
191
        QGeoBoundingArea *bounds)
198
192
{
199
 
    Q_UNUSED(bounds)
200
 
 
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;
217
209
 
218
 
    // TODO locale / language handling
219
 
    //requestString += "&lg=";
220
 
    //requestString += request->locale().language();
 
210
    requestString += "&lg=";
 
211
    requestString += languageToMarc(locale().language());
221
212
 
222
213
    requestString += "&obloc=";
223
214
    requestString += searchString;
224
215
 
225
 
    if(limit>0) {
 
216
    if (limit > 0) {
226
217
        requestString += "&total=";
227
218
        requestString += QString::number(limit);
228
219
    }
229
220
 
230
 
    if(offset>0) {
 
221
    if (offset > 0) {
231
222
        requestString += "&offset=";
232
223
        requestString += QString::number(offset);
233
224
    }
234
225
 
235
 
    return search(requestString);
 
226
    return search(requestString, bounds, limit, offset);
236
227
}
237
228
 
238
 
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(QString requestString)
 
229
QGeoSearchReply* QGeoSearchManagerEngineNokia::search(QString requestString,
 
230
        QGeoBoundingArea *bounds,
 
231
        int limit,
 
232
        int offset)
239
233
{
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);
242
236
 
243
237
    connect(reply,
244
238
            SIGNAL(finished()),
294
288
 
295
289
    emit this->error(reply, error, errorString);
296
290
}
 
291
 
 
292
QString QGeoSearchManagerEngineNokia::languageToMarc(QLocale::Language language)
 
293
{
 
294
    uint offset = 3 * (uint(language));
 
295
    if (language == QLocale::C || offset + 2 > sizeof(marc_language_code_list))
 
296
        return QLatin1String("eng");
 
297
 
 
298
    const unsigned char *c = marc_language_code_list + offset;
 
299
    if (c[0] == 0)
 
300
        return QLatin1String("eng");
 
301
 
 
302
    QString code(3, Qt::Uninitialized);
 
303
    code[0] = ushort(c[0]);
 
304
    code[1] = ushort(c[1]);
 
305
    code[2] = ushort(c[2]);
 
306
 
 
307
    return code;
 
308
}