Removed FacebookLoginBrowser class, replaced with QWebView.
[situare] / src / facebookservice / facebookauthentication.h
index 653c2fd..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,147 +50,58 @@ 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:
 
     /**
-    * @brief Loads username from settings
-    *
-    * @return QString Loaded username
-    */
-    const QString loadUsername();
-
-    /**
-    * @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();
-
-    /**
     * @brief Clears account iformation from settings
     *
+    * @param keepUsername keep = true, false otherwise
     */
-    void clearAccountInformation();
-
-private: 
-
-    /**
-    * @brief Creates login url with given parameters
-    *
-    * @param urlParts Url parts
-    * @return QUrl Login page url
-    */
-    QUrl formLoginPageUrl(const QStringList & urlParts) 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);
+private:
+    QString parseSession(const QUrl &url);
 
-    /**
-    * @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;   
+private slots:
+    void browserDestroyed();
 
-    /**
-    * @brief Writes credentials to File
-    *
-    * @param credentials Contents of this dataclass is stored to file
-    */
-    void writeCredentials(const FacebookCredentials &credentials);
+    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 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 freshLogin Was login done via login dialog
-    * @param credentials New credentials
-    */
-    void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
-
     /**
-    * @brief Signals changed credentials
+    * @brief Signals error
     *
-    * @param credentials New credentials
+    * @param context error context
+    * @param error error code
     */
-    void credentialsChanged(const FacebookCredentials &credentials);
+    void error(const int context, const int error);
 
-    /**
-    * @brief This signal is emitted if updateCredentials method can't find credentials from URL
-    *
-    */
-    void loginFailure();
-
-    /**
-    * @brief Signals when credentials are invalid new login is needed
-    *
-    * @param url Login page url
-    */
-    void newLoginRequest(const QUrl &url);
+    void loggedIn(const QString session);
 
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
-
 private:
-
-    int m_loginAttempts; ///< Indicates login attempts
-
-    /**
-    * @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