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 "facebookservice/facebookauthentication.h"
28 #include "gps/gpspositioninterface.h"
31 #include "gps/gpsposition.h"
33 #include "gps/gpspositionmockup.h"
36 #include "map/mapengine.h"
37 #include "situareservice/situareservice.h"
38 #include "ui/mainwindow.h"
42 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
43 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
45 SituareEngine::SituareEngine(QMainWindow *parent)
47 m_autoCenteringEnabled(false)
49 qDebug() << __PRETTY_FUNCTION__;
50 m_ui = new MainWindow;
53 m_mapEngine = new MapEngine(this);
54 m_ui->setMapViewScene(m_mapEngine->scene());
58 m_gps = new GPSPosition(this);
60 m_gps = new GPSPositionMockup(this);
62 m_gps->setMode(GPSPositionInterface::Default);
64 // build SituareService
65 m_situareService = new SituareService(this);
67 // build FacebookAuthenticator
68 m_facebookAuthenticator = new FacebookAuthentication(this);
71 signalsFromMapEngine();
73 signalsFromSituareService();
74 signalsFromMainWindow();
75 signalsFromFacebookAuthenticator();
77 connect(this, SIGNAL(userLocationReady(User*)),
78 m_ui, SIGNAL(userLocationReady(User*)));
80 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
81 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
83 connect(this, SIGNAL(userLocationReady(User*)),
84 m_mapEngine, SLOT(receiveOwnLocation(User*)));
86 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
87 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
89 // signals connected, now it's time to show the main window
90 // but init the MapEngine before so starting location is set
94 QSettings settings(DIRECTORY_NAME, FILE_NAME);
95 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
96 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
98 // set features on / off based on settings
99 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
100 enableGPS(gpsEnabled.toBool());
102 // show messages at startup if features are enabled automatically
103 if (gpsEnabled.toBool())
104 m_ui->showMaemoInformationBox(tr("GPS enabled"));
105 if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
106 m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
108 m_facebookAuthenticator->start();
111 SituareEngine::~SituareEngine()
113 qDebug() << __PRETTY_FUNCTION__;
117 QSettings settings(DIRECTORY_NAME, FILE_NAME);
118 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
119 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
120 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
123 void SituareEngine::changeAutoCenteringSetting(bool enabled)
125 qDebug() << __PRETTY_FUNCTION__;
127 m_autoCenteringEnabled = enabled;
128 enableAutoCentering(enabled);
131 void SituareEngine::disableAutoCentering()
133 qDebug() << __PRETTY_FUNCTION__;
135 changeAutoCenteringSetting(false);
136 m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
139 void SituareEngine::enableAutoCentering(bool enabled)
141 qDebug() << __PRETTY_FUNCTION__;
143 m_ui->setAutoCenteringButtonEnabled(enabled);
144 m_mapEngine->setAutoCentering(enabled);
147 m_gps->requestLastPosition();
150 void SituareEngine::enableGPS(bool enabled)
152 qDebug() << __PRETTY_FUNCTION__;
154 m_ui->setGPSButtonEnabled(enabled);
155 m_mapEngine->setGPSEnabled(enabled);
159 enableAutoCentering(m_autoCenteringEnabled);
160 m_gps->requestLastPosition();
164 enableAutoCentering(false);
168 void SituareEngine::error(const QString &error)
170 qDebug() << __PRETTY_FUNCTION__;
175 void SituareEngine::loginOk()
177 qDebug() << __PRETTY_FUNCTION__;
180 m_situareService->fetchLocations(); // request user locations
183 void SituareEngine::loginProcessCancelled()
185 qDebug() << __PRETTY_FUNCTION__;
187 m_ui->toggleProgressIndicator(false);
191 void SituareEngine::refreshUserData()
193 qDebug() << __PRETTY_FUNCTION__;
195 m_ui->toggleProgressIndicator(true);
197 m_situareService->fetchLocations();
200 void SituareEngine::requestAddress()
202 qDebug() << __PRETTY_FUNCTION__;
204 if (m_gps->isRunning())
205 m_situareService->reverseGeo(m_gps->lastPosition());
207 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
210 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
212 qDebug() << __PRETTY_FUNCTION__;
214 m_ui->toggleProgressIndicator(true);
216 if (m_gps->isRunning())
217 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
219 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
222 void SituareEngine::signalsFromFacebookAuthenticator()
224 qDebug() << __PRETTY_FUNCTION__;
226 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
227 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
229 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
230 this, SLOT(loginOk()));
232 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
233 m_ui, SLOT(startLoginProcess(QUrl)));
235 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
236 m_ui, SLOT(loginFailed()));
239 void SituareEngine::signalsFromGPS()
241 qDebug() << __PRETTY_FUNCTION__;
243 connect(m_gps, SIGNAL(position(QPointF,qreal)),
244 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
246 connect(m_gps, SIGNAL(timeout()),
247 m_ui, SLOT(gpsTimeout()));
249 connect(m_gps, SIGNAL(error(QString)),
250 m_ui, SLOT(gpsError(QString)));
253 void SituareEngine::signalsFromMainWindow()
255 qDebug() << __PRETTY_FUNCTION__;
257 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
258 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
260 // signals from map view
261 connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
262 m_mapEngine, SLOT(setLocation(QPoint)));
264 connect(m_ui, SIGNAL(mapViewResized(QSize)),
265 m_mapEngine, SLOT(viewResized(QSize)));
267 connect(m_ui, SIGNAL(viewZoomFinished()),
268 m_mapEngine, SLOT(viewZoomFinished()));
270 // signals from zoom buttons (zoom panel and volume buttons)
271 connect(m_ui, SIGNAL(zoomIn()),
272 m_mapEngine, SLOT(zoomIn()));
274 connect(m_ui, SIGNAL(zoomOut()),
275 m_mapEngine, SLOT(zoomOut()));
277 // signals from menu buttons
278 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
279 this, SLOT(changeAutoCenteringSetting(bool)));
281 connect(m_ui, SIGNAL(gpsTriggered(bool)),
282 this, SLOT(enableGPS(bool)));
284 //signals from dialogs
285 connect(m_ui, SIGNAL(cancelLoginProcess()),
286 this, SLOT(loginProcessCancelled()));
288 connect(m_ui, SIGNAL(requestReverseGeo()),
289 this, SLOT(requestAddress()));
291 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
292 this, SLOT(requestUpdateLocation(QString,bool)));
294 // signals from user info tab
295 connect(m_ui, SIGNAL(refreshUserData()),
296 this, SLOT(refreshUserData()));
298 // signals from friend list tab
299 connect(m_ui, SIGNAL(findFriend(QPointF)),
300 m_mapEngine, SLOT(setViewLocation(QPointF)));
303 void SituareEngine::signalsFromMapEngine()
305 qDebug() << __PRETTY_FUNCTION__;
307 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
308 m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
310 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
311 m_ui, SIGNAL(zoomLevelChanged(int)));
313 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
314 this, SLOT(disableAutoCentering()));
316 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
317 m_ui, SIGNAL(maxZoomLevelReached()));
319 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
320 m_ui, SIGNAL(minZoomLevelReached()));
323 void SituareEngine::signalsFromSituareService()
325 qDebug() << __PRETTY_FUNCTION__;
327 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
328 m_ui, SIGNAL(reverseGeoReady(QString)));
330 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
331 this, SLOT(userDataChanged(User*, QList<User*>&)));
333 connect(m_situareService, SIGNAL(error(QString)),
334 this, SLOT(error(QString)));
336 connect(m_situareService, SIGNAL(updateWasSuccessful()),
337 this, SLOT(updateWasSuccessful()));
340 void SituareEngine::updateWasSuccessful()
342 qDebug() << __PRETTY_FUNCTION__;
344 m_situareService->fetchLocations();
347 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
349 qDebug() << __PRETTY_FUNCTION__;
351 m_ui->toggleProgressIndicator(false);
353 emit userLocationReady(user);
354 emit friendsLocationsReady(friendsList);