modified code to obey general namings and style
[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
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #ifndef FACEBOOKAUTHENTICATION_H
24 #define FACEBOOKAUTHENTICATION_H
25
26 #include <QtGui>
27 #include <QtWebKit>
28 #include <QString>
29 #include <QLayout>
30 #include "facebookcredentials.h"
31
32 /**
33 * @brief FacebookAuthentication class takes care of transmitting username and password to facebook. And it also receives credentials from Facebook. Other components of Situare application needs credentials to communicate with facebook.
34 *
35 * @author Ville Tiensuu
36 * @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
37 */
38 class FacebookAuthentication : public QMainWindow
39 {
40     Q_OBJECT
41
42 public:
43     /**
44     * @brief FacebookAuthentication constructor
45     *
46     * -Composes Loginpage from pieces of strings.
47     * -Checks if there is valid credentials stored on the file. If there is emits signal. If not it calls start method.
48     * -Connects signal from m_webView to UpdateCredentials() method. With this feature it is verified that class tries always update credentials when web page changes.
49     * -Allocates memory for m_webView and m_mainlayout
50     *
51     * @fn FacebookAuthentication
52     * @param parent
53     */
54     FacebookAuthentication(QWidget *parent = 0);
55
56     /**
57     * @brief Releases allocated memory for m_webView and m_mainlayout
58     *
59     */
60     ~FacebookAuthentication();
61
62     /**
63     * @brief Getter for m_loginCredentials
64     *
65     *
66     * @return FacebookCredentials
67     */
68     FacebookCredentials loginCredentials() const;
69
70 public slots:
71     /**
72     * @brief shows the m_webView and loads page that is specified in the m_facebookLoginPage variable. Specifies font size for the page.
73     *    
74     */
75     void start();
76
77 private slots:
78     /**
79     * @brief  search credentials from URL that is given parameter. If credentials are found thay are stored to loginCredentials variable.
80     *
81     * @param url, URL where this method tries to find credentials.
82     * @return bool, if credentials are found return true, if credentials are not found return false.
83     */
84     bool updateCredentials(const QUrl & url);
85
86 signals:    
87
88     /**
89     * @brief this signal is emitted if user exits logging in by pressing X
90     *
91     */
92     void userExit();
93
94     /**
95     * @brief this signal is emitted if updateCredentials method finds credentials from URL. signal is also emitted at the beginning of the program if there is valid credentials in the file.
96     *
97     */
98     void credentialsReady();
99
100     /**
101     * @brief this signal is emitted if updateCredentials method can't find credentials from URL
102     *
103     */
104     void loginFailure();
105
106 private:
107
108     /**
109     * @brief Program cames to this method when user closes login screen by pressing X.
110     *        method sends userExit() signal in this function
111     *
112     * @param event, without parameter programs does not come to this function when user exits by pressing X.
113     */
114     void closeEvent(QCloseEvent *event);
115
116     /**
117     * @brief checks expiration time of credentials and compares it to current time.
118     *
119     * @param credentials, this parameter represents credentials that will be verified.
120     * @return bool, returns true if expiration time is after current time. in other cases returns false.
121     */
122     bool verifyCredentials(const FacebookCredentials &credentials) const;
123
124     /**
125     * @brief Reads previous stored credentials from file.
126     *
127     * @param credentialsFromFile, This dataclass is the place where method stores credentials. Corrent parameter here is m_loginCredentials (private member of FacebookAuthentication class)
128     */
129     void readCredentials(FacebookCredentials &credentialsFromFile);
130
131     /**
132     * @brief Writes credentials to File
133     *
134     * @param credentials, Contents of this dataclass is stored to file
135     */
136     void writeCredentials(const FacebookCredentials &credentials);
137
138     /**
139     * @brief, shows facebook login page.
140     *
141     * @var m_webView
142     */
143     QWebView *m_webView;
144
145     /**
146     * @brief, lays out m_webView in window.
147     *
148     * @var m_mainlayout
149     */
150     QHBoxLayout *m_mainlayout;
151
152     /**
153     * @brief string that contantains URL of facebook loginpage.
154     *
155     * @var m_facebookLoginPage
156     */
157     QString m_facebookLoginPage;
158
159     /**
160     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five QStrings and setters and getters.
161     *
162     * @var m_loginCredentials
163     */
164     FacebookCredentials m_loginCredentials;
165 };
166
167 #endif // FACEBOOKAUTHENTICATION_H