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"
32 #include "networkhandler.h"
36 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
37 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
39 SituareEngine::SituareEngine(QMainWindow *parent)
41 m_autoCenteringEnabled(false)
43 qDebug() << __PRETTY_FUNCTION__;
44 m_ui = new MainWindow;
46 // build NetworkHandler
47 m_networkHandler = new NetworkHandler(this);
50 m_mapEngine = new MapEngine(this);
51 m_ui->setMapViewScene(m_mapEngine->scene());
54 m_gps = new GPSPosition(this);
55 m_gps->setMode(GPSPosition::Default);
57 // build SituareService
58 m_situareService = new SituareService(this);
60 // build FacebookAuthenticator
61 m_facebookAuthenticator = new FacebookAuthentication(this);
64 signalsFromNetworkHandler();
65 signalsFromMapEngine();
67 signalsFromSituareService();
68 signalsFromMainWindow();
69 signalsFromFacebookAuthenticator();
71 connect(this, SIGNAL(userLocationReady(User*)),
72 m_ui, SIGNAL(userLocationReady(User*)));
74 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
75 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
77 connect(this, SIGNAL(userLocationReady(User*)),
78 m_mapEngine, SLOT(receiveOwnLocation(User*)));
80 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
81 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
83 // signals connected, now it's time to show the main window
84 // but init the MapEngine before so starting location is set
88 QSettings settings(DIRECTORY_NAME, FILE_NAME);
89 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
90 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
92 // set features on / off based on settings
93 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
94 enableGPS(gpsEnabled.toBool());
96 // show messages at startup if features are enabled automatically
97 if (gpsEnabled.toBool())
98 m_ui->showMaemoInformationBox(tr("GPS enabled"));
99 if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
100 m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
102 //Request network connection.
103 // m_networkHandler->connect();
104 m_facebookAuthenticator->start();
107 SituareEngine::~SituareEngine()
109 qDebug() << __PRETTY_FUNCTION__;
113 QSettings settings(DIRECTORY_NAME, FILE_NAME);
114 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
115 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
116 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
119 void SituareEngine::changeAutoCenteringSetting(bool enabled)
121 qDebug() << __PRETTY_FUNCTION__;
123 m_autoCenteringEnabled = enabled;
124 enableAutoCentering(enabled);
127 void SituareEngine::connectedToNetwork()
129 qDebug() << __PRETTY_FUNCTION__;
131 m_facebookAuthenticator->start();
132 //TODO: Start map image fetching
135 void SituareEngine::disableAutoCentering()
137 qDebug() << __PRETTY_FUNCTION__;
139 changeAutoCenteringSetting(false);
140 m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
143 void SituareEngine::disconnectedFromNetwork()
145 qDebug() << __PRETTY_FUNCTION__;
146 //TODO: Stop map image fetching
149 void SituareEngine::enableAutoCentering(bool enabled)
151 qDebug() << __PRETTY_FUNCTION__;
153 m_ui->setAutoCenteringButtonEnabled(enabled);
154 m_mapEngine->setAutoCentering(enabled);
157 m_gps->requestLastPosition();
160 void SituareEngine::enableGPS(bool enabled)
162 qDebug() << __PRETTY_FUNCTION__;
164 m_ui->setGPSButtonEnabled(enabled);
165 m_mapEngine->setGPSEnabled(enabled);
169 enableAutoCentering(m_autoCenteringEnabled);
170 m_gps->requestLastPosition();
174 enableAutoCentering(false);
178 void SituareEngine::error(const QString &error)
180 qDebug() << __PRETTY_FUNCTION__;
185 void SituareEngine::fetchUsernameFromSettings()
187 qDebug() << __PRETTY_FUNCTION__;
188 m_ui->setUsername(m_facebookAuthenticator->loadUsername());
191 void SituareEngine::loginOk(bool freshLogin)
193 qDebug() << __PRETTY_FUNCTION__;
196 m_facebookAuthenticator->saveUsername(m_ui->username());
199 m_situareService->fetchLocations(); // request user locations
202 void SituareEngine::loginProcessCancelled()
204 qDebug() << __PRETTY_FUNCTION__;
206 m_ui->toggleProgressIndicator(false);
210 void SituareEngine::refreshUserData()
212 qDebug() << __PRETTY_FUNCTION__;
214 m_ui->toggleProgressIndicator(true);
216 m_situareService->fetchLocations();
219 void SituareEngine::requestAddress()
221 qDebug() << __PRETTY_FUNCTION__;
223 if (m_gps->isRunning())
224 m_situareService->reverseGeo(m_gps->lastPosition());
226 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
229 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
231 qDebug() << __PRETTY_FUNCTION__;
233 m_ui->toggleProgressIndicator(true);
235 if (m_gps->isRunning())
236 m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
238 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
241 void SituareEngine::signalsFromFacebookAuthenticator()
243 qDebug() << __PRETTY_FUNCTION__;
245 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
246 m_situareService, SLOT(credentialsReady(bool, FacebookCredentials)));
248 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
249 this, SLOT(loginOk(bool)));
251 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
252 m_ui, SLOT(startLoginProcess(QUrl)));
254 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
255 m_ui, SLOT(loginFailed()));
258 void SituareEngine::signalsFromGPS()
260 qDebug() << __PRETTY_FUNCTION__;
262 connect(m_gps, SIGNAL(position(QPointF,qreal)),
263 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
265 connect(m_gps, SIGNAL(timeout()),
266 m_ui, SLOT(gpsTimeout()));
268 connect(m_gps, SIGNAL(error(QString)),
269 m_ui, SLOT(gpsError(QString)));
272 void SituareEngine::signalsFromMainWindow()
274 qDebug() << __PRETTY_FUNCTION__;
276 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
277 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
279 connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
280 this, SLOT(fetchUsernameFromSettings()));
282 // signals from map view
283 connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
284 m_mapEngine, SLOT(setLocation(QPoint)));
286 connect(m_ui, SIGNAL(mapViewResized(QSize)),
287 m_mapEngine, SLOT(viewResized(QSize)));
289 connect(m_ui, SIGNAL(viewZoomFinished()),
290 m_mapEngine, SLOT(viewZoomFinished()));
292 // signals from zoom buttons (zoom panel and volume buttons)
293 connect(m_ui, SIGNAL(zoomIn()),
294 m_mapEngine, SLOT(zoomIn()));
296 connect(m_ui, SIGNAL(zoomOut()),
297 m_mapEngine, SLOT(zoomOut()));
299 // signals from menu buttons
300 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
301 this, SLOT(changeAutoCenteringSetting(bool)));
303 connect(m_ui, SIGNAL(gpsTriggered(bool)),
304 this, SLOT(enableGPS(bool)));
306 //signals from dialogs
307 connect(m_ui, SIGNAL(cancelLoginProcess()),
308 this, SLOT(loginProcessCancelled()));
310 connect(m_ui, SIGNAL(requestReverseGeo()),
311 this, SLOT(requestAddress()));
313 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
314 this, SLOT(requestUpdateLocation(QString,bool)));
316 // signals from user info tab
317 connect(m_ui, SIGNAL(refreshUserData()),
318 this, SLOT(refreshUserData()));
320 // signals from friend list tab
321 connect(m_ui, SIGNAL(findFriend(QPointF)),
322 m_mapEngine, SLOT(setViewLocation(QPointF)));
325 void SituareEngine::signalsFromMapEngine()
327 qDebug() << __PRETTY_FUNCTION__;
329 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
330 m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
332 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
333 m_ui, SIGNAL(zoomLevelChanged(int)));
335 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
336 this, SLOT(disableAutoCentering()));
338 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
339 m_ui, SIGNAL(maxZoomLevelReached()));
341 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
342 m_ui, SIGNAL(minZoomLevelReached()));
344 connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
345 m_ui, SIGNAL(locationItemClicked(QList<QString>)));
348 void SituareEngine::signalsFromNetworkHandler()
350 qDebug() << __PRETTY_FUNCTION__;
352 connect(m_networkHandler, SIGNAL(connected()),
353 this, SLOT(connectedToNetwork()));
355 connect(m_networkHandler, SIGNAL(disconnected()),
356 this, SLOT(disconnectedFromNetwork()));
359 void SituareEngine::signalsFromSituareService()
361 qDebug() << __PRETTY_FUNCTION__;
363 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
364 m_ui, SIGNAL(reverseGeoReady(QString)));
366 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
367 this, SLOT(userDataChanged(User*, QList<User*>&)));
369 connect(m_situareService, SIGNAL(error(QString)),
370 this, SLOT(error(QString)));
372 connect(m_situareService, SIGNAL(updateWasSuccessful()),
373 this, SLOT(updateWasSuccessful()));
376 void SituareEngine::updateWasSuccessful()
378 qDebug() << __PRETTY_FUNCTION__;
380 m_situareService->fetchLocations();
383 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
385 qDebug() << __PRETTY_FUNCTION__;
387 m_ui->toggleProgressIndicator(false);
389 emit userLocationReady(user);
390 emit friendsLocationsReady(friendsList);