2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
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
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.
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.
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,
27 #include <QMessageBox>
28 #include <QNetworkReply>
30 #include "application.h"
32 #include "contactmanager.h"
34 #include "facebookservice/facebookauthentication.h"
35 #include "gps/gpsposition.h"
36 #include "map/mapengine.h"
37 #include "routing/geocodingservice.h"
38 #include "routing/routingservice.h"
40 #include "network/networkaccessmanager.h"
41 #include "situareservice/situareservice.h"
42 #include "ui/mainwindow.h"
46 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
47 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
48 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
49 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
50 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
51 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
53 SituareEngine::SituareEngine()
54 : m_autoCenteringEnabled(false),
55 m_automaticUpdateFirstStart(true),
56 m_automaticUpdateRequest(false),
58 m_automaticUpdateIntervalTimer(0),
59 m_lastUpdatedGPSPosition(GeoCoordinate())
61 qDebug() << __PRETTY_FUNCTION__;
63 m_ui = new MainWindow;
64 m_ui->updateItemVisibility(false);
66 Application *application = static_cast<Application *>(qApp);
67 application->registerWindow(m_ui->winId());
69 connect(application, SIGNAL(topmostWindowChanged(bool)),
70 this, SLOT(topmostWindowChanged(bool)));
72 m_networkAccessManager = new NetworkAccessManager(this);
75 m_mapEngine = new MapEngine(this);
76 m_ui->setMapViewScene(m_mapEngine->scene());
79 m_gps = new GPSPosition(this);
81 // build SituareService
82 m_situareService = new SituareService(this);
84 // build FacebookAuthenticator
85 m_facebookAuthenticator = new FacebookAuthentication(m_ui, this);
87 // build routing service
88 m_routingService = new RoutingService(this); // create this when needed, not in constructor!
90 // build geocoding service
91 m_geocodingService = new GeocodingService(this);
94 signalsFromMapEngine();
95 signalsFromGeocodingService();
97 signalsFromRoutingService();
98 signalsFromSituareService();
99 signalsFromMainWindow();
100 signalsFromFacebookAuthenticator();
102 connect(this, SIGNAL(userLocationReady(User*)),
103 m_ui, SIGNAL(userLocationReady(User*)));
105 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
106 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
108 connect(this, SIGNAL(userLocationReady(User*)),
109 m_mapEngine, SLOT(receiveOwnLocation(User*)));
111 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
112 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
114 connect(this, SIGNAL(friendImageReady(User*)),
115 m_ui, SIGNAL(friendImageReady(User*)));
117 connect(this, SIGNAL(friendImageReady(User*)),
118 m_mapEngine, SIGNAL(friendImageReady(User*)));
120 m_automaticUpdateIntervalTimer = new QTimer(this);
121 connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
122 this, SLOT(startAutomaticUpdate()));
124 // signals connected, now it's time to show the main window
125 // but init the MapEngine before so starting location is set
129 m_gps->setMode(GPSPosition::Default);
130 initializeGpsAndAutocentering();
132 m_mce = new MCE(this);
133 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
135 m_contactManager = new ContactManager(this);
136 m_contactManager->requestContactGuids();
138 m_facebookAuthenticator->login();
141 SituareEngine::~SituareEngine()
143 qDebug() << __PRETTY_FUNCTION__;
147 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
148 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
149 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
152 void SituareEngine::changeAutoCenteringSetting(bool enabled)
154 qDebug() << __PRETTY_FUNCTION__ << enabled;
156 m_autoCenteringEnabled = enabled;
157 setAutoCentering(enabled);
160 void SituareEngine::disableAutoCentering()
162 qDebug() << __PRETTY_FUNCTION__;
164 changeAutoCenteringSetting(false);
167 void SituareEngine::draggingModeTriggered()
169 qDebug() << __PRETTY_FUNCTION__;
172 m_mce->vibrationFeedback();
175 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
177 qDebug() << __PRETTY_FUNCTION__;
179 //Show automatic update confirmation dialog
180 if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
181 m_ui->showEnableAutomaticUpdateLocationDialog(
182 tr("Do you want to enable automatic location update with %1 min update interval?")
183 .arg(updateIntervalMsecs/1000/60));
184 m_automaticUpdateFirstStart = false;
186 if (enabled && m_gps->isRunning()) {
187 m_ui->buildInformationBox(tr("Automatic location update enabled"));
188 if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
189 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
191 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
193 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
194 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
196 m_automaticUpdateIntervalTimer->start();
199 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
200 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
202 m_automaticUpdateIntervalTimer->stop();
207 void SituareEngine::error(const int context, const int error)
209 qDebug() << __PRETTY_FUNCTION__;
213 case SituareError::ERROR_GENERAL:
214 if(context == ErrorContext::SITUARE) {
215 m_ui->toggleProgressIndicator(false);
216 m_ui->buildInformationBox(tr("Unknown server error"), true);
219 case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
220 m_ui->toggleProgressIndicator(false);
221 if(context == ErrorContext::SITUARE) {
222 m_ui->buildInformationBox(tr("Missing parameter from request"), true);
223 } else if(context == ErrorContext::NETWORK) {
224 m_ui->buildInformationBox(tr("Connection refused by the server"), true);
227 case QNetworkReply::RemoteHostClosedError:
228 if(context == ErrorContext::NETWORK) {
229 m_ui->toggleProgressIndicator(false);
230 m_ui->buildInformationBox(tr("Connection closed by the server"), true);
233 case QNetworkReply::HostNotFoundError:
234 if(context == ErrorContext::NETWORK) {
235 m_ui->toggleProgressIndicator(false);
236 m_ui->buildInformationBox(tr("Remote server not found"), true);
239 case QNetworkReply::TimeoutError:
240 if(context == ErrorContext::NETWORK) {
241 m_ui->toggleProgressIndicator(false);
242 m_ui->buildInformationBox(tr("Connection timed out"), true);
245 case QNetworkReply::UnknownNetworkError:
246 if(context == ErrorContext::NETWORK) {
247 m_ui->toggleProgressIndicator(false);
248 m_ui->buildInformationBox(tr("No network connection"), true);
251 case SituareError::SESSION_EXPIRED:
252 m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
253 m_facebookAuthenticator->logOut();
254 m_facebookAuthenticator->login();
256 case SituareError::UPDATE_FAILED:
257 m_ui->toggleProgressIndicator(false);
258 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
260 case SituareError::DATA_RETRIEVAL_FAILED:
261 m_ui->toggleProgressIndicator(false);
262 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
264 case SituareError::ADDRESS_RETRIEVAL_FAILED:
265 m_ui->toggleProgressIndicator(false);
266 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
268 case SituareError::IMAGE_DOWNLOAD_FAILED:
269 m_ui->buildInformationBox(tr("Image download failed"), true);
271 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
272 m_ui->buildInformationBox(tr("Map image download failed"), true);
274 case SituareError::GPS_INITIALIZATION_FAILED:
276 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
278 case SituareError::INVALID_JSON:
279 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
280 m_ui->loggedIn(false);
281 m_facebookAuthenticator->clearAccountInformation(false); // clean all
283 case SituareError::ERROR_ROUTING_FAILED:
284 m_ui->toggleProgressIndicator(false);
285 m_ui->buildInformationBox(tr("Routing failed"), true);
287 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
288 m_ui->buildInformationBox(tr("No results found"), true);
291 m_ui->toggleProgressIndicator(false);
292 if(context == ErrorContext::NETWORK)
293 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
295 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
300 void SituareEngine::imageReady(User *user)
302 qDebug() << __PRETTY_FUNCTION__;
305 emit userLocationReady(user);
307 emit friendImageReady(user);
310 void SituareEngine::initializeGpsAndAutocentering()
312 qDebug() << __PRETTY_FUNCTION__;
314 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
315 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
316 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
318 if (m_gps->isInitialized()) {
320 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
322 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
323 this, SLOT(setFirstStartZoomLevel()));
325 changeAutoCenteringSetting(true);
328 m_ui->buildInformationBox(tr("GPS enabled"));
330 } else { // Normal start
331 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
332 setGPS(gpsEnabled.toBool());
334 if (gpsEnabled.toBool())
335 m_ui->buildInformationBox(tr("GPS enabled"));
342 void SituareEngine::locationSearch(QString location)
344 qDebug() << __PRETTY_FUNCTION__;
346 if(!location.isEmpty())
347 m_geocodingService->requestLocation(location);
350 void SituareEngine::loginActionPressed()
352 qDebug() << __PRETTY_FUNCTION__;
354 if (m_facebookAuthenticator->isLoggedIn())
355 m_facebookAuthenticator->logOut(true);
356 else if (m_networkAccessManager->isConnected())
357 m_facebookAuthenticator->login();
359 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
362 void SituareEngine::onLogin()
364 qDebug() << __PRETTY_FUNCTION__;
366 m_ui->loggedIn(true);
368 m_situareService->fetchLocations();
370 if (m_gps->isRunning())
371 m_ui->readAutomaticLocationUpdateSettings();
374 void SituareEngine::onLogout()
376 qDebug() << __PRETTY_FUNCTION__;
378 m_ui->loggedIn(false);
379 m_ui->clearUpdateLocationDialogData();
380 m_situareService->updateSession(""); // empty session string means logged out
381 m_automaticUpdateFirstStart = true;
384 void SituareEngine::refreshUserData()
386 qDebug() << __PRETTY_FUNCTION__;
388 if (m_networkAccessManager->isConnected()) {
389 m_ui->toggleProgressIndicator(true);
390 m_situareService->fetchLocations();
393 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
397 void SituareEngine::requestAddress()
399 qDebug() << __PRETTY_FUNCTION__;
401 if (m_networkAccessManager->isConnected()) {
402 if (m_gps->isRunning())
403 m_situareService->reverseGeo(m_gps->lastPosition());
405 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
408 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
412 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
414 qDebug() << __PRETTY_FUNCTION__;
416 if (m_networkAccessManager->isConnected()) {
417 m_ui->toggleProgressIndicator(true);
419 if (m_gps->isRunning())
420 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
422 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
425 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
429 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
431 qDebug() << __PRETTY_FUNCTION__;
433 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
434 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
435 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
436 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
438 m_lastUpdatedGPSPosition = position;
442 if (m_automaticUpdateRequest && m_userMoved) {
443 requestUpdateLocation(tr("Automatic location update"));
444 m_automaticUpdateRequest = false;
449 void SituareEngine::routeParsed(Route &route)
451 qDebug() << __PRETTY_FUNCTION__;
455 m_ui->toggleProgressIndicator(false);
458 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
460 qDebug() << __PRETTY_FUNCTION__;
462 m_ui->toggleProgressIndicator(true);
464 if (m_gps->isRunning())
465 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
467 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
470 void SituareEngine::routeToCursor()
472 qDebug() << __PRETTY_FUNCTION__;
474 routeTo(m_mapEngine->centerGeoCoordinate());
477 void SituareEngine::setAutoCentering(bool enabled)
479 qDebug() << __PRETTY_FUNCTION__ << enabled;
481 m_ui->setIndicatorButtonEnabled(enabled);
482 m_mapEngine->setAutoCentering(enabled);
483 m_ui->setCrosshairVisibility(!enabled);
487 m_gps->requestLastPosition();
491 void SituareEngine::setFirstStartZoomLevel()
493 qDebug() << __PRETTY_FUNCTION__;
495 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
496 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
498 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
499 this, SLOT(setFirstStartZoomLevel()));
502 void SituareEngine::setGPS(bool enabled)
504 qDebug() << __PRETTY_FUNCTION__ << enabled;
506 if (m_gps->isInitialized()) {
507 m_ui->setGPSButtonEnabled(enabled);
508 m_mapEngine->setGPSEnabled(enabled);
510 if (enabled && !m_gps->isRunning()) {
512 m_gps->requestLastPosition();
514 if(m_facebookAuthenticator->isLoggedIn())
515 m_ui->readAutomaticLocationUpdateSettings();
517 else if (!enabled && m_gps->isRunning()) {
519 changeAutoCenteringSetting(false);
520 enableAutomaticLocationUpdate(false);
525 m_ui->buildInformationBox(tr("Unable to start GPS"));
526 m_ui->setGPSButtonEnabled(false);
527 m_mapEngine->setGPSEnabled(false);
531 void SituareEngine::setPowerSaving(bool enabled)
533 qDebug() << __PRETTY_FUNCTION__ << enabled;
535 m_gps->enablePowerSave(enabled);
537 if(m_autoCenteringEnabled)
538 m_mapEngine->setAutoCentering(!enabled);
541 void SituareEngine::showContactDialog(const QString &facebookId)
543 qDebug() << __PRETTY_FUNCTION__;
545 QString guid = m_contactManager->contactGuid(facebookId);
548 m_ui->showContactDialog(guid);
550 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
551 "account from Conversations to use this feature."), true);
554 void SituareEngine::signalsFromFacebookAuthenticator()
556 qDebug() << __PRETTY_FUNCTION__;
558 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
559 this, SLOT(error(int, int)));
561 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
562 m_situareService, SLOT(updateSession(QString)));
564 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
565 this, SLOT(onLogin()));
567 connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
570 void SituareEngine::signalsFromGeocodingService()
572 qDebug() << __PRETTY_FUNCTION__;
574 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
575 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
577 connect(m_geocodingService, SIGNAL(error(int, int)),
578 this, SLOT(error(int, int)));
581 void SituareEngine::signalsFromGPS()
583 qDebug() << __PRETTY_FUNCTION__;
585 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
586 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
588 connect(m_gps, SIGNAL(timeout()),
589 m_ui, SLOT(gpsTimeout()));
591 connect(m_gps, SIGNAL(error(int, int)),
592 this, SLOT(error(int, int)));
595 void SituareEngine::signalsFromMainWindow()
597 qDebug() << __PRETTY_FUNCTION__;
599 connect(m_ui, SIGNAL(error(int, int)),
600 this, SLOT(error(int, int)));
602 connect(m_ui, SIGNAL(loginActionPressed()),
603 this, SLOT(loginActionPressed()));
605 // signals from map view
606 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
607 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
609 connect(m_ui, SIGNAL(mapViewResized(QSize)),
610 m_mapEngine, SLOT(viewResized(QSize)));
612 connect(m_ui, SIGNAL(viewZoomFinished()),
613 m_mapEngine, SLOT(viewZoomFinished()));
615 // signals from zoom buttons (zoom panel and volume buttons)
616 connect(m_ui, SIGNAL(zoomIn()),
617 m_mapEngine, SLOT(zoomIn()));
619 connect(m_ui, SIGNAL(zoomOut()),
620 m_mapEngine, SLOT(zoomOut()));
622 // signals from menu buttons
623 connect(m_ui, SIGNAL(gpsTriggered(bool)),
624 this, SLOT(setGPS(bool)));
626 connect(m_ui, SIGNAL(requestReverseGeo()),
627 this, SLOT(requestAddress()));
629 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
630 this, SLOT(requestUpdateLocation(QString,bool)));
632 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
633 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
635 // signals from user info tab
636 connect(m_ui, SIGNAL(refreshUserData()),
637 this, SLOT(refreshUserData()));
639 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
640 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
642 // routing signal from friend list tab & search location tab
643 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
644 this, SLOT(routeTo(const GeoCoordinate&)));
646 // signals from location search panel
648 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
650 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
652 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
653 this, SLOT(locationSearch(QString)));
655 // signals from routing tab
656 connect(m_ui, SIGNAL(clearRoute()),
657 m_mapEngine, SLOT(clearRoute()));
659 connect(m_ui, SIGNAL(routeToCursor()),
660 this, SLOT(routeToCursor()));
662 // signals from distance indicator button
663 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
664 this, SLOT(changeAutoCenteringSetting(bool)));
666 connect(m_ui, SIGNAL(draggingModeTriggered()),
667 this, SLOT(draggingModeTriggered()));
669 // signal from search location dialog
670 connect(m_ui, SIGNAL(searchForLocation(QString)),
671 this, SLOT(locationSearch(QString)));
673 // signal from friend list panel
674 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
675 this, SLOT(showContactDialog(const QString &)));
678 void SituareEngine::signalsFromMapEngine()
680 qDebug() << __PRETTY_FUNCTION__;
682 connect(m_mapEngine, SIGNAL(error(int, int)),
683 this, SLOT(error(int, int)));
685 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
686 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
688 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
689 m_ui, SIGNAL(zoomLevelChanged(int)));
691 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
692 this, SLOT(disableAutoCentering()));
694 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
695 m_ui, SIGNAL(maxZoomLevelReached()));
697 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
698 m_ui, SIGNAL(minZoomLevelReached()));
700 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
701 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
703 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
704 m_ui, SIGNAL(newMapResolution(qreal)));
706 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
707 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
710 void SituareEngine::signalsFromRoutingService()
712 qDebug() << __PRETTY_FUNCTION__;
714 connect(m_routingService, SIGNAL(routeParsed(Route&)),
715 this, SLOT(routeParsed(Route&)));
717 connect(m_routingService, SIGNAL(routeParsed(Route&)),
718 m_mapEngine, SLOT(setRoute(Route&)));
720 connect(m_routingService, SIGNAL(routeParsed(Route&)),
721 m_ui, SIGNAL(routeParsed(Route&)));
723 connect(m_routingService, SIGNAL(error(int, int)),
724 this, SLOT(error(int, int)));
727 void SituareEngine::signalsFromSituareService()
729 qDebug() << __PRETTY_FUNCTION__;
731 connect(m_situareService, SIGNAL(error(int, int)),
732 this, SLOT(error(int, int)));
734 connect(m_situareService, SIGNAL(imageReady(User*)),
735 this, SLOT(imageReady(User*)));
737 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
738 m_ui, SIGNAL(reverseGeoReady(QString)));
740 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
741 this, SLOT(userDataChanged(User*, QList<User*>&)));
743 connect(m_situareService, SIGNAL(updateWasSuccessful()),
744 this, SLOT(updateWasSuccessful()));
746 connect(m_situareService, SIGNAL(updateWasSuccessful()),
747 m_ui, SLOT(clearUpdateLocationDialogData()));
750 void SituareEngine::startAutomaticUpdate()
752 qDebug() << __PRETTY_FUNCTION__;
754 m_gps->requestUpdate();
755 m_automaticUpdateRequest = true;
758 void SituareEngine::topmostWindowChanged(bool isMainWindow)
760 qDebug() << __PRETTY_FUNCTION__;
762 setPowerSaving(!isMainWindow);
765 void SituareEngine::updateWasSuccessful()
767 qDebug() << __PRETTY_FUNCTION__;
769 if (m_networkAccessManager->isConnected())
770 m_situareService->fetchLocations();
772 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
775 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
777 qDebug() << __PRETTY_FUNCTION__;
779 m_ui->toggleProgressIndicator(false);
781 emit userLocationReady(user);
782 emit friendsLocationsReady(friendsList);