refactored engine and situareservice
authorlampehe-local <henri.lampela@ixonos.com>
Wed, 28 Apr 2010 07:44:51 +0000 (10:44 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Wed, 28 Apr 2010 07:44:51 +0000 (10:44 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h

index b2e877c..54ab250 100644 (file)
@@ -34,15 +34,15 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     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_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)));
 
-    m_situareService->fetchLocations(); // request user locations
-
     start();
 }
 
@@ -62,19 +62,9 @@ void SituareEngine::loginOk()
 {
     qDebug() << __PRETTY_FUNCTION__;
     m_loggedIn = true;
-    m_facebookAuthenticator->close();
-}
-
-void SituareEngine::loginScreenClosed()
-{
-    qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
-    if (m_loggedIn) {
-        m_ui->show();
-        return;
-    }
-    else {
-        m_ui->close();
-    }
+    m_facebookAuthenticator->hide();
+    m_ui->show();
+    m_situareService->fetchLocations(); // request user locations
 }
 
 void SituareEngine::requestAddress()
index 70bcf40..9e81a86 100644 (file)
@@ -65,10 +65,6 @@ public:
     void start();
 
 public slots:
-    /**
-    * @brief Slot to intercept signal from login screen closure
-    */
-    void loginScreenClosed();
 
     /**
     * @brief Slot to intercept signal from successful login
index d04a2cf..55d75ba 100644 (file)
@@ -61,7 +61,7 @@ void FacebookAuthentication::start()
         this->show();
     }
     else
-        emit credentialsReady();
+        emit credentialsReady(m_loginCredentials);
 }
 
 
@@ -168,8 +168,8 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
             }
 
             m_webView->hide();
-            emit credentialsReady();
             writeCredentials(m_loginCredentials);
+            emit credentialsReady(m_loginCredentials);
         }
 
         else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
@@ -253,16 +253,6 @@ void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFro
      }
  }
 
- void FacebookAuthentication::closeEvent(QCloseEvent *event)
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     int eventNumber = 0;     
-     eventNumber = event->registerEventType();
-     qDebug() << "event number" << eventNumber;
-     emit userExit();
-     event->accept();
- }
-
  QString FacebookAuthentication::formLoginPage(const QString & part1, const QString & part2,
                                  const QString & part3, const QString & part4,
                                  const QString & part5, const QString & part6,
index 0d07323..785d909 100644 (file)
@@ -77,16 +77,7 @@ public slots:
     */
     void start();
 
-private:
-
-    /**
-    * @brief Program cames to this method when user closes login screen by pressing X.
-    *        method sends userExit() signal in this function
-    *
-    * @param event without parameter program does not come to this function when user exits by
-    *               pressing X.
-    */
-    void closeEvent(QCloseEvent *event);
+private: 
 
     /**
     * @brief  Appends given parts to returned string. Method is used to form facebook login page
@@ -146,8 +137,9 @@ signals:
     *        Signal is also emitted at the beginning of the program if there is valid credentials
     *        in the file.
     *
+    * @param credentials New credentials
     */
-    void credentialsReady();
+    void credentialsReady(const FacebookCredentials &credentials);
 
     /**
     * @brief This signal is emitted if updateCredentials method can't find credentials from URL
@@ -155,12 +147,6 @@ signals:
     */
     void loginFailure();
 
-    /**
-    * @brief This signal is emitted if user exits logging in by pressing X
-    *
-    */
-    void userExit();
-
 private:
 
     /**
index aaa9d83..f937e0b 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtGlobal>
 #include <QStringList>
 #include <QPixmap>
+#include <QNetworkReply>
 #include "situareservice.h"
 #include "situarecommon.h"
 #include "../cookiehandler/cookiehandler.h"
@@ -33,8 +34,6 @@ SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(&m_facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
-
     connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
 
     m_imageFetcher = new ImageFetcher(new QNetworkAccessManager(this), this);
@@ -42,7 +41,6 @@ SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
     connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QPixmap)), this,
             SLOT(imageReceived(QUrl, QPixmap)));
 
-    m_credentials = m_facebookAuthentication.loginCredentials();
 }
 
 SituareService::~SituareService()
@@ -50,7 +48,9 @@ SituareService::~SituareService()
     qDebug() << __PRETTY_FUNCTION__;
 
     delete m_networkManager;
-    delete m_user;
+    if(m_user) {
+        delete m_user;
+    }
 }
 
 void SituareService::fetchLocations()
@@ -226,10 +226,11 @@ void SituareService::requestFinished(QNetworkReply *reply)
     reply->deleteLater();
 }
 
-void SituareService::credentialsReady()
+void SituareService::credentialsReady(const FacebookCredentials &credentials)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    m_credentials = m_facebookAuthentication.loginCredentials();
+    m_credentials = credentials;
+    
 }
 
 void SituareService::parseUserData(const QByteArray &jsonReply)
@@ -250,8 +251,6 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
         exit (1);
     }
 
-    //QList<User *> friendsList;
-
     QVariant userVariant = result.value("user");
     QMap<QString, QVariant> userMap = userVariant.toMap();
 
index e775a54..626ac97 100644 (file)
@@ -24,7 +24,6 @@
 #define SITUARESERVICE_H
 
 #include <QObject>
-#include "../facebookservice/facebookauthentication.h"
 #include "../facebookservice/facebookcredentials.h"
 #include "../user/user.h"
 #include "imagefetcher.h"
@@ -99,8 +98,9 @@ public slots:
     /**
     * @brief Public slot, which indicates when facebook credentials are ready
     *
+    * @param credentials New credentials
     */
-    void credentialsReady();
+    void credentialsReady(const FacebookCredentials &credentials);
 
 private:
 
@@ -200,7 +200,6 @@ private:
 
     FacebookCredentials m_credentials; ///< handle for FacebookCredentials
     QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
-    FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
     QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
     ImageFetcher *m_imageFetcher;