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"
43 #include "qmlui/geomap.h"
44 #include "qmlui/rotation.h"
45 #include "qmlui/loginlogic.h"
46 #include <qdeclarative.h>
47 #include <QDeclarativeView>
48 #include <QDeclarativeContext>
49 #include <QApplication>
50 #include <QDesktopWidget>
51 #include <QDeclarativeEngine>
53 #include "routing/routemodel.h"
54 #include "user/friendmodel.h"
56 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
57 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
58 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
59 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
60 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
61 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
63 class SituareEnginePrivate
65 Q_DECLARE_PUBLIC(SituareEngine)
69 FriendModel friendModel;
70 RouteModel routeModel;
74 int progressIndicatorCount;
76 SituareEnginePrivate(SituareEngine* parent)
77 : q_ptr(parent), routeModel(0), ui(0), progressIndicatorCount(0)
80 void toggleProgressIndicator(bool value)
83 qDebug() << __PRETTY_FUNCTION__;
87 progressIndicatorCount++;
88 ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
90 if(progressIndicatorCount > 0)
91 progressIndicatorCount--;
93 if(progressIndicatorCount == 0)
94 ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
98 #endif // Q_WS_MAEMO_5
101 q->m_ui->toggleProgressIndicator(value);
106 SituareEngine::SituareEngine()
107 : d_ptr(new SituareEnginePrivate(this)),
108 m_autoCenteringEnabled(false),
109 m_automaticUpdateFirstStart(true),
110 m_automaticUpdateRequest(false),
112 m_automaticUpdateIntervalTimer(0),
113 m_lastUpdatedGPSPosition(GeoCoordinate())
115 qDebug() << __PRETTY_FUNCTION__;
117 m_ui = new MainWindow;
118 m_ui->updateItemVisibility(false);
120 Application *application = static_cast<Application *>(qApp);
121 application->registerWindow(m_ui->winId());
123 connect(application, SIGNAL(topmostWindowChanged(bool)),
124 this, SLOT(topmostWindowChanged(bool)));
126 m_networkAccessManager = new NetworkAccessManager(this);
129 m_mapEngine = new MapEngine(this);
130 m_ui->setMapViewScene(m_mapEngine->scene());
133 m_gps = new GPSPosition(this);
135 // build SituareService
136 m_situareService = new SituareService(this);
138 // build FacebookAuthenticator
139 m_facebookAuthenticator = new FacebookAuthentication(m_ui, this);
141 // build routing service
142 m_routingService = new RoutingService(this); // create this when needed, not in constructor!
144 // build geocoding service
145 m_geocodingService = new GeocodingService(this);
148 signalsFromMapEngine();
149 signalsFromGeocodingService();
151 signalsFromRoutingService();
152 signalsFromSituareService();
153 signalsFromMainWindow();
154 signalsFromFacebookAuthenticator();
156 connect(this, SIGNAL(userLocationReady(User*)),
157 m_ui, SIGNAL(userLocationReady(User*)));
159 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
160 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
162 connect(this, SIGNAL(userLocationReady(User*)),
163 m_mapEngine, SLOT(receiveOwnLocation(User*)));
165 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
166 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
168 connect(this, SIGNAL(friendImageReady(User*)),
169 m_ui, SIGNAL(friendImageReady(User*)));
171 connect(this, SIGNAL(friendImageReady(User*)),
172 m_mapEngine, SIGNAL(friendImageReady(User*)));
174 m_automaticUpdateIntervalTimer = new QTimer(this);
175 connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
176 this, SLOT(startAutomaticUpdate()));
178 // signals connected, now it's time to show the main window
179 // but init the MapEngine before so starting location is set
183 qmlRegisterType<GeoMap>("MapPlugin", 1, 0, "GeoMap");
187 d->ui = new QDeclarativeView(QApplication::desktop());
189 // d->ui->setAttribute(Qt::WA_Maemo5AutoOrientation, true);
191 Rotation *rotation = new Rotation();
192 d->ui->rootContext()->setContextProperty("deviceRotation", static_cast<QObject *>(rotation));
193 d->ui->rootContext()->setContextProperty("facebookAuthenticator", m_facebookAuthenticator);
194 d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
195 d->ui->rootContext()->setContextProperty("friendModel", &d->friendModel);
196 d->ui->rootContext()->setContextProperty("engine", this);
198 d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
199 d->ui->rootContext()->setContextProperty("engine", this);
201 d->ui->setSource(QUrl("qrc:/Main.qml"));
202 d->ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
205 connect(d->ui->engine()->networkAccessManager(),
206 SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
207 m_facebookAuthenticator, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
212 m_gps->setMode(GPSPosition::Default);
213 initializeGpsAndAutocentering();
215 m_mce = new MCE(this);
216 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
218 m_contactManager = new ContactManager(this);
219 m_contactManager->requestContactGuids();
221 m_facebookAuthenticator->login();
224 SituareEngine::~SituareEngine()
226 qDebug() << __PRETTY_FUNCTION__;
230 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
231 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
232 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
235 void SituareEngine::changeAutoCenteringSetting(bool enabled)
237 qDebug() << __PRETTY_FUNCTION__ << enabled;
239 m_autoCenteringEnabled = enabled;
240 setAutoCentering(enabled);
243 void SituareEngine::disableAutoCentering()
245 qDebug() << __PRETTY_FUNCTION__;
247 changeAutoCenteringSetting(false);
250 void SituareEngine::draggingModeTriggered()
252 qDebug() << __PRETTY_FUNCTION__;
255 m_mce->vibrationFeedback();
258 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
260 qDebug() << __PRETTY_FUNCTION__;
262 //Show automatic update confirmation dialog
263 if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
264 m_ui->showEnableAutomaticUpdateLocationDialog(
265 tr("Do you want to enable automatic location update with %1 min update interval?")
266 .arg(updateIntervalMsecs/1000/60));
267 m_automaticUpdateFirstStart = false;
269 if (enabled && m_gps->isRunning()) {
270 m_ui->buildInformationBox(tr("Automatic location update enabled"));
271 if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
272 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
274 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
276 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
277 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
279 m_automaticUpdateIntervalTimer->start();
282 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
283 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
285 m_automaticUpdateIntervalTimer->stop();
290 void SituareEngine::error(const int context, const int error)
293 qDebug() << __PRETTY_FUNCTION__;
296 case SituareError::ERROR_GENERAL:
297 if(context == ErrorContext::SITUARE) {
298 d->toggleProgressIndicator(false);
299 m_ui->buildInformationBox(tr("Unknown server error"), true);
302 case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
303 d->toggleProgressIndicator(false);
304 if(context == ErrorContext::SITUARE) {
305 m_ui->buildInformationBox(tr("Missing parameter from request"), true);
306 } else if(context == ErrorContext::NETWORK) {
307 m_ui->buildInformationBox(tr("Connection refused by the server"), true);
310 case QNetworkReply::RemoteHostClosedError:
311 if(context == ErrorContext::NETWORK) {
312 d->toggleProgressIndicator(false);
313 m_ui->buildInformationBox(tr("Connection closed by the server"), true);
316 case QNetworkReply::HostNotFoundError:
317 if(context == ErrorContext::NETWORK) {
318 d->toggleProgressIndicator(false);
319 m_ui->buildInformationBox(tr("Remote server not found"), true);
322 case QNetworkReply::TimeoutError:
323 if(context == ErrorContext::NETWORK) {
324 d->toggleProgressIndicator(false);
325 m_ui->buildInformationBox(tr("Connection timed out"), true);
328 case QNetworkReply::UnknownNetworkError:
329 if(context == ErrorContext::NETWORK) {
330 d->toggleProgressIndicator(false);
331 m_ui->buildInformationBox(tr("No network connection"), true);
334 case SituareError::SESSION_EXPIRED:
335 m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
336 m_facebookAuthenticator->logOut();
337 m_facebookAuthenticator->login();
339 case SituareError::UPDATE_FAILED:
340 d->toggleProgressIndicator(false);
341 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
343 case SituareError::DATA_RETRIEVAL_FAILED:
344 d->toggleProgressIndicator(false);
345 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
347 case SituareError::ADDRESS_RETRIEVAL_FAILED:
348 d->toggleProgressIndicator(false);
349 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
351 case SituareError::IMAGE_DOWNLOAD_FAILED:
352 m_ui->buildInformationBox(tr("Image download failed"), true);
354 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
355 m_ui->buildInformationBox(tr("Map image download failed"), true);
357 case SituareError::GPS_INITIALIZATION_FAILED:
359 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
361 case SituareError::INVALID_JSON:
362 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
363 m_ui->loggedIn(false);
364 m_facebookAuthenticator->clearAccountInformation(false); // clean all
366 case SituareError::ERROR_ROUTING_FAILED:
367 d->toggleProgressIndicator(false);
368 m_ui->buildInformationBox(tr("Routing failed"), true);
370 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
371 m_ui->buildInformationBox(tr("No results found"), true);
374 d->toggleProgressIndicator(false);
375 if(context == ErrorContext::NETWORK)
376 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
378 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
383 void SituareEngine::imageReady(User *user)
385 qDebug() << __PRETTY_FUNCTION__;
388 emit userLocationReady(user);
390 emit friendImageReady(user);
393 void SituareEngine::initializeGpsAndAutocentering()
395 qDebug() << __PRETTY_FUNCTION__;
397 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
398 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
399 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
401 if (m_gps->isInitialized()) {
403 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
405 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
406 this, SLOT(setFirstStartZoomLevel()));
408 changeAutoCenteringSetting(true);
411 m_ui->buildInformationBox(tr("GPS enabled"));
413 } else { // Normal start
414 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
415 setGPS(gpsEnabled.toBool());
417 if (gpsEnabled.toBool())
418 m_ui->buildInformationBox(tr("GPS enabled"));
425 void SituareEngine::locationSearch(QString location)
427 qDebug() << __PRETTY_FUNCTION__;
429 if(!location.isEmpty())
430 m_geocodingService->requestLocation(location);
433 void SituareEngine::loginActionPressed()
435 qDebug() << __PRETTY_FUNCTION__;
437 if (m_facebookAuthenticator->isLoggedIn())
438 m_facebookAuthenticator->logOut(true);
439 else if (m_networkAccessManager->isConnected())
440 m_facebookAuthenticator->login();
442 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
445 void SituareEngine::onLogin()
447 qDebug() << __PRETTY_FUNCTION__;
449 m_ui->loggedIn(true);
451 m_situareService->fetchLocations();
453 if (m_gps->isRunning())
454 m_ui->readAutomaticLocationUpdateSettings();
457 void SituareEngine::onLogout()
459 qDebug() << __PRETTY_FUNCTION__;
461 m_ui->loggedIn(false);
462 m_situareService->updateSession(""); // empty session string means logged out
463 m_automaticUpdateFirstStart = true;
466 void SituareEngine::refreshUserData()
470 qDebug() << __PRETTY_FUNCTION__;
472 if (m_networkAccessManager->isConnected()) {
473 d->toggleProgressIndicator(true);
474 m_situareService->fetchLocations();
477 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
481 void SituareEngine::requestAddress()
483 qDebug() << __PRETTY_FUNCTION__;
485 if (m_networkAccessManager->isConnected()) {
486 if (m_gps->isRunning())
487 m_situareService->reverseGeo(m_gps->lastPosition());
489 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
492 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
496 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
498 qDebug() << __PRETTY_FUNCTION__;
501 if (m_networkAccessManager->isConnected()) {
502 d->toggleProgressIndicator(true);
504 if (m_gps->isRunning())
505 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
507 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
510 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
514 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
516 qDebug() << __PRETTY_FUNCTION__;
518 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
519 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
520 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
521 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
523 m_lastUpdatedGPSPosition = position;
527 if (m_automaticUpdateRequest && m_userMoved) {
528 requestUpdateLocation(tr("Automatic location update"));
529 m_automaticUpdateRequest = false;
534 void SituareEngine::routeParsed(Route &route)
536 qDebug() << __PRETTY_FUNCTION__;
540 d->routeModel.setSegments(route.segments());
542 d->toggleProgressIndicator(false);
545 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
548 qDebug() << __PRETTY_FUNCTION__;
550 d->toggleProgressIndicator(true);
552 if (m_gps->isRunning())
553 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
555 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
558 void SituareEngine::routeToCursor()
560 qDebug() << __PRETTY_FUNCTION__;
562 routeTo(m_mapEngine->centerGeoCoordinate());
565 void SituareEngine::setAutoCentering(bool enabled)
567 qDebug() << __PRETTY_FUNCTION__ << enabled;
569 m_ui->setIndicatorButtonEnabled(enabled);
570 m_mapEngine->setAutoCentering(enabled);
571 m_ui->setCrosshairVisibility(!enabled);
575 m_gps->requestLastPosition();
579 void SituareEngine::setFirstStartZoomLevel()
581 qDebug() << __PRETTY_FUNCTION__;
583 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
584 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
586 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
587 this, SLOT(setFirstStartZoomLevel()));
590 void SituareEngine::setGPS(bool enabled)
592 qDebug() << __PRETTY_FUNCTION__ << enabled;
594 if (m_gps->isInitialized()) {
595 m_ui->setGPSButtonEnabled(enabled);
596 m_mapEngine->setGPSEnabled(enabled);
598 if (enabled && !m_gps->isRunning()) {
600 m_gps->requestLastPosition();
602 if(m_facebookAuthenticator->isLoggedIn())
603 m_ui->readAutomaticLocationUpdateSettings();
605 else if (!enabled && m_gps->isRunning()) {
607 changeAutoCenteringSetting(false);
608 enableAutomaticLocationUpdate(false);
613 m_ui->buildInformationBox(tr("Unable to start GPS"));
614 m_ui->setGPSButtonEnabled(false);
615 m_mapEngine->setGPSEnabled(false);
619 void SituareEngine::setPowerSaving(bool enabled)
621 qDebug() << __PRETTY_FUNCTION__ << enabled;
623 m_gps->enablePowerSave(enabled);
625 if(m_autoCenteringEnabled)
626 m_mapEngine->setAutoCentering(!enabled);
629 void SituareEngine::showContactDialog(const QString &facebookId)
631 qDebug() << __PRETTY_FUNCTION__;
633 QString guid = m_contactManager->contactGuid(facebookId);
636 m_ui->showContactDialog(guid);
638 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
639 "account from Conversations to use this feature."), true);
642 void SituareEngine::signalsFromFacebookAuthenticator()
644 qDebug() << __PRETTY_FUNCTION__;
646 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
647 this, SLOT(error(int, int)));
649 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
650 m_situareService, SLOT(updateSession(QString)));
652 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
653 this, SLOT(onLogin()));
655 connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
658 void SituareEngine::signalsFromGeocodingService()
660 qDebug() << __PRETTY_FUNCTION__;
662 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
663 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
665 connect(m_geocodingService, SIGNAL(error(int, int)),
666 this, SLOT(error(int, int)));
669 void SituareEngine::signalsFromGPS()
671 qDebug() << __PRETTY_FUNCTION__;
673 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
674 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
676 connect(m_gps, SIGNAL(timeout()),
677 m_ui, SLOT(gpsTimeout()));
679 connect(m_gps, SIGNAL(error(int, int)),
680 this, SLOT(error(int, int)));
683 void SituareEngine::signalsFromMainWindow()
685 qDebug() << __PRETTY_FUNCTION__;
687 connect(m_ui, SIGNAL(error(int, int)),
688 this, SLOT(error(int, int)));
690 connect(m_ui, SIGNAL(loginActionPressed()),
691 this, SLOT(loginActionPressed()));
693 // signals from map view
694 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
695 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
697 connect(m_ui, SIGNAL(mapViewResized(QSize)),
698 m_mapEngine, SLOT(viewResized(QSize)));
700 connect(m_ui, SIGNAL(viewZoomFinished()),
701 m_mapEngine, SLOT(viewZoomFinished()));
703 // signals from zoom buttons (zoom panel and volume buttons)
704 connect(m_ui, SIGNAL(zoomIn()),
705 m_mapEngine, SLOT(zoomIn()));
707 connect(m_ui, SIGNAL(zoomOut()),
708 m_mapEngine, SLOT(zoomOut()));
710 // signals from menu buttons
711 connect(m_ui, SIGNAL(gpsTriggered(bool)),
712 this, SLOT(setGPS(bool)));
714 connect(m_ui, SIGNAL(requestReverseGeo()),
715 this, SLOT(requestAddress()));
717 connect(m_ui, SIGNAL(locationUpdate(QString,bool)),
718 this, SLOT(requestUpdateLocation(QString,bool)));
720 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
721 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
723 // signals from user info tab
724 connect(m_ui, SIGNAL(refreshUserData()),
725 this, SLOT(refreshUserData()));
727 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
728 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
730 // routing signal from friend list tab & search location tab
731 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
732 this, SLOT(routeTo(const GeoCoordinate&)));
734 // signals from location search panel
736 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
738 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
740 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
741 this, SLOT(locationSearch(QString)));
743 // signals from routing tab
744 connect(m_ui, SIGNAL(clearRoute()),
745 m_mapEngine, SLOT(clearRoute()));
747 connect(m_ui, SIGNAL(routeToCursor()),
748 this, SLOT(routeToCursor()));
750 // signals from distance indicator button
751 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
752 this, SLOT(changeAutoCenteringSetting(bool)));
754 connect(m_ui, SIGNAL(draggingModeTriggered()),
755 this, SLOT(draggingModeTriggered()));
757 // signal from search location dialog
758 connect(m_ui, SIGNAL(searchForLocation(QString)),
759 this, SLOT(locationSearch(QString)));
761 // signal from friend list panel
762 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
763 this, SLOT(showContactDialog(const QString &)));
766 void SituareEngine::signalsFromMapEngine()
768 qDebug() << __PRETTY_FUNCTION__;
770 connect(m_mapEngine, SIGNAL(error(int, int)),
771 this, SLOT(error(int, int)));
773 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
774 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
776 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
777 m_ui, SIGNAL(zoomLevelChanged(int)));
779 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
780 this, SLOT(disableAutoCentering()));
782 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
783 m_ui, SIGNAL(maxZoomLevelReached()));
785 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
786 m_ui, SIGNAL(minZoomLevelReached()));
788 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
789 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
791 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
792 m_ui, SIGNAL(newMapResolution(qreal)));
794 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
795 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
798 void SituareEngine::signalsFromRoutingService()
800 qDebug() << __PRETTY_FUNCTION__;
802 connect(m_routingService, SIGNAL(routeParsed(Route&)),
803 this, SLOT(routeParsed(Route&)));
805 connect(m_routingService, SIGNAL(routeParsed(Route&)),
806 m_mapEngine, SLOT(setRoute(Route&)));
808 connect(m_routingService, SIGNAL(routeParsed(Route&)),
809 m_ui, SIGNAL(routeParsed(Route&)));
811 connect(m_routingService, SIGNAL(error(int, int)),
812 this, SLOT(error(int, int)));
815 void SituareEngine::signalsFromSituareService()
817 qDebug() << __PRETTY_FUNCTION__;
819 connect(m_situareService, SIGNAL(error(int, int)),
820 this, SLOT(error(int, int)));
822 connect(m_situareService, SIGNAL(imageReady(User*)),
823 this, SLOT(imageReady(User*)));
825 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
826 m_ui, SIGNAL(reverseGeoReady(QString)));
828 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
829 this, SLOT(userDataChanged(User*, QList<User*>&)));
831 connect(m_situareService, SIGNAL(updateWasSuccessful()),
832 this, SLOT(updateWasSuccessful()));
834 connect(m_situareService, SIGNAL(updateWasSuccessful()),
835 m_ui, SIGNAL(updateWasSuccessful()));
838 void SituareEngine::startAutomaticUpdate()
840 qDebug() << __PRETTY_FUNCTION__;
842 m_gps->requestUpdate();
843 m_automaticUpdateRequest = true;
846 void SituareEngine::topmostWindowChanged(bool isMainWindow)
848 qDebug() << __PRETTY_FUNCTION__;
850 setPowerSaving(!isMainWindow);
853 void SituareEngine::updateWasSuccessful()
855 qDebug() << __PRETTY_FUNCTION__;
857 if (m_networkAccessManager->isConnected())
858 m_situareService->fetchLocations();
860 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
863 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
865 qDebug() << __PRETTY_FUNCTION__;
867 d->toggleProgressIndicator(false);
869 emit userLocationReady(user);
870 emit friendsLocationsReady(friendsList);
871 d->friendModel.setFriends(friendsList);
874 void SituareEngine::routeFromTo(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude)
876 qDebug() << __PRETTY_FUNCTION__;
879 d->toggleProgressIndicator(true);
881 m_routingService->requestRoute(GeoCoordinate(fromLatitude, fromLongitude), GeoCoordinate(toLatitude, toLongitude));