Merge branch 'master' of https://vcs.maemo.org/git/situare
[situare] / src / engine / engine.cpp
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7         Jussi Laitinen - jussi.laitinen@ixonos.com
8         Sami Rämö - sami.ramo@ixonos.com
9
10     Situare is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     version 2 as published by the Free Software Foundation.
13
14     Situare is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with Situare; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22     USA.
23  */
24
25 #include <QMessageBox>
26 #include <QNetworkReply>
27
28 #include "common.h"
29 #include "facebookservice/facebookauthentication.h"
30 #include "gps/gpsposition.h"
31 #include "map/mapengine.h"
32 #include "situareservice/situareservice.h"
33 #include "ui/mainwindow.h"
34 #include "mce.h"
35 #include <cmath>
36
37 #include "engine.h"
38
39 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
40 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
41 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12;  ///< Default zoom level when GPS available
42 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
43 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
44 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
45
46 SituareEngine::SituareEngine(QMainWindow *parent)
47     : QObject(parent),
48       m_autoCenteringEnabled(false),
49       m_automaticUpdateFirstStart(true),
50       m_automaticUpdateRequest(false),
51       m_userMoved(false),
52       m_automaticUpdateIntervalTimer(0),
53       m_lastUpdatedGPSPosition(QPointF())
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56     m_ui = new MainWindow;
57     m_ui->updateItemVisibility();
58
59     // build MapEngine
60     m_mapEngine = new MapEngine(this);
61     m_ui->setMapViewScene(m_mapEngine->scene());
62
63     // build GPS
64     m_gps = new GPSPosition(this);
65
66     // build SituareService
67     m_situareService = new SituareService(this);
68
69     // build FacebookAuthenticator
70     m_facebookAuthenticator = new FacebookAuthentication(this);
71
72     // connect signals
73     signalsFromMapEngine();
74     signalsFromGPS();
75     signalsFromSituareService();
76     signalsFromMainWindow();
77     signalsFromFacebookAuthenticator();
78
79     connect(this, SIGNAL(userLocationReady(User*)),
80             m_ui, SIGNAL(userLocationReady(User*)));
81
82     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
83             m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
84
85     connect(this, SIGNAL(userLocationReady(User*)),
86             m_mapEngine, SLOT(receiveOwnLocation(User*)));
87
88     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
89             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
90
91     m_automaticUpdateIntervalTimer = new QTimer(this);
92     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
93             this, SLOT(startAutomaticUpdate()));
94
95     // signals connected, now it's time to show the main window
96     // but init the MapEngine before so starting location is set
97     m_mapEngine->init();
98     m_ui->show();
99
100     m_facebookAuthenticator->start();
101
102     m_gps->setMode(GPSPosition::Default);
103     initializeGpsAndAutocentering();
104
105     m_mce = new MCE(this);
106     connect(m_mce, SIGNAL(displayStateChanged(bool)), this, SLOT(displayStateChanged(bool)));
107 }
108
109 SituareEngine::~SituareEngine()
110 {
111     qDebug() << __PRETTY_FUNCTION__;
112
113     delete m_ui;
114
115     QSettings settings(DIRECTORY_NAME, FILE_NAME);
116     settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
117     settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
118 }
119
120 void SituareEngine::changeAutoCenteringSetting(bool enabled)
121 {
122     qDebug() << __PRETTY_FUNCTION__;
123
124     m_autoCenteringEnabled = enabled;
125     enableAutoCentering(enabled);
126 }
127
128 void SituareEngine::disableAutoCentering()
129 {
130     qDebug() << __PRETTY_FUNCTION__;
131
132     changeAutoCenteringSetting(false);
133     m_ui->buildInformationBox(tr("Auto centering disabled"));
134 }
135
136 void SituareEngine::displayStateChanged(bool enabled)
137 {
138     qDebug() << __PRETTY_FUNCTION__;
139
140     m_gps->enablePowerSave(!enabled);
141
142     if (m_autoCenteringEnabled)
143         enableAutoCentering(enabled);
144 }
145
146 void SituareEngine::enableAutoCentering(bool enabled)
147 {
148     qDebug() << __PRETTY_FUNCTION__;
149
150     m_ui->setAutoCenteringButtonEnabled(enabled);
151     m_mapEngine->setAutoCentering(enabled);
152
153     if (enabled)
154         m_gps->requestLastPosition();
155 }
156
157 void SituareEngine::enableGPS(bool enabled)
158 {
159     qDebug() << __PRETTY_FUNCTION__;
160
161     m_ui->setOwnLocationCrosshairVisibility(!enabled);
162
163     if (m_gps->isInitialized()) {
164         m_ui->setGPSButtonEnabled(enabled);
165         m_mapEngine->setGPSEnabled(enabled);
166
167         if (enabled && !m_gps->isRunning()) {
168             m_gps->start();
169             enableAutoCentering(m_autoCenteringEnabled);
170             m_gps->requestLastPosition();
171
172             if(m_ui->loginState())
173                 m_ui->readAutomaticLocationUpdateSettings();
174         }
175         else if (!enabled && m_gps->isRunning()) {
176             m_gps->stop();
177             enableAutoCentering(false);
178             enableAutomaticLocationUpdate(false);
179         }
180     }
181     else {
182         if (enabled)
183             m_ui->buildInformationBox(tr("Unable to start GPS"));
184         m_ui->setGPSButtonEnabled(false);
185         m_mapEngine->setGPSEnabled(false);
186     }
187 }
188
189 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
190 {
191     qDebug() << __PRETTY_FUNCTION__;
192
193     //Show automatic update confirmation dialog
194     if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
195         m_ui->showEnableAutomaticUpdateLocationDialog(
196                 tr("Do you want to enable automatic location update with %1 min update interval?")
197                 .arg(updateIntervalMsecs/1000/60));
198         m_automaticUpdateFirstStart = false;
199     } else {
200         if (enabled && m_gps->isRunning()) {
201             m_ui->buildInformationBox(tr("Automatic location update enabled"));
202             if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
203                 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
204             else
205                 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
206
207             connect(m_gps, SIGNAL(position(QPointF,qreal)),
208                     this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
209
210             m_automaticUpdateIntervalTimer->start();
211
212         } else {
213             disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
214                     this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
215
216             m_automaticUpdateIntervalTimer->stop();
217         }
218     }
219 }
220
221 void SituareEngine::error(const int context, const int error)
222 {
223     qDebug() << __PRETTY_FUNCTION__;
224
225     switch(error)
226     {
227     case SituareError::ERROR_GENERAL:
228         if(context == ErrorContext::SITUARE) {
229             m_ui->toggleProgressIndicator(false);
230             m_ui->buildInformationBox(tr("Unknown server error"), true);
231         }
232         break;
233     case SituareError::ERROR_MISSING_ARGUMENT | QNetworkReply::ConnectionRefusedError :
234         m_ui->toggleProgressIndicator(false);
235         if(context == ErrorContext::SITUARE) {
236             m_ui->buildInformationBox(tr("Missing argument from request"), true);
237         } else if(context == ErrorContext::NETWORK) {
238             m_ui->buildInformationBox(tr("Connection refused by the server"), true);
239         }
240         break;
241     case QNetworkReply::RemoteHostClosedError:
242         if(context == ErrorContext::NETWORK) {
243             m_ui->toggleProgressIndicator(false);
244             m_ui->buildInformationBox(tr("Connection closed by the server"), true);
245         }
246         break;
247     case QNetworkReply::HostNotFoundError:
248         if(context == ErrorContext::NETWORK) {
249             m_ui->toggleProgressIndicator(false);
250             m_ui->buildInformationBox(tr("Remote server not found"), true);
251         }
252         break;
253     case QNetworkReply::TimeoutError:
254         if(context == ErrorContext::NETWORK) {
255             m_ui->toggleProgressIndicator(false);
256             m_ui->buildInformationBox(tr("Connection timed out"), true);
257         }
258         break;
259     case SituareError::SESSION_EXPIRED:
260         m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
261         m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
262         m_situareService->clearUserData();
263         m_ui->loggedIn(false);
264         m_ui->loginFailed();
265         break;
266     case SituareError::LOGIN_FAILED:
267         m_ui->toggleProgressIndicator(false);
268         m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
269         m_ui->loginFailed();
270         break;
271     case SituareError::UPDATE_FAILED:
272         m_ui->toggleProgressIndicator(false);
273         m_ui->buildInformationBox(tr("Update failed, please try again"), true);
274         break;
275     case SituareError::DATA_RETRIEVAL_FAILED:
276         m_ui->toggleProgressIndicator(false);
277         m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
278         break;
279     case SituareError::ADDRESS_RETRIEVAL_FAILED:
280         m_ui->buildInformationBox(tr("Address retrieval failed"), true);
281         break;
282     case SituareError::IMAGE_DOWNLOAD_FAILED:
283         m_ui->buildInformationBox(tr("Image download failed"), true);
284         break;
285     case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
286         m_ui->buildInformationBox(tr("Map image download failed"), true);
287         break;
288     case SituareError::GPS_INITIALIZATION_FAILED:
289         enableGPS(false);
290         m_ui->buildInformationBox(tr("GPS initialization failed"), true);
291         break;
292     case SituareError::INVALID_JSON:
293         m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
294         m_ui->loggedIn(false);
295         m_facebookAuthenticator->clearAccountInformation(false); // clean all
296         break;
297     case SituareError::ERROR_GEOLOCATION_SERVER_UNAVAILABLE:
298         m_ui->toggleProgressIndicator(false);
299         m_ui->buildInformationBox(tr("Geolocation server not responding"), true);
300         break;
301     case SituareError::ERROR_GEOLOCATION_REQUEST_FAIL:
302         m_ui->toggleProgressIndicator(false);
303         m_ui->buildInformationBox(tr("Geolocation request failed, please try again"), true);
304         break;
305     case SituareError::ERROR_GEOLOCATION_LONLAT_INVALID:
306         m_ui->toggleProgressIndicator(false);
307         m_ui->buildInformationBox(tr("Invalid lat/lon value, please try again"), true);
308         break;
309     default:
310         m_ui->toggleProgressIndicator(false);
311         if(context == ErrorContext::NETWORK)
312             qCritical() << "QNetworkReply::NetworkError: " << error;
313         else
314             qCritical() << "Unknown error: " << error;
315
316         break;
317     }
318 }
319
320 void SituareEngine::fetchUsernameFromSettings()
321 {
322     qDebug() << __PRETTY_FUNCTION__;
323
324     m_ui->setUsername(m_facebookAuthenticator->loadUsername());
325 }
326
327 void SituareEngine::initializeGpsAndAutocentering()
328 {
329     qDebug() << __PRETTY_FUNCTION__;
330
331     QSettings settings(DIRECTORY_NAME, FILE_NAME);
332     QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
333     QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
334
335     if (m_gps->isInitialized()) {
336
337         if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
338
339             connect(m_gps, SIGNAL(position(QPointF,qreal)),
340                     this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
341
342             changeAutoCenteringSetting(true);
343             enableGPS(true);
344
345             m_ui->buildInformationBox(tr("GPS enabled"));
346             m_ui->buildInformationBox(tr("Auto centering enabled"));
347
348         } else { // Normal start
349             changeAutoCenteringSetting(autoCenteringEnabled.toBool());
350             enableGPS(gpsEnabled.toBool());
351
352             if (gpsEnabled.toBool())
353                 m_ui->buildInformationBox(tr("GPS enabled"));
354
355             if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
356                 m_ui->buildInformationBox(tr("Auto centering enabled"));
357         }
358     } else {
359         enableGPS(false);
360     }
361 }
362
363 void SituareEngine::loginActionPressed()
364 {
365     qDebug() << __PRETTY_FUNCTION__;
366
367     if(m_ui->loginState()) {
368         logout();
369         m_situareService->clearUserData();
370     } else {
371         m_facebookAuthenticator->start();
372     }
373 }
374
375 void SituareEngine::loginOk()
376 {
377     qDebug() << __PRETTY_FUNCTION__;
378
379     m_ui->loggedIn(true);
380
381     m_ui->show();
382     m_situareService->fetchLocations(); // request user locations
383
384     if (m_gps->isRunning())
385         m_ui->readAutomaticLocationUpdateSettings();
386 }
387
388 void SituareEngine::loginProcessCancelled()
389 {
390     qDebug() << __PRETTY_FUNCTION__;
391
392     m_ui->toggleProgressIndicator(false);
393     m_ui->updateItemVisibility();
394 }
395
396 void SituareEngine::logout()
397 {
398     qDebug() << __PRETTY_FUNCTION__;
399
400     m_ui->loggedIn(false);
401
402     // signal to clear locationUpdateDialog's data
403     connect(this, SIGNAL(clearUpdateLocationDialogData()),
404             m_ui, SIGNAL(clearUpdateLocationDialogData()));
405     emit clearUpdateLocationDialogData();
406
407     m_facebookAuthenticator->clearAccountInformation(); // clear all
408     m_automaticUpdateFirstStart = true;
409 }
410
411 void SituareEngine::refreshUserData()
412 {
413     qDebug() << __PRETTY_FUNCTION__;
414
415     m_ui->toggleProgressIndicator(true);
416
417     m_situareService->fetchLocations();
418 }
419
420 void SituareEngine::requestAddress()
421 {
422     qDebug() << __PRETTY_FUNCTION__;
423
424     if (m_gps->isRunning())
425         m_situareService->reverseGeo(m_gps->lastPosition());
426     else
427         m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
428 }
429
430 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
431 {
432     qDebug() << __PRETTY_FUNCTION__;
433
434     m_ui->toggleProgressIndicator(true);
435
436     if (m_gps->isRunning())
437         m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
438     else
439         m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
440 }
441
442 void SituareEngine::requestAutomaticUpdateIfMoved(QPointF position)
443 {
444     qDebug() << __PRETTY_FUNCTION__;
445
446     if ((fabs(m_lastUpdatedGPSPosition.x() - position.x()) >
447          USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
448         (fabs(m_lastUpdatedGPSPosition.y() - position.y()) >
449          USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
450
451         m_lastUpdatedGPSPosition = position;
452         m_userMoved = true;
453     }
454
455     if (m_automaticUpdateRequest && m_userMoved) {
456         requestUpdateLocation(tr("Automatic location update."));
457         m_automaticUpdateRequest = false;
458         m_userMoved = false;
459     }
460 }
461
462 void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
463 {
464     qDebug() << __PRETTY_FUNCTION__;
465
466     Q_UNUSED(latLonCoordinate);
467     Q_UNUSED(accuracy);
468
469     if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
470         m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
471
472     disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
473                this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
474 }
475
476 void SituareEngine::signalsFromFacebookAuthenticator()
477 {
478     qDebug() << __PRETTY_FUNCTION__;
479
480     connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
481             this, SLOT(error(int, int)));
482
483     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
484             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
485
486     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
487             this, SLOT(loginOk()));
488
489     connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
490             m_ui, SLOT(startLoginProcess()));
491
492     connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
493             m_ui, SLOT(saveCookies()));
494
495     connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
496             m_ui, SLOT(loginUsingCookies()));
497 }
498
499 void SituareEngine::signalsFromGPS()
500 {
501     qDebug() << __PRETTY_FUNCTION__;
502
503     connect(m_gps, SIGNAL(position(QPointF,qreal)),
504             m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
505
506     connect(m_gps, SIGNAL(timeout()),
507             m_ui, SLOT(gpsTimeout()));
508
509     connect(m_gps, SIGNAL(error(int, int)),
510             this, SLOT(error(int, int)));
511 }
512
513 void SituareEngine::signalsFromMainWindow()
514 {
515     qDebug() << __PRETTY_FUNCTION__;
516
517     connect(m_ui, SIGNAL(error(int, int)),
518             this, SLOT(error(int, int)));
519
520     connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
521             this, SLOT(fetchUsernameFromSettings()));
522
523     connect(m_ui, SIGNAL(loginActionPressed()),
524             this, SLOT(loginActionPressed()));
525
526     connect(m_ui, SIGNAL(saveUsername(QString)),
527             m_facebookAuthenticator, SLOT(saveUsername(QString)));
528
529     connect(m_ui, SIGNAL(updateCredentials(QUrl)),
530             m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
531
532     // signals from map view
533     connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
534             m_mapEngine, SLOT(setCenterPosition(QPoint)));
535
536     connect(m_ui, SIGNAL(mapViewResized(QSize)),
537             m_mapEngine, SLOT(viewResized(QSize)));
538
539     connect(m_ui, SIGNAL(viewZoomFinished()),
540             m_mapEngine, SLOT(viewZoomFinished()));
541
542     // signals from zoom buttons (zoom panel and volume buttons)
543     connect(m_ui, SIGNAL(zoomIn()),
544             m_mapEngine, SLOT(zoomIn()));
545
546     connect(m_ui, SIGNAL(zoomOut()),
547             m_mapEngine, SLOT(zoomOut()));
548
549     // signals from menu buttons
550     connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
551             this, SLOT(changeAutoCenteringSetting(bool)));
552
553     connect(m_ui, SIGNAL(gpsTriggered(bool)),
554             this, SLOT(enableGPS(bool)));
555
556     //signals from dialogs
557     connect(m_ui, SIGNAL(cancelLoginProcess()),
558             this, SLOT(loginProcessCancelled()));
559
560     connect(m_ui, SIGNAL(requestReverseGeo()),
561             this, SLOT(requestAddress()));
562
563     connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
564             this, SLOT(requestUpdateLocation(QString,bool)));
565
566     connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
567             this, SLOT(enableAutomaticLocationUpdate(bool, int)));
568
569     // signals from user info tab
570     connect(m_ui, SIGNAL(refreshUserData()),
571             this, SLOT(refreshUserData()));
572
573     connect(m_ui, SIGNAL(findUser(QPointF)),
574             m_mapEngine, SLOT(centerToCoordinates(QPointF)));
575
576     // signals from friend list tab
577     connect(m_ui, SIGNAL(findFriend(QPointF)),
578             m_mapEngine, SLOT(centerToCoordinates(QPointF)));
579 }
580
581 void SituareEngine::signalsFromMapEngine()
582 {
583     qDebug() << __PRETTY_FUNCTION__;
584
585     connect(m_mapEngine, SIGNAL(error(int, int)),
586             this, SLOT(error(int, int)));
587
588     connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
589             m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
590
591     connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
592             m_ui, SIGNAL(zoomLevelChanged(int)));
593
594     connect(m_mapEngine, SIGNAL(mapScrolledManually()),
595             this, SLOT(disableAutoCentering()));
596
597     connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
598             m_ui, SIGNAL(maxZoomLevelReached()));
599
600     connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
601             m_ui, SIGNAL(minZoomLevelReached()));
602
603     connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
604             m_ui, SIGNAL(locationItemClicked(QList<QString>)));
605
606     connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
607             m_ui, SIGNAL(newMapResolution(qreal)));
608 }
609
610 void SituareEngine::signalsFromSituareService()
611 {
612     qDebug() << __PRETTY_FUNCTION__;
613
614     connect(m_situareService, SIGNAL(error(int, int)),
615             this, SLOT(error(int, int)));
616
617     connect(m_situareService, SIGNAL(error(int, int)),
618             m_ui, SIGNAL(messageSendingFailed(int)));
619
620     connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
621             m_ui, SIGNAL(reverseGeoReady(QString)));
622
623     connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
624             this, SLOT(userDataChanged(User*, QList<User*>&)));
625
626     connect(m_situareService, SIGNAL(updateWasSuccessful()),
627             this, SLOT(updateWasSuccessful()));
628
629     connect(m_situareService, SIGNAL(updateWasSuccessful()),
630             m_ui, SIGNAL(clearUpdateLocationDialogData()));
631 }
632
633 void SituareEngine::startAutomaticUpdate()
634 {
635     qDebug() << __PRETTY_FUNCTION__;
636
637     m_gps->requestUpdate();
638     m_automaticUpdateRequest = true;
639 }
640
641 void SituareEngine::updateWasSuccessful()
642 {
643     qDebug() << __PRETTY_FUNCTION__;
644
645     m_situareService->fetchLocations();
646 }
647
648 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
649 {
650     qDebug() << __PRETTY_FUNCTION__;
651
652     m_ui->toggleProgressIndicator(false);
653     m_ui->showPanels();
654
655     emit userLocationReady(user);
656     emit friendsLocationsReady(friendsList);
657 }