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/gpsposition.h"
29 #include "map/mapengine.h"
30 #include "situareservice/situareservice.h"
31 #include "ui/mainwindow.h"
35 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
36 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
38 SituareEngine::SituareEngine(QMainWindow *parent)
40 m_autoCenteringEnabled(false),
43 qDebug() << __PRETTY_FUNCTION__;
44 m_ui = new MainWindow;
45 m_ui->showPanels(m_loggedIn);
48 m_mapEngine = new MapEngine(this);
49 m_ui->setMapViewScene(m_mapEngine->scene());
52 m_gps = new GPSPosition(this);
53 m_gps->setMode(GPSPosition::Default);
55 // build SituareService
56 m_situareService = new SituareService(this);
58 // build FacebookAuthenticator
59 m_facebookAuthenticator = new FacebookAuthentication(this);
62 signalsFromMapEngine();
64 signalsFromSituareService();
65 signalsFromMainWindow();
66 signalsFromFacebookAuthenticator();
68 connect(this, SIGNAL(userLocationReady(User*)),
69 m_ui, SIGNAL(userLocationReady(User*)));
71 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
72 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
74 connect(this, SIGNAL(userLocationReady(User*)),
75 m_mapEngine, SLOT(receiveOwnLocation(User*)));
77 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
78 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
80 // signals connected, now it's time to show the main window
81 // but init the MapEngine before so starting location is set
85 QSettings settings(DIRECTORY_NAME, FILE_NAME);
86 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
87 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
89 // set features on / off based on settings
90 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
91 enableGPS(gpsEnabled.toBool());
93 // show messages at startup if features are enabled automatically
94 if (gpsEnabled.toBool())
95 m_ui->showMaemoInformationBox(tr("GPS enabled"));
96 if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
97 m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
99 m_facebookAuthenticator->start();
102 SituareEngine::~SituareEngine()
104 qDebug() << __PRETTY_FUNCTION__;
108 QSettings settings(DIRECTORY_NAME, FILE_NAME);
109 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
110 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
111 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
114 void SituareEngine::changeAutoCenteringSetting(bool enabled)
116 qDebug() << __PRETTY_FUNCTION__;
118 m_autoCenteringEnabled = enabled;
119 enableAutoCentering(enabled);
122 void SituareEngine::disableAutoCentering()
124 qDebug() << __PRETTY_FUNCTION__;
126 changeAutoCenteringSetting(false);
127 m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
130 void SituareEngine::enableAutoCentering(bool enabled)
132 qDebug() << __PRETTY_FUNCTION__;
134 m_ui->setAutoCenteringButtonEnabled(enabled);
135 m_mapEngine->setAutoCentering(enabled);
138 m_gps->requestLastPosition();
141 void SituareEngine::enableGPS(bool enabled)
143 qDebug() << __PRETTY_FUNCTION__;
145 m_ui->setGPSButtonEnabled(enabled);
146 m_mapEngine->setGPSEnabled(enabled);
150 enableAutoCentering(m_autoCenteringEnabled);
151 m_gps->requestLastPosition();
155 enableAutoCentering(false);
159 void SituareEngine::error(const QString &error)
161 qDebug() << __PRETTY_FUNCTION__;
166 void SituareEngine::fetchUsernameFromSettings()
168 qDebug() << __PRETTY_FUNCTION__;
169 m_ui->setUsername(m_facebookAuthenticator->loadUsername());
172 void SituareEngine::invalidCredentials()
174 qDebug() << __PRETTY_FUNCTION__;
176 m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
177 //m_facebookAuthenticator->start();
178 m_ui->loginUsingCookies();
181 void SituareEngine::loginActionPressed()
183 qDebug() << __PRETTY_FUNCTION__;
187 m_situareService->clearUserData();
190 m_facebookAuthenticator->start();
194 void SituareEngine::loginOk(bool freshLogin, const FacebookCredentials &credentials)
196 qDebug() << __PRETTY_FUNCTION__;
199 m_ui->loggedIn(m_loggedIn);
202 m_facebookAuthenticator->saveUsername(m_ui->username());
205 m_situareService->credentialsReady(credentials);
206 m_situareService->fetchLocations(); // request user locations
209 void SituareEngine::loginProcessCancelled()
211 qDebug() << __PRETTY_FUNCTION__;
213 m_ui->toggleProgressIndicator(false);
214 m_ui->showPanels(m_loggedIn);
217 void SituareEngine::logout()
219 qDebug() << __PRETTY_FUNCTION__;
222 m_ui->loggedIn(m_loggedIn);
223 m_facebookAuthenticator->clearAccountInformation();
226 void SituareEngine::refreshUserData()
228 qDebug() << __PRETTY_FUNCTION__;
230 m_ui->toggleProgressIndicator(true);
232 m_situareService->fetchLocations();
235 void SituareEngine::requestAddress()
237 qDebug() << __PRETTY_FUNCTION__;
239 if (m_gps->isRunning())
240 m_situareService->reverseGeo(m_gps->lastPosition());
242 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
245 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
247 qDebug() << __PRETTY_FUNCTION__;
249 m_ui->toggleProgressIndicator(true);
251 if (m_gps->isRunning())
252 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
254 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
257 void SituareEngine::signalsFromFacebookAuthenticator()
259 qDebug() << __PRETTY_FUNCTION__;
261 connect(m_facebookAuthenticator, SIGNAL(credentialsChanged(FacebookCredentials)),
262 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
264 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
265 this, SLOT(loginOk(bool, FacebookCredentials)));
267 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
268 m_ui, SLOT(startLoginProcess(QUrl)));
270 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
271 m_ui, SLOT(loginFailed()));
273 connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
274 m_ui, SLOT(saveCookies()));
276 connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
277 m_ui, SLOT(loginUsingCookies()));
280 void SituareEngine::signalsFromGPS()
282 qDebug() << __PRETTY_FUNCTION__;
284 connect(m_gps, SIGNAL(position(QPointF,qreal)),
285 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
287 connect(m_gps, SIGNAL(timeout()),
288 m_ui, SLOT(gpsTimeout()));
290 connect(m_gps, SIGNAL(error(QString)),
291 m_ui, SLOT(gpsError(QString)));
294 void SituareEngine::signalsFromMainWindow()
296 qDebug() << __PRETTY_FUNCTION__;
298 connect(m_ui, SIGNAL(loginActionPressed()),
299 this, SLOT(loginActionPressed()));
301 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
302 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
304 connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
305 this, SLOT(fetchUsernameFromSettings()));
307 // signals from map view
308 connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
309 m_mapEngine, SLOT(setLocation(QPoint)));
311 connect(m_ui, SIGNAL(mapViewResized(QSize)),
312 m_mapEngine, SLOT(viewResized(QSize)));
314 connect(m_ui, SIGNAL(viewZoomFinished()),
315 m_mapEngine, SLOT(viewZoomFinished()));
317 // signals from zoom buttons (zoom panel and volume buttons)
318 connect(m_ui, SIGNAL(zoomIn()),
319 m_mapEngine, SLOT(zoomIn()));
321 connect(m_ui, SIGNAL(zoomOut()),
322 m_mapEngine, SLOT(zoomOut()));
324 // signals from menu buttons
325 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
326 this, SLOT(changeAutoCenteringSetting(bool)));
328 connect(m_ui, SIGNAL(gpsTriggered(bool)),
329 this, SLOT(enableGPS(bool)));
331 //signals from dialogs
332 connect(m_ui, SIGNAL(cancelLoginProcess()),
333 this, SLOT(loginProcessCancelled()));
335 connect(m_ui, SIGNAL(requestReverseGeo()),
336 this, SLOT(requestAddress()));
338 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
339 this, SLOT(requestUpdateLocation(QString,bool)));
341 // signals from user info tab
342 connect(m_ui, SIGNAL(refreshUserData()),
343 this, SLOT(refreshUserData()));
345 // signals from friend list tab
346 connect(m_ui, SIGNAL(findFriend(QPointF)),
347 m_mapEngine, SLOT(setViewLocation(QPointF)));
350 void SituareEngine::signalsFromMapEngine()
352 qDebug() << __PRETTY_FUNCTION__;
354 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
355 m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
357 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
358 m_ui, SIGNAL(zoomLevelChanged(int)));
360 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
361 this, SLOT(disableAutoCentering()));
363 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
364 m_ui, SIGNAL(maxZoomLevelReached()));
366 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
367 m_ui, SIGNAL(minZoomLevelReached()));
369 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
370 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
373 void SituareEngine::signalsFromSituareService()
375 qDebug() << __PRETTY_FUNCTION__;
377 connect(m_situareService, SIGNAL(error(QString)),
378 this, SLOT(error(QString)));
380 connect(m_situareService, SIGNAL(invalidSessionCredentials()),
381 this, SLOT(invalidCredentials()));
383 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
384 m_ui, SIGNAL(reverseGeoReady(QString)));
386 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
387 this, SLOT(userDataChanged(User*, QList<User*>&)));
389 connect(m_situareService, SIGNAL(updateWasSuccessful()),
390 this, SLOT(updateWasSuccessful()));
393 void SituareEngine::updateWasSuccessful()
395 qDebug() << __PRETTY_FUNCTION__;
397 m_situareService->fetchLocations();
400 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
402 qDebug() << __PRETTY_FUNCTION__;
404 m_ui->toggleProgressIndicator(false);
406 emit userLocationReady(user);
407 emit friendsLocationsReady(friendsList);