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,
24 #include "situarecommon.h"
26 #include "ui/mainwindow.h"
27 #include "gps/gpspositioninterface.h"
30 #include "gps/gpsposition.h"
32 #include "gps/gpspositionmockup.h"
35 SituareEngine::SituareEngine(QMainWindow *parent)
37 m_autoCenteringEnabled(false),
40 qDebug() << __PRETTY_FUNCTION__;
41 m_ui = new MainWindow;
43 m_situareService = new SituareService(this);
45 m_facebookAuthenticator = new FacebookAuthentication(this);
48 m_gps = new GPSPosition(this);
50 m_gps = new GPSPositionMockup(this);
52 m_gps->setMode(GPSPositionInterface::Default);
54 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
55 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
56 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
57 this, SLOT(loginOk()));
58 connect(m_ui, SIGNAL(cancelLoginProcess()),
59 this, SLOT(loginProcessCancelled()));
61 connect(m_ui, SIGNAL(requestReverseGeo()),
62 this, SLOT(requestAddress()));
63 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
64 m_ui, SIGNAL(reverseGeoReady(QString)));
65 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
66 this, SLOT(requestUpdateLocation(QString,bool)));
67 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
68 this, SLOT(userDataChanged(User*,QList<User*>&)));
69 connect(this, SIGNAL(userLocationReady(User*)),
70 m_ui, SIGNAL(userLocationReady(User*)));
71 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
72 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
73 connect(m_situareService, SIGNAL(error(QString)),
74 this, SLOT(error(QString)));
75 connect(m_situareService, SIGNAL(updateWasSuccessful()),
76 this, SLOT(updateWasSuccessful()));
78 connect(m_ui, SIGNAL(refreshUserData()),
79 this, SLOT(refreshUserData()));
81 connect(m_gps, SIGNAL(timeout()),
82 m_ui, SLOT(gpsTimeout()));
83 connect(m_gps, SIGNAL(error(QString)),
84 m_ui, SLOT(gpsError(QString)));
85 connect(m_ui, SIGNAL(enableGPS(bool)),
86 this, SLOT(enableGPS(bool)));
87 connect(m_gps, SIGNAL(position(QPointF, qreal)),
88 m_ui, SIGNAL(positionReceived(QPointF, qreal)));
89 connect(m_ui, SIGNAL(enableAutoCentering(bool)),
90 this, SLOT(enableAutoCentering(bool)));
92 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
93 m_ui, SLOT(startLoginProcess(QUrl)));
94 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
95 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
96 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
97 m_ui, SLOT(loginFailed()));
99 QSettings settings(DIRECTORY_NAME, FILE_NAME);
100 QVariant gpsEnabled = settings.value(GPS_ENABLED);
101 QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
103 enableGPS(gpsEnabled.toBool());
104 enableAutoCentering(autoCenteringEnabled.toBool());
106 m_facebookAuthenticator->start();
109 SituareEngine::~SituareEngine()
111 qDebug() << __PRETTY_FUNCTION__;
115 QSettings settings(DIRECTORY_NAME, FILE_NAME);
116 qDebug() << __PRETTY_FUNCTION__ << m_gpsEnabled;
117 qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
118 settings.setValue(GPS_ENABLED, m_gpsEnabled);
119 settings.setValue(AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
122 void SituareEngine::loginProcessCancelled()
124 qDebug() << __PRETTY_FUNCTION__;
126 m_ui->toggleProgressIndicator(false);
130 void SituareEngine::error(const QString &error)
132 qDebug() << __PRETTY_FUNCTION__;
137 void SituareEngine::loginOk()
139 qDebug() << __PRETTY_FUNCTION__;
142 m_situareService->fetchLocations(); // request user locations
145 void SituareEngine::requestAddress()
147 qDebug() << __PRETTY_FUNCTION__;
149 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
150 m_situareService->reverseGeo(coordinates);
153 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
155 qDebug() << __PRETTY_FUNCTION__;
157 m_ui->toggleProgressIndicator(true);
159 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
160 m_situareService->updateLocation(coordinates, status, publish);
163 void SituareEngine::updateWasSuccessful()
165 qDebug() << __PRETTY_FUNCTION__;
167 m_situareService->fetchLocations();
170 void SituareEngine::refreshUserData()
172 qDebug() << __PRETTY_FUNCTION__;
174 m_ui->toggleProgressIndicator(true);
176 m_situareService->fetchLocations();
179 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
181 qDebug() << __PRETTY_FUNCTION__;
183 m_ui->toggleProgressIndicator(false);
185 emit userLocationReady(user);
186 emit friendsLocationsReady(friendsList);
189 void SituareEngine::enableGPS(bool enabled)
191 qDebug() << __PRETTY_FUNCTION__;
193 m_gpsEnabled = enabled;
196 m_gps->lastPosition();
198 m_ui->setGPSButton(true);
202 m_ui->setGPSButton(false);
206 void SituareEngine::enableAutoCentering(bool enabled)
208 qDebug() << __PRETTY_FUNCTION__;
210 m_autoCenteringEnabled = enabled;
213 m_ui->setAutoCenteringButton(true);
214 m_ui->autoCenteringEnabled(true);
215 m_gps->lastPosition();
218 m_ui->setAutoCenteringButton(false);
219 m_ui->autoCenteringEnabled(false);