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
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "situarecommon.h"
26 #include "ui/mainwindow.h"
27 #include "gps/gpspositioninterface.h"
30 #include "gps/gpsposition.h"
32 #include "gps/gpspositionmockup.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;
46 m_situareService = new SituareService(this);
48 m_facebookAuthenticator = new FacebookAuthentication(this);
51 m_gps = new GPSPosition(this);
53 m_gps = new GPSPositionMockup(this);
55 m_gps->setMode(GPSPositionInterface::Default);
57 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
58 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
59 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
60 this, SLOT(loginOk()));
61 connect(m_ui, SIGNAL(cancelLoginProcess()),
62 this, SLOT(loginProcessCancelled()));
64 connect(m_ui, SIGNAL(requestReverseGeo()),
65 this, SLOT(requestAddress()));
66 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
67 m_ui, SIGNAL(reverseGeoReady(QString)));
68 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
69 this, SLOT(requestUpdateLocation(QString,bool)));
70 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
71 this, SLOT(userDataChanged(User*,QList<User*>&)));
72 connect(this, SIGNAL(userLocationReady(User*)),
73 m_ui, SIGNAL(userLocationReady(User*)));
74 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
75 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
76 connect(m_situareService, SIGNAL(error(QString)),
77 this, SLOT(error(QString)));
78 connect(m_situareService, SIGNAL(updateWasSuccessful()),
79 this, SLOT(updateWasSuccessful()));
81 connect(m_ui, SIGNAL(refreshUserData()),
82 this, SLOT(refreshUserData()));
84 connect(m_gps, SIGNAL(timeout()),
85 m_ui, SLOT(gpsTimeout()));
86 connect(m_gps, SIGNAL(error(QString)),
87 m_ui, SLOT(gpsError(QString)));
88 connect(m_ui, SIGNAL(enableGPS(bool)),
89 this, SLOT(enableGPS(bool)));
90 connect(m_gps, SIGNAL(position(QPointF, qreal)),
91 m_ui, SIGNAL(positionReceived(QPointF, qreal)));
92 connect(m_ui, SIGNAL(enableAutoCentering(bool)),
93 this, SLOT(enableAutoCentering(bool)));
95 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
96 m_ui, SLOT(startLoginProcess(QUrl)));
97 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
98 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
99 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
100 m_ui, SLOT(loginFailed()));
102 QSettings settings(DIRECTORY_NAME, FILE_NAME);
103 QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
104 QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
106 enableGPS(gpsEnabled.toBool());
107 enableAutoCentering(autoCenteringEnabled.toBool());
109 m_facebookAuthenticator->start();
112 SituareEngine::~SituareEngine()
114 qDebug() << __PRETTY_FUNCTION__;
118 QSettings settings(DIRECTORY_NAME, FILE_NAME);
119 qDebug() << __PRETTY_FUNCTION__ << m_gpsEnabled;
120 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
121 settings.setValue(SETTINGS_GPS_ENABLED, m_gpsEnabled);
122 settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
125 void SituareEngine::loginProcessCancelled()
127 qDebug() << __PRETTY_FUNCTION__;
129 m_ui->toggleProgressIndicator(false);
133 void SituareEngine::error(const QString &error)
135 qDebug() << __PRETTY_FUNCTION__;
140 void SituareEngine::loginOk()
142 qDebug() << __PRETTY_FUNCTION__;
145 m_situareService->fetchLocations(); // request user locations
148 void SituareEngine::requestAddress()
150 qDebug() << __PRETTY_FUNCTION__;
155 coordinates = m_gps->lastPosition();
157 coordinates = QPointF(0, 0); //Manual position from map
159 m_situareService->reverseGeo(coordinates);
162 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
164 qDebug() << __PRETTY_FUNCTION__;
166 m_ui->toggleProgressIndicator(true);
171 coordinates = m_gps->lastPosition();
173 coordinates = QPointF(0, 0); //Manual position from map
175 m_situareService->updateLocation(coordinates, status, publish);
178 void SituareEngine::updateWasSuccessful()
180 qDebug() << __PRETTY_FUNCTION__;
182 m_situareService->fetchLocations();
185 void SituareEngine::refreshUserData()
187 qDebug() << __PRETTY_FUNCTION__;
189 m_ui->toggleProgressIndicator(true);
191 m_situareService->fetchLocations();
194 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
196 qDebug() << __PRETTY_FUNCTION__;
198 m_ui->toggleProgressIndicator(false);
200 emit userLocationReady(user);
201 emit friendsLocationsReady(friendsList);
204 void SituareEngine::enableGPS(bool enabled)
206 qDebug() << __PRETTY_FUNCTION__;
208 m_gpsEnabled = enabled;
211 m_gps->requestLastPosition();
213 m_ui->setGPSButton(true);
217 m_ui->setGPSButton(false);
221 void SituareEngine::enableAutoCentering(bool enabled)
223 qDebug() << __PRETTY_FUNCTION__;
225 m_autoCenteringEnabled = enabled;
228 m_ui->setAutoCenteringButton(true);
229 m_ui->autoCenteringEnabled(true);
230 m_gps->requestLastPosition();
233 m_ui->setAutoCenteringButton(false);
234 m_ui->autoCenteringEnabled(false);