f7f8082f156efdbd295580e35b25cfbb6a00a434
[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 #include "facebookcredentials.h"
29
30 /**
31 * @brief FacebookAuthentication class takes care of parsing and handling of  credentials for
32 *        Facebook. Other components of Situare application needs credentials to communicate with
33 *        facebook.
34 *
35 * @author Ville Tiensuu
36 */
37 class FacebookAuthentication : public QObject
38 {
39     Q_OBJECT
40
41 public:
42     /**
43     * @brief FacebookAuthentication constructor
44     *
45     * -Checks if there is valid credentials stored on the file. If there is emits signal.
46     *
47     * @param parent instance of parent
48     */
49     FacebookAuthentication(QObject *parent = 0);
50
51 /*******************************************************************************
52  * MEMBER FUNCTIONS AND SLOTS
53  ******************************************************************************/
54 public:
55     /**
56     * @brief Getter for m_loginCredentials
57     *
58     * @return FacebookCredentials
59     */
60     FacebookCredentials loginCredentials() const;
61
62 public slots:
63
64     /**
65     * @brief Clears account iformation from settings
66     *
67     * @param keepUsername keep = true, false otherwise
68     */
69     void clearAccountInformation(bool keepUsername = false);
70
71     /**
72     * @brief Loads username from settings
73     *
74     * @return QString Loaded username
75     */
76     const QString loadUsername();
77
78     /**
79     * @brief Saves username to settings
80     *
81     * @param username Username to be saved
82     */
83     void saveUsername(const QString &username);
84
85     /**
86     * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
87     *        variable. Specifies font size for the page.
88     *    
89     */
90     void start();
91
92 private slots:
93
94     /**
95     * @brief  Search credentials from URL that is given as parameter.
96     *         If credentials are found thay are stored to loginCredentials variable.
97     *
98     * @param url URL where this method tries to find credentials.
99     * @return bool if credentials are found returns true,
100     *               if credentials are not found returns false.
101     */
102     bool updateCredentials(const QUrl & url);
103
104 /*******************************************************************************
105  * SIGNALS
106  ******************************************************************************/
107
108 signals:
109
110     /**
111     * @brief Signals error
112     *
113     * @param context error context
114     * @param error error code
115     */
116     void error(const int context, const int error);
117
118     /**
119     * @brief This signal is emitted if updateCredentials method finds credentials from URL.
120     *        Signal is also emitted at the beginning of the program if there is valid credentials
121     *        in the file.
122     *
123     * @param credentials New credentials
124     */
125     void credentialsReady(const FacebookCredentials &credentials);
126
127     /**
128     * @brief This signal is emitted always when login is called. At first  the application tries
129     *        to login using saved cookies
130     *
131     */
132     void loginUsingCookies();
133
134     /**
135     * @brief Signals when credentials are invalid new login is needed
136     *
137     */
138     void newLoginRequest();
139
140     /**
141     * @brief This signal is emitted when new cookies need to be saved.
142     *
143     */
144     void saveCookiesRequest();
145
146 /*******************************************************************************
147  * DATA MEMBERS
148  ******************************************************************************/
149
150 private:
151
152     bool m_freshLogin;  ///< Flag for fresh login
153
154     /**
155     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
156     *        QStrings and setters and getters.
157     *
158     * @var m_loginCredentials
159     */
160     FacebookCredentials m_loginCredentials;
161 };
162
163 #endif // FACEBOOKAUTHENTICATION_H