Ville Tiensuu - ville.tiensuu@ixonos.com
Kaj Wallin - kaj.wallin@ixonos.com
+ Henri Lampela - henri.lampela@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#ifndef FACEBOOKAUTHENTICATION_H
#define FACEBOOKAUTHENTICATION_H
-#include <QtGui>
-#include <QtWebKit>
-#include <QString>
-#include <QLayout>
-#include "facebookcredentials.h"
+#include <QUrl>
+
+class QNetworkReply;
+class QWebView;
+
+class MainWindow;
/**
-* @brief FacebookAuthentication class takes care of transmitting username and password to facebook. And it also receives credentials from 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
-* @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
+* @author Sami Rämö - sami.ramo (at) ixonos.com
*/
-class FacebookAuthentication : public QMainWindow
+class FacebookAuthentication : public QObject
{
Q_OBJECT
/**
* @brief FacebookAuthentication constructor
*
- * -Composes Loginpage from pieces of strings.
- * -Checks if there is valid credentials stored on the file. If there is emits signal. If not it calls start method.
- * -Connects signal from m_webView to UpdateCredentials() method. With this feature it is verified that class tries always update credentials when web page changes.
- * -Allocates memory for m_webView and m_mainlayout
+ * -Checks if there is valid credentials stored on the file. If there is emits signal.
*
- * @fn FacebookAuthentication
- * @param parent
+ * @param mainWindow MainWindow instance
+ * @param parent instance of parent
*/
- FacebookAuthentication(QWidget *parent = 0);
+ FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
- /**
- * @brief Releases allocated memory for m_webView and m_mainlayout
- *
- */
- ~FacebookAuthentication();
-
- /**
- * @brief Getter for m_loginCredentials
- *
- *
- * @return FacebookCredentials
- */
- FacebookCredentials loginCredentials() const;
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+ void login();
public slots:
- /**
- * @brief shows the m_webView and loads page that is specified in the m_facebookLoginPage variable. Specifies font size for the page.
- *
- */
- void start();
-private slots:
/**
- * @brief search credentials from URL that is given parameter. If credentials are found thay are stored to loginCredentials variable.
+ * @brief Clears account iformation from settings
*
- * @param url, URL where this method tries to find credentials.
- * @return bool, if credentials are found return true, if credentials are not found return false.
+ * @param keepUsername keep = true, false otherwise
*/
- bool updateCredentials(const QUrl & url);
-
-signals:
-
- /**
- * @brief this signal is emitted if user exits logging in by pressing X
- *
- */
- void userExit();
-
- /**
- * @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.
- *
- */
- void credentialsReady();
-
- /**
- * @brief this signal is emitted if updateCredentials method can't find credentials from URL
- *
- */
- void loginFailure();
+ void clearAccountInformation(bool keepUsername = false);
private:
+ QString parseSession(const QUrl &url);
- /**
- * @brief Program cames to this method when user closes login screen by pressing X.
- * method sends userExit() signal in this function
- *
- * @param event, without parameter programs does not come to this function when user exits by pressing X.
- */
- void closeEvent(QCloseEvent *event);
+private slots:
+ void browserDestroyed();
- /**
- * @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;
+ void loadFinished(bool ok);
- /**
- * @brief Reads previous stored credentials from file.
- *
- * @param credentialsFromFile, This dataclass is the place where method stores credentials. Corrent parameter here is m_loginCredentials (private member of FacebookAuthentication class)
- */
- void readCredentials(FacebookCredentials &credentialsFromFile);
+ void networkReplyHandler(QNetworkReply *reply);
- /**
- * @brief Writes credentials to File
- *
- * @param credentials, Contents of this dataclass is stored to file
- */
- void writeCredentials(const FacebookCredentials &credentials);
-
- /**
- * @brief, shows facebook login page.
- *
- * @var m_webView
- */
- QWebView *m_webView;
+ void urlChanged(const QUrl &url);
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
/**
- * @brief, lays out m_webView in window.
+ * @brief Signals error
*
- * @var m_mainlayout
+ * @param context error context
+ * @param error error code
*/
- QHBoxLayout *m_mainlayout;
+ void error(const int context, const int error);
- /**
- * @brief string that contantains URL of facebook loginpage.
- *
- * @var m_facebookLoginPage
- */
- QString m_facebookLoginPage;
+ void loggedIn(const QString session);
- /**
- * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five QStrings and setters and getters.
- *
- * @var m_loginCredentials
- */
- FacebookCredentials m_loginCredentials;
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+ QWebView *m_browser;
+ MainWindow *m_mainWindow;
};
#endif // FACEBOOKAUTHENTICATION_H