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();
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(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_facebookAuthenticator->start();
131 m_gps->setMode(GPSPosition::Default);
132 initializeGpsAndAutocentering();
134 m_mce = new MCE(this);
135 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
137 m_contactManager = new ContactManager(this);
138 m_contactManager->requestContactGuids();
141 SituareEngine::~SituareEngine()
143 qDebug() << __PRETTY_FUNCTION__;
147 QSettings settings(DIRECTORY_NAME, FILE_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->clearAccountInformation(true); // keep username = true
254 m_situareService->clearUserData();
255 m_ui->loggedIn(false);
258 case SituareError::LOGIN_FAILED:
259 m_ui->toggleProgressIndicator(false);
260 m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
263 case SituareError::UPDATE_FAILED:
264 m_ui->toggleProgressIndicator(false);
265 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
267 case SituareError::DATA_RETRIEVAL_FAILED:
268 m_ui->toggleProgressIndicator(false);
269 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
271 case SituareError::ADDRESS_RETRIEVAL_FAILED:
272 m_ui->toggleProgressIndicator(false);
273 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
275 case SituareError::IMAGE_DOWNLOAD_FAILED:
276 m_ui->buildInformationBox(tr("Image download failed"), true);
278 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
279 m_ui->buildInformationBox(tr("Map image download failed"), true);
281 case SituareError::GPS_INITIALIZATION_FAILED:
283 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
285 case SituareError::INVALID_JSON:
286 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
287 m_ui->loggedIn(false);
288 m_facebookAuthenticator->clearAccountInformation(false); // clean all
290 case SituareError::ERROR_ROUTING_FAILED:
291 m_ui->toggleProgressIndicator(false);
292 m_ui->buildInformationBox(tr("Routing failed"), true);
294 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
295 m_ui->buildInformationBox(tr("No results found"), true);
298 m_ui->toggleProgressIndicator(false);
299 if(context == ErrorContext::NETWORK)
300 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
302 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
307 void SituareEngine::fetchUsernameFromSettings()
309 qDebug() << __PRETTY_FUNCTION__;
311 m_ui->setUsername(m_facebookAuthenticator->loadUsername());
314 void SituareEngine::imageReady(User *user)
316 qDebug() << __PRETTY_FUNCTION__;
319 emit userLocationReady(user);
321 emit friendImageReady(user);
324 void SituareEngine::initializeGpsAndAutocentering()
326 qDebug() << __PRETTY_FUNCTION__;
328 QSettings settings(DIRECTORY_NAME, FILE_NAME);
329 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
330 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
332 if (m_gps->isInitialized()) {
334 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
336 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
337 this, SLOT(setFirstStartZoomLevel()));
339 changeAutoCenteringSetting(true);
342 m_ui->buildInformationBox(tr("GPS enabled"));
344 } else { // Normal start
345 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
346 setGPS(gpsEnabled.toBool());
348 if (gpsEnabled.toBool())
349 m_ui->buildInformationBox(tr("GPS enabled"));
356 void SituareEngine::locationSearch(QString location)
358 qDebug() << __PRETTY_FUNCTION__;
360 if(!location.isEmpty())
361 m_geocodingService->requestLocation(location);
364 void SituareEngine::loginActionPressed()
366 qDebug() << __PRETTY_FUNCTION__;
368 if (m_networkAccessManager->isConnected()) {
369 if(m_ui->loginState()) {
371 m_situareService->clearUserData();
373 m_facebookAuthenticator->start();
377 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
381 void SituareEngine::loginOk()
383 qDebug() << __PRETTY_FUNCTION__;
385 m_ui->loggedIn(true);
388 m_situareService->fetchLocations(); // request user locations
390 if (m_gps->isRunning())
391 m_ui->readAutomaticLocationUpdateSettings();
394 void SituareEngine::loginProcessCancelled()
396 qDebug() << __PRETTY_FUNCTION__;
398 m_ui->toggleProgressIndicator(false);
399 m_ui->updateItemVisibility();
402 void SituareEngine::logout()
404 qDebug() << __PRETTY_FUNCTION__;
406 m_ui->loggedIn(false);
408 // signal to clear locationUpdateDialog's data
409 connect(this, SIGNAL(clearUpdateLocationDialogData()),
410 m_ui, SIGNAL(clearUpdateLocationDialogData()));
411 emit clearUpdateLocationDialogData();
413 m_facebookAuthenticator->clearAccountInformation(); // clear all
414 m_automaticUpdateFirstStart = true;
417 void SituareEngine::refreshUserData()
419 qDebug() << __PRETTY_FUNCTION__;
421 if (m_networkAccessManager->isConnected()) {
422 m_ui->toggleProgressIndicator(true);
423 m_situareService->fetchLocations();
426 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
430 void SituareEngine::requestAddress()
432 qDebug() << __PRETTY_FUNCTION__;
434 if (m_networkAccessManager->isConnected()) {
435 if (m_gps->isRunning())
436 m_situareService->reverseGeo(m_gps->lastPosition());
438 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
441 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
445 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
447 qDebug() << __PRETTY_FUNCTION__;
449 if (m_networkAccessManager->isConnected()) {
450 m_ui->toggleProgressIndicator(true);
452 if (m_gps->isRunning())
453 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
455 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
458 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
462 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
464 qDebug() << __PRETTY_FUNCTION__;
466 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
467 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
468 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
469 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
471 m_lastUpdatedGPSPosition = position;
475 if (m_automaticUpdateRequest && m_userMoved) {
476 requestUpdateLocation(tr("Automatic location update"));
477 m_automaticUpdateRequest = false;
482 void SituareEngine::requestInterestingPeople()
484 qWarning() << __PRETTY_FUNCTION__;
486 QRectF currentSceneRect = m_mapEngine->currentViewSceneRect();
487 SceneCoordinate bottomLeftSceneCoordinate(currentSceneRect.left(), currentSceneRect.bottom());
488 SceneCoordinate topRightSceneCoordinate(currentSceneRect.right(), currentSceneRect.top());
491 qWarning() << GeoCoordinate(bottomLeftSceneCoordinate).latitude() <<
492 GeoCoordinate(bottomLeftSceneCoordinate).longitude();
493 qWarning() << GeoCoordinate(topRightSceneCoordinate).latitude() <<
494 GeoCoordinate(topRightSceneCoordinate).longitude();
496 m_situareService->fetchPeopleWithSimilarInterest(GeoCoordinate(bottomLeftSceneCoordinate),
497 GeoCoordinate(topRightSceneCoordinate));
500 void SituareEngine::routeParsed(Route &route)
502 qDebug() << __PRETTY_FUNCTION__;
506 m_ui->toggleProgressIndicator(false);
509 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
511 qDebug() << __PRETTY_FUNCTION__;
513 m_ui->toggleProgressIndicator(true);
515 if (m_gps->isRunning())
516 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
518 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
521 void SituareEngine::routeToCursor()
523 qDebug() << __PRETTY_FUNCTION__;
525 routeTo(m_mapEngine->centerGeoCoordinate());
528 void SituareEngine::setAutoCentering(bool enabled)
530 qDebug() << __PRETTY_FUNCTION__ << enabled;
532 m_ui->setIndicatorButtonEnabled(enabled);
533 m_mapEngine->setAutoCentering(enabled);
534 m_ui->setCrosshairVisibility(!enabled);
538 m_gps->requestLastPosition();
542 void SituareEngine::setFirstStartZoomLevel()
544 qDebug() << __PRETTY_FUNCTION__;
546 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
547 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
549 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
550 this, SLOT(setFirstStartZoomLevel()));
553 void SituareEngine::setGPS(bool enabled)
555 qDebug() << __PRETTY_FUNCTION__ << enabled;
557 if (m_gps->isInitialized()) {
558 m_ui->setGPSButtonEnabled(enabled);
559 m_mapEngine->setGPSEnabled(enabled);
561 if (enabled && !m_gps->isRunning()) {
563 m_gps->requestLastPosition();
565 if(m_ui->loginState())
566 m_ui->readAutomaticLocationUpdateSettings();
568 else if (!enabled && m_gps->isRunning()) {
570 changeAutoCenteringSetting(false);
571 enableAutomaticLocationUpdate(false);
576 m_ui->buildInformationBox(tr("Unable to start GPS"));
577 m_ui->setGPSButtonEnabled(false);
578 m_mapEngine->setGPSEnabled(false);
582 void SituareEngine::setPowerSaving(bool enabled)
584 qDebug() << __PRETTY_FUNCTION__ << enabled;
586 m_gps->enablePowerSave(enabled);
588 if(m_autoCenteringEnabled)
589 m_mapEngine->setAutoCentering(!enabled);
592 void SituareEngine::showContactDialog(const QString &facebookId)
594 qDebug() << __PRETTY_FUNCTION__;
596 QString guid = m_contactManager->contactGuid(facebookId);
599 m_ui->showContactDialog(guid);
602 void SituareEngine::signalsFromFacebookAuthenticator()
604 qDebug() << __PRETTY_FUNCTION__;
606 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
607 this, SLOT(error(int, int)));
609 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
610 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
612 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
613 this, SLOT(loginOk()));
615 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
616 m_ui, SLOT(startLoginProcess()));
618 connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
619 m_ui, SLOT(saveCookies()));
621 connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
622 m_ui, SLOT(loginUsingCookies()));
625 void SituareEngine::signalsFromGeocodingService()
627 qDebug() << __PRETTY_FUNCTION__;
629 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
630 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
632 connect(m_geocodingService, SIGNAL(error(int, int)),
633 this, SLOT(error(int, int)));
636 void SituareEngine::signalsFromGPS()
638 qDebug() << __PRETTY_FUNCTION__;
640 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
641 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
643 connect(m_gps, SIGNAL(timeout()),
644 m_ui, SLOT(gpsTimeout()));
646 connect(m_gps, SIGNAL(error(int, int)),
647 this, SLOT(error(int, int)));
650 void SituareEngine::signalsFromMainWindow()
652 qDebug() << __PRETTY_FUNCTION__;
654 connect(m_ui, SIGNAL(error(int, int)),
655 this, SLOT(error(int, int)));
657 connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
658 this, SLOT(fetchUsernameFromSettings()));
660 connect(m_ui, SIGNAL(loginActionPressed()),
661 this, SLOT(loginActionPressed()));
663 connect(m_ui, SIGNAL(saveUsername(QString)),
664 m_facebookAuthenticator, SLOT(saveUsername(QString)));
666 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
667 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
669 // signals from map view
670 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
671 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
673 connect(m_ui, SIGNAL(mapViewResized(QSize)),
674 m_mapEngine, SLOT(viewResized(QSize)));
676 connect(m_ui, SIGNAL(viewZoomFinished()),
677 m_mapEngine, SLOT(viewZoomFinished()));
679 // signals from zoom buttons (zoom panel and volume buttons)
680 connect(m_ui, SIGNAL(zoomIn()),
681 m_mapEngine, SLOT(zoomIn()));
683 connect(m_ui, SIGNAL(zoomOut()),
684 m_mapEngine, SLOT(zoomOut()));
686 // signals from menu buttons
687 connect(m_ui, SIGNAL(gpsTriggered(bool)),
688 this, SLOT(setGPS(bool)));
690 //signals from dialogs
691 connect(m_ui, SIGNAL(cancelLoginProcess()),
692 this, SLOT(loginProcessCancelled()));
694 connect(m_ui, SIGNAL(requestReverseGeo()),
695 this, SLOT(requestAddress()));
697 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
698 this, SLOT(requestUpdateLocation(QString,bool)));
700 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
701 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
703 // signals from user info tab
704 connect(m_ui, SIGNAL(refreshUserData()),
705 this, SLOT(refreshUserData()));
707 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
708 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
710 // routing signal from friend list tab & search location tab
711 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
712 this, SLOT(routeTo(const GeoCoordinate&)));
714 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
715 this, SLOT(showContactDialog(const QString &)));
717 // signals from location search panel
719 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
721 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
723 // signals from routing tab
724 connect(m_ui, SIGNAL(clearRoute()),
725 m_mapEngine, SLOT(clearRoute()));
727 connect(m_ui, SIGNAL(routeToCursor()),
728 this, SLOT(routeToCursor()));
730 // signals from distance indicator button
731 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
732 this, SLOT(changeAutoCenteringSetting(bool)));
734 connect(m_ui, SIGNAL(draggingModeTriggered()),
735 this, SLOT(draggingModeTriggered()));
737 // signal from search location dialog
738 connect(m_ui, SIGNAL(searchForLocation(QString)),
739 this, SLOT(locationSearch(QString)));
741 // signals from meet people panel
742 connect(m_ui, SIGNAL(requestInterestingPeople()),
743 this, SLOT(requestInterestingPeople()));
746 void SituareEngine::signalsFromMapEngine()
748 qDebug() << __PRETTY_FUNCTION__;
750 connect(m_mapEngine, SIGNAL(error(int, int)),
751 this, SLOT(error(int, int)));
753 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
754 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
756 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
757 m_ui, SIGNAL(zoomLevelChanged(int)));
759 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
760 this, SLOT(disableAutoCentering()));
762 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
763 m_ui, SIGNAL(maxZoomLevelReached()));
765 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
766 m_ui, SIGNAL(minZoomLevelReached()));
768 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
769 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
771 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
772 m_ui, SIGNAL(newMapResolution(qreal)));
774 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
775 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
778 void SituareEngine::signalsFromRoutingService()
780 qDebug() << __PRETTY_FUNCTION__;
782 connect(m_routingService, SIGNAL(routeParsed(Route&)),
783 this, SLOT(routeParsed(Route&)));
785 connect(m_routingService, SIGNAL(routeParsed(Route&)),
786 m_mapEngine, SLOT(setRoute(Route&)));
788 connect(m_routingService, SIGNAL(routeParsed(Route&)),
789 m_ui, SIGNAL(routeParsed(Route&)));
791 connect(m_routingService, SIGNAL(error(int, int)),
792 this, SLOT(error(int, int)));
795 void SituareEngine::signalsFromSituareService()
797 qDebug() << __PRETTY_FUNCTION__;
799 connect(m_situareService, SIGNAL(error(int, int)),
800 this, SLOT(error(int, int)));
802 connect(m_situareService, SIGNAL(imageReady(User*)),
803 this, SLOT(imageReady(User*)));
805 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
806 m_ui, SIGNAL(reverseGeoReady(QString)));
808 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
809 this, SLOT(userDataChanged(User*, QList<User*>&)));
811 connect(m_situareService, SIGNAL(updateWasSuccessful()),
812 this, SLOT(updateWasSuccessful()));
814 connect(m_situareService, SIGNAL(updateWasSuccessful()),
815 m_ui, SIGNAL(clearUpdateLocationDialogData()));
817 connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User*>&)),
818 m_ui, SIGNAL(interestingPeopleReceived(QList<User*>&)));
820 connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&)),
821 m_ui, SIGNAL(messagesReceived(QList<Message>&)));
824 void SituareEngine::startAutomaticUpdate()
826 qDebug() << __PRETTY_FUNCTION__;
828 m_gps->requestUpdate();
829 m_automaticUpdateRequest = true;
832 void SituareEngine::topmostWindowChanged(bool isMainWindow)
834 qDebug() << __PRETTY_FUNCTION__;
836 setPowerSaving(!isMainWindow);
839 void SituareEngine::updateWasSuccessful()
841 qDebug() << __PRETTY_FUNCTION__;
843 if (m_networkAccessManager->isConnected())
844 m_situareService->fetchLocations();
846 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
849 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
851 qDebug() << __PRETTY_FUNCTION__;
853 m_ui->toggleProgressIndicator(false);
855 emit userLocationReady(user);
856 emit friendsLocationsReady(friendsList);