Kaj Wallin - kaj.wallin@ixonos.com
Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
USA.
*/
+#include "situarecommon.h"
#include "engine.h"
#include "ui/mainwindow.h"
+#include "gps/gpspositioninterface.h"
+
+#ifdef Q_WS_MAEMO_5
+#include "gps/gpsposition.h"
+#else
+#include "gps/gpspositionmockup.h"
+#endif
SituareEngine::SituareEngine(QMainWindow *parent)
: QObject(parent)
{
+ qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
- m_networkManager = new QNetworkAccessManager;
- m_situareService = new SituareService(this,m_networkManager);
-
- m_loggedIn = false;
- m_facebookAuthenticator = new FacebookAuthentication();
-
- connect(m_facebookAuthenticator, SIGNAL(credentialsReady()), this, SLOT(loginOk()));
- connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
-
- connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress()));
- connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString)));
- connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool)));
-
- m_situareService->fetchLocations(); // request user locations
-
- start();
+ m_situareService = new SituareService(this);
+
+ m_facebookAuthenticator = new FacebookAuthentication(this);
+
+#ifdef Q_WS_MAEMO_5
+ m_gps = new GPSPosition(this);
+#else
+ m_gps = new GPSPositionMockup(this);
+#endif
+ m_gps->setMode(GPSPositionInterface::Default);
+
+ connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
+ m_situareService, SLOT(credentialsReady(FacebookCredentials)));
+ connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
+ this, SLOT(loginOk()));
+ connect(m_ui, SIGNAL(cancelLoginProcess()),
+ this, SLOT(loginProcessCancelled()));
+
+ connect(m_ui, SIGNAL(requestReverseGeo()),
+ this, SLOT(requestAddress()));
+ connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
+ m_ui, SIGNAL(reverseGeoReady(QString)));
+ connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
+ this, SLOT(requestUpdateLocation(QString,bool)));
+ connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
+ this, SLOT(userDataChanged(User*,QList<User*>&)));
+ connect(this, SIGNAL(userLocationReady(User*)),
+ m_ui, SIGNAL(userLocationReady(User*)));
+ connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+ m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
+ connect(m_situareService, SIGNAL(error(QString)),
+ this, SLOT(error(QString)));
+ connect(m_situareService, SIGNAL(updateWasSuccessful()),
+ this, SLOT(updateWasSuccessful()));
+
+ connect(m_ui, SIGNAL(refreshUserData()),
+ this, SLOT(refreshUserData()));
+
+ connect(m_gps, SIGNAL(timeout()),
+ m_ui, SLOT(gpsTimeout()));
+ connect(m_gps, SIGNAL(error(QString)),
+ m_ui, SLOT(gpsError(QString)));
+ connect(m_ui, SIGNAL(enableGPS(bool)),
+ this, SLOT(enableGPS(bool)));
+ connect(m_gps, SIGNAL(position(QPointF, qreal)),
+ m_ui, SIGNAL(positionReceived(QPointF, qreal)));
+ connect(m_ui, SIGNAL(enableAutoCentering(bool)),
+ this, SLOT(enableAutoCentering(bool)));
+
+ connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
+ m_ui, SLOT(startLoginProcess(QUrl)));
+ connect(m_ui, SIGNAL(updateCredentials(QUrl)),
+ m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
+ connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
+ m_ui, SLOT(loginFailed()));
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ QVariant gpsEnabled = settings.value(GPS_ENABLED);
+ QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
+
+ enableGPS(gpsEnabled.toBool());
+ enableAutoCentering(autoCenteringEnabled.toBool());
+
+ m_facebookAuthenticator->start();
}
SituareEngine::~SituareEngine()
{
qDebug() << __PRETTY_FUNCTION__;
+
delete m_ui;
}
-void SituareEngine::start()
+void SituareEngine::loginProcessCancelled()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_ui->toggleProgressIndicator(false);
+ //ToDo: do something
+}
+
+void SituareEngine::error(const QString &error)
{
- m_facebookAuthenticator->start();
+ qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << error;
+ // ToDo: signal UI?
}
void SituareEngine::loginOk()
-
{
qDebug() << __PRETTY_FUNCTION__;
- m_loggedIn = true;
- m_facebookAuthenticator->hide();
+
m_ui->show();
+ m_situareService->fetchLocations(); // request user locations
}
void SituareEngine::requestAddress()
{
qDebug() << __PRETTY_FUNCTION__;
- QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+
+ QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
m_situareService->reverseGeo(coordinates);
}
-void SituareEngine::requestUpdateLocation(const QString &status, const bool &publish)
+void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
{
qDebug() << __PRETTY_FUNCTION__;
- QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+
+ m_ui->toggleProgressIndicator(true);
+
+ QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
m_situareService->updateLocation(coordinates, status, publish);
}
-void SituareEngine::updateFriendsList()
+void SituareEngine::updateWasSuccessful()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_situareService->fetchLocations();
+}
+
+void SituareEngine::refreshUserData()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_ui->toggleProgressIndicator(true);
+
+ m_situareService->fetchLocations();
+}
+
+void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_ui->toggleProgressIndicator(false);
+
+ emit userLocationReady(user);
+ emit friendsLocationsReady(friendsList);
+}
+
+void SituareEngine::enableGPS(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
- //code here
+
+ if (enabled) {
+ m_gps->lastPosition();
+ m_gps->start();
+ m_ui->setGPSButton(true);
+ }
+ else {
+ m_gps->stop();
+ m_ui->setGPSButton(false);
+ }
+}
+
+void SituareEngine::enableAutoCentering(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (enabled) {
+ m_ui->setAutoCenteringButton(true);
+ m_ui->autoCenteringEnabled(true);
+ m_gps->lastPosition();
+ }
+ else {
+ m_ui->setAutoCenteringButton(false);
+ m_ui->autoCenteringEnabled(false);
+ }
}