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"
55 #include "user/profile.h"
56 #include "qmlui/userimageprovider.h"
57 #include "updatelocation.h"
61 #include <X11/Xatom.h>
65 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
66 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
67 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
68 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
69 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
70 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
72 class SituareEnginePrivate
74 Q_DECLARE_PUBLIC(SituareEngine)
78 FilteredFriendModel friendProxyModel;
79 FriendModel friendModel;
80 RouteModel routeModel;
82 UpdateLocation updateLocation;
86 int progressIndicatorCount;
88 SituareEnginePrivate(SituareEngine* parent)
89 : q_ptr(parent), routeModel(0), ui(0), progressIndicatorCount(0)
92 void toggleProgressIndicator(bool value)
95 qDebug() << __PRETTY_FUNCTION__;
99 progressIndicatorCount++;
100 ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
102 if(progressIndicatorCount > 0)
103 progressIndicatorCount--;
105 if(progressIndicatorCount == 0)
106 ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
110 #endif // Q_WS_MAEMO_5
113 q->m_ui->toggleProgressIndicator(value);
117 void grabZoomKeys(bool grab)
121 // Can't grab keys unless we have a window id
125 unsigned long val = (grab) ? 1 : 0;
126 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
130 XChangeProperty (QX11Info::display(),
136 reinterpret_cast<unsigned char *>(&val),
144 SituareEngine::SituareEngine()
145 : d_ptr(new SituareEnginePrivate(this)),
146 m_autoCenteringEnabled(false),
147 m_automaticUpdateFirstStart(true),
148 m_automaticUpdateRequest(false),
150 m_automaticUpdateIntervalTimer(0),
151 m_lastUpdatedGPSPosition(GeoCoordinate())
153 qDebug() << __PRETTY_FUNCTION__;
155 m_ui = new MainWindow;
156 m_ui->updateItemVisibility(false);
158 Application *application = static_cast<Application *>(qApp);
159 application->registerWindow(m_ui->winId());
161 connect(application, SIGNAL(topmostWindowChanged(bool)),
162 this, SLOT(topmostWindowChanged(bool)));
164 m_networkAccessManager = new NetworkAccessManager(this);
167 m_mapEngine = new MapEngine(this);
168 m_ui->setMapViewScene(m_mapEngine->scene());
171 m_gps = new GPSPosition(this);
173 // build SituareService
174 m_situareService = new SituareService(this);
176 // build FacebookAuthenticator
177 m_facebookAuthenticator = new FacebookAuthentication(m_ui, this);
179 // build routing service
180 m_routingService = new RoutingService(this); // create this when needed, not in constructor!
182 // build geocoding service
183 m_geocodingService = new GeocodingService(this);
186 signalsFromMapEngine();
187 signalsFromGeocodingService();
189 signalsFromRoutingService();
190 signalsFromSituareService();
191 signalsFromMainWindow();
192 signalsFromFacebookAuthenticator();
194 connect(this, SIGNAL(userLocationReady(User*)),
195 m_ui, SIGNAL(userLocationReady(User*)));
197 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
198 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
200 connect(this, SIGNAL(userLocationReady(User*)),
201 m_mapEngine, SLOT(receiveOwnLocation(User*)));
203 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
204 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
206 connect(this, SIGNAL(friendImageReady(User*)),
207 m_ui, SIGNAL(friendImageReady(User*)));
209 connect(this, SIGNAL(friendImageReady(User*)),
210 m_mapEngine, SIGNAL(friendImageReady(User*)));
212 m_automaticUpdateIntervalTimer = new QTimer(this);
213 connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
214 this, SLOT(startAutomaticUpdate()));
216 // signals connected, now it's time to show the main window
217 // but init the MapEngine before so starting location is set
221 qmlRegisterType<GeoMap>("MapPlugin", 1, 0, "GeoMap");
225 d->ui = new QDeclarativeView(QApplication::desktop());
226 d->grabZoomKeys(true);
228 // d->ui->setAttribute(Qt::WA_Maemo5AutoOrientation, true);
231 d->friendProxyModel.setSourceModel(&d->friendModel);
233 Rotation *rotation = new Rotation();
234 d->ui->rootContext()->setContextProperty("deviceRotation", static_cast<QObject *>(rotation));
235 d->ui->rootContext()->setContextProperty("facebookAuthenticator", m_facebookAuthenticator);
236 d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
237 d->ui->rootContext()->setContextProperty("friendModel", &d->friendProxyModel);
238 d->ui->rootContext()->setContextProperty("userProfile", &d->profile);
239 d->ui->rootContext()->setContextProperty("locationUpdate", &d->updateLocation);
240 d->ui->rootContext()->setContextProperty("engine", this);
242 d->ui->setSource(QUrl("qrc:/Main.qml"));
243 d->ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
244 d->ui->engine()->addImageProvider(QLatin1String("user"), new UserImageProvider(&d->friendModel, &d->profile));
247 GeoMap* geoMap = qobject_cast<GeoMap*>(d->ui->rootObject()->findChild<QObject*>("geoMap"));
249 geoMap->setFriendModels(&d->friendModel, &d->friendProxyModel);
250 geoMap->setRouteModel(&d->routeModel);
252 connect(d->ui->engine()->networkAccessManager(),
253 SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
254 m_facebookAuthenticator, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
255 d->ui->engine()->networkAccessManager()->setCookieJar(new NetworkCookieJar());
261 m_gps->setMode(GPSPosition::Default);
262 initializeGpsAndAutocentering();
264 m_mce = new MCE(this);
265 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
267 m_contactManager = new ContactManager(this);
268 m_contactManager->requestContactGuids();
270 m_facebookAuthenticator->login();
272 connect(&d->updateLocation, SIGNAL(locationUpdate(QString,bool)),
273 this, SLOT(requestUpdateLocation(QString,bool)));
276 SituareEngine::~SituareEngine()
278 qDebug() << __PRETTY_FUNCTION__;
281 d->grabZoomKeys(false);
285 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
286 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
287 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
290 void SituareEngine::changeAutoCenteringSetting(bool enabled)
292 qDebug() << __PRETTY_FUNCTION__ << enabled;
294 m_autoCenteringEnabled = enabled;
295 setAutoCentering(enabled);
298 void SituareEngine::disableAutoCentering()
300 qDebug() << __PRETTY_FUNCTION__;
302 changeAutoCenteringSetting(false);
305 void SituareEngine::draggingModeTriggered()
307 qDebug() << __PRETTY_FUNCTION__;
310 m_mce->vibrationFeedback();
313 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
315 qDebug() << __PRETTY_FUNCTION__;
317 //Show automatic update confirmation dialog
318 if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
319 m_ui->showEnableAutomaticUpdateLocationDialog(
320 tr("Do you want to enable automatic location update with %1 min update interval?")
321 .arg(updateIntervalMsecs/1000/60));
322 m_automaticUpdateFirstStart = false;
324 if (enabled && m_gps->isRunning()) {
325 m_ui->buildInformationBox(tr("Automatic location update enabled"));
326 if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
327 m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
329 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
331 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
332 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
334 m_automaticUpdateIntervalTimer->start();
337 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
338 this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
340 m_automaticUpdateIntervalTimer->stop();
345 void SituareEngine::error(const int context, const int error)
348 qDebug() << __PRETTY_FUNCTION__;
351 case SituareError::ERROR_GENERAL:
352 if(context == ErrorContext::SITUARE) {
353 d->toggleProgressIndicator(false);
354 m_ui->buildInformationBox(tr("Unknown server error"), true);
357 case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
358 d->toggleProgressIndicator(false);
359 if(context == ErrorContext::SITUARE) {
360 m_ui->buildInformationBox(tr("Missing parameter from request"), true);
361 } else if(context == ErrorContext::NETWORK) {
362 m_ui->buildInformationBox(tr("Connection refused by the server"), true);
365 case QNetworkReply::RemoteHostClosedError:
366 if(context == ErrorContext::NETWORK) {
367 d->toggleProgressIndicator(false);
368 m_ui->buildInformationBox(tr("Connection closed by the server"), true);
371 case QNetworkReply::HostNotFoundError:
372 if(context == ErrorContext::NETWORK) {
373 d->toggleProgressIndicator(false);
374 m_ui->buildInformationBox(tr("Remote server not found"), true);
377 case QNetworkReply::TimeoutError:
378 if(context == ErrorContext::NETWORK) {
379 d->toggleProgressIndicator(false);
380 m_ui->buildInformationBox(tr("Connection timed out"), true);
383 case QNetworkReply::UnknownNetworkError:
384 if(context == ErrorContext::NETWORK) {
385 d->toggleProgressIndicator(false);
386 m_ui->buildInformationBox(tr("No network connection"), true);
389 case SituareError::SESSION_EXPIRED:
390 m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
391 m_facebookAuthenticator->logOut();
392 m_facebookAuthenticator->login();
394 case SituareError::UPDATE_FAILED:
395 d->toggleProgressIndicator(false);
396 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
398 case SituareError::DATA_RETRIEVAL_FAILED:
399 d->toggleProgressIndicator(false);
400 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
402 case SituareError::ADDRESS_RETRIEVAL_FAILED:
403 d->toggleProgressIndicator(false);
404 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
406 case SituareError::IMAGE_DOWNLOAD_FAILED:
407 m_ui->buildInformationBox(tr("Image download failed"), true);
409 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
410 m_ui->buildInformationBox(tr("Map image download failed"), true);
412 case SituareError::GPS_INITIALIZATION_FAILED:
414 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
416 case SituareError::INVALID_JSON:
417 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
418 m_ui->loggedIn(false);
419 m_facebookAuthenticator->clearAccountInformation(false); // clean all
421 case SituareError::ERROR_ROUTING_FAILED:
422 d->toggleProgressIndicator(false);
423 m_ui->buildInformationBox(tr("Routing failed"), true);
425 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
426 m_ui->buildInformationBox(tr("No results found"), true);
429 d->toggleProgressIndicator(false);
430 if(context == ErrorContext::NETWORK)
431 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
433 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
438 void SituareEngine::imageReady(User *user)
440 qDebug() << __PRETTY_FUNCTION__;
443 emit userLocationReady(user);
444 d->profile.setProfile(*user);
446 emit friendImageReady(user);
447 d->friendModel.resetFriends();
451 void SituareEngine::initializeGpsAndAutocentering()
453 qDebug() << __PRETTY_FUNCTION__;
455 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
456 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
457 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
459 if (m_gps->isInitialized()) {
461 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
463 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
464 this, SLOT(setFirstStartZoomLevel()));
466 changeAutoCenteringSetting(true);
469 m_ui->buildInformationBox(tr("GPS enabled"));
471 } else { // Normal start
472 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
473 setGPS(gpsEnabled.toBool());
475 if (gpsEnabled.toBool())
476 m_ui->buildInformationBox(tr("GPS enabled"));
483 void SituareEngine::locationSearch(QString location)
485 qDebug() << __PRETTY_FUNCTION__;
487 if(!location.isEmpty())
488 m_geocodingService->requestLocation(location);
491 void SituareEngine::loginActionPressed()
493 qDebug() << __PRETTY_FUNCTION__;
495 if (m_facebookAuthenticator->isLoggedIn())
496 m_facebookAuthenticator->logOut(true);
497 else if (m_networkAccessManager->isConnected())
498 m_facebookAuthenticator->login();
500 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
503 void SituareEngine::onLogin()
505 qDebug() << __PRETTY_FUNCTION__;
507 m_ui->loggedIn(true);
509 m_situareService->fetchLocations();
511 if (m_gps->isRunning())
512 m_ui->readAutomaticLocationUpdateSettings();
515 void SituareEngine::onLogout()
517 qDebug() << __PRETTY_FUNCTION__;
519 m_ui->loggedIn(false);
520 m_situareService->updateSession(""); // empty session string means logged out
521 m_automaticUpdateFirstStart = true;
524 void SituareEngine::refreshUserData()
528 qDebug() << __PRETTY_FUNCTION__;
530 if (m_networkAccessManager->isConnected()) {
531 d->toggleProgressIndicator(true);
532 m_situareService->fetchLocations();
535 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
539 void SituareEngine::requestAddress()
541 qDebug() << __PRETTY_FUNCTION__;
543 if (m_networkAccessManager->isConnected()) {
544 if (m_gps->isRunning())
545 m_situareService->reverseGeo(m_gps->lastPosition());
547 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
550 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
554 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
556 qDebug() << __PRETTY_FUNCTION__;
559 if (m_networkAccessManager->isConnected()) {
560 d->toggleProgressIndicator(true);
562 if (m_gps->isRunning())
563 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
565 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
568 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
572 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
574 qDebug() << __PRETTY_FUNCTION__;
576 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
577 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
578 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
579 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
581 m_lastUpdatedGPSPosition = position;
585 if (m_automaticUpdateRequest && m_userMoved) {
586 requestUpdateLocation(tr("Automatic location update"));
587 m_automaticUpdateRequest = false;
592 void SituareEngine::routeParsed(Route &route)
594 qDebug() << __PRETTY_FUNCTION__;
598 d->routeModel.setSegments(route.segments(), route.geometryPoints());
600 d->toggleProgressIndicator(false);
603 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
606 qDebug() << __PRETTY_FUNCTION__;
608 d->toggleProgressIndicator(true);
610 if (m_gps->isRunning())
611 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
613 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
616 void SituareEngine::routeToCursor()
618 qDebug() << __PRETTY_FUNCTION__;
620 routeTo(m_mapEngine->centerGeoCoordinate());
623 void SituareEngine::setAutoCentering(bool enabled)
625 qDebug() << __PRETTY_FUNCTION__ << enabled;
627 m_ui->setIndicatorButtonEnabled(enabled);
628 m_mapEngine->setAutoCentering(enabled);
629 m_ui->setCrosshairVisibility(!enabled);
633 m_gps->requestLastPosition();
637 void SituareEngine::setFirstStartZoomLevel()
639 qDebug() << __PRETTY_FUNCTION__;
641 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
642 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
644 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
645 this, SLOT(setFirstStartZoomLevel()));
648 void SituareEngine::setGPS(bool enabled)
650 qDebug() << __PRETTY_FUNCTION__ << enabled;
652 if (m_gps->isInitialized()) {
653 m_ui->setGPSButtonEnabled(enabled);
654 m_mapEngine->setGPSEnabled(enabled);
656 if (enabled && !m_gps->isRunning()) {
658 m_gps->requestLastPosition();
660 if(m_facebookAuthenticator->isLoggedIn())
661 m_ui->readAutomaticLocationUpdateSettings();
663 else if (!enabled && m_gps->isRunning()) {
665 changeAutoCenteringSetting(false);
666 enableAutomaticLocationUpdate(false);
671 m_ui->buildInformationBox(tr("Unable to start GPS"));
672 m_ui->setGPSButtonEnabled(false);
673 m_mapEngine->setGPSEnabled(false);
677 void SituareEngine::setPowerSaving(bool enabled)
679 qDebug() << __PRETTY_FUNCTION__ << enabled;
681 m_gps->enablePowerSave(enabled);
683 if(m_autoCenteringEnabled)
684 m_mapEngine->setAutoCentering(!enabled);
687 void SituareEngine::showContactDialog(const QString &facebookId)
689 qDebug() << __PRETTY_FUNCTION__;
691 QString guid = m_contactManager->contactGuid(facebookId);
694 m_ui->showContactDialog(guid);
696 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
697 "account from Conversations to use this feature."), true);
700 void SituareEngine::signalsFromFacebookAuthenticator()
702 qDebug() << __PRETTY_FUNCTION__;
704 connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
705 this, SLOT(error(int, int)));
707 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
708 m_situareService, SLOT(updateSession(QString)));
710 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
711 this, SLOT(onLogin()));
713 connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
716 void SituareEngine::signalsFromGeocodingService()
718 qDebug() << __PRETTY_FUNCTION__;
720 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
721 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
723 connect(m_geocodingService, SIGNAL(error(int, int)),
724 this, SLOT(error(int, int)));
727 void SituareEngine::signalsFromGPS()
729 qDebug() << __PRETTY_FUNCTION__;
731 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
732 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
734 connect(m_gps, SIGNAL(timeout()),
735 m_ui, SLOT(gpsTimeout()));
737 connect(m_gps, SIGNAL(error(int, int)),
738 this, SLOT(error(int, int)));
741 void SituareEngine::signalsFromMainWindow()
743 qDebug() << __PRETTY_FUNCTION__;
745 connect(m_ui, SIGNAL(error(int, int)),
746 this, SLOT(error(int, int)));
748 connect(m_ui, SIGNAL(loginActionPressed()),
749 this, SLOT(loginActionPressed()));
751 // signals from map view
752 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
753 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
755 connect(m_ui, SIGNAL(mapViewResized(QSize)),
756 m_mapEngine, SLOT(viewResized(QSize)));
758 connect(m_ui, SIGNAL(viewZoomFinished()),
759 m_mapEngine, SLOT(viewZoomFinished()));
761 // signals from zoom buttons (zoom panel and volume buttons)
762 connect(m_ui, SIGNAL(zoomIn()),
763 m_mapEngine, SLOT(zoomIn()));
765 connect(m_ui, SIGNAL(zoomOut()),
766 m_mapEngine, SLOT(zoomOut()));
768 // signals from menu buttons
769 connect(m_ui, SIGNAL(gpsTriggered(bool)),
770 this, SLOT(setGPS(bool)));
772 connect(m_ui, SIGNAL(requestReverseGeo()),
773 this, SLOT(requestAddress()));
775 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
776 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
778 // signals from user info tab
779 connect(m_ui, SIGNAL(refreshUserData()),
780 this, SLOT(refreshUserData()));
782 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
783 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
785 // routing signal from friend list tab & search location tab
786 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
787 this, SLOT(routeTo(const GeoCoordinate&)));
789 // signals from location search panel
791 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
793 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
795 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
796 this, SLOT(locationSearch(QString)));
798 // signals from routing tab
799 connect(m_ui, SIGNAL(clearRoute()),
800 m_mapEngine, SLOT(clearRoute()));
802 connect(m_ui, SIGNAL(routeToCursor()),
803 this, SLOT(routeToCursor()));
805 // signals from distance indicator button
806 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
807 this, SLOT(changeAutoCenteringSetting(bool)));
809 connect(m_ui, SIGNAL(draggingModeTriggered()),
810 this, SLOT(draggingModeTriggered()));
812 // signal from search location dialog
813 connect(m_ui, SIGNAL(searchForLocation(QString)),
814 this, SLOT(locationSearch(QString)));
816 // signal from friend list panel
817 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
818 this, SLOT(showContactDialog(const QString &)));
821 void SituareEngine::signalsFromMapEngine()
823 qDebug() << __PRETTY_FUNCTION__;
825 connect(m_mapEngine, SIGNAL(error(int, int)),
826 this, SLOT(error(int, int)));
828 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
829 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
831 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
832 m_ui, SIGNAL(zoomLevelChanged(int)));
834 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
835 this, SLOT(disableAutoCentering()));
837 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
838 m_ui, SIGNAL(maxZoomLevelReached()));
840 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
841 m_ui, SIGNAL(minZoomLevelReached()));
843 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
844 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
846 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
847 m_ui, SIGNAL(newMapResolution(qreal)));
849 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
850 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
853 void SituareEngine::signalsFromRoutingService()
855 qDebug() << __PRETTY_FUNCTION__;
857 connect(m_routingService, SIGNAL(routeParsed(Route&)),
858 this, SLOT(routeParsed(Route&)));
860 connect(m_routingService, SIGNAL(routeParsed(Route&)),
861 m_mapEngine, SLOT(setRoute(Route&)));
863 connect(m_routingService, SIGNAL(routeParsed(Route&)),
864 m_ui, SIGNAL(routeParsed(Route&)));
866 connect(m_routingService, SIGNAL(error(int, int)),
867 this, SLOT(error(int, int)));
870 void SituareEngine::signalsFromSituareService()
872 qDebug() << __PRETTY_FUNCTION__;
874 connect(m_situareService, SIGNAL(error(int, int)),
875 this, SLOT(error(int, int)));
877 connect(m_situareService, SIGNAL(imageReady(User*)),
878 this, SLOT(imageReady(User*)));
880 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
881 m_ui, SIGNAL(reverseGeoReady(QString)));
883 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
884 this, SLOT(userDataChanged(User*, QList<User*>&)));
886 connect(m_situareService, SIGNAL(updateWasSuccessful()),
887 this, SLOT(updateWasSuccessful()));
890 connect(m_situareService, SIGNAL(updateWasSuccessful()), &d->updateLocation, SLOT(clear()));
893 void SituareEngine::startAutomaticUpdate()
895 qDebug() << __PRETTY_FUNCTION__;
897 m_gps->requestUpdate();
898 m_automaticUpdateRequest = true;
901 void SituareEngine::topmostWindowChanged(bool isMainWindow)
903 qDebug() << __PRETTY_FUNCTION__;
905 setPowerSaving(!isMainWindow);
908 void SituareEngine::updateWasSuccessful()
910 qDebug() << __PRETTY_FUNCTION__;
912 if (m_networkAccessManager->isConnected())
913 m_situareService->fetchLocations();
915 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
918 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
920 qDebug() << __PRETTY_FUNCTION__;
922 d->toggleProgressIndicator(false);
924 emit userLocationReady(user);
925 d->profile.setProfile(*user);
927 emit friendsLocationsReady(friendsList);
928 d->friendModel.setFriends(friendsList);
931 void SituareEngine::routeFromTo(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude)
933 qDebug() << __PRETTY_FUNCTION__;
936 d->toggleProgressIndicator(true);
938 m_routingService->requestRoute(GeoCoordinate(fromLatitude, fromLongitude), GeoCoordinate(toLatitude, toLongitude));