#include <QUrl>
class QNetworkReply;
+class QSslError;
+class QWebView;
-class FacebookLoginBrowser;
+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:
- void login();
-
public slots:
-
/**
- * @brief Clears account iformation from settings
+ * @brief Clears account information from settings
*
- * @param keepUsername keep = true, false otherwise
+ * @param clearUserInformation True if user information should be cleared
*/
- void clearAccountInformation(bool keepUsername = false);
+ void clearAccountInformation(bool clearUserInformation = false);
+
+ /**
+ * @brief Is the user currently logged in
+ *
+ * @returns True if the user is logged in, otherwise false
+ */
+ bool isLoggedIn() const;
- void setBrowser(FacebookLoginBrowser *browser);
+ /**
+ * @brief Initiate login process
+ *
+ * Builds login browser and starts loading login URL.
+ */
+ void login();
+
+ /**
+ * @brief Log out
+ *
+ * @param clearUserInformation True if user information should be cleared
+ */
+ void logOut(bool clearUserInformation = false);
private:
+ /**
+ * @brief Destroy login dialog and browser
+ */
+ void destroyLogin();
+
+ /**
+ * @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 slots:
+ /**
+ * @brief Cleanup after browser is destructed
+ *
+ * Clears the pointer to the browser and disables the progress indicator.
+ */
void browserDestroyed();
- void loadFinished(bool ok);
-
+ /**
+ * @brief Handler for login page loading errors
+ *
+ * @param reply Network reply
+ */
void networkReplyHandler(QNetworkReply *reply);
+ /**
+ * @brief Handler for SSL errors, ignores the error
+ */
+ void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
+
+ /**
+ * @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:
- void buildLoginBrowser();
-
/**
* @brief Signals error
*
*/
void error(const int context, const int error);
- void loggedIn(const QString session);
+ /**
+ * @brief Emitted when logged in successfully
+ *
+ * All login related actions should be connected to this signal.
+ *
+ * @param session Session data
+ * @param wallPostPermission Has the user granted rights for posting to wall
+ */
+ void loggedIn(const QString session, bool wallPostPermission);
+
+ /**
+ * @brief Emitted when logged out
+ *
+ * All logout related actions should be connected to this signal.
+ */
+ void loggedOut();
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- FacebookLoginBrowser *m_browser;
+ bool m_loggedIn; ///< Is the user currently logged in
+ QWebView *m_browser; ///< Login browser
+ MainWindow *m_mainWindow; ///< MainWindow
};
#endif // FACEBOOKAUTHENTICATION_H