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)
38 qDebug() << __PRETTY_FUNCTION__;
39 m_ui = new MainWindow;
41 m_situareService = new SituareService(this);
43 m_facebookAuthenticator = new FacebookAuthentication(this);
46 m_gps = new GPSPosition(this);
48 m_gps = new GPSPositionMockup(this);
50 m_gps->setMode(GPSPositionInterface::Default);
52 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
53 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
54 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
55 this, SLOT(loginOk()));
56 connect(m_ui, SIGNAL(cancelLoginProcess()),
57 this, SLOT(loginProcessCancelled()));
59 connect(m_ui, SIGNAL(requestReverseGeo()),
60 this, SLOT(requestAddress()));
61 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
62 m_ui, SIGNAL(reverseGeoReady(QString)));
63 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
64 this, SLOT(requestUpdateLocation(QString,bool)));
65 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
66 this, SLOT(userDataChanged(User*,QList<User*>&)));
67 connect(this, SIGNAL(userLocationReady(User*)),
68 m_ui, SIGNAL(userLocationReady(User*)));
69 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
70 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
71 connect(m_situareService, SIGNAL(error(QString)),
72 this, SLOT(error(QString)));
73 connect(m_situareService, SIGNAL(updateWasSuccessful()),
74 this, SLOT(updateWasSuccessful()));
76 connect(m_ui, SIGNAL(refreshUserData()),
77 this, SLOT(refreshUserData()));
79 connect(m_gps, SIGNAL(timeout()),
80 m_ui, SLOT(gpsTimeout()));
81 connect(m_gps, SIGNAL(error(QString)),
82 m_ui, SLOT(gpsError(QString)));
83 connect(m_ui, SIGNAL(enableGPS(bool)),
84 this, SLOT(enableGPS(bool)));
85 connect(m_gps, SIGNAL(position(QPointF, qreal)),
86 m_ui, SIGNAL(positionReceived(QPointF, qreal)));
87 connect(m_ui, SIGNAL(enableAutoCentering(bool)),
88 this, SLOT(enableAutoCentering(bool)));
90 connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
91 m_ui, SLOT(startLoginProcess(QUrl)));
92 connect(m_ui, SIGNAL(updateCredentials(QUrl)),
93 m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
94 connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
95 m_ui, SLOT(loginFailed()));
97 QSettings settings(DIRECTORY_NAME, FILE_NAME);
98 QVariant gpsEnabled = settings.value(GPS_ENABLED);
99 QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
101 enableGPS(gpsEnabled.toBool());
102 enableAutoCentering(autoCenteringEnabled.toBool());
104 m_facebookAuthenticator->start();
107 SituareEngine::~SituareEngine()
109 qDebug() << __PRETTY_FUNCTION__;
114 void SituareEngine::loginProcessCancelled()
116 qDebug() << __PRETTY_FUNCTION__;
118 m_ui->toggleProgressIndicator(false);
122 void SituareEngine::error(const QString &error)
124 qDebug() << __PRETTY_FUNCTION__;
129 void SituareEngine::loginOk()
131 qDebug() << __PRETTY_FUNCTION__;
134 m_situareService->fetchLocations(); // request user locations
137 void SituareEngine::requestAddress()
139 qDebug() << __PRETTY_FUNCTION__;
141 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
142 m_situareService->reverseGeo(coordinates);
145 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
147 qDebug() << __PRETTY_FUNCTION__;
149 m_ui->toggleProgressIndicator(true);
151 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
152 m_situareService->updateLocation(coordinates, status, publish);
155 void SituareEngine::updateWasSuccessful()
157 qDebug() << __PRETTY_FUNCTION__;
159 m_situareService->fetchLocations();
162 void SituareEngine::refreshUserData()
164 qDebug() << __PRETTY_FUNCTION__;
166 m_ui->toggleProgressIndicator(true);
168 m_situareService->fetchLocations();
171 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
173 qDebug() << __PRETTY_FUNCTION__;
175 m_ui->toggleProgressIndicator(false);
177 emit userLocationReady(user);
178 emit friendsLocationsReady(friendsList);
181 void SituareEngine::enableGPS(bool enabled)
183 qDebug() << __PRETTY_FUNCTION__;
186 m_gps->lastPosition();
188 m_ui->setGPSButton(true);
192 m_ui->setGPSButton(false);
196 void SituareEngine::enableAutoCentering(bool enabled)
198 qDebug() << __PRETTY_FUNCTION__;
201 m_ui->setAutoCenteringButton(true);
202 m_ui->autoCenteringEnabled(true);
203 m_gps->lastPosition();
206 m_ui->setAutoCenteringButton(false);
207 m_ui->autoCenteringEnabled(false);