9ad879fa65ceb713d81105a285cf89cbfb7e6b3b
[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 <QHash>
29 #include <QString>
30 #include <QLayout>
31 #include "facebookcredentials.h"
32
33 /**
34 * @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.
35 *
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 webview to UpdateCredentials() method. With this feature it is verified that class tries always update credentials when web page changes.
49     * -Allocates memory for webView and mainlayout
50     *
51     * @fn FacebookAuthentication
52     * @param parent
53     */
54     FacebookAuthentication(QWidget *parent = 0);
55
56     /**
57     * @brief Releases allocated memory for webView and mainLayout
58     *
59     * @fn ~FacebookAuthentication
60     */
61     ~FacebookAuthentication();
62
63     /**
64     * @brief Getter for loginCredentials
65     *
66     * @fn getLoginCredentials
67     * @return FacebookCredentials
68     */
69     FacebookCredentials getLoginCredentials() const;   
70
71 public slots:
72     /**
73     * @brief shows the webView and loads page that is specified in the facebookLoginPage variable. Specifies font size for the page.
74     *
75     * @fn start
76     */
77     void start();
78
79 private slots:
80     /**
81     * @brief  search credentials from URL that is given parameter. If credentials are found thay are stored to loginCredentials variable.
82     *
83     * @fn updateCredentials
84     * @param url, URL where this method tries to find credentials.
85     * @return bool, if credentials are found return true, if credentials are not found return false.
86     */
87     bool updateCredentials(const QUrl & url);
88
89 signals:    
90
91     /**
92     * @brief this signal is emitted if user exits logging in by pressing X
93     *
94     * @fn userExit
95     */
96     void userExit();
97
98     /**
99     * @brief this signal is emitted updateCredentials method finds credentials from URL. signal is also emitted at the beginning of the program if there is valid credentials in the file.
100     *
101     * @fn credentialsReady
102     */
103     void credentialsReady();
104
105     /**
106     * @brief this signal is emitted if updateCredentials method can't find credentials from URL
107     *
108     * @fn loginFailure
109     */
110     void loginFailure();
111
112 private:
113
114     /**
115     * @brief Program cames to this method when user closes login screen by pressing X.
116     *        method send userExit() signal in this function
117     *
118     * @fn closeEvent
119     * @param event, without parameter programs does not come to this function when user exits by pressing X.
120     */
121     void closeEvent(QCloseEvent *event);
122
123     /**
124     * @brief checks expiration time of credentials and compares it to current time.
125     *
126     * @fn verifyCredentials
127     * @param credentials, this parameter represents credentials that will be verified.
128     * @return bool, returns true if expiration time is after current time. in other cases returns false.
129     */
130     bool verifyCredentials(const FacebookCredentials &credentials) const;
131
132     /**
133     * @brief Reads previous stored credentials from file.
134     *
135     * @fn readCredentials
136     * @param credentialsFromFile, This dataclass is the place where method stores credentials. Corrent parameter here is loginCredentials (private member of FacebookAuthentication class)
137     */
138     void readCredentials(FacebookCredentials &credentialsFromFile);
139
140     /**
141     * @brief Writes credentials to File
142     *
143     * @fn writeCredentials
144     * @param credentials, Contents of this dataclass is stored to file
145     */
146     void writeCredentials(const FacebookCredentials &credentials);
147
148     /**
149     * @brief, shows facebook login page.
150     *
151     * @var webView
152     */
153     QWebView *webView;
154
155     /**
156     * @brief, lays out webview in window.
157     *
158     * @var mainlayout
159     */
160     QHBoxLayout *mainlayout;
161
162     /**
163     * @brief string that contantains URL of facebook loginpage.
164     *
165     * @var facebookLoginPage
166     */
167     QString facebookLoginPage;
168
169     /**
170     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five QStrings and setters and getters.
171     *
172     * @var loginCredentials
173     */
174     FacebookCredentials loginCredentials;
175 };
176
177 #endif // FACEBOOKAUTHENTICATION_H