#define FACEBOOKAUTHENTICATION_H
#include <QUrl>
-#include "facebookcredentials.h"
+
+class QNetworkReply;
+class QSslError;
+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
{
public:
/**
- * @brief FacebookAuthentication constructor
+ * @brief Constructor
*
- * -Checks if there is valid credentials stored on the file. If there is emits signal.
+ * Initiates internal data members.
*
- * @param parent instance of parent
+ * @param mainWindow MainWindow instance
+ * @param parent Instance of the parent
*/
- FacebookAuthentication(QObject *parent = 0);
+ FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-
+public slots:
/**
- * @brief Getter for m_loginCredentials
+ * @brief Clears account information from settings
*
- * @return FacebookCredentials
+ * @param keepUsername keep = true, false otherwise
*/
- FacebookCredentials loginCredentials() const;
+ void clearAccountInformation(bool keepUsername = false);
-public slots:
+ /**
+ * @brief Is the user currently logged in
+ *
+ * @returns True if the user is logged in, otherwise false
+ */
+ bool isLoggedIn();
/**
- * @brief Clears account iformation from settings
- *
- */
- void clearAccountInformation();
+ * @brief Initiate login process
+ *
+ * Builds login browser and starts loading login URL.
+ */
+ void login();
/**
- * @brief Loads username from settings
- *
- * @return QString Loaded username
- */
- const QString loadUsername();
+ * @brief Log out
+ */
+ void logOut();
+private:
/**
- * @brief Saves username to settings
- *
- * @param username Username to be saved
- */
- void saveUsername(const QString &username);
+ * @brief Destroy login dialog and browser
+ */
+ void destroyLogin();
/**
- * @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 Parses the session information from the URL
+ *
+ * @param url URL
+ * @returns Parsed session, or empty string if parsing failed.
+ */
+ QString parseSession(const QUrl &url);
-private:
+private slots:
+ /**
+ * @brief Cleanup after browser is destructed
+ *
+ * Clears the pointer to the browser and disables the progress indicator.
+ */
+ void browserDestroyed();
/**
- * @brief Creates login url with given parameters
- *
- * @param urlParts Url parts
- * @return QUrl Login page url
- */
- QUrl formLoginPageUrl(const QStringList & urlParts) const;
+ * @brief Handler for login page loading errors
+ *
+ * @param reply Network reply
+ */
+ void networkReplyHandler(QNetworkReply *reply);
-private slots:
+ /**
+ * @brief Handler for SSL errors, ignores the error
+ */
+ void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
/**
- * @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);
+ * @brief Handler for browser URL changes
+ *
+ * Does check the new URL and based on that invokes the login dialog with visible browser view
+ * or parses the session from the new URL.
+ *
+ * @param url New 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.
+ * @brief Signals error
*
- * @param credentials New credentials
+ * @param context error context
+ * @param error error code
*/
- void credentialsReady(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();
-
- void loginUsingCookies();
+ * @brief Emitted when logged in successfully
+ *
+ * All login related actions should be connected to this signal.
+ *
+ * @param session Session data
+ */
+ void loggedIn(const QString session);
/**
- * @brief Signals when credentials are invalid new login is needed
- *
- * @param url Login page url
- */
- void newLoginRequest(const QUrl &url);
-
- void saveCookiesRequest();
+ * @brief Emitted when logged out
+ *
+ * All logout related actions should be connected to this signal.
+ */
+ void loggedOut();
/*******************************************************************************
* 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;
+ bool m_loggedIn; ///< Is the user currently logged in
+ QWebView *m_browser; ///< Login browser
+ MainWindow *m_mainWindow; ///< MainWindow
};
#endif // FACEBOOKAUTHENTICATION_H