Removed FacebookLoginBrowser class, replaced with QWebView.
[situare] / src / facebookservice / facebookauthentication.h
index 4ffea66..5d12838 100644 (file)
 #define FACEBOOKAUTHENTICATION_H
 
 #include <QUrl>
-#include "facebookcredentials.h"
+
+class QNetworkReply;
+class QWebView;
+
+class MainWindow;
 
 /**
-* @brief FacebookAuthentication class takes care of parsing and handling of  credentials for
-*        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
+* @author Sami Rämö - sami.ramo (at) ixonos.com
 */
 class FacebookAuthentication : public QObject
 {
@@ -44,20 +50,16 @@ public:
     *
     * -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(QObject *parent = 0);
+    FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
-
-    /**
-    * @brief Getter for m_loginCredentials
-    *
-    * @return FacebookCredentials
-    */
-    FacebookCredentials loginCredentials() const;
+public:
+    void login();
 
 public slots:
 
@@ -68,101 +70,38 @@ public slots:
     */
     void clearAccountInformation(bool keepUsername = false);
 
-    /**
-    * @brief Loads username from settings
-    *
-    * @return QString Loaded username
-    */
-    const QString loadUsername();
+private:
+    QString parseSession(const QUrl &url);
 
-    /**
-    * @brief Saves username to settings
-    *
-    * @param username Username to be saved
-    */
-    void saveUsername(const QString &username);
+private slots:
+    void browserDestroyed();
 
-    /**
-    * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
-    *        variable. Specifies font size for the page.
-    *    
-    */
-    void start();
+    void loadFinished(bool ok);
 
-private slots:
+    void networkReplyHandler(QNetworkReply *reply);
 
-    /**
-    * @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 urlChanged(const QUrl &url);
 
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
-
 signals:
-
     /**
     * @brief Signals error
     *
-    * @param error error message
-    */
-    void error(const QString &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 if updateCredentials method can't find credentials from URL
-    *
-    */
-    void loginFailure();
-
-    /**
-    * @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
-    *
+    * @param context error context
+    * @param error error code
     */
-    void newLoginRequest();
+    void error(const int context, const int error);
 
-    /**
-    * @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;
-
-    /**
-    * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
-    *        QStrings and setters and getters.
-    *
-    * @var m_loginCredentials
-    */
-    FacebookCredentials m_loginCredentials;
+    QWebView *m_browser;
+    MainWindow *m_mainWindow;
 };
 
 #endif // FACEBOOKAUTHENTICATION_H