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