Removed FacebookLoginBrowser class, replaced with QWebView.
[situare] / src / facebookservice / facebookauthentication.h
index 785d909..5d12838 100644 (file)
@@ -4,6 +4,7 @@
 
        Ville Tiensuu - ville.tiensuu@ixonos.com
        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
 #ifndef FACEBOOKAUTHENTICATION_H
 #define FACEBOOKAUTHENTICATION_H
 
-#include <QtGui>
-#include <QtWebKit>
-#include <QString>
-#include <QLayout>
-#include "facebookcredentials.h"
+#include <QUrl>
+
+class QNetworkReply;
+class QWebView;
+
+class MainWindow;
 
 /**
-* @brief FacebookAuthentication class takes care of transmitting username and password to facebook.
-*        And it also receives credentials from Facebook. Other components of Situare application
-*        needs credentials to communicate with facebook.
+* @brief FacebookAuthentication class takes care of Facebook login process. It creates
+         QWebView instance and tries to login with cookies using hidden browser.
+         If failed, then visible login browser dialog is invoked. Class also does parse the
+         accuired credentials.
 *
 * @author Ville Tiensuu
-* @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
+* @author Sami Rämö - sami.ramo (at) ixonos.com
 */
-class FacebookAuthentication : public QMainWindow
+class FacebookAuthentication : public QObject
 {
     Q_OBJECT
 
@@ -45,138 +48,60 @@ public:
     /**
     * @brief FacebookAuthentication constructor
     *
-    * -Composes Loginpage from pieces of strings.
-    * -Checks if there is valid credentials stored on the file. If there is emits signal. If not it
-    *  calls start method.
-    * -Connects signal from m_webView to UpdateCredentials() method. With this feature it is
-    *  verified that class tries always update credentials when web page changes.
-    * -Allocates memory for m_webView and m_mainlayout
+    * -Checks if there is valid credentials stored on the file. If there is emits signal.
     *
+    * @param mainWindow MainWindow instance
     * @param parent instance of parent
     */
-    FacebookAuthentication(QWidget *parent = 0);
+    FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
 
-    /**
-    * @brief Releases allocated memory for m_webView and m_mainlayout
-    *
-    */
-    ~FacebookAuthentication();
-
-    /**
-    * @brief Getter for m_loginCredentials
-    *
-    * @return FacebookCredentials
-    */
-    FacebookCredentials loginCredentials() const;
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    void login();
 
 public slots:
-    /**
-    * @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: 
 
     /**
-    * @brief  Appends given parts to returned string. Method is used to form facebook login page
-              from given parts.
+    * @brief Clears account iformation from settings
     *
-    * @param  part1 first part of the formed string
-    * @param  part2 second part of the formed string
-    * @param  part3 third part of the formed string
-    * @param  part4 fouth part of the formed string
-    * @param  part5 fifth part of the formed string
-    * @param  part6 sixth part of the formed string
-    * @param  part7 sevents part of the formed string
+    * @param keepUsername keep = true, false otherwise
     */
-    QString formLoginPage(const QString & part1, const QString & part2, const QString & part3,
-                          const QString & part4, const QString & part5, const QString & part6,
-                          const QString & part7) const;
+    void clearAccountInformation(bool keepUsername = false);
 
-    /**
-    * @brief Reads previous stored credentials from file.
-    *
-    * @param credentialsFromFile This dataclass is the place where method stores credentials.
-    *        Corrent parameter here is m_loginCredentials
-    */
-    void readCredentials(FacebookCredentials &credentialsFromFile);
-
-    /**
-    * @brief Checks expiration time of credentials and compares it to current time.
-    *
-    * @param credentials this parameter represents credentials that will be verified.
-    * @return bool returns true if expiration time is after current time. in other cases returns
-    *               false.
-    */
-    bool verifyCredentials(const FacebookCredentials &credentials) const;   
-
-    /**
-    * @brief Writes credentials to File
-    *
-    * @param credentials Contents of this dataclass is stored to file
-    */
-    void writeCredentials(const FacebookCredentials &credentials);
+private:
+    QString parseSession(const QUrl &url);
 
 private slots:
-    /**
-    * @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);
-
-signals:
-
-    /**
-    * @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);
+    void browserDestroyed();
 
-    /**
-    * @brief This signal is emitted if updateCredentials method can't find credentials from URL
-    *
-    */
-    void loginFailure();
+    void loadFinished(bool ok);
 
-private:
+    void networkReplyHandler(QNetworkReply *reply);
 
-    /**
-    * @brief String that contantains URL of facebook loginpage.
-    *
-    * @var m_facebookLoginPage
-    */
-    QString m_facebookLoginPage;
+    void urlChanged(const QUrl &url);
 
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
     /**
-    * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
-    *        QStrings and setters and getters.
+    * @brief Signals error
     *
-    * @var m_loginCredentials
+    * @param context error context
+    * @param error error code
     */
-    FacebookCredentials m_loginCredentials;
+    void error(const int context, const int error);
 
-    /**
-    * @brief Lays out m_webView in window.
-    *
-    * @var m_mainlayout
-    */
-    QHBoxLayout *m_mainlayout;
+    void loggedIn(const QString session);
 
-    /**
-    * @brief Shows facebook login page.
-    *
-    * @var m_webView
-    */
-    QWebView *m_webView;
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    QWebView *m_browser;
+    MainWindow *m_mainWindow;
 };
 
 #endif // FACEBOOKAUTHENTICATION_H