Added toggleProgressInidicator to engine.cpp.
[situare] / src / engine / engine.cpp
index a1b29be..605bc33 100644 (file)
@@ -4,6 +4,7 @@
 
         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
@@ -39,10 +40,16 @@ SituareEngine::SituareEngine(QMainWindow *parent)
             this, SLOT(loginOk()));
 
     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(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()));
 
     m_facebookAuthenticator->start();
 }
@@ -54,6 +61,13 @@ SituareEngine::~SituareEngine()
     delete m_facebookAuthenticator;
 }
 
+void SituareEngine::error(const QString &error)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << error;
+    // ToDo: signal UI?
+}
+
 void SituareEngine::loginOk()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -65,19 +79,43 @@ void SituareEngine::loginOk()
 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, 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__;
-    //code here
+
+    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);
 }