First draft, credentials are still saved to settings
[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       Sami Rämö - sami.ramo@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 MAINWINDOW_H
25 #define MAINWINDOW_H
26
27 #include <QtGui/QMainWindow>
28 #include <QUrl>
29
30 #include "networkcookiejar.h"
31 #include "panelsidebar.h"
32
33 class QGraphicsScene;
34 class QLabel;
35 class QWebView;
36
37 class FacebookAuthentication;
38 class FriendListPanel;
39 class LoginDialog;
40 class MapScene;
41 class MapView;
42 class SituareService;
43 class User;
44 class UserInfoPanel;
45 class ZoomButtonPanel;
46
47 /**
48 * @brief Main Window Class
49 */
50 class MainWindow : public QMainWindow
51 {
52     Q_OBJECT
53
54 public:
55     /**
56     * @brief Constructor
57     *
58     * @param parent Parent
59     */
60     MainWindow(QWidget *parent = 0);
61
62     /**
63     * @brief Destructor
64     *
65     */
66     ~MainWindow();
67
68 /*******************************************************************************
69  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
70  ******************************************************************************/
71 private:
72     /**
73       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
74       */
75     void keyPressEvent(QKeyEvent* event);
76
77 /*******************************************************************************
78  * MEMBER FUNCTIONS AND SLOTS
79  ******************************************************************************/
80 public:    
81     /**
82     * @brief
83     *
84     * @param logged
85     */
86     void loggedIn(bool logged);
87
88     /**
89     * @brief Enable / disable auto centering button.
90     *
91     * @param enabled true if shoud be enabled, false otherwise
92     */
93     void setAutoCenteringButtonEnabled(bool enabled);
94
95     /**
96     * @brief Enable / disable GPS button.
97     *
98     * Does set visibilities for manual location cursor and auto centering menu button.
99     *
100     * @param enabled true if enabled, false otherwise
101     */
102     void setGPSButtonEnabled(bool enabled);
103
104     /**
105       * @brief Set scene for MapView
106       *
107       * @param scene Scene to be set
108       */
109     void setMapViewScene(QGraphicsScene *scene);
110
111     /**
112     * @brief Show Maemo information box with message.
113     *
114     * @brief message information message
115     */
116     void showMaemoInformationBox(const QString &message);
117
118     /**
119     * @brief Gets the username from member variable for saving purposes
120     *
121     * @return QString Username
122     */
123     const QString username();
124
125 public slots:
126     /**
127     * @brief Slot to intercept signal when user has pressed connect button from loginDialog
128     *
129     * @param email E-mail
130     * @param password Password
131     */
132     void loginDialogDone(const QString &email, const QString &password);
133
134     /**
135     * @brief Slot to intercept signal when login has failed (loginFailure signal)
136     *
137     */
138     void loginFailed();
139
140     void loginUsingCookies();
141
142     /**
143     * @brief Public slot, which open settings dialog
144     */
145     void openSettingsDialog();
146
147     /**
148     * @brief Sets username to member variable for login dialog
149     *
150     * @param username Username to be set
151     */
152     void setUsername(const QString &username);
153
154     /**
155     * @brief
156     *
157     * @param show
158     */
159     void showPanels(bool show);
160
161     /**
162     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
163     *        doesn't exist yet
164     *
165     * @param url Login page url
166     */
167     void startLoginProcess(const QUrl &url);
168
169     /**
170     * @brief Toggle progress indicator.
171     *
172     * @param state true if progress indicator should be shown, false otherwise
173     */
174     void toggleProgressIndicator(bool state);
175
176 private:
177     /**
178       * @brief Build friend list panel and connect slots
179       */
180     void buildFriendListPanel();
181
182     void buildLoginDialog();
183
184     /**
185       * @brief Build manual location setting cross hair and connect slots
186       */
187     void buildManualLocationCrosshair();
188
189     /**
190       * @brief Build map and connect slots
191       */
192     void buildMap();
193
194     /**
195       * @brief Build OSM license and connect slots
196       */
197     void buildOsmLicense();
198
199     /**
200       * @brief Build user info panel and connect slots
201       */
202     void buildUserInfoPanel();
203
204     void buildWebView();
205
206     /**
207       * @brief Build zoom button panel and connect slots
208       */
209     void buildZoomButtonPanel();
210
211     void clearCookieJar();
212
213     /**
214     * @brief Private method to create the Menu items
215     */
216     void createMenus();
217
218     /**
219       * @brief Grab or release HW increase and decrease buttons.
220       *
221       * @param grab Use true for grabbing and false for releasing the keys
222       */
223     void grabZoomKeys(bool grab);
224
225     /**
226       * @brief Set own location crosshair visibility
227       *
228       * @param visible
229       */
230     void setOwnLocationCrosshairVisibility(bool visible);
231
232 private slots:
233     /**
234     * @brief Slot for drawing the Open Street Map license text
235     *
236     * @param size Size of the screen
237     */
238     void drawOsmLicense(const QSize &size);
239
240     /**
241     * @brief Slot for drawing the own location crosshair
242     *
243     * @param width Width of the viewport
244     * @param height Height of the viewport
245     */
246     void drawOwnLocationCrosshair(int width, int height);
247
248     /**
249     * @brief Slot for gps error.
250     *
251     * @param message error message
252     */
253     void gpsError(const QString &message);
254
255     /**
256     * @brief Slot for gps timeout.
257     *
258     * Called when request timeout occurs.
259     */
260     void gpsTimeout();
261
262     void loadCookies();
263
264     /**
265     * @brief Slot to intercept signal when webview has finished loading webpage
266     *
267     * @param done Status of the loading
268     */
269     void loadDone(bool done);
270
271     void saveCookies();
272
273     /**
274     * @brief Set correnct view port size to datamembers
275     *
276     * @param width Width of the viewport
277     * @param height Height of the viewport
278     */
279     void setViewPortSize(const int width, const int height);
280
281 /*******************************************************************************
282  * SIGNALS
283  ******************************************************************************/
284 signals:
285     /**
286     * @brief Automatic centering setting changed by user
287     *
288     * @param enabled True if automatic centering is enabled, otherwise false
289     */
290     void autoCenteringTriggered(bool enabled);
291
292     /**
293     * @brief Signal that indicates when user has cancelled login process
294     *
295     */
296     void cancelLoginProcess();
297
298     /**
299     * @brief View should be centered to new location
300     *
301     * @param sceneCoordinate Scene coordinates of the new center point
302     */
303     void centerToSceneCoordinates(QPoint sceneCoordinate);
304
305     /**
306     * @brief Signal for requesting username from settings
307     *
308     */
309     void fetchUsernameFromSettings();
310
311     /**
312     * @brief GPS setting changed
313     *
314     * @param enabled True if GPS is enabled, otherwise false
315     */
316     void gpsTriggered(bool enabled);
317
318     /**
319     * @brief Signal for finding friend.
320     *
321     * @param coordinates friend's geo coordinates
322     */
323     void findFriend(const QPointF &coordinates);
324
325     /**
326     * @brief Signal for friend location ready.
327     *
328     * @param friendsList
329     */
330     void friendsLocationsReady(QList<User *> &friendsList);
331
332     /**
333     * @brief Signal is emitted when location item is clicked.
334     *
335     * @param userIDs list of friends user IDs in the group
336     */
337     void locationItemClicked(const QList<QString> &userIDs);
338
339     /**
340     * @brief Signals when Login/Logout action is pressed
341     *
342     */
343     void loginActionPressed();
344
345     /**
346     * @brief MapView has been resized
347     *
348     * @param size view size
349     */
350     void mapViewResized(const QSize &size);
351
352     /**
353       * @brief Forwarding signal from MapView to MapEngine
354       *
355       * @param sceneCoordinate
356       */
357     void mapViewScrolled(QPoint sceneCoordinate);
358
359     /**
360       * @brief Forwarding signal from MapEngine to MapView
361       */
362     void maxZoomLevelReached();
363
364     /**
365       * @brief Forwarding signal from MapEngine to MapView
366       */
367     void minZoomLevelReached();
368
369     /**
370     * @brief Signal for refreshing user data.
371     *
372     */
373     void refreshUserData();
374
375     /**
376     * @brief Signal for requesting reverseGeo from SituareEngine
377     *
378     */
379     void requestReverseGeo();
380
381     /**
382     * @brief Signals, when address data is ready
383     *
384     * @param address Street address
385     */
386     void reverseGeoReady(const QString &address);
387
388     /**
389     * @brief Signal for requestLocationUpdate from SituareEngine
390     *
391     * @param status Status message
392     * @param publish Publish on Facebook
393     */
394     void statusUpdate(const QString &status, const bool &publish);
395
396     /**
397     * @brief Signals when webview's urlChanged signal is emitted
398     *
399     * @param url New url
400     */
401     void updateCredentials(const QUrl &url);
402
403     /**
404     * @brief MapView has finished zooming
405     */
406     void viewZoomFinished();
407
408     /**
409     * @brief Signal for use location ready.
410     *
411     * @param user User object
412     */
413     void userLocationReady(User *user);
414
415     /**
416     * @brief Map zoom in request
417     */
418     void zoomIn();
419
420     /**
421       * @brief Forwarding signal from MapEngine to MapView
422       */
423     void zoomLevelChanged(int zoomLevel);
424
425     /**
426     * @brief Map zoom out request
427     */
428     void zoomOut();
429
430 /*******************************************************************************
431  * DATA MEMBERS
432  ******************************************************************************/
433 private:
434
435     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
436     bool m_loggedIn;                        ///< Indicates login state
437     bool m_refresh;                         ///< Indicates when webpage is refreshed
438
439     int m_viewPortHeight;                   ///< Height of view port
440     int m_viewPortWidth;                    ///< Width of view port
441
442     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
443     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
444     QAction *m_loginAct;                    ///< Action to Login/Logout
445     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
446
447     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
448     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
449
450     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
451
452     QString m_email;                        ///< Placeholder for email
453     QString m_password;                     ///< Placeholder for password
454
455     QWebView *m_webView;                    ///< Shows facebook login page
456
457     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
458     LoginDialog *m_loginDialog;             ///< Login dialog
459     MapView *m_mapView;                     ///< Instance of the map view
460     NetworkCookieJar *m_cookieJar;
461     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
462     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
463     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
464     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
465 };
466
467 #endif // MAINWINDOW_H