Emit error signal when login fails
[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 QWebView;
31
32 class MainWindow;
33
34 /**
35 * @brief FacebookAuthentication class takes care of Facebook login process. It creates
36          QWebView instance and tries to login with cookies using hidden browser.
37          If failed, then visible login browser dialog is invoked. Class also does parse the
38          accuired credentials.
39 *
40 * @author Ville Tiensuu
41 * @author Sami Rämö - sami.ramo (at) ixonos.com
42 */
43 class FacebookAuthentication : public QObject
44 {
45     Q_OBJECT
46
47 public:
48     /**
49     * @brief Constructor
50     *
51     * Initiates internal data members.
52     *
53     * @param mainWindow MainWindow instance
54     * @param parent Instance of the parent
55     */
56     FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
57
58 /*******************************************************************************
59  * MEMBER FUNCTIONS AND SLOTS
60  ******************************************************************************/
61 public:
62     /**
63       * @brief Initiate login process
64       *
65       * Builds login browser and starts loading login URL.
66       */
67     void login();
68
69 public slots:
70
71     /**
72     * @brief Clears account information from settings
73     *
74     * @param keepUsername keep = true, false otherwise
75     */
76     void clearAccountInformation(bool keepUsername = false);
77
78 private:
79     /**
80       * @brief Destroy login dialog and browser
81       */
82     void destroyLogin();
83
84     /**
85       * @brief Parses the session information from the URL
86       *
87       * @param url URL
88       * @returns Parsed session, or empty string if parsing failed.
89       */
90     QString parseSession(const QUrl &url);
91
92 private slots:
93     /**
94       * @brief Cleanup after browser is destructed
95       *
96       * Clears the pointer to the browser and disables the progress indicator.
97       */
98     void browserDestroyed();
99
100     /**
101       * @brief Handler for login page loading errors
102       *
103       * @param reply Network reply
104       */
105     void networkReplyHandler(QNetworkReply *reply);
106
107     /**
108       * @brief Handler for browser URL changes
109       *
110       * Does check the new URL and based on that invokes the login dialog with visible browser view
111       * or parses the session from the new URL.
112       *
113       * @param url New URL
114       */
115     void urlChanged(const QUrl &url);
116
117 /*******************************************************************************
118  * SIGNALS
119  ******************************************************************************/
120 signals:
121     /**
122     * @brief Signals error
123     *
124     * @param context error context
125     * @param error error code
126     */
127     void error(const int context, const int error);
128
129     /**
130       * @brief Emitted when logged in successfully
131       *
132       * @param session Session data
133       */
134     void loggedIn(const QString session);
135
136 /*******************************************************************************
137  * DATA MEMBERS
138  ******************************************************************************/
139 private:
140     QWebView *m_browser;            ///< Login browser
141     MainWindow *m_mainWindow;       ///< MainWindow
142 };
143
144 #endif // FACEBOOKAUTHENTICATION_H