3699687dcece2ccb6bb9c1fe036278a47ab08c58
[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 FacebookAuthentication constructor
50     *
51     * -Checks if there is valid credentials stored on the file. If there is emits signal.
52     *
53     * @param mainWindow MainWindow instance
54     * @param parent instance of parent
55     */
56     FacebookAuthentication(MainWindow *mainWindow, QObject *parent = 0);
57
58 /*******************************************************************************
59  * MEMBER FUNCTIONS AND SLOTS
60  ******************************************************************************/
61 public:
62     void login();
63
64 public slots:
65
66     /**
67     * @brief Clears account iformation from settings
68     *
69     * @param keepUsername keep = true, false otherwise
70     */
71     void clearAccountInformation(bool keepUsername = false);
72
73 private:
74     void destroyLogin();
75
76     QString parseSession(const QUrl &url);
77
78 private slots:
79     void browserDestroyed();
80
81     void loadFinished(bool ok);
82
83     void networkReplyHandler(QNetworkReply *reply);
84
85     void urlChanged(const QUrl &url);
86
87 /*******************************************************************************
88  * SIGNALS
89  ******************************************************************************/
90 signals:
91     /**
92     * @brief Signals error
93     *
94     * @param context error context
95     * @param error error code
96     */
97     void error(const int context, const int error);
98
99     void loggedIn(const QString session);
100
101 /*******************************************************************************
102  * DATA MEMBERS
103  ******************************************************************************/
104 private:
105     QWebView *m_browser;
106     MainWindow *m_mainWindow;
107 };
108
109 #endif // FACEBOOKAUTHENTICATION_H