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_facebookAuthenticator->start();
132 m_gps->setMode(GPSPosition::Default);
133 initializeGpsAndAutocentering();
135 m_mce = new MCE(this);
136 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
138 m_contactManager = new ContactManager(this);
139 m_contactManager->requestContactGuids();
141 ///< @todo just for testing the login browser
145 SituareEngine::~SituareEngine()
147 qDebug() << __PRETTY_FUNCTION__;
151 QSettings settings(DIRECTORY_NAME, FILE_NAME);
152 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
153 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
156 void SituareEngine::changeAutoCenteringSetting(bool enabled)
158 qDebug() << __PRETTY_FUNCTION__ << enabled;
160 m_autoCenteringEnabled = enabled;
161 setAutoCentering(enabled);
164 void SituareEngine::disableAutoCentering()
166 qDebug() << __PRETTY_FUNCTION__;
168 changeAutoCenteringSetting(false);
171 void SituareEngine::draggingModeTriggered()
173 qDebug() << __PRETTY_FUNCTION__;
176 m_mce->vibrationFeedback();
179 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
181 qDebug() << __PRETTY_FUNCTION__;
183 //Show automatic update confirmation dialog
184 if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
185 m_ui->showEnableAutomaticUpdateLocationDialog(
186 tr("Do you want to enable automatic location update with %1 min update interval?")
187 .arg(updateIntervalMsecs/1000/60));
188 m_automaticUpdateFirstStart = false;
190 if (enabled && m_gps->isRunning()) {
191 m_ui->buildInformationBox(tr("Automatic location update enabled"));
192 if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
193 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
195 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
197 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
198 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
200 m_automaticUpdateIntervalTimer->start();
203 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
204 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
206 m_automaticUpdateIntervalTimer->stop();
211 void SituareEngine::error(const int context, const int error)
213 qDebug() << __PRETTY_FUNCTION__;
217 case SituareError::ERROR_GENERAL:
218 if(context == ErrorContext::SITUARE) {
219 m_ui->toggleProgressIndicator(false);
220 m_ui->buildInformationBox(tr("Unknown server error"), true);
223 case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
224 m_ui->toggleProgressIndicator(false);
225 if(context == ErrorContext::SITUARE) {
226 m_ui->buildInformationBox(tr("Missing parameter from request"), true);
227 } else if(context == ErrorContext::NETWORK) {
228 m_ui->buildInformationBox(tr("Connection refused by the server"), true);
231 case QNetworkReply::RemoteHostClosedError:
232 if(context == ErrorContext::NETWORK) {
233 m_ui->toggleProgressIndicator(false);
234 m_ui->buildInformationBox(tr("Connection closed by the server"), true);
237 case QNetworkReply::HostNotFoundError:
238 if(context == ErrorContext::NETWORK) {
239 m_ui->toggleProgressIndicator(false);
240 m_ui->buildInformationBox(tr("Remote server not found"), true);
243 case QNetworkReply::TimeoutError:
244 if(context == ErrorContext::NETWORK) {
245 m_ui->toggleProgressIndicator(false);
246 m_ui->buildInformationBox(tr("Connection timed out"), true);
249 case QNetworkReply::UnknownNetworkError:
250 if(context == ErrorContext::NETWORK) {
251 m_ui->toggleProgressIndicator(false);
252 m_ui->buildInformationBox(tr("No network connection"), true);
255 case SituareError::SESSION_EXPIRED:
256 m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
257 m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
258 m_situareService->clearUserData();
259 m_ui->loggedIn(false);
262 case SituareError::LOGIN_FAILED:
263 m_ui->toggleProgressIndicator(false);
264 m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
267 case SituareError::UPDATE_FAILED:
268 m_ui->toggleProgressIndicator(false);
269 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
271 case SituareError::DATA_RETRIEVAL_FAILED:
272 m_ui->toggleProgressIndicator(false);
273 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
275 case SituareError::ADDRESS_RETRIEVAL_FAILED:
276 m_ui->toggleProgressIndicator(false);
277 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
279 case SituareError::IMAGE_DOWNLOAD_FAILED:
280 m_ui->buildInformationBox(tr("Image download failed"), true);
282 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
283 m_ui->buildInformationBox(tr("Map image download failed"), true);
285 case SituareError::GPS_INITIALIZATION_FAILED:
287 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
289 case SituareError::INVALID_JSON:
290 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
291 m_ui->loggedIn(false);
292 m_facebookAuthenticator->clearAccountInformation(false); // clean all
294 case SituareError::ERROR_ROUTING_FAILED:
295 m_ui->toggleProgressIndicator(false);
296 m_ui->buildInformationBox(tr("Routing failed"), true);
298 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
299 m_ui->buildInformationBox(tr("No results found"), true);
302 m_ui->toggleProgressIndicator(false);
303 if(context == ErrorContext::NETWORK)
304 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
306 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
311 void SituareEngine::fetchUsernameFromSettings()
313 qDebug() << __PRETTY_FUNCTION__;
315 m_ui->setUsername(m_facebookAuthenticator->loadUsername());
318 void SituareEngine::imageReady(User *user)
320 qDebug() << __PRETTY_FUNCTION__;
323 emit userLocationReady(user);
325 emit friendImageReady(user);
328 void SituareEngine::initializeGpsAndAutocentering()
330 qDebug() << __PRETTY_FUNCTION__;
332 QSettings settings(DIRECTORY_NAME, FILE_NAME);
333 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
334 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
336 if (m_gps->isInitialized()) {
338 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
340 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
341 this, SLOT(setFirstStartZoomLevel()));
343 changeAutoCenteringSetting(true);
346 m_ui->buildInformationBox(tr("GPS enabled"));
348 } else { // Normal start
349 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
350 setGPS(gpsEnabled.toBool());
352 if (gpsEnabled.toBool())
353 m_ui->buildInformationBox(tr("GPS enabled"));
360 void SituareEngine::locationSearch(QString location)
362 qDebug() << __PRETTY_FUNCTION__;
364 if(!location.isEmpty())
365 m_geocodingService->requestLocation(location);
368 void SituareEngine::login()
370 qWarning() << __PRETTY_FUNCTION__;
372 FacebookLoginBrowser *browser = m_ui->buildFacebookLoginBrowser();
374 connect(browser, SIGNAL(loadFinished(bool)),
375 m_facebookAuthenticator, SLOT(loadFinished(bool)));
377 connect(browser, SIGNAL(urlChanged(QUrl)),
378 m_facebookAuthenticator, SLOT(urlChanged(QUrl)));
380 browser->load(QUrl("https://graph.facebook.com/oauth/authorize?client_id=4197c64da2fb6b927236feaea32d7d81&redirect_uri=http://www.facebook.com/connect/login_success.html&display=touch&type=user_agent"));
383 void SituareEngine::loggedIn()
385 qWarning() << __PRETTY_FUNCTION__;
387 m_ui->destroyFacebookLoginBrowser();
390 void SituareEngine::loginActionPressed()
392 qDebug() << __PRETTY_FUNCTION__;
394 if (m_networkAccessManager->isConnected()) {
395 if(m_ui->loginState()) {
397 m_situareService->clearUserData();
399 m_facebookAuthenticator->start();
403 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
407 void SituareEngine::loginOk()
409 qDebug() << __PRETTY_FUNCTION__;
411 m_ui->loggedIn(true);
414 m_situareService->fetchLocations(); // request user locations
416 if (m_gps->isRunning())
417 m_ui->readAutomaticLocationUpdateSettings();
420 void SituareEngine::loginProcessCancelled()
422 qDebug() << __PRETTY_FUNCTION__;
424 m_ui->toggleProgressIndicator(false);
425 m_ui->updateItemVisibility();
428 void SituareEngine::logout()
430 qDebug() << __PRETTY_FUNCTION__;
432 m_ui->loggedIn(false);
434 // signal to clear locationUpdateDialog's data
435 connect(this, SIGNAL(clearUpdateLocationDialogData()),
436 m_ui, SIGNAL(clearUpdateLocationDialogData()));
437 emit clearUpdateLocationDialogData();
439 m_facebookAuthenticator->clearAccountInformation(); // clear all
440 m_automaticUpdateFirstStart = true;
443 void SituareEngine::refreshUserData()
445 qDebug() << __PRETTY_FUNCTION__;
447 if (m_networkAccessManager->isConnected()) {
448 m_ui->toggleProgressIndicator(true);
449 m_situareService->fetchLocations();
452 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
456 void SituareEngine::requestAddress()
458 qDebug() << __PRETTY_FUNCTION__;
460 if (m_networkAccessManager->isConnected()) {
461 if (m_gps->isRunning())
462 m_situareService->reverseGeo(m_gps->lastPosition());
464 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
467 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
471 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
473 qDebug() << __PRETTY_FUNCTION__;
475 if (m_networkAccessManager->isConnected()) {
476 m_ui->toggleProgressIndicator(true);
478 if (m_gps->isRunning())
479 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
481 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
484 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
488 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
490 qDebug() << __PRETTY_FUNCTION__;
492 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
493 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
494 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
495 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
497 m_lastUpdatedGPSPosition = position;
501 if (m_automaticUpdateRequest && m_userMoved) {
502 requestUpdateLocation(tr("Automatic location update"));
503 m_automaticUpdateRequest = false;
508 void SituareEngine::routeParsed(Route &route)
510 qDebug() << __PRETTY_FUNCTION__;
514 m_ui->toggleProgressIndicator(false);
517 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
519 qDebug() << __PRETTY_FUNCTION__;
521 m_ui->toggleProgressIndicator(true);
523 if (m_gps->isRunning())
524 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
526 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
529 void SituareEngine::routeToCursor()
531 qDebug() << __PRETTY_FUNCTION__;
533 routeTo(m_mapEngine->centerGeoCoordinate());
536 void SituareEngine::setAutoCentering(bool enabled)
538 qDebug() << __PRETTY_FUNCTION__ << enabled;
540 m_ui->setIndicatorButtonEnabled(enabled);
541 m_mapEngine->setAutoCentering(enabled);
542 m_ui->setCrosshairVisibility(!enabled);
546 m_gps->requestLastPosition();
550 void SituareEngine::setFirstStartZoomLevel()
552 qDebug() << __PRETTY_FUNCTION__;
554 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
555 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
557 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
558 this, SLOT(setFirstStartZoomLevel()));
561 void SituareEngine::setGPS(bool enabled)
563 qDebug() << __PRETTY_FUNCTION__ << enabled;
565 if (m_gps->isInitialized()) {
566 m_ui->setGPSButtonEnabled(enabled);
567 m_mapEngine->setGPSEnabled(enabled);
569 if (enabled && !m_gps->isRunning()) {
571 m_gps->requestLastPosition();
573 if(m_ui->loginState())
574 m_ui->readAutomaticLocationUpdateSettings();
576 else if (!enabled && m_gps->isRunning()) {
578 changeAutoCenteringSetting(false);
579 enableAutomaticLocationUpdate(false);
584 m_ui->buildInformationBox(tr("Unable to start GPS"));
585 m_ui->setGPSButtonEnabled(false);
586 m_mapEngine->setGPSEnabled(false);
590 void SituareEngine::setPowerSaving(bool enabled)
592 qDebug() << __PRETTY_FUNCTION__ << enabled;
594 m_gps->enablePowerSave(enabled);
596 if(m_autoCenteringEnabled)
597 m_mapEngine->setAutoCentering(!enabled);
600 void SituareEngine::showContactDialog(const QString &facebookId)
602 qDebug() << __PRETTY_FUNCTION__;
604 QString guid = m_contactManager->contactGuid(facebookId);
607 m_ui->showContactDialog(guid);
609 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
610 "account from Conversations to use this feature."), true);
613 void SituareEngine::signalsFromFacebookAuthenticator()
615 qDebug() << __PRETTY_FUNCTION__;
617 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
618 this, SLOT(error(int, int)));
620 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
621 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
623 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
624 this, SLOT(loginOk()));
626 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
627 m_ui, SLOT(startLoginProcess()));
629 connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
630 m_ui, SLOT(saveCookies()));
632 connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
633 m_ui, SLOT(loginUsingCookies()));
635 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
636 this, SLOT(loggedIn()));
639 void SituareEngine::signalsFromGeocodingService()
641 qDebug() << __PRETTY_FUNCTION__;
643 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
644 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
646 connect(m_geocodingService, SIGNAL(error(int, int)),
647 this, SLOT(error(int, int)));
650 void SituareEngine::signalsFromGPS()
652 qDebug() << __PRETTY_FUNCTION__;
654 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
655 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
657 connect(m_gps, SIGNAL(timeout()),
658 m_ui, SLOT(gpsTimeout()));
660 connect(m_gps, SIGNAL(error(int, int)),
661 this, SLOT(error(int, int)));
664 void SituareEngine::signalsFromMainWindow()
666 qDebug() << __PRETTY_FUNCTION__;
668 connect(m_ui, SIGNAL(error(int, int)),
669 this, SLOT(error(int, int)));
671 connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
672 this, SLOT(fetchUsernameFromSettings()));
674 connect(m_ui, SIGNAL(loginActionPressed()),
675 this, SLOT(loginActionPressed()));
677 connect(m_ui, SIGNAL(saveUsername(QString)),
678 m_facebookAuthenticator, SLOT(saveUsername(QString)));
680 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
681 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
683 // signals from map view
684 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
685 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
687 connect(m_ui, SIGNAL(mapViewResized(QSize)),
688 m_mapEngine, SLOT(viewResized(QSize)));
690 connect(m_ui, SIGNAL(viewZoomFinished()),
691 m_mapEngine, SLOT(viewZoomFinished()));
693 // signals from zoom buttons (zoom panel and volume buttons)
694 connect(m_ui, SIGNAL(zoomIn()),
695 m_mapEngine, SLOT(zoomIn()));
697 connect(m_ui, SIGNAL(zoomOut()),
698 m_mapEngine, SLOT(zoomOut()));
700 // signals from menu buttons
701 connect(m_ui, SIGNAL(gpsTriggered(bool)),
702 this, SLOT(setGPS(bool)));
704 //signals from dialogs
705 connect(m_ui, SIGNAL(cancelLoginProcess()),
706 this, SLOT(loginProcessCancelled()));
708 connect(m_ui, SIGNAL(requestReverseGeo()),
709 this, SLOT(requestAddress()));
711 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
712 this, SLOT(requestUpdateLocation(QString,bool)));
714 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
715 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
717 // signals from user info tab
718 connect(m_ui, SIGNAL(refreshUserData()),
719 this, SLOT(refreshUserData()));
721 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
722 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
724 // routing signal from friend list tab & search location tab
725 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
726 this, SLOT(routeTo(const GeoCoordinate&)));
728 // signals from location search panel
730 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
732 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
734 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
735 this, SLOT(locationSearch(QString)));
737 // signals from routing tab
738 connect(m_ui, SIGNAL(clearRoute()),
739 m_mapEngine, SLOT(clearRoute()));
741 connect(m_ui, SIGNAL(routeToCursor()),
742 this, SLOT(routeToCursor()));
744 // signals from distance indicator button
745 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
746 this, SLOT(changeAutoCenteringSetting(bool)));
748 connect(m_ui, SIGNAL(draggingModeTriggered()),
749 this, SLOT(draggingModeTriggered()));
751 // signal from search location dialog
752 connect(m_ui, SIGNAL(searchForLocation(QString)),
753 this, SLOT(locationSearch(QString)));
755 // signal from friend list panel
756 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
757 this, SLOT(showContactDialog(const QString &)));
760 void SituareEngine::signalsFromMapEngine()
762 qDebug() << __PRETTY_FUNCTION__;
764 connect(m_mapEngine, SIGNAL(error(int, int)),
765 this, SLOT(error(int, int)));
767 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
768 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
770 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
771 m_ui, SIGNAL(zoomLevelChanged(int)));
773 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
774 this, SLOT(disableAutoCentering()));
776 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
777 m_ui, SIGNAL(maxZoomLevelReached()));
779 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
780 m_ui, SIGNAL(minZoomLevelReached()));
782 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
783 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
785 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
786 m_ui, SIGNAL(newMapResolution(qreal)));
788 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
789 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
792 void SituareEngine::signalsFromRoutingService()
794 qDebug() << __PRETTY_FUNCTION__;
796 connect(m_routingService, SIGNAL(routeParsed(Route&)),
797 this, SLOT(routeParsed(Route&)));
799 connect(m_routingService, SIGNAL(routeParsed(Route&)),
800 m_mapEngine, SLOT(setRoute(Route&)));
802 connect(m_routingService, SIGNAL(routeParsed(Route&)),
803 m_ui, SIGNAL(routeParsed(Route&)));
805 connect(m_routingService, SIGNAL(error(int, int)),
806 this, SLOT(error(int, int)));
809 void SituareEngine::signalsFromSituareService()
811 qDebug() << __PRETTY_FUNCTION__;
813 connect(m_situareService, SIGNAL(error(int, int)),
814 this, SLOT(error(int, int)));
816 connect(m_situareService, SIGNAL(imageReady(User*)),
817 this, SLOT(imageReady(User*)));
819 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
820 m_ui, SIGNAL(reverseGeoReady(QString)));
822 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
823 this, SLOT(userDataChanged(User*, QList<User*>&)));
825 connect(m_situareService, SIGNAL(updateWasSuccessful()),
826 this, SLOT(updateWasSuccessful()));
828 connect(m_situareService, SIGNAL(updateWasSuccessful()),
829 m_ui, SIGNAL(clearUpdateLocationDialogData()));
832 void SituareEngine::startAutomaticUpdate()
834 qDebug() << __PRETTY_FUNCTION__;
836 m_gps->requestUpdate();
837 m_automaticUpdateRequest = true;
840 void SituareEngine::topmostWindowChanged(bool isMainWindow)
842 qDebug() << __PRETTY_FUNCTION__;
844 setPowerSaving(!isMainWindow);
847 void SituareEngine::updateWasSuccessful()
849 qDebug() << __PRETTY_FUNCTION__;
851 if (m_networkAccessManager->isConnected())
852 m_situareService->fetchLocations();
854 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
857 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
859 qDebug() << __PRETTY_FUNCTION__;
861 m_ui->toggleProgressIndicator(false);
863 emit userLocationReady(user);
864 emit friendsLocationsReady(friendsList);