Implemented username saving to settings and loading. Saved username
[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
55     /**
56     * @brief Getter for m_loginCredentials
57     *
58     * @return FacebookCredentials
59     */
60     FacebookCredentials loginCredentials() const;
61
62 public slots:
63
64     /**
65     * @brief Loads username from settings
66     *
67     * @return QString Loaded username
68     */
69     const QString loadUsername();
70
71     /**
72     * @brief Saves username to settings
73     *
74     * @param username Username to be saved
75     */
76     void saveUsername(const QString &username);
77
78     /**
79     * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
80     *        variable. Specifies font size for the page.
81     *    
82     */
83     void start();
84
85 private: 
86
87     /**
88     * @brief Creates login url with given parameters
89     *
90     * @param urlParts Url parts
91     * @return QUrl Login page url
92     */
93     QUrl formLoginPageUrl(const QStringList & urlParts) const;
94
95     /**
96     * @brief Reads previous stored credentials from file.
97     *
98     * @param credentialsFromFile This dataclass is the place where method stores credentials.
99     *        Corrent parameter here is m_loginCredentials
100     */
101     void readCredentials(FacebookCredentials &credentialsFromFile);
102
103     /**
104     * @brief Checks expiration time of credentials and compares it to current time.
105     *
106     * @param credentials this parameter represents credentials that will be verified.
107     * @return bool returns true if expiration time is after current time. in other cases returns
108     *               false.
109     */
110     bool verifyCredentials(const FacebookCredentials &credentials) const;   
111
112     /**
113     * @brief Writes credentials to File
114     *
115     * @param credentials Contents of this dataclass is stored to file
116     */
117     void writeCredentials(const FacebookCredentials &credentials);
118
119 private slots:
120
121     /**
122     * @brief  Search credentials from URL that is given as parameter.
123     *         If credentials are found thay are stored to loginCredentials variable.
124     *
125     * @param url URL where this method tries to find credentials.
126     * @return bool if credentials are found returns true,
127     *               if credentials are not found returns false.
128     */
129     bool updateCredentials(const QUrl & url);
130
131 /*******************************************************************************
132  * SIGNALS
133  ******************************************************************************/
134
135 signals:
136
137     /**
138     * @brief This signal is emitted if updateCredentials method finds credentials from URL.
139     *        Signal is also emitted at the beginning of the program if there is valid credentials
140     *        in the file.
141     *
142     * @param freshLogin Was login done via login dialog
143     * @param credentials New credentials
144     */
145     void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
146
147     /**
148     * @brief This signal is emitted if updateCredentials method can't find credentials from URL
149     *
150     */
151     void loginFailure();
152
153     /**
154     * @brief Signals when credentials are invalid new login is needed
155     *
156     * @param url Login page url
157     */
158     void newLoginRequest(const QUrl &url);
159
160 /*******************************************************************************
161  * DATA MEMBERS
162  ******************************************************************************/
163
164 private:
165
166     int m_loginAttempts; ///< Indicates login attempts
167
168     /**
169     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
170     *        QStrings and setters and getters.
171     *
172     * @var m_loginCredentials
173     */
174     FacebookCredentials m_loginCredentials;
175 };
176
177 #endif // FACEBOOKAUTHENTICATION_H