Merge branch 'master' into login_browser
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 8 Nov 2010 07:43:59 +0000 (09:43 +0200)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 8 Nov 2010 07:43:59 +0000 (09:43 +0200)
19 files changed:
src/common.h
src/engine/engine.cpp
src/engine/engine.h
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/facebookservice/facebookcommon.h
src/facebookservice/facebookcredentials.cpp [deleted file]
src/facebookservice/facebookcredentials.h [deleted file]
src/network/networkcookiejar.cpp
src/network/networkcookiejar.h
src/situareservice/situarecommon.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro
src/ui/facebookloginbrowser.cpp [new file with mode: 0644]
src/ui/facebookloginbrowser.h [new file with mode: 0644]
src/ui/locationsearchpanel.cpp
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 8d74ac9..8733932 100644 (file)
@@ -47,6 +47,7 @@ const QColor COLOR_GRAY = QColor(152, 152, 152);                        ///< Gra
 const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
 const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);  ///< Small font
 
+///< @todo remove / change old fb login url stuff
 // Facebook login page pieces
 const QString FACEBOOK_LOGINBASE = "http://www.facebook.com/login.php?";
 const QString API_KEY_PARAMETER_NAME = "api_key=";
index f8fcf91..48fa6cd 100644 (file)
@@ -31,6 +31,7 @@
 #include "common.h"
 #include "contactmanager.h"
 #include "../error.h"
+#include "ui/facebookloginbrowser.h"
 #include "facebookservice/facebookauthentication.h"
 #include "gps/gpsposition.h"
 #include "map/mapengine.h"
@@ -126,16 +127,16 @@ SituareEngine::SituareEngine()
     m_mapEngine->init();
     m_ui->show();
 
-    m_facebookAuthenticator->start();
-
     m_gps->setMode(GPSPosition::Default);
     initializeGpsAndAutocentering();
 
     m_mce = new MCE(this);
     connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
-    
+
     m_contactManager = new ContactManager(this);
     m_contactManager->requestContactGuids();
+
+    m_facebookAuthenticator->login();
 }
 
 SituareEngine::~SituareEngine()
@@ -304,13 +305,6 @@ void SituareEngine::error(const int context, const int error)
     }
 }
 
-void SituareEngine::fetchUsernameFromSettings()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->setUsername(m_facebookAuthenticator->loadUsername());
-}
-
 void SituareEngine::imageReady(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -361,6 +355,15 @@ void SituareEngine::locationSearch(QString location)
         m_geocodingService->requestLocation(location);
 }
 
+void SituareEngine::loggedIn()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_ui->destroyFacebookLoginBrowser();
+
+    loginOk();
+}
+
 void SituareEngine::loginActionPressed()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -370,7 +373,7 @@ void SituareEngine::loginActionPressed()
             logout();
             m_situareService->clearUserData();
         } else {
-            m_facebookAuthenticator->start();
+            m_facebookAuthenticator->login();
         }
     }
     else {
@@ -605,6 +608,15 @@ void SituareEngine::signalsFromFacebookAuthenticator()
 
     connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
             m_ui, SLOT(loginUsingCookies()));
+
+    connect(m_facebookAuthenticator, SIGNAL(buildLoginBrowser()),
+            m_ui, SLOT(buildFacebookLoginBrowser()));
+
+    connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
+            m_situareService, SLOT(updateSession(QString)));
+
+    connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
+            this, SLOT(loggedIn()));
 }
 
 void SituareEngine::signalsFromGeocodingService()
@@ -639,18 +651,15 @@ void SituareEngine::signalsFromMainWindow()
     connect(m_ui, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
-            this, SLOT(fetchUsernameFromSettings()));
-
     connect(m_ui, SIGNAL(loginActionPressed()),
             this, SLOT(loginActionPressed()));
 
-    connect(m_ui, SIGNAL(saveUsername(QString)),
-            m_facebookAuthenticator, SLOT(saveUsername(QString)));
-
     connect(m_ui, SIGNAL(updateCredentials(QUrl)),
             m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
 
+    connect(m_ui, SIGNAL(loginBrowserCreated(FacebookLoginBrowser*)),
+            m_facebookAuthenticator, SLOT(setBrowser(FacebookLoginBrowser*)));
+
     // signals from map view
     connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
             m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
index aacd9e5..26f16c6 100644 (file)
@@ -83,12 +83,6 @@ public slots:
     void error(const int context, const int error);
 
     /**
-    * @brief Slot to intercept signal when username is fetched from settings
-    *
-    */
-    void fetchUsernameFromSettings();
-
-    /**
     * @brief Slot to intercept signal when location search is issued
     *
     * @param location QString location
@@ -233,6 +227,8 @@ private slots:
     */
     void imageReady(User *user);
 
+    void loggedIn();
+
     /**
     * @brief Requests automatic update.
     *
index 4b5d300..4c2d804 100644 (file)
 #include "common.h"
 #include "error.h"
 #include "facebookcommon.h"
+#include "ui/facebookloginbrowser.h"
 
 #include "facebookauthentication.h"
 
+const QString REDIRECT_URI = "http://www.facebook.com/connect/login_success.html";
+
 FacebookAuthentication::FacebookAuthentication(QObject *parent)
     : QObject(parent),
-    m_freshLogin(false)
+      m_browser(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
 }
 
+void FacebookAuthentication::browserDestroyed()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    ///< @todo (HIGH) Is newer called!
+
+    m_browser = 0;
+}
+
 void FacebookAuthentication::clearAccountInformation(bool keepUsername)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_loginCredentials.clearCredentials();
+    ///< @todo (HIGH) clear session from SituareService
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
     if(!keepUsername) {
-        settings.remove(USERNAME);
         settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
         settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
     }
@@ -65,128 +76,80 @@ void FacebookAuthentication::clearAccountInformation(bool keepUsername)
     settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
 }
 
-const QString FacebookAuthentication::loadUsername()
+void FacebookAuthentication::loadFinished(bool ok)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__ << ok;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    return settings.value(USERNAME, EMPTY).toString();
+    ///< @todo show browsed window if url != redirect url
 }
 
-FacebookCredentials FacebookAuthentication::loginCredentials() const
+void FacebookAuthentication::login()
 {
-    qDebug() << __PRETTY_FUNCTION__;
-    return m_loginCredentials;
+    qWarning() << __PRETTY_FUNCTION__;
+
+    emit buildLoginBrowser();
 }
 
-void FacebookAuthentication::saveUsername(const QString &username)
+QString FacebookAuthentication::parseSession(const QUrl &url)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(USERNAME, username);
+    const QString BEGIN("session={");
+    const QString END("}");
+
+    QString urlString = url.toString();
+
+    int begin = urlString.indexOf(BEGIN);
+    int end = urlString.indexOf(END, begin);
+
+    if ((begin > -1) && (end > -1))
+        return urlString.mid(begin, end - begin + 1);
+    else
+        return QString();
 }
 
-void FacebookAuthentication::start()
+void FacebookAuthentication::setBrowser(FacebookLoginBrowser *browser)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    m_browser = browser;
 
-    QStringList cookies = settings.value(COOKIES).toStringList();
-    if(!cookies.isEmpty()) {
-        emit loginUsingCookies();
-    }
-    else {
-        m_freshLogin = true;
-        emit newLoginRequest();
+    if (m_browser) {
+        connect(m_browser, SIGNAL(loadFinished(bool)),
+                this, SLOT(loadFinished(bool)));
+
+        connect(m_browser, SIGNAL(urlChanged(QUrl)),
+                this, SLOT(urlChanged(QUrl)));
+
+        connect(m_browser, SIGNAL(destroyed()),
+                this, SLOT(browserDestroyed()));
+
+        //    browser->load(QUrl("https://graph.facebook.com/oauth/authorize?client_id=4197c64da2fb6b927236feaea32d7d81&redirect_uri=http://www.facebook.com/connect/login_success.html&display=touch&type=user_agent"));
+
+        QString url = "https://www.facebook.com/login.php?";
+        url.append("api_key=cf77865a5070f2c2ba3b52cbf3371579&"); ///< @todo hard coded test server api key
+        url.append("cancel_url=http://www.facebook.com/connect/login_failure.html&");
+        url.append("display=popup&");
+        url.append("fbconnect=1&");
+        url.append("next=http://www.facebook.com/connect/login_success.html&");
+        url.append("return_session=1&");
+        url.append("session_version=3&");
+        url.append("v=1.0&");
+        url.append("req_perms=publish_stream");
+
+        m_browser->load(QUrl(url));
     }
 }
 
-bool FacebookAuthentication::updateCredentials(const QUrl &url)
+void FacebookAuthentication::urlChanged(const QUrl &url)
 {
-    qDebug() << __PRETTY_FUNCTION__ << url.toString();
-
-    bool found = false;
-
-    if (url.isValid()) {
-         qDebug() << "url is valid";
-
-        QString callbackUrl = url.toString();
-        qDebug() << "callbackUrl:  " << callbackUrl.toAscii();
-
-        if (callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0) {
-            qDebug() << "login success";
-
-            // let's find out session credentials
-            if(callbackUrl.contains(SESSION_KEY)) {
-
-                QJson::Parser parser;
-                bool ok;
-
-                // split string into string part and json part
-                QStringList list = url.toString().split("=");
-
-                for(int i=0;i<list.count();i++) {
-                    // if string starts with json item
-                    if(list.at(i).startsWith("{")) {
-                        QByteArray jsonString = list.at(i).toAscii();
-                        QVariantMap result = parser.parse (jsonString, &ok).toMap();
-
-                        if (!ok) {
-                            emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
-                            found = false;
-                        } else {
-                            qDebug() << "Session Key" << result[SESSION_KEY].toString();
-                            m_loginCredentials.setSessionKey(result[SESSION_KEY].toString());
-
-    //                        // commeted out until qjson parser can handle 64-bit integers
-    //                        qDebug() << "userID" << result[USER_ID].toString();
-    //                        m_loginCredentials.setUserID(result[USER_ID].toString().toAscii());
-
-                            // dirty fix, get user id from session_key
-                            QStringList list = result[SESSION_KEY].toString().split("-");
-                            m_loginCredentials.setUserID(list.at(1));
-                            qDebug() << m_loginCredentials.userID();
-
-                            qDebug() << "Expires" << result[EXPIRES].toString();
-                            m_loginCredentials.setExpires(result[EXPIRES].toString());
-
-                            qDebug() << "Session Secret" << result[SESSION_SECRET].toString();
-                            m_loginCredentials.setSessionSecret(result[SESSION_SECRET].toString());
-
-                            qDebug() << "Signature" << result[SIGNATURE].toString();
-                            m_loginCredentials.setSig(result[SIGNATURE].toString());
-
-                            found = true;
-                            m_freshLogin = false;
-                            emit saveCookiesRequest();
-                            emit credentialsReady(m_loginCredentials);
-                        }
-                    }
-                }
-            }
-        } else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0) {
-            qDebug() << "login failure";
-            qDebug() << callbackUrl;
-            clearAccountInformation(true);
-            if(m_freshLogin) {
-                emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
-            } else {
-                m_freshLogin = true;
-                emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
-            }
-        } else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {
-            qDebug() << "correct loginPage";
-        } else {
-            qDebug() << "totally wrong webPage";
-            // we should not get a wrong page at this point
-            emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
-        }
-    } else {
-        qDebug() << " Loading of page failed invalid URL" << endl;
-        // we should not get a wrong page at this point
-        emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
+    qWarning() << __PRETTY_FUNCTION__ << url.toString();
+
+    // if login succeeded
+    if (url.toString().startsWith(REDIRECT_URI)) {
+        const QString session = parseSession(url);
+        qWarning() << __PRETTY_FUNCTION__ << "parsed session:" << session;
+        if (!session.isEmpty())
+            emit loggedIn(session);
     }
-    return found;
 }
index 11dc05a..0d3cbfa 100644 (file)
@@ -25,7 +25,8 @@
 #define FACEBOOKAUTHENTICATION_H
 
 #include <QUrl>
-#include "facebookcredentials.h"
+
+class FacebookLoginBrowser;
 
 /**
 * @brief FacebookAuthentication class takes care of parsing and handling of  credentials for
@@ -51,13 +52,8 @@ public:
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
-
-    /**
-    * @brief Getter for m_loginCredentials
-    *
-    * @return FacebookCredentials
-    */
-    FacebookCredentials loginCredentials() const;
+public:
+    void login();
 
 public slots:
 
@@ -68,44 +64,23 @@ public slots:
     */
     void clearAccountInformation(bool keepUsername = false);
 
-    /**
-    * @brief Loads username from settings
-    *
-    * @return QString Loaded username
-    */
-    const QString loadUsername();
+    void setBrowser(FacebookLoginBrowser *browser);
 
-    /**
-    * @brief Saves username to settings
-    *
-    * @param username Username to be saved
-    */
-    void saveUsername(const QString &username);
-
-    /**
-    * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
-    *        variable. Specifies font size for the page.
-    *    
-    */
-    void start();
+private:
+    QString parseSession(const QUrl &url);
 
 private slots:
+    void browserDestroyed();
 
-    /**
-    * @brief  Search credentials from URL that is given as parameter.
-    *         If credentials are found thay are stored to loginCredentials variable.
-    *
-    * @param url URL where this method tries to find credentials.
-    * @return bool if credentials are found returns true,
-    *               if credentials are not found returns false.
-    */
-    bool updateCredentials(const QUrl & url);
+    void loadFinished(bool ok);
+
+    void urlChanged(const QUrl &url);
 
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
-
 signals:
+    void buildLoginBrowser();
 
     /**
     * @brief Signals error
@@ -115,49 +90,13 @@ signals:
     */
     void error(const int context, const int error);
 
-    /**
-    * @brief This signal is emitted if updateCredentials method finds credentials from URL.
-    *        Signal is also emitted at the beginning of the program if there is valid credentials
-    *        in the file.
-    *
-    * @param credentials New credentials
-    */
-    void credentialsReady(const FacebookCredentials &credentials);
-
-    /**
-    * @brief This signal is emitted always when login is called. At first  the application tries
-    *        to login using saved cookies
-    *
-    */
-    void loginUsingCookies();
-
-    /**
-    * @brief Signals when credentials are invalid new login is needed
-    *
-    */
-    void newLoginRequest();
-
-    /**
-    * @brief This signal is emitted when new cookies need to be saved.
-    *
-    */
-    void saveCookiesRequest();
+    void loggedIn(const QString session);
 
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
-
 private:
-
-    bool m_freshLogin;  ///< Flag for fresh login
-
-    /**
-    * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
-    *        QStrings and setters and getters.
-    *
-    * @var m_loginCredentials
-    */
-    FacebookCredentials m_loginCredentials;
+    FacebookLoginBrowser *m_browser;
 };
 
 #endif // FACEBOOKAUTHENTICATION_H
index e3eb52f..4f5e927 100644 (file)
 
 const QString ERROR = "Error";
 
-// Facebook webView font size
-const double FACEBOOK_LOGINPAGE_FONT_SIZE = 1.2;
-
 // Facebook callback url indentifiers and setting items
+///< @todo remove
 const QString SESSION_KEY = "session_key";
 const QString USER_ID = "uid";
 const QString EXPIRES = "expires";
 const QString SESSION_SECRET = "secret";
 const QString SIGNATURE = "sig";
 
-// Login setting items
-const QString USERNAME = "username";
-
 const QString LOGIN_SUCCESS_REPLY = "http://www.facebook.com/connect/login_success.html";
 const QString LOGIN_FAILURE_REPLY = "https://login.facebook.com/login.php?login_attempt=";
 const QString LOGIN_PAGE = "http://www.facebook.com/login.php?api_key=";
diff --git a/src/facebookservice/facebookcredentials.cpp b/src/facebookservice/facebookcredentials.cpp
deleted file mode 100644 (file)
index 9e4d225..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Ville Tiensuu - ville.tiensuu@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#include <QtGlobal>
-#include "facebookcredentials.h"
-
-FacebookCredentials::FacebookCredentials()
-{
-}
-
-void FacebookCredentials::clearCredentials()
-{
-    m_expires.clear();
-    m_sessionKey.clear();
-    m_sessionSecret.clear();
-    m_sig.clear();
-    m_userID.clear();
-}
-
-void FacebookCredentials::setSessionKey(const QString & sessionKeyParameter)
-{
-    m_sessionKey = sessionKeyParameter;
-}
-
-void FacebookCredentials::setSessionSecret(const QString & sessionSecretParameter)
-{
-    m_sessionSecret = sessionSecretParameter;
-}
-
-
-void FacebookCredentials::setExpires (const QString & expiresParameter)
-{
-    m_expires = expiresParameter;
-}
-
-void FacebookCredentials::setUserID (const QString & userIDParameter)
-{
-    m_userID = userIDParameter;
-}
-
-void FacebookCredentials::setSig(const QString & sigParameter)
-{
-    m_sig = sigParameter;
-}
-
-QString FacebookCredentials::sessionKey() const
-{
-    return m_sessionKey;
-}
-
-QString FacebookCredentials::sessionSecret() const
-{
-    return m_sessionSecret;
-}
-
-QString FacebookCredentials::expires() const
-{
-    return m_expires;
-}
-
-QString FacebookCredentials::userID() const
-{
-    return m_userID;
-}
-
-QString FacebookCredentials::sig() const
-{
-    return m_sig;
-}
-
-bool FacebookCredentials::operator==(const FacebookCredentials &credentials)
-{
-    bool expireBool = (m_expires == credentials.expires());
-    bool sessionKeyBool = (m_sessionKey == credentials.sessionKey());
-    bool sessionSecretBool = (m_sessionSecret == credentials.sessionSecret());
-    bool sigBool = (m_sig == credentials.sig());
-    bool userIdBool = (m_userID == credentials.userID());
-
-    return expireBool && sessionKeyBool && sessionSecretBool && sigBool && userIdBool;
-}
diff --git a/src/facebookservice/facebookcredentials.h b/src/facebookservice/facebookcredentials.h
deleted file mode 100644 (file)
index b93378d..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Ville Tiensuu - ville.tiensuu@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#ifndef FACEBOOKCREDENTIALS_H
-#define FACEBOOKCREDENTIALS_H
-
-#include <QString>
-
-/**
-* @brief Class is used to integrate facebook credentials together.
-*
-* @author Ville Tiensuu
-* @class FacebookCredentials facebookcredentials.h "situare/src/facebookservice/facebookcredentials.h"
-*/
-class FacebookCredentials
-{
-public:
-    /**
-    * @brief Default constructor
-    *
-    */
-    FacebookCredentials();
-
-    /**
-    * @brief Clears credentials
-    *
-    */
-    void clearCredentials();
-
-    /**
-    * @brief Set funtion for m_expires member
-    *
-    * @param expiresParameter value of parameter is set to m_expires member
-    */
-    void setExpires (const QString & expiresParameter);
-
-    /**
-    * @brief Set function for m_sessionKey member
-    *
-    * @param sessionKeyParameter value of parameter is set to m_sessionKey member
-    */
-    void setSessionKey(const QString & sessionKeyParameter);
-
-    /**
-    * @brief Set function for m_sessionSecret member
-    *
-    * @param sessionSecretParameter value of parameter is set to m_sessionSecret member
-    */
-    void setSessionSecret(const QString & sessionSecretParameter);
-
-    /**
-    * @brief Set funtion for m_sig member
-    *
-    * @param sigParameter value of parameter is set to m_sig member
-    */
-    void setSig(const QString & sigParameter);
-
-    /**
-    * @brief Set function for m_userID member
-    *
-    * @param userIDParameter value of parameter is set to m_userID member
-    */
-    void setUserID(const QString & userIDParameter);
-
-    /**
-    * @brief Get function for m_expires member
-    *
-    * @return QString m_expires
-    */
-    QString expires() const;
-
-    /**
-    * @brief Get function for m_sessionKey member
-    *
-    * @return QString m_sessionKey
-    */
-    QString sessionKey() const;
-
-    /**
-    * @brief Get funtion for m_sessionSecret member
-    *
-    * @return QString m_sessionSecret
-    */
-    QString sessionSecret() const;
-
-    /**
-    * @brief Get function for m_sig member
-    *
-    * @return QString m_sig
-    */
-    QString sig() const;
-
-    /**
-    * @brief Get function for m_userID member
-    *
-    * @return QString m_userID
-    */
-    QString userID() const;   
-
-    /**
-    * @brief Overloaded operator == is used to compare two FacebookCredentials.
-    *
-    * @param credentials to be checked
-    * @return bool returns true if all members are same, else returns false
-    */
-    bool operator==(const FacebookCredentials& credentials);
-
-private:
-
-    /**
-    * @brief String for storing expires
-    *
-    * @var m_expires
-    */
-    QString m_expires;
-
-    /**
-    * @brief String for storing sessionKey
-    *
-    * @var m_sessionKey
-    */
-    QString m_sessionKey;
-
-    /**
-    * @brief String for storing sessionSecret
-    *
-    * @var m_sessionSecret
-    */
-    QString m_sessionSecret;
-
-    /**
-    * @brief String for storing sig
-    *
-    * @var m_sig
-    */
-    QString m_sig;
-
-    /**
-    * @brief String for storing userID
-    *
-    * @var m_userID
-    */
-    QString m_userID;    
-};
-
-#endif // FACEBOOKCREDENTIALS_H
index da28e2f..d1ccaea 100644 (file)
@@ -3,6 +3,7 @@
     Copyright (C) 2010  Ixonos Plc. Authors:
 
         Henri Lampela - henri.lampela@ixonos.com
+        Sami Rämö - sami.ramo@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 "networkcookiejar.h"
 #include <QDebug>
+#include <QSettings>
 
-NetworkCookieJar::NetworkCookieJar(QObject *parent) :
-    QNetworkCookieJar(parent)
-{
-    m_cookieList.clear();
-}
+#include "common.h"
+
+#include "networkcookiejar.h"
 
-void NetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList)
+NetworkCookieJar::NetworkCookieJar(QObject *parent)
+    : QNetworkCookieJar(parent)
 {
-    m_cookieList = cookieList;
+    qWarning() << __PRETTY_FUNCTION__;
+
+    loadCookies();
 }
 
-QList<QNetworkCookie> NetworkCookieJar::allCookies() const
+NetworkCookieJar::~NetworkCookieJar()
 {
-    return m_cookieList;
+    qWarning() << __PRETTY_FUNCTION__;
+
+    saveCookies();
 }
 
-bool NetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
+void NetworkCookieJar::loadCookies()
 {
-    Q_UNUSED(url);
+    qWarning() << __PRETTY_FUNCTION__;
 
-    QList<QNetworkCookie> cookies = allCookies();
-    foreach(QNetworkCookie cookie, cookieList) {
-        cookies += cookie;
-    }
-    setAllCookies(cookies);
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    return true;
+    QStringList list = settings.value(COOKIES, EMPTY).toStringList();
+
+    if(!list.isEmpty()) {
+        QList<QNetworkCookie> cookieList;
+        for(int i = 0; i < list.count(); i++) {
+            cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
+        }
+
+        setAllCookies(cookieList);
+    }
 }
 
-QList<QNetworkCookie> NetworkCookieJar::cookiesForUrl ( const QUrl & url ) const
+void NetworkCookieJar::saveCookies()
 {
-    Q_UNUSED(url);
-    return m_cookieList;
+    qWarning() << __PRETTY_FUNCTION__;
+
+    QList<QNetworkCookie> cookieList = allCookies();
+    QStringList list;
+
+    for(int i = 0; i < cookieList.count(); i++) {
+        QNetworkCookie cookie = cookieList.at(i);
+        QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
+        list.append(QString(byteArray));
+    }
+    list.removeDuplicates();
+
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    settings.setValue(COOKIES, list);
 }
index ff05178..8f6ef62 100644 (file)
@@ -3,6 +3,7 @@
     Copyright (C) 2010  Ixonos Plc. Authors:
 
         Henri Lampela - henri.lampela@ixonos.com
+        Sami Rämö - sami.ramo@ixonos.com
 
     Situare is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
 * @brief Sub-class of QNetworkCookieJar, needed for cookie saving
 *
 * @author Henri Lampela
+* @author Sami Rämö - sami.ramo (at) ixonos.com
 */
 class NetworkCookieJar : public QNetworkCookieJar
 {
     Q_OBJECT
 
 public:
-
     /**
     * @brief Constructor
     *
@@ -42,49 +43,15 @@ public:
     */
     explicit NetworkCookieJar(QObject *parent = 0);
 
-/*******************************************************************************
- * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
- ******************************************************************************/
-
-    /**
-    * @brief Sets all network cookies
-    *
-    * @param cookieList Network cookie list
-    */
-    void setAllCookies ( const QList<QNetworkCookie> & cookieList );
-
-    /**
-    * @brief Gets all networks cookies
-    *
-    * @return QList<QNetworkCookie> Network cookie list
-    */
-    QList<QNetworkCookie> allCookies() const;
-
-    /**
-    * @brief Sets network cookies from url
-    *
-    * @param cookieList Network cookie list
-    * @param url Url
-    * @return bool Return value
-    */
-    bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
-
-    /**
-    * @brief Empty implementation
-    *
-    * @param url Url
-    * @return QList<QNetworkCookie> Network cookie list
-    */
-    QList<QNetworkCookie> cookiesForUrl(const QUrl & url) const;
+    ~NetworkCookieJar();
 
 /*******************************************************************************
- * DATA MEMBERS
+ * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
-
 private:
+    void loadCookies();
 
-    QList<QNetworkCookie> m_cookieList; ///< Placeholder for network cookies
-
+    void saveCookies();
 };
 
 #endif // NETWORKCOOKIEJAR_H
index 0f7b4a2..1d627da 100644 (file)
@@ -41,8 +41,7 @@ const QString NORMAL_SIZE_PROFILE_IMAGE = "pic";
 // Situare PHP scripts
 const QString UPDATE_LOCATION = "updateLocation.php";
 const QString REVERSE_GEO = "reversegeo.php";
-const QString GET_LOCATIONS =
-        QString("getLocations.php?extra_user_data=%1").arg(NORMAL_SIZE_PROFILE_IMAGE);
+const QString GET_LOCATIONS = "getLocations.php";
 
 // Cookies
 const QString COOKIE = "Cookie";
index ed789ad..87847c4 100644 (file)
 
 #include <qjson/parser.h>
 
-#include <QtAlgorithms>
 #include <QDebug>
 #include <QNetworkReply>
 #include <QPixmap>
 #include <QStringList>
+#include <QtAlgorithms>
 #include <QtGlobal>
 
 #include "error.h"
@@ -67,46 +67,96 @@ SituareService::~SituareService()
     m_friendsList.clear();
 }
 
-void SituareService::fetchLocations()
+void SituareService::addProfileImages(const QList<QUrl> &imageUrlList)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+    foreach(QUrl url, imageUrlList) {
+        emit fetchImage(url);
+    }
+}
+
+void SituareService::appendAccessToken(QString &requestUrl)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+//    requestUrl.append("access_token=");
+    requestUrl.append(m_session);
 
-    QUrl url = formUrl(SITUARE_URL, GET_LOCATIONS);
-    sendRequest(url, COOKIE, cookie);
+//    qWarning() << __PRETTY_FUNCTION__ << "request url with parameters and access token:" << requestUrl;
 }
 
-void SituareService::reverseGeo(const GeoCoordinate &coordinates)
+void SituareService::buildRequest(const QString &script, const QHash<QString, QString> &parameters)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
+
+    const QString PARAMETER_KEY_API = "api";
+    const QString PARAMETER_VALUE_API = "2.0";
+
+    QString url = SITUARE_URL;
+    url.append(script);
+    url.append("?");
+
+    // append default api version parameter if not yet specified
+    if (!parameters.contains(PARAMETER_KEY_API))
+        url.append(PARAMETER_KEY_API + "=" + PARAMETER_VALUE_API + "&");
+
+    // append parameters
+    if (!parameters.isEmpty()) {
+        QHash<QString, QString>::const_iterator i = parameters.constBegin();
+        while (i != parameters.constEnd()) {
+            url.append(i.key());
+            url.append("=");
+            url.append(i.value());
+            url.append("&");
+            i++;
+        }
+    }
+
+//    qWarning() << __PRETTY_FUNCTION__ << "request url with parameters:" << url;
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+    if (!m_session.isEmpty()) {
+        appendAccessToken(url);
+        sendRequest(url);
+    } else {
+        m_requestsWaitingAccessToken.append(url);
+        ///< @todo emit login request
+    }
+}
+
+void SituareService::clearUserData()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    QString urlParameters = formUrlParameters(coordinates);
-    urlParameters.append(JSON_FORMAT);
-    QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
+    qDeleteAll(m_friendsList.begin(), m_friendsList.end());
+    m_friendsList.clear();
 
-    sendRequest(url, COOKIE, cookie);
+    if(m_user) {
+        delete m_user;
+        m_user = 0;
+    }
+    emit userDataChanged(m_user, m_friendsList);
 }
 
-void SituareService::updateLocation(const GeoCoordinate &coordinates, const QString &status,
-                                    const bool &publish)
+QString SituareService::degreesToString(double degrees)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString urlParameters = formUrlParameters(coordinates, status, publish);
-    QUrl url = formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
+    // one scene pixel is about 5.4e-6 degrees, the integer part is max three digits and one
+    // additional digit is added for maximum precision
+    const int PRECISION = 10;
+
+    return QString::number(degrees, 'f', PRECISION);
+}
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+void SituareService::fetchLocations()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    sendRequest(url, COOKIE, cookie);
+    QHash<QString, QString> parameters;
+    parameters.insert("extra_user_data", NORMAL_SIZE_PROFILE_IMAGE);
+
+    buildRequest(GET_LOCATIONS, parameters);
 }
 
 QString SituareService::formCookie(const QString &apiKeyValue, QString expiresValue,
@@ -222,76 +272,44 @@ QString SituareService::formUrlParameters(const GeoCoordinate &coordinates, QStr
     return parameters;
 }
 
-void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QNetworkRequest request;
-
-    request.setUrl(url);
-    request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
-    request.setRawHeader(cookieType.toAscii(), cookie.toUtf8());
-
-    QNetworkReply *reply = m_networkManager->get(request, true);
-
-    m_currentRequests.append(reply);
-}
-
-void SituareService::requestFinished(QNetworkReply *reply)
+void SituareService::imageReceived(const QUrl &url, const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << "Image URL: " << url << " size :" << image.size();
 
-    //Reply from situare
-    if (m_currentRequests.contains(reply)) {
-
-        qDebug() << "BytesAvailable: " << reply->bytesAvailable();
-
-        if (reply->error()) {
-            emit error(ErrorContext::NETWORK, reply->error());
-        } else {
-            QByteArray replyArray = reply->readAll();
-            qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
-
-            if(replyArray == ERROR_LAT.toAscii()) {
-                qDebug() << "Error: " << ERROR_LAT;
-                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
-            } else if(replyArray == ERROR_LON.toAscii()) {
-                qDebug() << "Error: " << ERROR_LON;
-                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
-            } else if(replyArray.contains(ERROR_SESSION.toAscii())) {
-                qDebug() << "Error: " << ERROR_SESSION;
-                emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
-            } else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
-                qDebug() << "JSON string";
-                parseUserData(replyArray);
-            } else if(replyArray.isEmpty()) {
-                if(reply->url().toString().contains(UPDATE_LOCATION.toAscii())) {
-                    emit updateWasSuccessful();
-                } else {
-                    // session credentials are invalid
-                    emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
-                }
-            } else {
-                // unknown reply
-                emit error(ErrorContext::SITUARE, SituareError::ERROR_GENERAL);
+    // assign facebook silhouette image to all who doesn't have a profile image
+    if(url == QUrl(SILHOUETTE_URL)) {
+        if(m_user->profileImageUrl().isEmpty()) {
+            m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
+            emit imageReady(m_user);
+        }
+        foreach(User *friendItem, m_friendsList) {
+            if(friendItem->profileImageUrl().isEmpty()) {
+                friendItem->setProfileImage(AvatarImage::create(image, AvatarImage::Small));
+                emit imageReady(friendItem);
             }
         }
-        m_currentRequests.removeAll(reply);
-        reply->deleteLater();
     }
-}
 
-void SituareService::credentialsReady(const FacebookCredentials &credentials)
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    if (m_user->profileImageUrl() == url) {
+        m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
+        emit imageReady(m_user);
+    }
 
-    m_credentials = credentials;
+    foreach(User *friendItem, m_friendsList) {
+        if(friendItem->profileImageUrl() == url) {
+            friendItem->setProfileImage(AvatarImage::create(image, AvatarImage::Small));
+            emit imageReady(friendItem);
+        }
+    }
 }
 
 void SituareService::parseUserData(const QByteArray &jsonReply)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    qWarning() << __PRETTY_FUNCTION__ << "Server reply:" << jsonReply;
+
     m_defaultImage = false;
 
     QJson::Parser parser;
@@ -448,57 +466,113 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
     }
 }
 
-void SituareService::imageReceived(const QUrl &url, const QPixmap &image)
+void SituareService::requestFinished(QNetworkReply *reply)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    qDebug() << "Image URL: " << url << " size :" << image.size();
 
-    // assign facebook silhouette image to all who doesn't have a profile image
-    if(url == QUrl(SILHOUETTE_URL)) {
-        if(m_user->profileImageUrl().isEmpty()) {
-            m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
-            emit imageReady(m_user);
-        }
-        foreach(User *friendItem, m_friendsList) {
-            if(friendItem->profileImageUrl().isEmpty()) {
-                friendItem->setProfileImage(AvatarImage::create(image, AvatarImage::Small));
-                emit imageReady(friendItem);
+    //Reply from situare
+    if (m_currentRequests.contains(reply)) {
+
+        qDebug() << "BytesAvailable: " << reply->bytesAvailable();
+
+        if (reply->error()) {
+            emit error(ErrorContext::NETWORK, reply->error());
+        } else {
+            QByteArray replyArray = reply->readAll();
+            qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
+
+            if(replyArray == ERROR_LAT.toAscii()) {
+                qDebug() << "Error: " << ERROR_LAT;
+                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
+            } else if(replyArray == ERROR_LON.toAscii()) {
+                qDebug() << "Error: " << ERROR_LON;
+                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
+            } else if(replyArray.contains(ERROR_SESSION.toAscii())) {
+                qDebug() << "Error: " << ERROR_SESSION;
+                emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
+            } else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
+                qDebug() << "JSON string";
+                parseUserData(replyArray);
+            } else if(replyArray.isEmpty()) {
+                if(reply->url().toString().contains(UPDATE_LOCATION.toAscii())) {
+                    emit updateWasSuccessful();
+                } else {
+                    // session credentials are invalid
+                    emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
+                }
+            } else {
+                // unknown reply
+                emit error(ErrorContext::SITUARE, SituareError::ERROR_GENERAL);
             }
         }
+        m_currentRequests.removeAll(reply);
+        reply->deleteLater();
     }
+}
 
-    if (m_user->profileImageUrl() == url) {
-        m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
-        emit imageReady(m_user);
-    }
+void SituareService::reverseGeo(const GeoCoordinate &coordinates)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    foreach(User *friendItem, m_friendsList) {
-        if(friendItem->profileImageUrl() == url) {
-            friendItem->setProfileImage(AvatarImage::create(image, AvatarImage::Small));
-            emit imageReady(friendItem);
-        }
-    }
+    QHash<QString, QString> parameters;
+    parameters.insert("lat", degreesToString(coordinates.latitude()));
+    parameters.insert("lon", degreesToString(coordinates.longitude()));
+    parameters.insert("format", "json");
+
+    buildRequest(REVERSE_GEO, parameters);
 }
 
-void SituareService::addProfileImages(const QList<QUrl> &imageUrlList)
+void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    foreach(QUrl url, imageUrlList) {
-        emit fetchImage(url);
+    QNetworkRequest request;
+
+    request.setUrl(url);
+    request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
+    request.setRawHeader(cookieType.toAscii(), cookie.toUtf8());
+
+    QNetworkReply *reply = m_networkManager->get(request, true);
+
+    m_currentRequests.append(reply);
+}
+
+void SituareService::sendRequest(const QString &requestUrl)
+{
+    qWarning() << __PRETTY_FUNCTION__ << "requestUrl" << requestUrl;
+
+    // make and send the request
+    QNetworkRequest request;
+    request.setUrl(QUrl(requestUrl));
+    request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
+    QNetworkReply *reply = m_networkManager->get(request, true);
+    m_currentRequests.append(reply);
+}
+
+void SituareService::updateSession(const QString &session)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_session = session;
+
+    foreach (QString request, m_requestsWaitingAccessToken) {
+        appendAccessToken(request);
+        sendRequest(request);
     }
+
+    m_requestsWaitingAccessToken.clear();
 }
 
-void SituareService::clearUserData()
+void SituareService::updateLocation(const GeoCoordinate &coordinates, const QString &status,
+                                    const bool &publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qDeleteAll(m_friendsList.begin(), m_friendsList.end());
-    m_friendsList.clear();
+    QHash<QString, QString> parameters;
+    parameters.insert("lat", degreesToString(coordinates.latitude()));
+    parameters.insert("lon", degreesToString(coordinates.longitude()));
+    parameters.insert("publish", publish ? "true" : "false");
+    parameters.insert("data", status); ///< @todo if !empty ???
 
-    if(m_user) {
-        delete m_user;
-        m_user = 0;
-    }
-    emit userDataChanged(m_user, m_friendsList);
+    buildRequest(UPDATE_LOCATION, parameters);
 }
index d34b357..a860340 100644 (file)
@@ -24,7 +24,7 @@
 #define SITUARESERVICE_H
 
 #include <QObject>
-#include "../facebookservice/facebookcredentials.h"
+
 #include "../user/user.h"
 #include "imagefetcher.h"
 
@@ -94,19 +94,14 @@ public slots:
     void clearUserData();
 
     /**
-    * @brief Public slot, which indicates when facebook credentials are ready
-    *
-    * @param credentials New credentials
-    */
-    void credentialsReady(const FacebookCredentials &credentials);
-
-    /**
     * @brief Public slot, which indicates when http request has been completed
     *
     * @param reply storage for http reply
     */
     void requestFinished(QNetworkReply *reply);
 
+    void updateSession(const QString &session);
+
 private:
 
     /**
@@ -117,6 +112,10 @@ private:
     */
     void addProfileImages(const QList<QUrl> &imageUrlList);
 
+    void appendAccessToken(QString &requestUrl);
+
+    QString degreesToString(double degrees);
+
     /**
     * @brief Forms a http cookie
     *
@@ -171,6 +170,11 @@ private:
     */
     void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
 
+
+    void buildRequest(const QString &script, const QHash<QString,QString> &parameters);
+
+    void sendRequest(const QString &requestUrl);
+
 private slots:
 
     /**
@@ -239,11 +243,13 @@ private:
     bool m_defaultImage;    ///< Indicates if some of the friends/user doesn't have a image
 
     QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
+    QList<QString> m_requestsWaitingAccessToken;
     QList<User *> m_friendsList;                ///< List of friends(User)
 
+    QString m_session;
+
     NetworkAccessManager *m_networkManager;    ///< Pointer to QNetworkAccessManager
 
-    FacebookCredentials m_credentials;          ///< handle for FacebookCredentials
     ImageFetcher *m_imageFetcher;               ///< Instance of the image fetcher
     User *m_user;                               ///< Pointer to User
 };
index a678492..1fcb5b7 100644 (file)
@@ -15,7 +15,6 @@ SOURCES += main.cpp \
     engine/engine.cpp \
     engine/mce.cpp \
     facebookservice/facebookauthentication.cpp \
-    facebookservice/facebookcredentials.cpp \
     gps/gpsposition.cpp \
     map/baselocationitem.cpp \
     map/friendgroupitem.cpp \
@@ -85,7 +84,8 @@ SOURCES += main.cpp \
     ui/zoombutton.cpp \
     ui/zoombuttonpanel.cpp \
     user/user.cpp \
-    ui/listitemcontextbuttonbar.cpp
+    ui/listitemcontextbuttonbar.cpp \
+    ui/facebookloginbrowser.cpp
 HEADERS += application.h \
     common.h \
     coordinates/geocoordinate.h \
@@ -96,7 +96,6 @@ HEADERS += application.h \
     error.h \
     facebookservice/facebookauthentication.h \
     facebookservice/facebookcommon.h \
-    facebookservice/facebookcredentials.h \
     gps/gpscommon.h \
     gps/gpsposition.h \
     map/baselocationitem.h \
@@ -173,7 +172,8 @@ HEADERS += application.h \
     ui/zoombutton.h \
     ui/zoombuttonpanel.h \
     user/user.h \
-    ui/listitemcontextbuttonbar.h
+    ui/listitemcontextbuttonbar.h \
+    ui/facebookloginbrowser.h
 QT += network \
     webkit
 DEFINES += QT_NO_DEBUG_OUTPUT
diff --git a/src/ui/facebookloginbrowser.cpp b/src/ui/facebookloginbrowser.cpp
new file mode 100644 (file)
index 0000000..917a55b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#include <QDebug>
+
+#include "network/networkcookiejar.h"
+
+#include "facebookloginbrowser.h"
+
+FacebookLoginBrowser::FacebookLoginBrowser(QWidget *parent) :
+    QWebView(parent)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    setWindowFlags(Qt::Dialog);
+    setWindowTitle(tr("Login"));
+
+    page()->networkAccessManager()->setCookieJar(new NetworkCookieJar());
+}
diff --git a/src/ui/facebookloginbrowser.h b/src/ui/facebookloginbrowser.h
new file mode 100644 (file)
index 0000000..3b5ca45
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+
+#ifndef FACEBOOKLOGINBROWSER_H
+#define FACEBOOKLOGINBROWSER_H
+
+#include <QWebView>
+
+class FacebookLoginBrowser : public QWebView
+{
+    Q_OBJECT
+public:
+    explicit FacebookLoginBrowser(QWidget *parent = 0);
+
+};
+
+#endif // FACEBOOKLOGINBROWSER_H
index 6a8cdd0..5b2c911 100644 (file)
@@ -248,8 +248,7 @@ void LocationSearchPanel::showEmptyPanel(bool show)
         m_noSearchLabel->show();
         m_searchHistoryListView->hide();
         m_locationListView->hide();
-    }
-    else {
+    } else {
         m_noSearchLabel->hide();
         m_resultsLabel->show();
     }
index 959936b..14a5a4d 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "common.h"
 #include "error.h"
+#include "facebookloginbrowser.h"
 #include "facebookservice/facebookauthentication.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
@@ -77,6 +78,7 @@ MainWindow::MainWindow(QWidget *parent)
       m_email(), ///< @todo WTF?!?!?!?
       m_password(),
       m_webView(0),
+      m_facebookLoginBrowser(0),
       m_fullScreenButton(0),
       m_indicatorButtonPanel(0),
       m_mapScale(0),
@@ -167,6 +169,18 @@ void MainWindow::buildCrosshair()
             this, SLOT(mapCenterHorizontalShiftingChanged(int)));
 }
 
+void MainWindow::buildFacebookLoginBrowser()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if (!m_facebookLoginBrowser)
+        m_facebookLoginBrowser = new FacebookLoginBrowser(this);
+
+    m_facebookLoginBrowser->show();
+
+    emit loginBrowserCreated(m_facebookLoginBrowser);
+}
+
 void MainWindow::buildFriendListPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -529,7 +543,7 @@ void MainWindow::clearCookieJar()
     QList<QNetworkCookie> emptyList;
     emptyList.clear();
 
-    m_cookieJar->setAllCookies(emptyList);
+//    m_cookieJar->setAllCookies(emptyList);
     m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
 }
 
@@ -562,6 +576,16 @@ void MainWindow::createMenus()
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
+void MainWindow::destroyFacebookLoginBrowser()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_facebookLoginBrowser->hide();
+    m_facebookLoginBrowser->disconnect();
+    m_facebookLoginBrowser->deleteLater();
+    m_facebookLoginBrowser = 0;
+}
+
 void MainWindow::dialogFinished(int status)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -570,6 +594,7 @@ void MainWindow::dialogFinished(int status)
     LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
     SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
     if(loginDialog) {
+        /// @todo Remove login related code
         if(status != 0) {
             buildWebView();
             loginDialog->userInput(m_email, m_password);
@@ -584,7 +609,6 @@ void MainWindow::dialogFinished(int status)
             urlParts.append(SITUARE_LOGIN_FAILURE);
             urlParts.append(FACEBOOK_LOGIN_ENDING);
 
-            emit saveUsername(m_email);
             m_refresh = true;
             m_webView->load(QUrl(urlParts.join(EMPTY)));
             toggleProgressIndicator(true);
@@ -706,26 +730,27 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
     QWidget::keyPressEvent(event);
 }
 
+///< @todo remove old, duplicate loadCookies()
 void MainWindow::loadCookies()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+//    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    QStringList list = settings.value(COOKIES, EMPTY).toStringList();
+//    QStringList list = settings.value(COOKIES, EMPTY).toStringList();
 
-    if(!list.isEmpty()) {
-        QList<QNetworkCookie> cookieList;
-        for(int i=0;i<list.count();i++) {
-            cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
-        }
+//    if(!list.isEmpty()) {
+//        QList<QNetworkCookie> cookieList;
+//        for(int i=0;i<list.count();i++) {
+//            cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
+//        }
 
-        if(!m_cookieJar)
-               m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+//        if(!m_cookieJar)
+//               m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
 
-        m_cookieJar->setAllCookies(cookieList);
-        m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-    }
+//        m_cookieJar->setAllCookies(cookieList);
+//        m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+//    }
 }
 
 void MainWindow::loadDone(bool done)
@@ -894,25 +919,26 @@ void MainWindow::readAutomaticLocationUpdateSettings()
     }
 }
 
+///< @todo remove old, duplicate saveCookies()
 void MainWindow::saveCookies()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(!m_cookieJar)
-        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+//    if(!m_cookieJar)
+//        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
 
-    QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
-    QStringList list;
+//    QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
+//    QStringList list;
 
-    for(int i=0;i<cookieList.count();i++) {
-        QNetworkCookie cookie = cookieList.at(i);
-        QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
-        list.append(QString(byteArray));
-    }
-    list.removeDuplicates();
+//    for(int i=0;i<cookieList.count();i++) {
+//        QNetworkCookie cookie = cookieList.at(i);
+//        QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
+//        list.append(QString(byteArray));
+//    }
+//    list.removeDuplicates();
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(COOKIES, list);
+//    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+//    settings.setValue(COOKIES, list);
 }
 
 void MainWindow::setCrosshairVisibility(bool visibility)
@@ -955,13 +981,6 @@ void MainWindow::settingsDialogAccepted()
     readAutomaticLocationUpdateSettings();
 }
 
-void MainWindow::setUsername(const QString &username)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_email = username;
-}
-
 void MainWindow::showContactDialog(const QString &guid)
 {
     qDebug() << __PRETTY_FUNCTION__;
index d07bbc7..95e58e3 100644 (file)
@@ -41,6 +41,7 @@ class QToolButton;
 class QWebView;
 
 class FacebookAuthentication;
+class FacebookLoginBrowser;
 class FriendListPanel;
 class FullScreenButton;
 class GeoCoordinate;
@@ -156,6 +157,10 @@ public:
     const QString username();
 
 public slots:
+    void buildFacebookLoginBrowser();
+
+    void destroyFacebookLoginBrowser();
+
     /**
      * @brief Builds information box with message.
      *
@@ -187,13 +192,6 @@ public slots:
     void setCrosshairVisibility(bool visible);
 
     /**
-     * @brief Sets username to member variable for login dialog
-     *
-     * @param username Username to be set
-     */
-    void setUsername(const QString &username);
-
-    /**
     * @brief Shows contact dialog.
     *
     * Shows contact dialog with contact's information.
@@ -542,6 +540,8 @@ signals:
      */
     void loginActionPressed();
 
+    void loginBrowserCreated(FacebookLoginBrowser *);
+
     /**
      * @brief MapView has been resized
      *
@@ -617,13 +617,6 @@ signals:
     void routeToCursor();
 
     /**
-     * @brief Signal to save username to settings
-     *
-     * @param username Username
-     */
-    void saveUsername(const QString &username);
-
-    /**
      * @brief Signal for location search
      *
      * @param location QString location
@@ -721,6 +714,7 @@ private:
 
     QWebView *m_webView;                    ///< Shows facebook login page
 
+    FacebookLoginBrowser *m_facebookLoginBrowser;
     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button