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