Changes to logout prosess and login state storing, logout bug fix
[situare] / src / facebookservice / facebookauthentication.h
index 5d12838..28725bd 100644 (file)
@@ -27,6 +27,7 @@
 #include <QUrl>
 
 class QNetworkReply;
+class QSslError;
 class QWebView;
 
 class MainWindow;
@@ -46,40 +47,87 @@ 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 mainWindow MainWindow instance
-    * @param parent instance of parent
+    * @param parent Instance of the parent
     */
     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
     */
     void clearAccountInformation(bool keepUsername = false);
 
+    /**
+      * @brief Is the user currently logged in
+      *
+      * @returns True if the user is logged in, otherwise false
+      */
+    bool isLoggedIn();
+
+    /**
+      * @brief Initiate login process
+      *
+      * Builds login browser and starts loading login URL.
+      */
+    void login();
+
+    /**
+      * @brief Log out
+      */
+    void logOut();
+
 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);
 
 /*******************************************************************************
@@ -94,14 +142,29 @@ signals:
     */
     void error(const int context, const int error);
 
+    /**
+      * @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 Emitted when logged out
+      *
+      * All logout related actions should be connected to this signal.
+      */
+    void loggedOut();
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QWebView *m_browser;
-    MainWindow *m_mainWindow;
+    bool m_loggedIn;                ///< Is the user currently logged in
+    QWebView *m_browser;            ///< Login browser
+    MainWindow *m_mainWindow;       ///< MainWindow
 };
 
 #endif // FACEBOOKAUTHENTICATION_H