Added wallPostPermission parameter to loggedIn signal
[situare] / src / facebookservice / facebookauthentication.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Ville Tiensuu - ville.tiensuu@ixonos.com
6        Kaj Wallin - kaj.wallin@ixonos.com
7        Henri Lampela - henri.lampela@ixonos.com
8
9    Situare is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as published by the Free Software Foundation.
12
13    Situare is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Situare; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21    USA.
22 */
23
24 #ifndef FACEBOOKAUTHENTICATION_H
25 #define FACEBOOKAUTHENTICATION_H
26
27 #include <QUrl>
28
29 class QNetworkReply;
30 class QSslError;
31 class QWebView;
32
33 class MainWindow;
34
35 /**
36 * @brief FacebookAuthentication class takes care of Facebook login process. It creates
37          QWebView instance and tries to login with cookies using hidden browser.
38          If failed, then visible login browser dialog is invoked. Class also does parse the
39          accuired credentials.
40 *
41 * @author Ville Tiensuu
42 * @author Sami Rämö - sami.ramo (at) ixonos.com
43 */
44 class FacebookAuthentication : public QObject
45 {
46     Q_OBJECT
47
48 public:
49     /**
50     * @brief Constructor
51     *
52     * Initiates internal data members.
53     *
54     * @param mainWindow MainWindow instance
55     * @param parent Instance of the parent
56     */
57     FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
58
59 /*******************************************************************************
60  * MEMBER FUNCTIONS AND SLOTS
61  ******************************************************************************/
62 public slots:
63     /**
64     * @brief Clears account information from settings
65     *
66     * @param clearUserInformation True if user information should be cleared
67     */
68     void clearAccountInformation(bool clearUserInformation = false);
69
70     /**
71       * @brief Is the user currently logged in
72       *
73       * @returns True if the user is logged in, otherwise false
74       */
75     bool isLoggedIn() const;
76
77     /**
78       * @brief Initiate login process
79       *
80       * Builds login browser and starts loading login URL.
81       */
82     void login();
83
84     /**
85       * @brief Log out
86       *
87       * @param clearUserInformation True if user information should be cleared
88       */
89     void logOut(bool clearUserInformation = false);
90
91 private:
92     /**
93       * @brief Destroy login dialog and browser
94       */
95     void destroyLogin();
96
97     /**
98       * @brief Parses the session information from the URL
99       *
100       * @param url URL
101       * @returns Parsed session, or empty string if parsing failed.
102       */
103     QString parseSession(const QUrl &url);
104
105 private slots:
106     /**
107       * @brief Cleanup after browser is destructed
108       *
109       * Clears the pointer to the browser and disables the progress indicator.
110       */
111     void browserDestroyed();
112
113     /**
114       * @brief Handler for login page loading errors
115       *
116       * @param reply Network reply
117       */
118     void networkReplyHandler(QNetworkReply *reply);
119
120     /**
121       * @brief Handler for SSL errors, ignores the error
122       */
123     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
124
125     /**
126       * @brief Handler for browser URL changes
127       *
128       * Does check the new URL and based on that invokes the login dialog with visible browser view
129       * or parses the session from the new URL.
130       *
131       * @param url New URL
132       */
133     void urlChanged(const QUrl &url);
134
135 /*******************************************************************************
136  * SIGNALS
137  ******************************************************************************/
138 signals:
139     /**
140     * @brief Signals error
141     *
142     * @param context error context
143     * @param error error code
144     */
145     void error(const int context, const int error);
146
147     /**
148       * @brief Emitted when logged in successfully
149       *
150       * All login related actions should be connected to this signal.
151       *
152       * @param session Session data
153       * @param wallPostPermission Has the user granted rights for posting to wall
154       */
155     void loggedIn(const QString session, bool wallPostPermission);
156
157     /**
158       * @brief Emitted when logged out
159       *
160       * All logout related actions should be connected to this signal.
161       */
162     void loggedOut();
163
164 /*******************************************************************************
165  * DATA MEMBERS
166  ******************************************************************************/
167 private:
168     bool m_loggedIn;                ///< Is the user currently logged in
169     QWebView *m_browser;            ///< Login browser
170     MainWindow *m_mainWindow;       ///< MainWindow
171 };
172
173 #endif // FACEBOOKAUTHENTICATION_H