#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
{
*
* -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();
+ void clearAccountInformation(bool keepUsername = false);
-private:
-
- /**
- * @brief Creates login url with given parameters
- *
- * @param urlParts Url parts
- * @return QUrl Login page url
- */
- QUrl formLoginPageUrl(const QStringList & urlParts) const;
+private:
+ QString parseSession(const QUrl &url);
private slots:
+ void browserDestroyed();
- /**
- * @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 loadFinished(bool ok);
+
+ void networkReplyHandler(QNetworkReply *reply);
+
+ 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 credentials New credentials
- */
- void credentialsReady(const FacebookCredentials &credentials);
-
/**
- * @brief This signal is emitted if updateCredentials method can't find credentials from URL
+ * @brief Signals error
*
+ * @param context error context
+ * @param error error code
*/
- void loginFailure();
+ void error(const int context, const int error);
- void loginUsingCookies();
-
- /**
- * @brief Signals when credentials are invalid new login is needed
- *
- * @param url Login page url
- */
- void newLoginRequest(const QUrl &url);
-
- void saveCookiesRequest();
+ 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