Merge branch 'list_panel'
[situare] / src / engine / engine.cpp
index f74c46c..4f69067 100644 (file)
@@ -40,7 +40,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
 
     m_situareService = new SituareService(this);
 
-    m_facebookAuthenticator = new FacebookAuthentication();
+    m_facebookAuthenticator = new FacebookAuthentication(this);
 
 #ifdef Q_WS_MAEMO_5
     m_gps = new GPSPosition(this);
@@ -53,8 +53,8 @@ SituareEngine::SituareEngine(QMainWindow *parent)
             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
             this, SLOT(loginOk()));
-    connect(m_facebookAuthenticator, SIGNAL(quitSituare()),
-            this, SLOT(quitApplication()));
+    connect(m_ui, SIGNAL(cancelLoginProcess()),
+            this, SLOT(loginProcessCancelled()));
 
     connect(m_ui, SIGNAL(requestReverseGeo()),
             this, SLOT(requestAddress()));
@@ -87,6 +87,20 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     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();
 }
 
@@ -97,12 +111,12 @@ SituareEngine::~SituareEngine()
     delete m_ui;
 }
 
-void SituareEngine::quitApplication()
+void SituareEngine::loginProcessCancelled()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
-    m_facebookAuthenticator->close();
+    m_ui->toggleProgressIndicator(false);
+    //ToDo: do something
 }
 
 void SituareEngine::error(const QString &error)
@@ -116,17 +130,8 @@ void SituareEngine::loginOk()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    QVariant gpsEnabled = settings.value(GPS_ENABLED);
-    QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
-
-    m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
-    m_facebookAuthenticator->close();
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
-
-    enableGPS(gpsEnabled.toBool());
-    enableAutoCentering(autoCenteringEnabled.toBool());
 }
 
 void SituareEngine::requestAddress()
@@ -175,7 +180,7 @@ void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
 
 void SituareEngine::enableGPS(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__ << enabled;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (enabled) {
         m_gps->lastPosition();
@@ -190,7 +195,7 @@ void SituareEngine::enableGPS(bool enabled)
 
 void SituareEngine::enableAutoCentering(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__ << enabled;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (enabled) {
         m_ui->setAutoCenteringButton(true);