Removed signals and information box for failed locationUpdate.
[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 Method to show panels
190     *
191     */
192     void showPanels();
193
194     /**
195     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
196     *        doesn't exist yet
197     *
198     */
199     void startLoginProcess();
200
201     /**
202     * @brief Toggle progress indicator.
203     *
204     * @param state true if progress indicator should be shown, false otherwise
205     */
206     void toggleProgressIndicator(bool state);
207
208     /**
209     * @brief Shows / hides Situare related UI items
210     *
211     */
212     void updateItemVisibility();
213
214 private:
215     /**
216       * @brief Build fullscreen toggle button and connect slots
217       */
218     void buildFullScreenButton();
219
220     /**
221       * @brief Build friend list panel and connect slots
222       */
223     void buildFriendListPanel();
224
225     /**
226       * @brief Build manual location setting cross hair and connect slots
227       */
228     void buildManualLocationCrosshair();
229
230     /**
231       * @brief Build map and connect slots
232       */
233     void buildMap();
234
235     /**
236      * @brief Build map scale and connect slots
237      */
238     void buildMapScale();
239
240     /**
241       * @brief Build OSM license and connect slots
242       */
243     void buildOsmLicense();
244
245     /**
246       * @brief Build user info panel and connect slots
247       */
248     void buildUserInfoPanel();
249
250     /**
251     * @brief Build webview and connect slots
252     *
253     */
254     void buildWebView();
255
256     /**
257       * @brief Build zoom button panel and connect slots
258       */
259     void buildZoomButtonPanel();
260
261     /**
262     * @brief Private method to create the Menu items
263     */
264     void createMenus();
265
266     /**
267       * @brief Grab or release HW increase and decrease buttons.
268       *
269       * @param grab Use true for grabbing and false for releasing the keys
270       */
271     void grabZoomKeys(bool grab);
272
273     /**
274     * @brief Queues dialog/information box
275     *
276     * @param dialog Dialog to be added into queue
277     */
278     void queueDialog(QDialog *dialog);
279
280     /**
281     * @brief Shows queued error information box
282     *
283     */
284     void showErrorInformationBox();
285
286     /**
287     * @brief Shows queued information box
288     *
289     * @fn showInformationBox
290     */
291     void showInformationBox();
292
293 private slots:
294     /**
295     * @brief Slot for automatic update dialog finished.
296     *
297     * @result result code
298     */
299     void automaticUpdateDialogFinished(int result);
300
301     /**
302     * @brief Slot to intercept signal when dialog/information note is processed
303     *
304     * @param status Status of the dialog
305     */
306     void dialogFinished(int status);
307
308     /**
309     * @brief Slot for drawing the fullscreen toggle button
310     *
311     * @param size Size of the screen
312     */
313     void drawFullScreenButton(const QSize &size);
314
315     /**
316     * @brief Slot for drawing the map distance scale
317     *
318     * @param size Size of the screen
319     */
320     void drawMapScale(const QSize &size);
321
322     /**
323     * @brief Slot for drawing the Open Street Map license text
324     *
325     * @param size Size of the screen
326     */
327     void drawOsmLicense(const QSize &size);
328
329     /**
330     * @brief Slot for drawing the own location crosshair
331     *
332     * @param size Size of the screen
333     */
334     void drawOwnLocationCrosshair(const QSize &size);
335
336     /**
337     * @brief Slot to intercept signal when error dialog/information note is processed
338     *
339     * @param status Status of the dialog
340     */
341     void errorDialogFinished(int status);
342
343     /**
344     * @brief Slot for gps timeout.
345     *
346     * Called when request timeout occurs.
347     */
348     void gpsTimeout();
349
350     /**
351     * @brief Slot to load cookies from settings
352     *
353     */
354     void loadCookies();
355
356     /**
357     * @brief Slot to intercept signal when webview has finished loading webpage
358     *
359     * @param done Status of the loading
360     */
361     void loadDone(bool done);
362
363     /**
364     * @brief Slot to save cookies to settings
365     *
366     */
367     void saveCookies();
368
369     /**
370     * @brief Slot for settings dialog accepted.
371     */
372     void settingsDialogAccepted();
373
374     /**
375     * @brief Set correnct view port size to datamembers
376     *
377     * @param size Size of the screen
378     */
379     void setViewPortSize(const QSize &size);
380
381     /**
382     * @brief Toggle between fullscreen and normal window mode
383     */
384     void toggleFullScreen();
385
386     /**
387     * @brief Slot to intercept signal from webview's networkaccessmanager
388     *
389     * @param reply Network reply (contains errors)
390     */
391     void webViewRequestFinished(QNetworkReply* reply);
392
393 /*******************************************************************************
394  * SIGNALS
395  ******************************************************************************/
396 signals:
397     /**
398     * @brief Automatic centering setting changed by user
399     *
400     * @param enabled True if automatic centering is enabled, otherwise false
401     */
402     void autoCenteringTriggered(bool enabled);
403
404     /**
405     * @brief Signal that indicates when user has cancelled login process
406     *
407     */
408     void cancelLoginProcess();
409
410     /**
411     * @brief View should be centered to new location
412     *
413     * @param sceneCoordinate Scene coordinates of the new center point
414     */
415     void centerToSceneCoordinates(QPoint sceneCoordinate);
416
417     /**
418     * @brief Signal for enabling automatic location update.
419     *
420     * @param enabled true if enabled, false otherwise
421     * @param updateIntervalMsecs update interval in milliseconds
422     */
423     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
424
425     /**
426     * @brief Signals error
427     *
428     * @param context error context
429     * @param error error code
430     */
431     void error(const int context, const int error);
432
433     /**
434     * @brief Signal for requesting username from settings
435     *
436     */
437     void fetchUsernameFromSettings();
438
439     /**
440     * @brief Signal for finding user.
441     *
442     * @param coordinates user geo coordinates
443     */
444     void findUser(const QPointF &coordinates);
445
446     /**
447     * @brief GPS setting changed
448     *
449     * @param enabled True if GPS is enabled, otherwise false
450     */
451     void gpsTriggered(bool enabled);
452
453     /**
454     * @brief Signal for finding friend.
455     *
456     * @param coordinates friend's geo coordinates
457     */
458     void findFriend(const QPointF &coordinates);
459
460     /**
461     * @brief Signal for friend location ready.
462     *
463     * @param friendsList
464     */
465     void friendsLocationsReady(QList<User *> &friendsList);
466
467     /**
468     * @brief Signal is emitted when location item is clicked.
469     *
470     * @param userIDs list of friends user IDs in the group
471     */
472     void locationItemClicked(const QList<QString> &userIDs);
473
474     /**
475     * @brief Signals when Login/Logout action is pressed
476     *
477     */
478     void loginActionPressed();
479
480     /**
481     * @brief MapView has been resized
482     *
483     * @param size view size
484     */
485     void mapViewResized(const QSize &size);
486
487     /**
488       * @brief Forwarding signal from MapView to MapEngine
489       *
490       * @param sceneCoordinate
491       */
492     void mapViewScrolled(QPoint sceneCoordinate);
493
494     /**
495       * @brief Forwarding signal from MapEngine to MapView
496       */
497     void maxZoomLevelReached();
498
499     /**
500       * @brief Forwarding signal from MapEngine to MapView
501       */
502     void minZoomLevelReached();
503
504     /**
505      * @brief Forwarding signal from MapEngine to MapScale
506      */
507     void newMapResolution(qreal scale);
508
509     /**
510     * @brief Signal for refreshing user data.
511     *
512     */
513     void refreshUserData();
514
515     /**
516     * @brief Signal for requesting reverseGeo from SituareEngine
517     *
518     */
519     void requestReverseGeo();
520
521     /**
522     * @brief Signals, when address data is ready
523     *
524     * @param address Street address
525     */
526     void reverseGeoReady(const QString &address);
527
528     /**
529     * @brief Signal to save username to settings
530     *
531     * @param username Username
532     */
533     void saveUsername(const QString &username);
534
535     /**
536     * @brief Signal for requestLocationUpdate from SituareEngine
537     *
538     * @param status Status message
539     * @param publish Publish on Facebook
540     */
541     void statusUpdate(const QString &status, const bool &publish);
542
543     /**
544     * @brief Signals when webview's urlChanged signal is emitted
545     *
546     * @param url New url
547     */
548     void updateCredentials(const QUrl &url);
549
550     /**
551     * @brief Signals when updateLocationDialog's data must be cleared
552     *
553     */
554     void clearUpdateLocationDialogData();
555
556     /**
557     * @brief MapView has finished zooming
558     */
559     void viewZoomFinished();
560
561     /**
562     * @brief Signal for use location ready.
563     *
564     * @param user User object
565     */
566     void userLocationReady(User *user);
567
568     /**
569     * @brief Map zoom in request
570     */
571     void zoomIn();
572
573     /**
574       * @brief Forwarding signal from MapEngine to MapView
575       */
576     void zoomLevelChanged(int zoomLevel);
577
578     /**
579     * @brief Map zoom out request
580     */
581     void zoomOut();
582
583 /*******************************************************************************
584  * DATA MEMBERS
585  ******************************************************************************/
586 private:
587     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
588     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
589     bool m_loggedIn;                        ///< Indicates login state
590     bool m_refresh;                         ///< Indicates when webpage is refreshed
591
592     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
593
594     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
595     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
596     QAction *m_loginAct;                    ///< Action to Login/Logout
597     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
598
599     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
600     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
601
602     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
603     QList<QDialog *> m_queue;               ///< QList type dialog queue
604
605     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
606
607     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
608
609     QSize m_viewPortSize;                 ///< Size of the viewport
610
611     QString m_email;                        ///< Placeholder for email
612     QString m_password;                     ///< Placeholder for password
613
614     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
615
616     QWebView *m_webView;                    ///< Shows facebook login page
617
618     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
619     MapScale *m_mapScale;                   ///< Instance of the map scale
620     MapView *m_mapView;                     ///< Instance of the map view
621     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
622     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
623     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
624     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
625     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
626 };
627
628 #endif // MAINWINDOW_H