Merge branch 'image_fetcher' of https://vcs.maemo.org/git/situare into friendlist
[situare] / src / engine / engine.cpp
index 625b873..3bbcc2d 100644 (file)
@@ -3,6 +3,7 @@
     Copyright (C) 2010  Ixonos Plc. Authors:
 
         Kaj Wallin - kaj.wallin@ixonos.com
+        Henri Lampela - henri.lampela@ixonos.com
 
     Situare is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
  */
 
 #include "engine.h"
+#include "ui/mainwindow.h"
 
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent)
 {
+    m_ui = new MainWindow;
+
+    m_networkManager = new QNetworkAccessManager;
+    m_situareService = new SituareService(this, m_networkManager);
+
     m_loggedIn = false;
     m_facebookAuthenticator = new FacebookAuthentication();
 
-    m_networkManager = new QNetworkAccessManager;
-    m_situareService = new SituareService(this,m_networkManager);
-    connect(m_facebookAuthenticator, SIGNAL(credentialsReady()), this, SLOT(loginOk()));
-    connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
+    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
+            m_situareService, SLOT(credentialsReady(FacebookCredentials)));
+    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
+            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(error(QString)), this, SLOT(error(QString)));
+
+    connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)), m_ui,
+            SIGNAL(userDataChanged(User*,QList<User*>&)));
+
+    connect(m_ui, SIGNAL(refreshUserData()), this, SLOT(refreshUserData()));
+
+    start();
 }
 
 SituareEngine::~SituareEngine()
 {
     qDebug() << __PRETTY_FUNCTION__;
+    delete m_ui;
+    delete m_facebookAuthenticator;
+}
+
+void SituareEngine::error(const QString &error)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << error;
+    // ToDo: signal UI?
 }
 
 void SituareEngine::start()
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_facebookAuthenticator->start();
 }
 
-
 void SituareEngine::loginOk()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
     m_loggedIn = true;
-    m_facebookAuthenticator->close();
+    m_facebookAuthenticator->hide();
+    m_ui->show();
+    m_situareService->fetchLocations(); // request user locations
 }
-void SituareEngine::loginScreenClosed()
+
+void SituareEngine::requestAddress()
 {
-    qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
-    if (m_loggedIn) {
-        emit engine_showMainWindow();
-        return;
-    }
-    else {
-        emit engine_closeMainWindow();
-    }
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+    m_situareService->reverseGeo(coordinates);
 }
-void SituareEngine::updateFriendsList()
+
+void SituareEngine::requestUpdateLocation(const QString &status, const bool &publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    //code here
+
+    QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+    m_situareService->updateLocation(coordinates, status, publish);
+}
+
+void SituareEngine::refreshUserData()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_situareService->fetchLocations();
 }