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 "ui/mainwindow.h"
28 #include "gps/gpspositioninterface.h"
29 #include "map/mapengine.h"
30 #include "map/mapview.h"
33 #include "gps/gpsposition.h"
35 #include "gps/gpspositionmockup.h"
38 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
39 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
41 SituareEngine::SituareEngine(QMainWindow *parent)
43 m_autoCenteringEnabled(false),
46 qDebug() << __PRETTY_FUNCTION__;
47 m_ui = new MainWindow;
50 m_mapEngine = new MapEngine(this);
51 m_ui->setMapViewScene(m_mapEngine->scene());
55 m_gps = new GPSPosition(this);
57 m_gps = new GPSPositionMockup(this);
59 m_gps->setMode(GPSPositionInterface::Default);
61 // build SituareService
62 m_situareService = new SituareService(this);
64 // build FacebookAuthenticator
65 m_facebookAuthenticator = new FacebookAuthentication(this);
68 signalsFromMapEngine();
70 signalsFromSituareService();
71 signalsFromMainWindow();
72 signalsFromFacebookAuthenticator();
74 connect(this, SIGNAL(userLocationReady(User*)),
75 m_ui, SIGNAL(userLocationReady(User*)));
77 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
78 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
80 QSettings settings(DIRECTORY_NAME, FILE_NAME);
81 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
82 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
84 // set features on / off based on settings
85 changeAutoCenteringSetting(autoCenteringEnabled.toBool());
86 enableGPS(gpsEnabled.toBool());
88 // show messages at startup if features are enabled automatically
89 if (gpsEnabled.toBool())
90 m_ui->showMaemoInformationBox(tr("GPS enabled"));
91 if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
92 m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
96 m_facebookAuthenticator->start();
99 SituareEngine::~SituareEngine()
101 qDebug() << __PRETTY_FUNCTION__;
105 QSettings settings(DIRECTORY_NAME, FILE_NAME);
106 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
107 settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
108 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
111 void SituareEngine::changeAutoCenteringSetting(bool enabled)
113 m_autoCenteringEnabled = enabled;
114 enableAutoCentering(enabled);
117 void SituareEngine::disableAutoCentering()
119 changeAutoCenteringSetting(false);
120 m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
123 void SituareEngine::enableAutoCentering(bool enabled)
125 qDebug() << __PRETTY_FUNCTION__;
127 m_ui->setAutoCenteringButtonEnabled(enabled);
128 m_mapEngine->setAutoCentering(enabled);
131 m_gps->requestLastPosition();
134 void SituareEngine::enableGPS(bool enabled)
136 qDebug() << __PRETTY_FUNCTION__;
138 m_ui->setGPSButtonEnabled(enabled);
139 m_mapEngine->setGPSEnabled(enabled);
143 enableAutoCentering(m_autoCenteringEnabled);
144 m_gps->requestLastPosition();
148 enableAutoCentering(false);
152 void SituareEngine::error(const QString &error)
154 qDebug() << __PRETTY_FUNCTION__;
159 void SituareEngine::loginOk()
161 qDebug() << __PRETTY_FUNCTION__;
164 m_situareService->fetchLocations(); // request user locations
167 void SituareEngine::loginProcessCancelled()
169 qDebug() << __PRETTY_FUNCTION__;
171 m_ui->toggleProgressIndicator(false);
175 void SituareEngine::refreshUserData()
177 qDebug() << __PRETTY_FUNCTION__;
179 m_ui->toggleProgressIndicator(true);
181 m_situareService->fetchLocations();
184 void SituareEngine::requestAddress()
186 qDebug() << __PRETTY_FUNCTION__;
188 if (m_gps->isRunning()) {
189 m_latestLocation = m_gps->lastPosition();
190 m_situareService->reverseGeo(m_latestLocation);
193 m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
197 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
199 qDebug() << __PRETTY_FUNCTION__;
201 m_ui->toggleProgressIndicator(true);
203 if (m_gps->isRunning()) {
204 m_latestLocation = m_gps->lastPosition();
205 m_situareService->updateLocation(m_latestLocation, status, publish);
208 m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
212 void SituareEngine::signalsFromFacebookAuthenticator()
214 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
215 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
217 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
218 this, SLOT(loginOk()));
220 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
221 m_ui, SLOT(startLoginProcess(QUrl)));
223 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
224 m_ui, SLOT(loginFailed()));
227 void SituareEngine::signalsFromGPS()
229 connect(m_gps, SIGNAL(position(QPointF,qreal)),
230 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
232 connect(m_gps, SIGNAL(timeout()),
233 m_ui, SLOT(gpsTimeout()));
235 connect(m_gps, SIGNAL(error(QString)),
236 m_ui, SLOT(gpsError(QString)));
239 void SituareEngine::signalsFromMainWindow()
241 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
242 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
244 // signals from map view
245 connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
246 m_mapEngine, SLOT(setLocation(QPoint)));
248 connect(m_ui, SIGNAL(mapViewResized(QSize)),
249 m_mapEngine, SLOT(viewResized(QSize)));
251 connect(m_ui, SIGNAL(viewZoomFinished()),
252 m_mapEngine, SLOT(viewZoomFinished()));
254 // signals from zoom buttons (zoom panel and volume buttons)
255 connect(m_ui, SIGNAL(zoomIn()),
256 m_mapEngine, SLOT(zoomIn()));
258 connect(m_ui, SIGNAL(zoomOut()),
259 m_mapEngine, SLOT(zoomOut()));
261 // signals from menu buttons
262 connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
263 this, SLOT(changeAutoCenteringSetting(bool)));
265 connect(m_ui, SIGNAL(gpsTriggered(bool)),
266 this, SLOT(enableGPS(bool)));
268 //signals from dialogs
269 connect(m_ui, SIGNAL(cancelLoginProcess()),
270 this, SLOT(loginProcessCancelled()));
272 connect(m_ui, SIGNAL(requestReverseGeo()),
273 this, SLOT(requestAddress()));
275 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
276 this, SLOT(requestUpdateLocation(QString,bool)));
278 // signals from user info tab
279 connect(m_ui, SIGNAL(refreshUserData()),
280 this, SLOT(refreshUserData()));
282 // signals from friend list tab
283 connect(m_ui, SIGNAL(findFriend(QPointF)),
284 m_mapEngine, SLOT(setViewLocation(QPointF)));
287 void SituareEngine::signalsFromMapEngine()
289 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
290 m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
292 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
293 m_ui, SIGNAL(zoomLevelChanged(int)));
295 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
296 this, SLOT(disableAutoCentering()));
298 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
299 m_ui, SIGNAL(maxZoomLevelReached()));
301 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
302 m_ui, SIGNAL(minZoomLevelReached()));
305 void SituareEngine::signalsFromSituareService()
307 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
308 m_ui, SIGNAL(reverseGeoReady(QString)));
310 connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
311 this, SLOT(userDataChanged(User*, QList<User*>&)));
313 connect(m_situareService, SIGNAL(error(QString)),
314 this, SLOT(error(QString)));
316 connect(m_situareService, SIGNAL(updateWasSuccessful()),
317 this, SLOT(updateWasSuccessful()));
319 connect(this, SIGNAL(userLocationReady(User*)),
320 m_mapEngine, SLOT(receiveOwnLocation(User*)));
322 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
323 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
326 void SituareEngine::updateWasSuccessful()
328 qDebug() << __PRETTY_FUNCTION__;
330 m_situareService->fetchLocations();
333 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
335 qDebug() << __PRETTY_FUNCTION__;
337 m_ui->toggleProgressIndicator(false);
339 emit userLocationReady(user);
340 emit friendsLocationsReady(friendsList);