Implemented username saving to settings and loading. Saved username
[situare] / src / ui / mainwindow.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@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
24 #ifndef MAINWINDOW_H
25 #define MAINWINDOW_H
26
27 #include <QtGui/QMainWindow>
28 #include <QWidget>
29 #include <QtWebKit>
30 #include <QDebug>
31 #include <QObject>
32 #include <QNetworkAccessManager>
33 #include "facebookservice/facebookauthentication.h"
34 #include "situareservice/situareservice.h"
35 #include "mapviewscreen.h"
36 #include "ui/logindialog.h"
37
38 class QLabel;
39
40 /**
41 * @brief Main Window Class
42 *
43 * @class MainWindow mainwindow.h "src/ui/mainwindow.h"
44 */
45 class MainWindow : public QMainWindow
46 {
47     Q_OBJECT
48
49 public:
50     /**
51     * @brief Constructor
52     *
53     * @param parent Parent
54     */
55     MainWindow(QWidget *parent = 0);
56
57     /**
58     * @brief Destructor
59     *
60     */
61     ~MainWindow();
62
63 /*******************************************************************************
64  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
65  ******************************************************************************/
66 private:
67     /**
68       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
69       */
70     void keyPressEvent(QKeyEvent* event);
71
72 /*******************************************************************************
73  * MEMBER FUNCTIONS AND SLOTS
74  ******************************************************************************/
75 public:
76     /**
77     * @brief Set auto centering button enabled.
78     *
79     * @param enabled true if enabled, false otherwise
80     */
81     void setAutoCenteringButton(bool enabled);
82
83     /**
84     * @brief Notify for auto centering enabling.
85     *
86     * @param enabled true if enabled, false otherwise
87     */
88     void autoCenteringEnabled(bool enabled);
89
90     /**
91     * @brief Set GPS button enabled.
92     *
93     * @param enabled true if enabled, false otherwise
94     */
95     void setGPSButton(bool enabled);
96
97     /**
98     * @brief Gets the username from member variable for saving purposes
99     *
100     * @return QString Username
101     */
102     const QString username();
103
104 public slots:
105     /**
106     * @brief Slot for auto centering enabling.
107     *
108     * @param checked true if button state is checked, false otherwise
109     */
110     void autoCenteringToggled(bool checked);
111
112         /**
113     * @brief Slot for gps enabling.
114     *
115     * @param checked true if button state is checked, false otherwise
116     */
117     void gpsToggled(bool checked);
118
119     /**
120     * @brief Slot to intercept signal when user has pressed connect button from loginDialog
121     *
122     * @param email E-mail
123     * @param password Password
124     */
125     void loginDialogDone(const QString &email, const QString &password);
126
127     /**
128     * @brief Slot to intercept signal when login has failed (loginFailure signal)
129     *
130     */
131     void loginFailed();
132
133         /**
134     * @brief Slot for map location change.
135     */
136     void mapLocationChanged();
137
138     /**
139     * @brief Public slot, which open settings dialog
140     */
141     void openSettingsDialog();
142
143     /**
144     * @brief Sets username to member variable for login dialog
145     *
146     * @param username Username to be set
147     */
148     void setUsername(const QString &username);
149
150     /**
151     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
152     *        doesn't exist yet
153     *
154     * @param url Login page url
155     */
156     void startLoginProcess(const QUrl &url);
157
158     /**
159     * @brief Toggle progress indicator.
160     *
161     * @param state true if progress indicator should be shown, false otherwise
162     */
163     void toggleProgressIndicator(bool state);
164
165 private:
166     /**
167     * @brief Private method to create the Menu items
168     */
169     void createMenus();
170
171     /**
172       * @brief Grab or release HW increase and decrease buttons.
173       *
174       * @param grab Use true for grabbing and false for releasing the keys
175       */
176     void grabZoomKeys(bool grab);
177
178     /**
179     * @brief Show Maemo information box with message.
180     *
181     * @brief message information message
182     */
183     void showMaemoInformationBox(const QString &message);
184
185 private slots:
186     /**
187     * @brief Slot for gps timeout.
188     *
189     * Called when request timeout occurs.
190     */
191     void gpsTimeout();
192
193     /**
194     * @brief Slot for gps error.
195     *
196     * @param message error message
197     */
198     void gpsError(const QString &message);
199
200     /**
201     * @brief Slot to intercept signal when webview has finished loading webpage
202     *
203     * @param done Status of the loading
204     */
205     void loadDone(bool done);
206
207 /*******************************************************************************
208  * SIGNALS
209  ******************************************************************************/
210 signals:
211     /**
212     * @brief Signal for map auto centering
213     *
214     * @param enabled true if map should auto center to gps location
215     */
216     void autoCentering(bool enabled);
217
218     /**
219     * @brief Signal that indicates when user has cancelled login process
220     *
221     */
222     void cancelLoginProcess();
223
224     /**
225     * @brief Signal for gps enabling.
226     *
227     * @param enabled true if gps should be enabled
228     */
229     void enableGPS(bool enabled);
230
231         /**
232     * @brief Signal for auto centering enabling.
233     *
234     * @param enabled if auto centering should be enabled
235     */
236     void enableAutoCentering(bool enabled);
237
238     /**
239     * @brief Signal for requesting username from settings
240     *
241     */
242     void fetchUsernameFromSettings();
243
244     /**
245     * @brief Signal for friend location ready.
246     *
247     * @param friendsList
248     */
249     void friendsLocationsReady(QList<User *> &friendsList);
250
251     /**
252     * @brief Signal from MapEngine to SituareEngine is travelling here
253     */
254     void ownLocation(QPointF ownLatitudeLongitudeLocation);
255
256     /**
257     * @brief Signal for gps position.
258     *
259     * @param position longitude and latitude values
260     * @param accuracy coordinate accuracy in metres
261     */
262     void positionReceived(QPointF position, qreal accuracy);
263
264     /**
265     * @brief Signal for refreshing user data.
266     *
267     */
268     void refreshUserData();
269
270     /**
271     * @brief Signal from SituareEngine to MapEngine is travelling here
272     */
273     void requestOwnLocation();
274
275     /**
276     * @brief Signal for requesting reverseGeo from SituareEngine
277     *
278     */
279     void requestReverseGeo();
280
281     /**
282     * @brief Signals, when address data is ready
283     *
284     * @param address Street address
285     */
286     void reverseGeoReady(const QString &address);
287
288     /**
289     * @brief Signal for requestLocationUpdate from SituareEngine
290     *
291     * @param status Status message
292     * @param publish Publish on Facebook
293     */
294     void statusUpdate(const QString &status, const bool &publish);
295
296     /**
297     * @brief Signals when webview's urlChanged signal is emitted
298     *
299     * @param url New url
300     */
301     void updateCredentials(const QUrl &url);
302
303     /**
304     * @brief Signal for use location ready.
305     *
306     * @param user User object
307     */
308     void userLocationReady(User *user);
309
310     /**
311     * @brief Signal for HW increase button
312     */
313     void zoomInKeyPressed();
314
315     /**
316     * @brief Signal for HW decrease button
317     */
318     void zoomOutKeyPressed();
319
320 /*******************************************************************************
321  * DATA MEMBERS
322  ******************************************************************************/
323 private:
324
325     QAction *m_autoCenteringAct;    ///< Action to auto center map using gps position
326     QString m_email; ///< Placeholder for email
327     QAction *m_gpsToggleAct;    ///< Action to trigger gps toggle
328     LoginDialog *m_loginDialog; ///< Login dialog
329     QUrl m_loginUrl; ///< Placeholder for login page url
330     MapViewScreen *m_mapViewScreen; ///< Instance of the map view
331     QString m_password; ///< Placeholder for password
332     bool m_refresh; ///< Indicates when webpage is refreshed
333     QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
334     QMenu *m_viewMenu; ///< Object that hold the view menu items
335     QWebView *m_webView; ///< Shows facebook login page
336 };
337
338 #endif // MAINWINDOW_H