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 "ui/facebookloginbrowser.h"
35 #include "facebookservice/facebookauthentication.h"
36 #include "gps/gpsposition.h"
37 #include "map/mapengine.h"
38 #include "routing/geocodingservice.h"
39 #include "routing/routingservice.h"
41 #include "network/networkaccessmanager.h"
42 #include "situareservice/situareservice.h"
43 #include "ui/mainwindow.h"
47 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
48 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
49 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
50 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
51 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
52 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
54 SituareEngine::SituareEngine()
55 : m_autoCenteringEnabled(false),
56 m_automaticUpdateFirstStart(true),
57 m_automaticUpdateRequest(false),
59 m_automaticUpdateIntervalTimer(0),
60 m_lastUpdatedGPSPosition(GeoCoordinate())
62 qDebug() << __PRETTY_FUNCTION__;
64 m_ui = new MainWindow;
65 m_ui->updateItemVisibility();
67 Application *application = static_cast<Application *>(qApp);
68 application->registerWindow(m_ui->winId());
70 connect(application, SIGNAL(topmostWindowChanged(bool)),
71 this, SLOT(topmostWindowChanged(bool)));
73 m_networkAccessManager = new NetworkAccessManager(this);
76 m_mapEngine = new MapEngine(this);
77 m_ui->setMapViewScene(m_mapEngine->scene());
80 m_gps = new GPSPosition(this);
82 // build SituareService
83 m_situareService = new SituareService(this);
85 // build FacebookAuthenticator
86 m_facebookAuthenticator = new FacebookAuthentication(this);
88 // build routing service
89 m_routingService = new RoutingService(this); // create this when needed, not in constructor!
91 // build geocoding service
92 m_geocodingService = new GeocodingService(this);
95 signalsFromMapEngine();
96 signalsFromGeocodingService();
98 signalsFromRoutingService();
99 signalsFromSituareService();
100 signalsFromMainWindow();
101 signalsFromFacebookAuthenticator();
103 connect(this, SIGNAL(userLocationReady(User*)),
104 m_ui, SIGNAL(userLocationReady(User*)));
106 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
107 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
109 connect(this, SIGNAL(userLocationReady(User*)),
110 m_mapEngine, SLOT(receiveOwnLocation(User*)));
112 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
113 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
115 connect(this, SIGNAL(friendImageReady(User*)),
116 m_ui, SIGNAL(friendImageReady(User*)));
118 connect(this, SIGNAL(friendImageReady(User*)),
119 m_mapEngine, SIGNAL(friendImageReady(User*)));
121 m_automaticUpdateIntervalTimer = new QTimer(this);
122 connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
123 this, SLOT(startAutomaticUpdate()));
125 // signals connected, now it's time to show the main window
126 // but init the MapEngine before so starting location is set
130 m_gps->setMode(GPSPosition::Default);
131 initializeGpsAndAutocentering();
133 m_mce = new MCE(this);
134 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
136 m_contactManager = new ContactManager(this);
137 m_contactManager->requestContactGuids();
139 m_facebookAuthenticator->login();
142 SituareEngine::~SituareEngine()
144 qDebug() << __PRETTY_FUNCTION__;
148 QSettings settings(DIRECTORY_NAME, FILE_NAME);
149 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
150 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
153 void SituareEngine::changeAutoCenteringSetting(bool enabled)
155 qDebug() << __PRETTY_FUNCTION__ << enabled;
157 m_autoCenteringEnabled = enabled;
158 setAutoCentering(enabled);
161 void SituareEngine::disableAutoCentering()
163 qDebug() << __PRETTY_FUNCTION__;
165 changeAutoCenteringSetting(false);
168 void SituareEngine::draggingModeTriggered()
170 qDebug() << __PRETTY_FUNCTION__;
173 m_mce->vibrationFeedback();
176 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
178 qDebug() << __PRETTY_FUNCTION__;
180 //Show automatic update confirmation dialog
181 if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
182 m_ui->showEnableAutomaticUpdateLocationDialog(
183 tr("Do you want to enable automatic location update with %1 min update interval?")
184 .arg(updateIntervalMsecs/1000/60));
185 m_automaticUpdateFirstStart = false;
187 if (enabled && m_gps->isRunning()) {
188 m_ui->buildInformationBox(tr("Automatic location update enabled"));
189 if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
190 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
192 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
194 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
195 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
197 m_automaticUpdateIntervalTimer->start();
200 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
201 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
203 m_automaticUpdateIntervalTimer->stop();
208 void SituareEngine::error(const int context, const int error)
210 qDebug() << __PRETTY_FUNCTION__;
214 case SituareError::ERROR_GENERAL:
215 if(context == ErrorContext::SITUARE) {
216 m_ui->toggleProgressIndicator(false);
217 m_ui->buildInformationBox(tr("Unknown server error"), true);
220 case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
221 m_ui->toggleProgressIndicator(false);
222 if(context == ErrorContext::SITUARE) {
223 m_ui->buildInformationBox(tr("Missing parameter from request"), true);
224 } else if(context == ErrorContext::NETWORK) {
225 m_ui->buildInformationBox(tr("Connection refused by the server"), true);
228 case QNetworkReply::RemoteHostClosedError:
229 if(context == ErrorContext::NETWORK) {
230 m_ui->toggleProgressIndicator(false);
231 m_ui->buildInformationBox(tr("Connection closed by the server"), true);
234 case QNetworkReply::HostNotFoundError:
235 if(context == ErrorContext::NETWORK) {
236 m_ui->toggleProgressIndicator(false);
237 m_ui->buildInformationBox(tr("Remote server not found"), true);
240 case QNetworkReply::TimeoutError:
241 if(context == ErrorContext::NETWORK) {
242 m_ui->toggleProgressIndicator(false);
243 m_ui->buildInformationBox(tr("Connection timed out"), true);
246 case QNetworkReply::UnknownNetworkError:
247 if(context == ErrorContext::NETWORK) {
248 m_ui->toggleProgressIndicator(false);
249 m_ui->buildInformationBox(tr("No network connection"), true);
252 case SituareError::SESSION_EXPIRED:
253 m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
254 m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
255 m_situareService->clearUserData();
256 m_ui->loggedIn(false);
259 case SituareError::LOGIN_FAILED:
260 m_ui->toggleProgressIndicator(false);
261 m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
264 case SituareError::UPDATE_FAILED:
265 m_ui->toggleProgressIndicator(false);
266 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
268 case SituareError::DATA_RETRIEVAL_FAILED:
269 m_ui->toggleProgressIndicator(false);
270 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
272 case SituareError::ADDRESS_RETRIEVAL_FAILED:
273 m_ui->toggleProgressIndicator(false);
274 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
276 case SituareError::IMAGE_DOWNLOAD_FAILED:
277 m_ui->buildInformationBox(tr("Image download failed"), true);
279 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
280 m_ui->buildInformationBox(tr("Map image download failed"), true);
282 case SituareError::GPS_INITIALIZATION_FAILED:
284 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
286 case SituareError::INVALID_JSON:
287 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
288 m_ui->loggedIn(false);
289 m_facebookAuthenticator->clearAccountInformation(false); // clean all
291 case SituareError::ERROR_ROUTING_FAILED:
292 m_ui->toggleProgressIndicator(false);
293 m_ui->buildInformationBox(tr("Routing failed"), true);
295 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
296 m_ui->buildInformationBox(tr("No results found"), true);
299 m_ui->toggleProgressIndicator(false);
300 if(context == ErrorContext::NETWORK)
301 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
303 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
308 void SituareEngine::imageReady(User *user)
310 qDebug() << __PRETTY_FUNCTION__;
313 emit userLocationReady(user);
315 emit friendImageReady(user);
318 void SituareEngine::initializeGpsAndAutocentering()
320 qDebug() << __PRETTY_FUNCTION__;
322 QSettings settings(DIRECTORY_NAME, FILE_NAME);
323 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
324 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
326 if (m_gps->isInitialized()) {
328 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
330 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
331 this, SLOT(setFirstStartZoomLevel()));
333 changeAutoCenteringSetting(true);
336 m_ui->buildInformationBox(tr("GPS enabled"));
338 } else { // Normal start
339 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
340 setGPS(gpsEnabled.toBool());
342 if (gpsEnabled.toBool())
343 m_ui->buildInformationBox(tr("GPS enabled"));
350 void SituareEngine::locationSearch(QString location)
352 qDebug() << __PRETTY_FUNCTION__;
354 if(!location.isEmpty())
355 m_geocodingService->requestLocation(location);
358 void SituareEngine::loggedIn()
360 qWarning() << __PRETTY_FUNCTION__;
362 m_ui->destroyFacebookLoginBrowser();
367 void SituareEngine::loginActionPressed()
369 qDebug() << __PRETTY_FUNCTION__;
371 if (m_networkAccessManager->isConnected()) {
372 if(m_ui->loginState()) {
374 m_situareService->clearUserData();
376 m_facebookAuthenticator->login();
380 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
384 void SituareEngine::loginOk()
386 /// @ OLD CODE, REFACTOR! loggedIn -> FB authenticator etc.
387 qDebug() << __PRETTY_FUNCTION__;
389 m_ui->loggedIn(true);
392 m_situareService->fetchLocations(); // request user locations
394 if (m_gps->isRunning())
395 m_ui->readAutomaticLocationUpdateSettings();
398 void SituareEngine::loginProcessCancelled()
400 qDebug() << __PRETTY_FUNCTION__;
402 m_ui->toggleProgressIndicator(false);
403 m_ui->updateItemVisibility();
406 void SituareEngine::logout()
408 qDebug() << __PRETTY_FUNCTION__;
410 m_ui->loggedIn(false);
412 // signal to clear locationUpdateDialog's data
413 connect(this, SIGNAL(clearUpdateLocationDialogData()),
414 m_ui, SIGNAL(clearUpdateLocationDialogData()));
415 emit clearUpdateLocationDialogData();
417 m_facebookAuthenticator->clearAccountInformation(); // clear all
418 m_automaticUpdateFirstStart = true;
421 void SituareEngine::refreshUserData()
423 qDebug() << __PRETTY_FUNCTION__;
425 if (m_networkAccessManager->isConnected()) {
426 m_ui->toggleProgressIndicator(true);
427 m_situareService->fetchLocations();
430 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
434 void SituareEngine::requestAddress()
436 qDebug() << __PRETTY_FUNCTION__;
438 if (m_networkAccessManager->isConnected()) {
439 if (m_gps->isRunning())
440 m_situareService->reverseGeo(m_gps->lastPosition());
442 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
445 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
449 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
451 qDebug() << __PRETTY_FUNCTION__;
453 if (m_networkAccessManager->isConnected()) {
454 m_ui->toggleProgressIndicator(true);
456 if (m_gps->isRunning())
457 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
459 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
462 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
466 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
468 qDebug() << __PRETTY_FUNCTION__;
470 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
471 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
472 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
473 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
475 m_lastUpdatedGPSPosition = position;
479 if (m_automaticUpdateRequest && m_userMoved) {
480 requestUpdateLocation(tr("Automatic location update"));
481 m_automaticUpdateRequest = false;
486 void SituareEngine::routeParsed(Route &route)
488 qDebug() << __PRETTY_FUNCTION__;
492 m_ui->toggleProgressIndicator(false);
495 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
497 qDebug() << __PRETTY_FUNCTION__;
499 m_ui->toggleProgressIndicator(true);
501 if (m_gps->isRunning())
502 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
504 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
507 void SituareEngine::routeToCursor()
509 qDebug() << __PRETTY_FUNCTION__;
511 routeTo(m_mapEngine->centerGeoCoordinate());
514 void SituareEngine::setAutoCentering(bool enabled)
516 qDebug() << __PRETTY_FUNCTION__ << enabled;
518 m_ui->setIndicatorButtonEnabled(enabled);
519 m_mapEngine->setAutoCentering(enabled);
520 m_ui->setCrosshairVisibility(!enabled);
524 m_gps->requestLastPosition();
528 void SituareEngine::setFirstStartZoomLevel()
530 qDebug() << __PRETTY_FUNCTION__;
532 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
533 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
535 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
536 this, SLOT(setFirstStartZoomLevel()));
539 void SituareEngine::setGPS(bool enabled)
541 qDebug() << __PRETTY_FUNCTION__ << enabled;
543 if (m_gps->isInitialized()) {
544 m_ui->setGPSButtonEnabled(enabled);
545 m_mapEngine->setGPSEnabled(enabled);
547 if (enabled && !m_gps->isRunning()) {
549 m_gps->requestLastPosition();
551 if(m_ui->loginState())
552 m_ui->readAutomaticLocationUpdateSettings();
554 else if (!enabled && m_gps->isRunning()) {
556 changeAutoCenteringSetting(false);
557 enableAutomaticLocationUpdate(false);
562 m_ui->buildInformationBox(tr("Unable to start GPS"));
563 m_ui->setGPSButtonEnabled(false);
564 m_mapEngine->setGPSEnabled(false);
568 void SituareEngine::setPowerSaving(bool enabled)
570 qDebug() << __PRETTY_FUNCTION__ << enabled;
572 m_gps->enablePowerSave(enabled);
574 if(m_autoCenteringEnabled)
575 m_mapEngine->setAutoCentering(!enabled);
578 void SituareEngine::showContactDialog(const QString &facebookId)
580 qDebug() << __PRETTY_FUNCTION__;
582 QString guid = m_contactManager->contactGuid(facebookId);
585 m_ui->showContactDialog(guid);
587 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
588 "account from Conversations to use this feature."), true);
591 void SituareEngine::signalsFromFacebookAuthenticator()
593 qDebug() << __PRETTY_FUNCTION__;
595 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
596 this, SLOT(error(int, int)));
598 connect(m_facebookAuthenticator, SIGNAL(buildLoginBrowser()),
599 m_ui, SLOT(buildFacebookLoginBrowser()));
601 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
602 m_situareService, SLOT(updateSession(QString)));
604 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
605 this, SLOT(loggedIn()));
608 void SituareEngine::signalsFromGeocodingService()
610 qDebug() << __PRETTY_FUNCTION__;
612 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
613 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
615 connect(m_geocodingService, SIGNAL(error(int, int)),
616 this, SLOT(error(int, int)));
619 void SituareEngine::signalsFromGPS()
621 qDebug() << __PRETTY_FUNCTION__;
623 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
624 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
626 connect(m_gps, SIGNAL(timeout()),
627 m_ui, SLOT(gpsTimeout()));
629 connect(m_gps, SIGNAL(error(int, int)),
630 this, SLOT(error(int, int)));
633 void SituareEngine::signalsFromMainWindow()
635 qDebug() << __PRETTY_FUNCTION__;
637 connect(m_ui, SIGNAL(error(int, int)),
638 this, SLOT(error(int, int)));
640 connect(m_ui, SIGNAL(loginActionPressed()),
641 this, SLOT(loginActionPressed()));
643 connect(m_ui, SIGNAL(loginBrowserCreated(FacebookLoginBrowser*)),
644 m_facebookAuthenticator, SLOT(setBrowser(FacebookLoginBrowser*)));
646 // signals from map view
647 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
648 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
650 connect(m_ui, SIGNAL(mapViewResized(QSize)),
651 m_mapEngine, SLOT(viewResized(QSize)));
653 connect(m_ui, SIGNAL(viewZoomFinished()),
654 m_mapEngine, SLOT(viewZoomFinished()));
656 // signals from zoom buttons (zoom panel and volume buttons)
657 connect(m_ui, SIGNAL(zoomIn()),
658 m_mapEngine, SLOT(zoomIn()));
660 connect(m_ui, SIGNAL(zoomOut()),
661 m_mapEngine, SLOT(zoomOut()));
663 // signals from menu buttons
664 connect(m_ui, SIGNAL(gpsTriggered(bool)),
665 this, SLOT(setGPS(bool)));
667 //signals from dialogs
668 connect(m_ui, SIGNAL(cancelLoginProcess()),
669 this, SLOT(loginProcessCancelled()));
671 connect(m_ui, SIGNAL(requestReverseGeo()),
672 this, SLOT(requestAddress()));
674 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
675 this, SLOT(requestUpdateLocation(QString,bool)));
677 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
678 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
680 // signals from user info tab
681 connect(m_ui, SIGNAL(refreshUserData()),
682 this, SLOT(refreshUserData()));
684 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
685 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
687 // routing signal from friend list tab & search location tab
688 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
689 this, SLOT(routeTo(const GeoCoordinate&)));
691 // signals from location search panel
693 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
695 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
697 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
698 this, SLOT(locationSearch(QString)));
700 // signals from routing tab
701 connect(m_ui, SIGNAL(clearRoute()),
702 m_mapEngine, SLOT(clearRoute()));
704 connect(m_ui, SIGNAL(routeToCursor()),
705 this, SLOT(routeToCursor()));
707 // signals from distance indicator button
708 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
709 this, SLOT(changeAutoCenteringSetting(bool)));
711 connect(m_ui, SIGNAL(draggingModeTriggered()),
712 this, SLOT(draggingModeTriggered()));
714 // signal from search location dialog
715 connect(m_ui, SIGNAL(searchForLocation(QString)),
716 this, SLOT(locationSearch(QString)));
718 // signal from friend list panel
719 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
720 this, SLOT(showContactDialog(const QString &)));
723 void SituareEngine::signalsFromMapEngine()
725 qDebug() << __PRETTY_FUNCTION__;
727 connect(m_mapEngine, SIGNAL(error(int, int)),
728 this, SLOT(error(int, int)));
730 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
731 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
733 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
734 m_ui, SIGNAL(zoomLevelChanged(int)));
736 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
737 this, SLOT(disableAutoCentering()));
739 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
740 m_ui, SIGNAL(maxZoomLevelReached()));
742 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
743 m_ui, SIGNAL(minZoomLevelReached()));
745 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
746 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
748 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
749 m_ui, SIGNAL(newMapResolution(qreal)));
751 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
752 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
755 void SituareEngine::signalsFromRoutingService()
757 qDebug() << __PRETTY_FUNCTION__;
759 connect(m_routingService, SIGNAL(routeParsed(Route&)),
760 this, SLOT(routeParsed(Route&)));
762 connect(m_routingService, SIGNAL(routeParsed(Route&)),
763 m_mapEngine, SLOT(setRoute(Route&)));
765 connect(m_routingService, SIGNAL(routeParsed(Route&)),
766 m_ui, SIGNAL(routeParsed(Route&)));
768 connect(m_routingService, SIGNAL(error(int, int)),
769 this, SLOT(error(int, int)));
772 void SituareEngine::signalsFromSituareService()
774 qDebug() << __PRETTY_FUNCTION__;
776 connect(m_situareService, SIGNAL(error(int, int)),
777 this, SLOT(error(int, int)));
779 connect(m_situareService, SIGNAL(imageReady(User*)),
780 this, SLOT(imageReady(User*)));
782 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
783 m_ui, SIGNAL(reverseGeoReady(QString)));
785 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
786 this, SLOT(userDataChanged(User*, QList<User*>&)));
788 connect(m_situareService, SIGNAL(updateWasSuccessful()),
789 this, SLOT(updateWasSuccessful()));
791 connect(m_situareService, SIGNAL(updateWasSuccessful()),
792 m_ui, SIGNAL(clearUpdateLocationDialogData()));
795 void SituareEngine::startAutomaticUpdate()
797 qDebug() << __PRETTY_FUNCTION__;
799 m_gps->requestUpdate();
800 m_automaticUpdateRequest = true;
803 void SituareEngine::topmostWindowChanged(bool isMainWindow)
805 qDebug() << __PRETTY_FUNCTION__;
807 setPowerSaving(!isMainWindow);
810 void SituareEngine::updateWasSuccessful()
812 qDebug() << __PRETTY_FUNCTION__;
814 if (m_networkAccessManager->isConnected())
815 m_situareService->fetchLocations();
817 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
820 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
822 qDebug() << __PRETTY_FUNCTION__;
824 m_ui->toggleProgressIndicator(false);
826 emit userLocationReady(user);
827 emit friendsLocationsReady(friendsList);