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(false);
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(m_networkAccessManager,
83 new ImageFetcher(m_networkAccessManager, this), this);
85 // build FacebookAuthenticator
86 m_facebookAuthenticator = new FacebookAuthentication(m_ui, 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(userImageReady(QString,QPixmap)),
116 m_ui, SIGNAL(userImageReady(QString,QPixmap)));
118 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
119 m_ui, SIGNAL(friendImageReady(QString,QPixmap)));
121 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
122 m_mapEngine, SIGNAL(friendImageReady(QString,QPixmap)));
124 m_automaticUpdateIntervalTimer = new QTimer(this);
125 connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
126 this, SLOT(startAutomaticUpdate()));
128 // signals connected, now it's time to show the main window
129 // but init the MapEngine before so starting location is set
133 m_gps->setMode(GPSPosition::Default);
134 initializeGpsAndAutocentering();
136 m_mce = new MCE(this);
137 connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
139 m_contactManager = new ContactManager(this);
140 m_contactManager->requestContactGuids();
142 m_facebookAuthenticator->login();
145 SituareEngine::~SituareEngine()
147 qDebug() << __PRETTY_FUNCTION__;
151 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_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->logOut();
258 m_facebookAuthenticator->login();
260 case SituareError::UPDATE_FAILED:
261 m_ui->toggleProgressIndicator(false);
262 m_ui->buildInformationBox(tr("Update failed, please try again"), true);
264 case SituareError::DATA_RETRIEVAL_FAILED:
265 m_ui->toggleProgressIndicator(false);
266 m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
268 case SituareError::ADDRESS_RETRIEVAL_FAILED:
269 m_ui->toggleProgressIndicator(false);
270 m_ui->buildInformationBox(tr("Address retrieval failed"), true);
272 case SituareError::IMAGE_DOWNLOAD_FAILED:
273 m_ui->buildInformationBox(tr("Image download failed"), true);
275 case SituareError::MAP_IMAGE_DOWNLOAD_FAILED:
276 m_ui->buildInformationBox(tr("Map image download failed"), true);
278 case SituareError::GPS_INITIALIZATION_FAILED:
280 m_ui->buildInformationBox(tr("GPS initialization failed"), true);
282 case SituareError::INVALID_JSON:
283 m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
284 m_ui->loggedIn(false);
285 m_facebookAuthenticator->clearAccountInformation(false); // clean all
287 case SituareError::ERROR_ROUTING_FAILED:
288 m_ui->toggleProgressIndicator(false);
289 m_ui->buildInformationBox(tr("Routing failed"), true);
291 case SituareError::ERROR_LOCATION_SEARCH_FAILED:
292 m_ui->buildInformationBox(tr("No results found"), true);
295 m_ui->toggleProgressIndicator(false);
296 if(context == ErrorContext::NETWORK)
297 qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
299 qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
304 void SituareEngine::imageReady(const QString &id, const QPixmap &image)
306 qDebug() << __PRETTY_FUNCTION__;
309 emit userImageReady(id, image);
311 emit friendImageReady(id, image);
314 void SituareEngine::initializeGpsAndAutocentering()
316 qDebug() << __PRETTY_FUNCTION__;
318 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
319 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
320 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
322 if (m_gps->isInitialized()) {
324 if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
326 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
327 this, SLOT(setFirstStartZoomLevel()));
329 changeAutoCenteringSetting(true);
332 m_ui->buildInformationBox(tr("GPS enabled"));
334 } else { // Normal start
335 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
336 setGPS(gpsEnabled.toBool());
338 if (gpsEnabled.toBool())
339 m_ui->buildInformationBox(tr("GPS enabled"));
346 void SituareEngine::locationSearch(QString location)
348 qDebug() << __PRETTY_FUNCTION__;
350 if(!location.isEmpty())
351 m_geocodingService->requestLocation(location);
354 void SituareEngine::loginActionPressed()
356 qDebug() << __PRETTY_FUNCTION__;
358 if (m_facebookAuthenticator->isLoggedIn())
359 m_facebookAuthenticator->logOut(true);
360 else if (m_networkAccessManager->isConnected())
361 m_facebookAuthenticator->login();
363 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
366 void SituareEngine::onLogin()
368 qDebug() << __PRETTY_FUNCTION__;
370 m_ui->loggedIn(true);
372 m_situareService->fetchLocations();
374 if (m_gps->isRunning())
375 m_ui->readAutomaticLocationUpdateSettings();
378 void SituareEngine::onLogout()
380 qDebug() << __PRETTY_FUNCTION__;
382 m_ui->loggedIn(false);
383 m_situareService->updateSession(""); // empty session string means logged out
384 m_automaticUpdateFirstStart = true;
387 void SituareEngine::refreshUserData()
389 qDebug() << __PRETTY_FUNCTION__;
391 if (m_networkAccessManager->isConnected()) {
392 m_situareService->fetchLocations();
395 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
399 void SituareEngine::requestAddress()
401 qDebug() << __PRETTY_FUNCTION__;
403 if (m_networkAccessManager->isConnected()) {
404 if (m_gps->isRunning())
405 m_situareService->reverseGeo(m_gps->lastPosition());
407 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
410 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
414 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
416 qDebug() << __PRETTY_FUNCTION__;
418 if (m_networkAccessManager->isConnected()) {
420 if (m_gps->isRunning())
421 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
423 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
426 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
430 void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
432 qDebug() << __PRETTY_FUNCTION__;
434 if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
435 USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
436 (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
437 USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
439 m_lastUpdatedGPSPosition = position;
443 if (m_automaticUpdateRequest && m_userMoved) {
444 requestUpdateLocation(tr("Automatic location update"));
445 m_automaticUpdateRequest = false;
450 void SituareEngine::requestInterestingPeople()
452 qDebug() << __PRETTY_FUNCTION__;
454 QRectF currentSceneRect = m_mapEngine->currentViewSceneRect();
455 GeoCoordinate centerGeoCoordinate = m_mapEngine->centerGeoCoordinate();
456 SceneCoordinate topCenterSceneCoordinate(
457 currentSceneRect.left() - currentSceneRect.width() / 2, currentSceneRect.top());
459 m_situareService->fetchPeopleWithSimilarInterest(
460 centerGeoCoordinate.distanceTo(GeoCoordinate(topCenterSceneCoordinate)));
463 void SituareEngine::requestSendMessage(const QString &receiverId, const QString &message,
466 qDebug() << __PRETTY_FUNCTION__;
469 m_situareService->sendMessage(receiverId, message, m_mapEngine->centerGeoCoordinate());
471 m_situareService->sendMessage(receiverId, message);
474 void SituareEngine::routeParsed(Route &route)
476 qDebug() << __PRETTY_FUNCTION__;
481 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
483 qDebug() << __PRETTY_FUNCTION__;
485 if (m_gps->isRunning())
486 m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
488 m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
491 void SituareEngine::routeToCursor()
493 qDebug() << __PRETTY_FUNCTION__;
495 routeTo(m_mapEngine->centerGeoCoordinate());
498 void SituareEngine::searchPeopleByTag(const QString &tag)
500 QRectF currentSceneRect = m_mapEngine->currentViewSceneRect();
501 GeoCoordinate centerGeoCoordinate = m_mapEngine->centerGeoCoordinate();
502 SceneCoordinate topCenterSceneCoordinate(
503 currentSceneRect.left() - currentSceneRect.width() / 2, currentSceneRect.top());
505 m_situareService->searchPeopleByTag(tag, centerGeoCoordinate.distanceTo(GeoCoordinate(topCenterSceneCoordinate)));
508 void SituareEngine::setAutoCentering(bool enabled)
510 qDebug() << __PRETTY_FUNCTION__ << enabled;
512 m_ui->setIndicatorButtonEnabled(enabled);
513 m_mapEngine->setAutoCentering(enabled);
514 m_ui->setCrosshairVisibility(!enabled);
518 m_gps->requestLastPosition();
522 void SituareEngine::setFirstStartZoomLevel()
524 qDebug() << __PRETTY_FUNCTION__;
526 if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
527 m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
529 disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
530 this, SLOT(setFirstStartZoomLevel()));
533 void SituareEngine::setGPS(bool enabled)
535 qDebug() << __PRETTY_FUNCTION__ << enabled;
537 if (m_gps->isInitialized()) {
538 m_ui->setGPSButtonEnabled(enabled);
539 m_mapEngine->setGPSEnabled(enabled);
541 if (enabled && !m_gps->isRunning()) {
543 m_gps->requestLastPosition();
545 if(m_facebookAuthenticator->isLoggedIn())
546 m_ui->readAutomaticLocationUpdateSettings();
548 else if (!enabled && m_gps->isRunning()) {
550 changeAutoCenteringSetting(false);
551 enableAutomaticLocationUpdate(false);
556 m_ui->buildInformationBox(tr("Unable to start GPS"));
557 m_ui->setGPSButtonEnabled(false);
558 m_mapEngine->setGPSEnabled(false);
562 void SituareEngine::setPowerSaving(bool enabled)
564 qDebug() << __PRETTY_FUNCTION__ << enabled;
566 m_gps->enablePowerSave(enabled);
568 if(m_autoCenteringEnabled)
569 m_mapEngine->setAutoCentering(!enabled);
572 void SituareEngine::setProgressIndicatorDisabled()
574 m_ui->toggleProgressIndicator(false);
577 void SituareEngine::setProgressIndicatorEnabled()
579 m_ui->toggleProgressIndicator(true);
582 void SituareEngine::showContactDialog(const QString &facebookId)
584 qDebug() << __PRETTY_FUNCTION__;
586 QString guid = m_contactManager->contactGuid(facebookId);
589 m_ui->showContactDialog(guid);
591 m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
592 "account from Conversations to use this feature."), true);
595 void SituareEngine::showMessageDialog(const QPair<QString, QString> &receiver)
597 qDebug() << __PRETTY_FUNCTION__;
599 m_ui->showMessageDialog(receiver);
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(loggedIn(QString, bool)),
610 m_situareService, SLOT(updateSession(QString)));
612 connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
613 this, SLOT(onLogin()));
615 connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
618 void SituareEngine::signalsFromGeocodingService()
620 qDebug() << __PRETTY_FUNCTION__;
622 connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
623 m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
625 connect(m_geocodingService, SIGNAL(error(int, int)),
626 this, SLOT(error(int, int)));
629 void SituareEngine::signalsFromGPS()
631 qDebug() << __PRETTY_FUNCTION__;
633 connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
634 m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
636 connect(m_gps, SIGNAL(timeout()),
637 m_ui, SLOT(gpsTimeout()));
639 connect(m_gps, SIGNAL(error(int, int)),
640 this, SLOT(error(int, int)));
643 void SituareEngine::signalsFromMainWindow()
645 qDebug() << __PRETTY_FUNCTION__;
647 connect(m_ui, SIGNAL(error(int, int)),
648 this, SLOT(error(int, int)));
650 connect(m_ui, SIGNAL(loginActionPressed()),
651 this, SLOT(loginActionPressed()));
653 // signals from map view
654 connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
655 m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
657 connect(m_ui, SIGNAL(mapViewResized(QSize)),
658 m_mapEngine, SLOT(viewResized(QSize)));
660 connect(m_ui, SIGNAL(viewZoomFinished()),
661 m_mapEngine, SLOT(viewZoomFinished()));
663 // signals from zoom buttons (zoom panel and volume buttons)
664 connect(m_ui, SIGNAL(zoomIn()),
665 m_mapEngine, SLOT(zoomIn()));
667 connect(m_ui, SIGNAL(zoomOut()),
668 m_mapEngine, SLOT(zoomOut()));
670 // signals from menu buttons
671 connect(m_ui, SIGNAL(gpsTriggered(bool)),
672 this, SLOT(setGPS(bool)));
674 connect(m_ui, SIGNAL(requestReverseGeo()),
675 this, SLOT(requestAddress()));
677 connect(m_ui, SIGNAL(locationUpdate(QString,bool)),
678 this, SLOT(setProgressIndicatorEnabled()));
680 connect(m_ui, SIGNAL(locationUpdate(QString,bool)),
681 this, SLOT(requestUpdateLocation(QString,bool)));
683 connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
684 this, SLOT(enableAutomaticLocationUpdate(bool, int)));
686 connect(m_ui, SIGNAL(addTags(QStringList)),
687 this, SLOT(setProgressIndicatorEnabled()));
689 connect(m_ui, SIGNAL(addTags(QStringList)),
690 m_situareService, SLOT(addTags(QStringList)));
692 connect(m_ui, SIGNAL(removeTags(QStringList)),
693 this, SLOT(setProgressIndicatorEnabled()));
695 connect(m_ui, SIGNAL(removeTags(QStringList)),
696 m_situareService, SLOT(removeTags(QStringList)));
698 // signals from user info tab
699 connect(m_ui, SIGNAL(refreshUserData()),
700 this, SLOT(setProgressIndicatorEnabled()));
702 connect(m_ui, SIGNAL(refreshUserData()),
703 this, SLOT(refreshUserData()));
705 connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
706 m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
708 connect(m_ui, SIGNAL(requestPopularTags()),
709 this, SLOT(setProgressIndicatorEnabled()));
711 connect(m_ui, SIGNAL(requestPopularTags()),
712 m_situareService, SLOT(fetchPopularTags()));
714 // routing signal from friend list tab & search location tab
715 connect(m_ui, SIGNAL(routeTo(GeoCoordinate)),
716 this, SLOT(setProgressIndicatorEnabled()));
718 connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
719 this, SLOT(routeTo(const GeoCoordinate&)));
721 connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
722 this, SLOT(showContactDialog(const QString &)));
724 // signals from location search panel
726 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
728 SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
730 connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
731 this, SLOT(locationSearch(QString)));
733 // signals from routing tab
734 connect(m_ui, SIGNAL(clearRoute()),
735 m_mapEngine, SLOT(clearRoute()));
737 connect(m_ui, SIGNAL(routeToCursor()),
738 this, SLOT(routeToCursor()));
740 // signals from distance indicator button
741 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
742 this, SLOT(changeAutoCenteringSetting(bool)));
744 connect(m_ui, SIGNAL(draggingModeTriggered()),
745 this, SLOT(draggingModeTriggered()));
747 // signal from search search dialogs
748 connect(m_ui, SIGNAL(searchForLocation(QString)),
749 this, SLOT(locationSearch(QString)));
751 connect(m_ui, SIGNAL(requestSearchPeopleByTag(QString)),
752 this, SLOT(setProgressIndicatorEnabled()));
754 connect(m_ui, SIGNAL(requestSearchPeopleByTag(QString)),
755 this, SLOT(searchPeopleByTag(QString)));
757 // signals from meet people panel
758 connect(m_ui, SIGNAL(requestInterestingPeople()),
759 this, SLOT(setProgressIndicatorEnabled()));
761 connect(m_ui, SIGNAL(requestInterestingPeople()),
762 this, SLOT(requestInterestingPeople()));
764 connect(m_ui, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
765 this, SLOT(showMessageDialog(QPair<QString, QString>)));
767 connect(m_ui, SIGNAL(sendMessage(QString,QString,bool)),
768 this, SLOT(setProgressIndicatorEnabled()));
770 connect(m_ui, SIGNAL(sendMessage(QString,QString,bool)),
771 this, SLOT(requestSendMessage(QString,QString,bool)));
773 // signals from message panel
774 connect(m_ui, SIGNAL(requestMessages()),
775 this, SLOT(setProgressIndicatorEnabled()));
777 connect(m_ui, SIGNAL(requestMessages()),
778 m_situareService, SLOT(fetchMessages()));
780 connect(m_ui, SIGNAL(requestRemoveMessage(QString)),
781 this, SLOT(setProgressIndicatorEnabled()));
783 connect(m_ui, SIGNAL(requestRemoveMessage(QString)),
784 m_situareService, SLOT(removeMessage(QString)));
787 void SituareEngine::signalsFromMapEngine()
789 qDebug() << __PRETTY_FUNCTION__;
791 connect(m_mapEngine, SIGNAL(error(int, int)),
792 this, SLOT(error(int, int)));
794 connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
795 m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
797 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
798 m_ui, SIGNAL(zoomLevelChanged(int)));
800 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
801 this, SLOT(disableAutoCentering()));
803 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
804 m_ui, SIGNAL(maxZoomLevelReached()));
806 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
807 m_ui, SIGNAL(minZoomLevelReached()));
809 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
810 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
812 connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
813 m_ui, SIGNAL(newMapResolution(qreal)));
815 connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
816 m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
819 void SituareEngine::signalsFromRoutingService()
821 qDebug() << __PRETTY_FUNCTION__;
823 connect(m_routingService, SIGNAL(routeParsed(Route&)),
824 this, SLOT(setProgressIndicatorDisabled()));
826 connect(m_routingService, SIGNAL(routeParsed(Route&)),
827 m_mapEngine, SLOT(setRoute(Route&)));
829 connect(m_routingService, SIGNAL(routeParsed(Route&)),
830 m_ui, SIGNAL(routeParsed(Route&)));
832 connect(m_routingService, SIGNAL(error(int, int)),
833 this, SLOT(error(int, int)));
836 void SituareEngine::signalsFromSituareService()
838 qDebug() << __PRETTY_FUNCTION__;
840 connect(m_situareService, SIGNAL(error(int, int)),
841 this, SLOT(error(int, int)));
843 connect(m_situareService, SIGNAL(imageReady(QString,QPixmap)),
844 this, SLOT(imageReady(QString,QPixmap)));
846 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
847 m_ui, SIGNAL(reverseGeoReady(QString)));
849 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
850 this, SLOT(setProgressIndicatorDisabled()));
852 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
853 this, SLOT(userDataChanged(User*, QList<User*>&)));
855 connect(m_situareService, SIGNAL(userTagsReceived(QHash<QString,QString>&)),
856 m_ui, SIGNAL(userTagsReceived(QHash<QString,QString>&)));
858 connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)),
859 this, SLOT(updateWasSuccessful(SituareService::SuccessfulMethod)));
861 connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
862 m_ui, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)));
864 connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
865 this, SLOT(setProgressIndicatorDisabled()));
867 connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&, QList<Message> &)),
868 this, SLOT(setProgressIndicatorDisabled()));
870 connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&, QList<Message> &)),
871 m_ui, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)));
873 connect(m_situareService, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
874 this, SLOT(setProgressIndicatorDisabled()));
876 connect(m_situareService, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
877 m_ui, SIGNAL(popularTagsReceived(QHash<QString,QString>&)));
880 void SituareEngine::startAutomaticUpdate()
882 qDebug() << __PRETTY_FUNCTION__;
884 m_gps->requestUpdate();
885 m_automaticUpdateRequest = true;
888 void SituareEngine::topmostWindowChanged(bool isMainWindow)
890 qDebug() << __PRETTY_FUNCTION__;
892 setPowerSaving(!isMainWindow);
895 void SituareEngine::updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod)
897 qDebug() << __PRETTY_FUNCTION__;
899 if (m_networkAccessManager->isConnected()) {
900 if (successfulMethod == SituareService::SuccessfulUpdateLocation) {
901 m_situareService->fetchLocations();
902 } else if ((successfulMethod == SituareService::SuccessfulRemoveMessage) ||
903 (successfulMethod == SituareService::SuccessfulSendMessage)) {
904 m_situareService->fetchMessages();
905 } else if ((successfulMethod == SituareService::SuccessfulAddTags) ||
906 (successfulMethod == SituareService::SuccessfulRemoveTags)) {
907 m_situareService->fetchLocations();
910 error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
914 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
916 qDebug() << __PRETTY_FUNCTION__;
918 emit userLocationReady(user);
919 emit friendsLocationsReady(friendsList);
920 m_situareService->getTags();