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 <QHash>
-#include <QString>
-#include <QLayout>
+#include <QUrl>
#include "facebookcredentials.h"
/**
-* @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 parsing and handling of credentials for
+* Facebook. Other components of Situare application needs credentials to communicate with
+* facebook.
*
-* @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
+* @author Ville Tiensuu
*/
-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 webview to UpdateCredentials() method. With this feature it is verified that class tries always update credentials when web page changes.
- * -Allocates memory for webView and mainlayout
+ * -Checks if there is valid credentials stored on the file. If there is emits signal.
*
- * @fn FacebookAuthentication
- * @param parent
+ * @param parent instance of parent
*/
- FacebookAuthentication(QWidget *parent = 0);
+ FacebookAuthentication(QObject *parent = 0);
- /**
- * @brief Releases allocated memory for webView and mainLayout
- *
- * @fn ~FacebookAuthentication
- */
- ~FacebookAuthentication();
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
/**
- * @brief Getter for loginCredentials
+ * @brief Getter for m_loginCredentials
*
- * @fn getLoginCredentials
* @return FacebookCredentials
*/
- FacebookCredentials getLoginCredentials() const;
+ FacebookCredentials loginCredentials() const;
public slots:
+
/**
- * @brief shows the webView and loads page that is specified in the facebookLoginPage variable. Specifies font size for the page.
+ * @brief Loads username from settings
*
- * @fn start
+ * @return QString Loaded username
*/
- void start();
+ const QString loadUsername();
-private slots:
/**
- * @brief search credentials from URL that is given parameter. If credentials are found thay are stored to loginCredentials variable.
+ * @brief Saves username to settings
*
- * @fn updateCredentials
- * @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 username Username to be saved
*/
- bool updateCredentials(const QUrl & url);
+ void saveUsername(const QString &username);
-signals:
+ /**
+ * @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 this signal is emitted if user exits logging in by pressing X
+ * @brief Clears account iformation from settings
*
- * @fn userExit
+ * @param keepUsername true = keep username
*/
- void userExit();
+ void clearAccountInformation(bool keepUsername = false);
+
+private:
/**
- * @brief this signal is emitted 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 Creates login url with given parameters
*
- * @fn credentialsReady
+ * @param urlParts Url parts
+ * @return QUrl Login page url
*/
- void credentialsReady();
+ QUrl formLoginPageUrl(const QStringList & urlParts) const;
/**
- * @brief this signal is emitted if updateCredentials method can't find credentials from URL
+ * @brief Reads previous stored credentials from file.
*
- * @fn loginFailure
+ * @param credentialsFromFile This dataclass is the place where method stores credentials.
+ * Corrent parameter here is m_loginCredentials
*/
- void loginFailure();
-
-private:
+ void readCredentials(FacebookCredentials &credentialsFromFile);
/**
- * @brief Program cames to this method when user closes login screen by pressing X.
- * method send userExit() signal in this function
+ * @brief Checks expiration time of credentials and compares it to current time.
*
- * @fn closeEvent
- * @param event, without parameter programs does not come to this function when user exits by pressing X.
+ * @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.
*/
- void closeEvent(QCloseEvent *event);
+ bool verifyCredentials(const FacebookCredentials &credentials) const;
/**
- * @brief checks expiration time of credentials and compares it to current time.
+ * @brief Writes credentials to File
*
- * @fn verifyCredentials
- * @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.
+ * @param credentials Contents of this dataclass is stored to file
*/
- bool verifyCredentials(const FacebookCredentials &credentials) const;
+ void writeCredentials(const FacebookCredentials &credentials);
+
+private slots:
/**
- * @brief Reads previous stored credentials from file.
+ * @brief Search credentials from URL that is given as parameter.
+ * If credentials are found thay are stored to loginCredentials variable.
*
- * @fn readCredentials
- * @param credentialsFromFile, This dataclass is the place where method stores credentials. Corrent parameter here is loginCredentials (private member of FacebookAuthentication class)
+ * @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.
*/
- void readCredentials(FacebookCredentials &credentialsFromFile);
+ bool updateCredentials(const QUrl & url);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+
+signals:
/**
- * @brief Writes credentials to File
+ * @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.
*
- * @fn writeCredentials
- * @param credentials, Contents of this dataclass is stored to file
+ * @param freshLogin Was login done via login dialog
+ * @param credentials New credentials
*/
- void writeCredentials(const FacebookCredentials &credentials);
+ void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
/**
- * @brief, shows facebook login page.
+ * @brief Signals changed credentials
*
- * @var webView
+ * @param credentials New credentials
*/
- QWebView *webView;
+ void credentialsChanged(const FacebookCredentials &credentials);
/**
- * @brief, lays out webview in window.
+ * @brief This signal is emitted if updateCredentials method can't find credentials from URL
*
- * @var mainlayout
*/
- QHBoxLayout *mainlayout;
+ void loginFailure();
/**
- * @brief string that contantains URL of facebook loginpage.
+ * @brief Signals when credentials are invalid new login is needed
*
- * @var facebookLoginPage
+ * @param url Login page url
*/
- QString facebookLoginPage;
+ void newLoginRequest(const QUrl &url);
+
+/*******************************************************************************
+ * 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.
+ * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
+ * QStrings and setters and getters.
*
- * @var loginCredentials
+ * @var m_loginCredentials
*/
- FacebookCredentials loginCredentials;
+ FacebookCredentials m_loginCredentials;
};
#endif // FACEBOOKAUTHENTICATION_H