Merge branch 'master' into situare_interact
[situare] / src / situareservice / situareservice.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Sami Rämö - sami.ramo@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <qjson/parser.h>
24
25 #include <QDebug>
26 #include <QtNetwork/QNetworkReply>
27 #include <QPixmap>
28 #include <QStringList>
29 #include <QtAlgorithms>
30 #include <QtGlobal>
31
32 #include "database.h"
33 #include "../error.h"
34 #include "network/networkaccessmanager.h"
35 #include "situarecommon.h"
36 #include "ui/avatarimage.h"
37
38 #include "situareservice.h"
39
40 SituareService::SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
41                                QObject *parent)
42         : QObject(parent),
43         m_user(0)
44 {
45     qDebug() << __PRETTY_FUNCTION__;
46
47     m_networkManager = networkManager;
48     connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
49             this, SLOT(requestFinished(QNetworkReply*)), Qt::QueuedConnection);
50
51     m_imageFetcher = imageFetcher;
52     connect(this, SIGNAL(fetchImage(QString, QUrl)),
53             m_imageFetcher, SLOT(fetchImage(QString, QUrl)));
54     connect(m_imageFetcher, SIGNAL(imageReceived(QString,QPixmap)),
55             this, SLOT(imageReceived(QString,QPixmap)));
56     connect(m_imageFetcher, SIGNAL(error(int, int)),
57             this, SIGNAL(error(int, int)));
58
59     m_database = new Database(this);
60     m_database->openDatabase();
61     m_database->createNotificationTable();
62     m_database->createUserTable();
63     m_database->createTagTable();
64     m_database->createUserTagTable();
65 }
66
67 SituareService::~SituareService()
68 {
69     qDebug() << __PRETTY_FUNCTION__;
70
71     if(m_user) {
72         delete m_user;
73         m_user = 0;
74     }
75
76     qDeleteAll(m_friendsList.begin(), m_friendsList.end());
77     m_friendsList.clear();
78 }
79
80 void SituareService::addProfileImages(const QHash<QString, QUrl> &imageUrlList)
81 {
82     qDebug() << __PRETTY_FUNCTION__;
83
84     QHashIterator<QString, QUrl> imageUrlListIterator(imageUrlList);
85
86     while (imageUrlListIterator.hasNext()) {
87         imageUrlListIterator.next();
88         emit fetchImage(imageUrlListIterator.key(), imageUrlListIterator.value());
89     }
90 }
91
92 void SituareService::addTags(const QStringList &tags)
93 {
94     qWarning() << __PRETTY_FUNCTION__ << tags.count();
95
96     foreach (QString tag, tags)
97         m_database->addTag(613374451, tag);
98
99     emit updateWasSuccessful(SituareService::SuccessfulAddTags);
100 }
101
102 void SituareService::appendAccessToken(QString &requestUrl)
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105
106     requestUrl.append(m_session);
107 }
108
109 void SituareService::buildRequest(const QString &script, const QHash<QString, QString> &parameters)
110 {
111     qDebug() << __PRETTY_FUNCTION__;
112
113     const QString PARAMETER_KEY_API = "api";
114     const QString PARAMETER_VALUE_API = "2.0";
115
116     QString url = SITUARE_URL;
117     url.append(script);
118     url.append("?");
119
120     // append default api version parameter if not yet specified
121 //    if (!parameters.contains(PARAMETER_KEY_API))
122 //        url.append(PARAMETER_KEY_API + "=" + PARAMETER_VALUE_API + "&");
123
124     // append parameters
125     if (!parameters.isEmpty()) {
126         QHash<QString, QString>::const_iterator i = parameters.constBegin();
127         while (i != parameters.constEnd()) {
128             url.append(i.key());
129             url.append("=");
130             url.append(i.value());
131             url.append("&");
132             i++;
133         }
134     }
135
136     /// @todo BUG: Url parameter strings are not url escaped
137
138 //    qWarning() << __PRETTY_FUNCTION__ << "request url with parameters:" << url;
139
140     if (!m_session.isEmpty()) {
141         appendAccessToken(url);
142         sendRequest(url);
143     } else {
144         emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
145     }
146 }
147
148 void SituareService::clearUserData()
149 {
150     qDebug() << __PRETTY_FUNCTION__;
151
152     qDeleteAll(m_friendsList.begin(), m_friendsList.end());
153     m_friendsList.clear();
154
155     if(m_user) {
156         delete m_user;
157         m_user = 0;
158     }
159     emit userDataChanged(m_user, m_friendsList);
160 }
161
162 QString SituareService::degreesToString(double degrees)
163 {
164     qDebug() << __PRETTY_FUNCTION__;
165
166     // one scene pixel is about 5.4e-6 degrees, the integer part is max three digits and one
167     // additional digit is added for maximum precision
168     const int PRECISION = 10;
169
170     return QString::number(degrees, 'f', PRECISION);
171 }
172
173 void SituareService::fetchMessages()
174 {
175     qDebug() << __PRETTY_FUNCTION__;
176
177     //Request sent to server does not need the UID
178     QByteArray arr = m_database->getNotifications(613374451);
179
180     parseMessagesData(arr);
181 }
182
183 void SituareService::fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
184                                                     const GeoCoordinate &northEastCoordinates)
185 {
186     qDebug() << __PRETTY_FUNCTION__;
187
188     //Request sent to server does not need the UID
189     QByteArray arr = m_database->getInterestingPeople(613374451,
190                                                       southWestCoordinates,
191                                                       northEastCoordinates);
192
193     parseInterestingPeopleData(arr);
194 }
195
196 void SituareService::fetchPopularTags()
197 {
198     qDebug() << __PRETTY_FUNCTION__;
199
200     QByteArray arr = m_database->getPopularTags();
201
202     parsePopularTagsData(arr);
203 }
204
205 void SituareService::fetchLocations()
206 {
207     qDebug() << __PRETTY_FUNCTION__;
208
209     QHash<QString, QString> parameters;
210     parameters.insert("extra_user_data", NORMAL_SIZE_PROFILE_IMAGE);
211
212     buildRequest(GET_LOCATIONS, parameters);
213 }
214
215 QHash<QString, QString> SituareService::getTags(const QString &userId)
216 {
217     qDebug() << __PRETTY_FUNCTION__;
218
219     return m_database->getTags(userId.toInt());
220 }
221
222 void SituareService::imageReceived(const QString &id, const QPixmap &image)
223 {
224     qDebug() << __PRETTY_FUNCTION__;
225
226     if (m_user->userId() == id)
227         emit imageReady(QString(), AvatarImage::create(image, AvatarImage::Large));
228     else
229         emit imageReady(id, AvatarImage::create(image, AvatarImage::Small));
230 }
231
232 void SituareService::parseInterestingPeopleData(const QByteArray &jsonReply)
233 {
234     qDebug() << __PRETTY_FUNCTION__;
235
236     QJson::Parser parser;
237     bool ok;
238
239     QVariantMap result = parser.parse(jsonReply, &ok).toMap();
240
241     if (!ok) {
242         emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
243         return;
244     } else {
245         QVariant people = result["people"];
246
247         QList<User> friends;
248         QList<User> others;
249
250         foreach (QVariant personVariant, people.toMap().value("friends").toList()) {
251             User user;
252             QMap<QString, QVariant> person = personVariant.toMap();
253             user.setUserId(person["uid"].toString());
254             user.setName(person["name"].toString());
255             user.setProfileImage(AvatarImage::create(
256                     QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
257             user.setProfileImageUrl(person["image_url"].toUrl());
258             user.setTags(person["tags"].toList());
259
260             bool latOk;
261             qreal latitude = person["latitude"].toReal(&latOk);
262             bool lonOk;
263             qreal longitude = person["longitude"].toReal(&lonOk);
264
265             if (latOk && lonOk) {
266                 user.setCoordinates(GeoCoordinate(latitude, longitude));
267
268                 //This should be from the server
269                 GeoCoordinate myCoord(65.008, 25.5523);
270                 qreal meters = myCoord.distanceTo(user.coordinates());
271                 qreal value;
272                 QString unit;
273                 if (meters < 1000) {
274                     value = meters;
275                     unit = "m";
276                 } else {
277                     value = meters/1000;
278                     unit = "km";
279                 }
280                 user.setDistance(value, unit);
281             }
282
283             friends.append(user);
284
285             //Remove comment when the actual server is used
286             //emit fetchImage(user.userId(), user.profileImageUrl());
287         }
288
289         foreach (QVariant personVariant, people.toMap().value("others").toList()) {
290             User user;
291             QMap<QString, QVariant> person = personVariant.toMap();
292             user.setUserId(person["uid"].toString());
293             user.setName(person["name"].toString());
294             user.setProfileImage(AvatarImage::create(
295                     QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
296             user.setProfileImageUrl(person["image_url"].toUrl());
297             user.setTags(person["tags"].toList());
298
299             others.append(user);
300
301             //Remove comment when the actual server is used
302             //emit fetchImage(user.userId(), user.profileImageUrl());
303         }
304
305         emit interestingPeopleReceived(friends, others);
306     }
307 }
308
309 void SituareService::parseUserData(const QByteArray &jsonReply)
310 {
311     qDebug() << __PRETTY_FUNCTION__;
312
313     m_defaultImage = false;
314
315     QJson::Parser parser;
316     bool ok;
317
318     QVariantMap result = parser.parse (jsonReply, &ok).toMap();
319     if (!ok) {
320         emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
321         return;
322     } else {
323
324         if(result.contains("ErrorCode")) {
325             QVariant errorVariant = result.value("ErrorCode");
326             emit error(ErrorContext::SITUARE, errorVariant.toInt());
327             return;
328         } else if(result.contains("user")) {
329
330             QVariant userVariant = result.value("user");
331             QMap<QString, QVariant> userMap = userVariant.toMap();
332
333             GeoCoordinate coordinates(userMap["latitude"].toReal(), userMap["longitude"].toReal());
334
335             QUrl imageUrl = userMap[NORMAL_SIZE_PROFILE_IMAGE].toUrl();
336
337             if(imageUrl.isEmpty()) {
338                 // user doesn't have profile image, so we need to get him a silhouette image
339                 m_defaultImage = true;
340             }
341
342             QString address = userMap["address"].toString();
343             if(address.isEmpty()) {
344                 QStringList location;
345                 location.append(QString::number(coordinates.latitude()));
346                 location.append(QString::number(coordinates.longitude()));
347                 address = location.join(", ");
348             }
349
350             User user = User(address, coordinates, userMap["name"].toString(),
351                           userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
352                           true, userMap["uid"].toString());
353
354             if(imageUrl.isEmpty()) {
355                 // user doesn't have profile image, so we need to get him a silhouette image
356                 m_defaultImage = true;
357                 user.setProfileImage(AvatarImage::create(
358                         QPixmap(":/res/images/empty_avatar_big.png"), AvatarImage::Large));
359             }
360
361             QList<User> tmpFriendsList;
362
363             foreach (QVariant friendsVariant, result["friends"].toList()) {
364               QMap<QString, QVariant> friendMap = friendsVariant.toMap();
365               QVariant distance = friendMap["distance"];
366               QMap<QString, QVariant> distanceMap = distance.toMap();
367
368               GeoCoordinate coordinates(friendMap["latitude"].toReal(),friendMap["longitude"].toReal());
369
370               QUrl imageUrl = friendMap["profile_pic"].toUrl();
371
372               if(imageUrl.isEmpty()) {
373                   // friend doesn't have profile image, so we need to get him a silhouette image
374                   m_defaultImage = true;
375               }
376
377               QString address = friendMap["address"].toString();
378               if(address.isEmpty()) {
379                   QStringList location;
380                   location.append(QString::number(coordinates.latitude()));
381                   location.append(QString::number(coordinates.longitude()));
382                   address = location.join(", ");
383               }
384
385               User buddy = User(address, coordinates, friendMap["name"].toString(),
386                                friendMap["note"].toString(), imageUrl,
387                                friendMap["timestamp"].toString(),
388                                false, friendMap["uid"].toString(), distanceMap["units"].toString(),
389                                distanceMap["value"].toDouble());
390
391               if(imageUrl.isEmpty()) {
392                   // friend doesn't have profile image, so we need to get him a silhouette image
393                   m_defaultImage = true;
394                   buddy.setProfileImage(AvatarImage::create(
395                           QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
396               }
397
398               tmpFriendsList.append(buddy);
399             }
400
401             QHash<QString, QUrl> imageUrlList; // url list for images
402
403             // set unchanged profile images or add new images to imageUrlList for downloading
404             if(m_user) {
405                 if(m_user->profileImageUrl() != user.profileImageUrl()) {
406                     if(!user.profileImageUrl().isEmpty())
407                         imageUrlList.insert(user.userId(), user.profileImageUrl());
408                 } else {
409                     user.setProfileImage(m_user->profileImage());
410                 }
411             } else {
412                 if(!user.profileImageUrl().isEmpty())
413                     imageUrlList.insert(user.userId(), user.profileImageUrl());
414             }
415
416             // clear old user object
417             if(m_user) {
418                 delete m_user;
419                 m_user = 0;
420             }
421
422             // create new user object from temporary user object
423             m_user = new User(user);
424
425             // set unchanged profile images or add new images to imageUrlList for downloading
426             if(!m_friendsList.isEmpty()) {
427                 foreach(User tmpBuddy, tmpFriendsList) {
428                     if(!tmpBuddy.profileImageUrl().isEmpty()) {
429                         bool found = false;
430                         foreach(User *buddy, m_friendsList) {
431                             if(tmpBuddy.profileImageUrl() == buddy->profileImageUrl()) {
432                                 tmpBuddy.setProfileImage(buddy->profileImage());
433                                 found = true;
434                                 break;
435                             }
436                         }
437                         if(!found && !tmpBuddy.profileImageUrl().isEmpty())
438                             imageUrlList.insert(tmpBuddy.userId(), tmpBuddy.profileImageUrl());
439                     }
440                 }
441             } else {
442                 foreach(User buddy, tmpFriendsList) {
443                     if(!buddy.profileImageUrl().isEmpty())
444                         imageUrlList.insert(buddy.userId(), buddy.profileImageUrl());
445                 }
446             }
447
448             // clear old friendlist
449             qDeleteAll(m_friendsList.begin(), m_friendsList.end());
450             m_friendsList.clear();
451
452             // populate new friendlist with temporary friendlist's data
453             foreach(User tmpFriendItem, tmpFriendsList) {
454                 User *friendItem = new User(tmpFriendItem);
455                 m_friendsList.append(friendItem);
456             }
457             tmpFriendsList.clear();
458
459             //REMOVE WHEN NOT NEEDED! get user tags and set tags to the user
460             m_user->setTags(getTags(m_user->userId()));
461
462             emit userDataChanged(m_user, m_friendsList);
463
464             // set silhouette image to imageUrlList for downloading
465             if(m_defaultImage)
466                 imageUrlList.insert("", QUrl(SILHOUETTE_URL));
467
468             addProfileImages(imageUrlList);
469             imageUrlList.clear();
470
471         } else {
472             QVariant address = result.value("address");
473             if(!address.toString().isEmpty()) {
474                 emit reverseGeoReady(address.toString());
475             } else {
476                 QStringList coordinates;
477                 coordinates.append(result.value("lat").toString());
478                 coordinates.append(result.value("lon").toString());
479
480                 emit error(ErrorContext::SITUARE, SituareError::ADDRESS_RETRIEVAL_FAILED);
481                 emit reverseGeoReady(coordinates.join(", "));
482             }
483         }
484     }
485 }
486
487 void SituareService::parseMessagesData(const QByteArray &jsonReply)
488 {
489     QJson::Parser parser;
490     bool ok;
491
492     QVariantMap result = parser.parse(jsonReply, &ok).toMap();
493
494     if (!ok) {
495         emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
496         return;
497     } else {
498         QVariant messages = result["messages"];
499
500         QList<Message> received;
501         QList<Message> sent;
502
503         foreach (QVariant messageVariant, messages.toMap().value("received").toList()) {
504             Message message(Message::MessageTypeReceived);
505             QMap<QString, QVariant> messageMap = messageVariant.toMap();
506             message.setId(messageMap["id"].toString());
507             message.setSenderId(messageMap["sender_id"].toString());
508             message.setReceiverId(messageMap["receiver_id"].toString());
509             message.setSenderName(messageMap["sender_name"].toString());
510             uint timestampSeconds = messageMap["timestamp"].toUInt();
511             message.setTimestamp(QDateTime::fromTime_t(timestampSeconds));
512             message.setText(messageMap["text"].toString());
513             message.setImage(AvatarImage::create(
514                     QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
515
516             bool latOk;
517             qreal latitude = messageMap["latitude"].toReal(&latOk);
518             bool lonOk;
519             qreal longitude = messageMap["longitude"].toReal(&lonOk);
520
521             if (latOk && lonOk) {
522                 message.setAddress(messageMap["address"].toString());
523                 message.setCoordinates(GeoCoordinate(latitude, longitude));
524             }
525
526             received.append(message);
527
528             //emit fetchImage(message.id(), messageMap["image_url"].toString());
529         }
530
531         foreach (QVariant messageVariant, messages.toMap().value("sent").toList()) {
532             Message message(Message::MessageTypeSent);
533             QMap<QString, QVariant> messageMap = messageVariant.toMap();
534             message.setId(messageMap["id"].toString());
535             message.setSenderId(messageMap["sender_id"].toString());
536             message.setReceiverId(messageMap["receiver_id"].toString());
537             message.setSenderName(messageMap["sender_name"].toString());
538             uint timestampSeconds = messageMap["timestamp"].toUInt();
539             message.setTimestamp(QDateTime::fromTime_t(timestampSeconds));
540             message.setText(messageMap["text"].toString());
541             message.setImage(AvatarImage::create(
542                     QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
543
544             bool latOk;
545             qreal latitude = messageMap["latitude"].toReal(&latOk);
546             bool lonOk;
547             qreal longitude = messageMap["longitude"].toReal(&lonOk);
548
549             if (latOk && lonOk) {
550                 message.setAddress(messageMap["address"].toString());
551                 message.setCoordinates(GeoCoordinate(latitude, longitude));
552             }
553
554             sent.append(message);
555
556             //emit fetchImage(message.id(), messageMap["image_url"].toString());
557         }
558
559         emit messagesReceived(received, sent);
560     }
561 }
562
563 void SituareService::parsePopularTagsData(const QByteArray &jsonReply)
564 {
565     qDebug() << __PRETTY_FUNCTION__;
566
567     QJson::Parser parser;
568     bool ok;
569
570     QVariantMap result = parser.parse(jsonReply, &ok).toMap();
571
572     if (!ok) {
573         emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
574         return;
575     } else {
576         QHash<QString, QString> popularTags;
577
578         foreach (QVariant tagVariant, result["popular_tags"].toList()) {
579             QMap<QString, QVariant> tag = tagVariant.toMap();
580             popularTags.insert(tag["id"].toString(), tag["name"].toString());
581         }
582
583         emit popularTagsReceived(popularTags);
584     }
585 }
586
587 void SituareService::removeMessage(const QString &id)
588 {
589     qDebug() << __PRETTY_FUNCTION__;
590
591     if (m_database->removeMessage(613374451, id))
592         emit updateWasSuccessful(SituareService::SuccessfulRemoveMessage);
593 }
594
595
596 void SituareService::removeTags(const QStringList &tags)
597 {
598     qDebug() << __PRETTY_FUNCTION__;
599
600     if (m_database->removeTags(613374451, tags))
601         emit updateWasSuccessful(SituareService::SuccessfulRemoveTags);
602 }
603
604 void SituareService::requestFinished(QNetworkReply *reply)
605 {
606     qDebug() << __PRETTY_FUNCTION__;
607
608     //Reply from situare
609     if (m_currentRequests.contains(reply)) {
610
611         qDebug() << "BytesAvailable: " << reply->bytesAvailable();
612
613         if (reply->error()) {
614             emit error(ErrorContext::NETWORK, reply->error());
615         } else {
616             QByteArray replyArray = reply->readAll();
617             qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
618
619             if(replyArray == ERROR_LAT.toAscii()) {
620                 qDebug() << "Error: " << ERROR_LAT;
621                 emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
622             } else if(replyArray == ERROR_LON.toAscii()) {
623                 qDebug() << "Error: " << ERROR_LON;
624                 emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
625             } else if(replyArray.contains(ERROR_SESSION.toAscii())) {
626                 qDebug() << "Error: " << ERROR_SESSION;
627                 emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
628             } else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
629                 qDebug() << "JSON string";
630                 parseUserData(replyArray);
631             } else if(replyArray.isEmpty()) {
632                 if(reply->url().toString().contains(UPDATE_LOCATION.toAscii())) {
633                     emit updateWasSuccessful(SituareService::SuccessfulUpdateLocation);
634                 } else {
635                     // session credentials are invalid
636                     emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
637                 }
638             } else {
639                 // unknown reply
640                 emit error(ErrorContext::SITUARE, SituareError::ERROR_GENERAL);
641             }
642         }
643         m_currentRequests.removeAll(reply);
644         reply->deleteLater();
645     }
646 }
647
648 void SituareService::reverseGeo(const GeoCoordinate &coordinates)
649 {
650     qDebug() << __PRETTY_FUNCTION__;
651
652     QHash<QString, QString> parameters;
653     parameters.insert("lat", degreesToString(coordinates.latitude()));
654     parameters.insert("lon", degreesToString(coordinates.longitude()));
655     parameters.insert("format", "json");
656
657     buildRequest(REVERSE_GEO, parameters);
658 }
659
660 void SituareService::searchPeopleByTag(const QString &tag)
661 {
662     qDebug() << __PRETTY_FUNCTION__;
663
664     QByteArray arr = m_database->getInterestingPeopleByTag(613374451, tag);
665
666     parseInterestingPeopleData(arr);
667 }
668
669 void SituareService::sendMessage(const QString &receiverId, const QString &message,
670                                  const GeoCoordinate &coordinates)
671 {
672     qDebug() << __PRETTY_FUNCTION__;
673
674     if (m_database->sendMessage(613374451, receiverId.toULongLong(), message, coordinates))
675         emit updateWasSuccessful(SituareService::SuccessfulSendMessage);
676 }
677
678 void SituareService::sendRequest(const QString &requestUrl)
679 {
680     qDebug() << __PRETTY_FUNCTION__ << "requestUrl" << requestUrl;
681
682     // make and send the request
683     QNetworkRequest request;
684     request.setUrl(QUrl(requestUrl));
685     request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
686     QNetworkReply *reply = m_networkManager->get(request, true);
687     m_currentRequests.append(reply);
688 }
689
690 void SituareService::updateSession(const QString &session)
691 {
692     qDebug() << __PRETTY_FUNCTION__;
693
694     m_session = session;
695
696     if (m_session.isEmpty())
697         clearUserData();
698 }
699
700 void SituareService::updateLocation(const GeoCoordinate &coordinates, const QString &status,
701                                     const bool &publish)
702 {
703     qDebug() << __PRETTY_FUNCTION__;
704
705     QHash<QString, QString> parameters;
706     parameters.insert("lat", degreesToString(coordinates.latitude()));
707     parameters.insert("lon", degreesToString(coordinates.longitude()));
708     parameters.insert("publish", publish ? "true" : "false");
709     parameters.insert("data", status); ///< @todo if !empty ???
710
711     buildRequest(UPDATE_LOCATION, parameters);
712 }