Documenting and some clean-up
[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         Jussi Laitinen - jussi.laitinen@ixonos.com
8         Sami Rämö - sami.ramo@ixonos.com
9         Ville Tiensuu - ville.tiensuu@ixonos.com
10         Katri Kaikkonen - katri.kaikkonen@ixonos.com
11
12     Situare is free software; you can redistribute it and/or
13     modify it under the terms of the GNU General Public License
14     version 2 as published by the Free Software Foundation.
15
16     Situare is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20
21     You should have received a copy of the GNU General Public License
22     along with Situare; if not, write to the Free Software
23     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24     USA.
25 */
26
27 #ifndef MAINWINDOW_H
28 #define MAINWINDOW_H
29
30 #include <QtGui/QMainWindow>
31 #include <QSslError>
32 #include <QUrl>
33
34 #include "network/networkcookiejar.h"
35
36 class QDialog;
37 class QGraphicsScene;
38 class QLabel;
39 class QMessageBox;
40 class QNetworkReply;
41 class QToolButton;
42 class QWebView;
43
44 class FriendListPanel;
45 class FullScreenButton;
46 class GeoCoordinate;
47 class IndicatorButtonPanel;
48 class Location;
49 class LocationSearchPanel;
50 class MapScale;
51 class MapScene;
52 class MapView;
53 class Route;
54 class RoutingPanel;
55 class SceneCoordinate;
56 class SettingsDialog;
57 class SituareService;
58 class TabbedPanel;
59 class User;
60 class UserInfoPanel;
61 class ZoomButtonPanel;
62
63 /**
64  * @brief Main Window Class
65  */
66 class MainWindow : public QMainWindow
67 {
68     Q_OBJECT
69
70 public:
71     /**
72      * @brief Constructor
73      *
74      * @param parent Parent
75      */
76     MainWindow(QWidget *parent = 0);
77
78     /**
79      * @brief Destructor
80      */
81     ~MainWindow();
82
83 /*******************************************************************************
84  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
85  ******************************************************************************/
86 private:
87     /**
88      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
89      */
90     void keyPressEvent(QKeyEvent* event);
91
92 /*******************************************************************************
93  * MEMBER FUNCTIONS AND SLOTS
94  ******************************************************************************/
95 public:
96     /**
97       * @brief Build and show login dialog with login browser
98       *
99       * @param browser Login browser instance
100       */
101     void buildLoginDialog(QWebView *browser);
102
103     /**
104      * @brief
105      *
106      * @param logged
107      */
108     void loggedIn(bool logged);
109
110     /**
111      * @brief Gets the login state (logged in/logged out)
112      *
113      * @return bool Login state
114      */
115     bool loginState();
116
117     /**
118      * @brief Reads automatic location update settings.
119      */
120     void readAutomaticLocationUpdateSettings();
121
122     /**
123      * @brief Enable / disable GPS button.
124      *
125      * Does set visibilities for manual location cursor and auto centering menu button.
126      *
127      * @param enabled true if enabled, false otherwise
128      */
129     void setGPSButtonEnabled(bool enabled);
130
131     /**
132      * @brief Enable / disable direction indicator button.
133      *
134      * @param enabled true if shoud be enabled, false otherwise
135      */
136     void setIndicatorButtonEnabled(bool enabled);
137
138     /**
139      * @brief Set scene for MapView
140      *
141      * @param scene Scene to be set
142      */
143     void setMapViewScene(QGraphicsScene *scene);
144
145     /**
146      * Shows dialog with enable automatic location update question.
147      *
148      * @param text text to show in dialog
149      */
150     void showEnableAutomaticUpdateLocationDialog(const QString &text);
151
152     /**
153      * @brief Gets the username from member variable for saving purposes
154      *
155      * @return QString Username
156      */
157     const QString username();
158
159 public slots:
160     /**
161      * @brief Builds information box with message.
162      *
163      * @param message Information message
164      * @param modal Modal = true, non-modal false
165      */
166     void buildInformationBox(const QString &message, bool modal=false);
167
168     /**
169       * @brief Hides and deletes login dialog
170       */
171     void destroyLoginDialog();
172
173     /**
174      * @brief Slot for failed login
175      */
176     void loginFailed();
177
178     /**
179      * @brief Public slot, which open settings dialog
180      */
181     void openSettingsDialog();
182
183     /**
184      * @brief Set own location crosshair visibility
185      *
186      * @param visible
187      */
188     void setCrosshairVisibility(bool visible);
189
190     /**
191     * @brief Shows contact dialog.
192     *
193     * Shows contact dialog with contact's information.
194     * @param guid globally unique ID of a contact
195     */
196     void showContactDialog(const QString &guid);
197
198     /**
199      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
200      *        doesn't exist yet
201      */
202     void startLoginProcess();
203
204     /**
205      * @brief Toggle progress indicator.
206      *
207      * @param state true if progress indicator should be shown, false otherwise
208      */
209     void toggleProgressIndicator(bool state);
210
211     /**
212      * @brief Shows / hides Situare related UI items
213      *
214      */
215     void updateItemVisibility();
216
217 private:
218     /**
219      * @brief Build manual location setting cross hair and connect slots
220      */
221     void buildCrosshair();
222
223     /**
224      * @brief Build friend list panel and connect slots
225      */
226     void buildFriendListPanel();
227
228     /**
229      * @brief Build fullscreen toggle button and connect slots
230      */
231     void buildFullScreenButton();
232
233     /**
234      * @brief Build direction indicator button panel and connect signals
235      */
236     void buildIndicatorButtonPanel();
237
238
239     /**
240      * @brief Build location search panel and connect signals
241      */
242     void buildLocationSearchPanel();
243
244     /**
245      * @brief Build map and connect slots
246      */
247     void buildMap();
248
249     /**
250      * @brief Build map scale and connect slots
251      */
252     void buildMapScale();
253
254     /**
255      * @brief Build OSM license and connect slots
256      */
257     void buildOsmLicense();
258
259     /**
260      * @brief Build application panels
261      */
262     void buildPanels();
263
264     /**
265      * @brief Build routing panel and connect slots
266      */
267     void buildRoutingPanel();
268
269     /**
270      * @brief Build user info panel and connect slots
271      */
272     void buildUserInfoPanel();
273
274     /**
275      * @brief Build zoom button panel and connect slots
276      */
277     void buildZoomButtonPanel();
278
279     /**
280      * @brief Private method to create the Menu items
281      */
282     void createMenus();
283
284     /**
285      * @brief Grab or release HW increase and decrease buttons.
286      *
287      * @param grab Use true for grabbing and false for releasing the keys
288      */
289     void grabZoomKeys(bool grab);
290
291     /**
292      * @brief Queues dialog/information box
293      *
294      * @param dialog Dialog to be added into queue
295      */
296     void queueDialog(QDialog *dialog);
297
298     /**
299      * @brief Shows queued error information box
300      *
301      */
302     void showErrorInformationBox();
303
304     /**
305      * @brief Shows queued information box
306      *
307      * @fn showInformationBox
308      */
309     void showInformationBox();
310
311 private slots:
312     /**
313      * @brief Slot for automatic update dialog finished.
314      *
315      * @result result code
316      */
317     void automaticUpdateDialogFinished(int result);
318
319     /**
320      * @brief Slot to intercept signal when dialog/information note is processed
321      *
322      * @param status Status of the dialog
323      */
324     void dialogFinished(int status);
325
326     /**
327      * @brief Slot for drawing the fullscreen toggle button
328      *
329      * @param size Size of the screen
330      */
331     void drawFullScreenButton(const QSize &size);
332
333     /**
334      * @brief Slot for drawing the map distance scale
335      *
336      * @param size Size of the screen
337      */
338     void drawMapScale(const QSize &size);
339
340     /**
341      * @brief Slot for drawing the Open Street Map license text
342      *
343      * @param size Size of the screen
344      */
345     void drawOsmLicense(const QSize &size);
346
347     /**
348      * @brief Slot to intercept signal when error dialog/information note is processed
349      *
350      * @param status Status of the dialog
351      */
352     void errorDialogFinished(int status);
353
354     /**
355      * @brief Slot for gps timeout.
356      *
357      * Called when request timeout occurs.
358      */
359     void gpsTimeout();
360
361     /**
362     * @brief Called when map center point horizontal shifting is changed
363     *
364     * @param shifting New shifting value
365     */
366     void mapCenterHorizontalShiftingChanged(int shifting);
367
368     /**
369      * @brief Move the crosshair
370      */
371     void moveCrosshair();
372
373     /**
374      * @brief Slot for settings dialog accepted.
375      */
376     void settingsDialogAccepted();
377
378     /**
379      * @brief Ignore SSL error from the reply
380      */
381     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
382
383     /**
384      * @brief Start location search (open search dialog)
385      */
386     void startLocationSearch();
387
388     /**
389      * @brief Toggle between fullscreen and normal window mode
390      */
391     void toggleFullScreen();
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 Signal for centering to coordinates.
412      *
413      * @param coordinates geo coordinates to center to.
414      */
415     void centerToCoordinates(const GeoCoordinate &coordinates);
416
417     /**
418      * @brief View should be centered to new location
419      *
420      * @param coordinate Scene coordinates of the new center point
421      */
422     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
423
424     /**
425     * @brief Emitted when route is cleared
426     */
427     void clearRoute();
428
429     /**
430     * @brief Signal when direction and distance from current map center point to current GPS
431     *        location is changed
432     *
433     * @param direction Direction in degrees
434     * @param distance Distance in meters
435     * @param draw Should the indicator triangle be drawn or not
436     */
437     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
438
439     /**
440      * @brief Signal for enabling automatic location update.
441      *
442      * @param enabled true if enabled, false otherwise
443      * @param updateIntervalMsecs update interval in milliseconds
444      */
445     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
446
447     /**
448      * @brief Signals error
449      *
450      * @param context error context
451      * @param error error code
452      */
453     void error(const int context, const int error);
454
455     /**
456      * @brief Signal for requesting username from settings
457      *
458      */
459     void fetchUsernameFromSettings();
460
461     /**
462      * @brief Signals when friend's profile image is ready
463      *
464      * @param user Friend
465      */
466     void friendImageReady(User *user);
467
468     /**
469      * @brief GPS setting changed
470      *
471      * @param enabled True if GPS is enabled, otherwise false
472      */
473     void gpsTriggered(bool enabled);
474
475     /**
476      * @brief Signal for friend location ready.
477      *
478      * @param friendsList
479      */
480     void friendsLocationsReady(QList<User *> &friendsList);
481
482     /**
483     * @brief Emited when location request is parsed and is ready for further processing
484     *
485     * @param result List of Location items
486     */
487     void locationDataParsed(const QList<Location> &result);
488
489     /**
490      * @brief Signal is emitted when location item is clicked on map.
491      *
492      * @param userIDs list of friends user IDs in the group
493      */
494     void locationItemClicked(const QList<QString> &userIDs);
495
496     /**
497      * @brief Signal is emitted when location item is clicked in list.
498      *
499      * @param swBound south-west bound in GeoCoorinate
500      * @param neBound north-east bound in GeoCoordinate
501      */
502     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
503
504     /**
505      * @brief Signals when Login/Logout action is pressed
506      *
507      */
508     void loginActionPressed();
509
510     /**
511      * @brief MapView has been resized
512      *
513      * @param size view size
514      */
515     void mapViewResized(const QSize &size);
516
517     /**
518      * @brief Forwarding signal from MapView to MapEngine
519      *
520      * @param coordinate New center point coordinate
521      */
522     void mapViewScrolled(const SceneCoordinate &coordinate);
523
524     /**
525      * @brief Forwarding signal from MapEngine to MapView
526      */
527     void maxZoomLevelReached();
528
529     /**
530      * @brief Forwarding signal from MapEngine to MapView
531      */
532     void minZoomLevelReached();
533
534     /**
535      * @brief Forwarding signal from MapEngine to MapScale
536      */
537     void newMapResolution(qreal scale);
538
539     /**
540      * @brief Signal for refreshing user data.
541      *
542      */
543     void refreshUserData();
544
545     /**
546     * @brief Requests contact dialog.
547     *
548     * @param facebookId contact's facebookId
549     */
550     void requestContactDialog(const QString &facebookId);
551
552     /**
553      * @brief Signal for requesting reverseGeo from SituareEngine
554      *
555      */
556     void requestReverseGeo();
557
558     /**
559      * @brief Signals, when address data is ready
560      *
561      * @param address Street address
562      */
563     void reverseGeoReady(const QString &address);
564
565     /**
566     * @brief Emited when route is parsed and is ready for further processing
567     *
568     * @param route Route item containing parsed route details
569     */
570     void routeParsed(Route &route);
571
572     /**
573     * @brief Signal for routing to geo coordinates.
574     *
575     * @param coordinates destination geo coordinates
576     */
577     void routeTo(const GeoCoordinate &coordinates);
578
579     /**
580     * @brief Request routing to current cursor position
581     */
582     void routeToCursor();
583
584     /**
585      * @brief Signal for location search
586      *
587      * @param location QString location
588      */
589     void searchForLocation(QString location);
590
591     /**
592     * @brief Signal is emitted when search history item is clicked.
593     *
594     * @param searchString search string used
595     */
596     void searchHistoryItemClicked(const QString &searchString);
597
598     /**
599      * @brief Signal for requestLocationUpdate from SituareEngine
600      *
601      * @param status Status message
602      * @param publish Publish on Facebook
603      */
604     void statusUpdate(const QString &status, const bool &publish);
605
606     /**
607      * @brief Signals when updateLocationDialog's data must be cleared
608      *
609      */
610     void clearUpdateLocationDialogData();
611
612     /**
613     * @brief Dragging mode triggered.
614     */
615     void draggingModeTriggered();
616
617     /**
618      * @brief MapView has finished zooming
619      */
620     void viewZoomFinished();
621
622     /**
623      * @brief Signal for use location ready.
624      *
625      * @param user User object
626      */
627     void userLocationReady(User *user);
628
629     /**
630      * @brief Map zoom in request
631      */
632     void zoomIn();
633
634     /**
635      * @brief Forwarding signal from MapEngine to MapView
636      */
637     void zoomLevelChanged(int zoomLevel);
638
639     /**
640      * @brief Map zoom out request
641      */
642     void zoomOut();
643
644 /*******************************************************************************
645  * DATA MEMBERS
646  ******************************************************************************/
647 private:
648     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
649     bool m_loggedIn;                        ///< Indicates login state
650     bool m_refresh;                         ///< Indicates when webpage is refreshed
651
652     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
653     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
654
655     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
656     QAction *m_loginAct;                    ///< Action to Login/Logout
657     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
658
659     QDialog *m_loginDialog;                 ///< Login dialog
660
661     QLabel *m_crosshair;                    ///< Label for center point crosshair
662     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
663
664     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
665     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
666     QList<QDialog *> m_queue;               ///< QList type dialog queue
667
668     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
669
670     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
671
672     QString m_email;                        ///< Placeholder for email
673     QString m_password;                     ///< Placeholder for password
674
675     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
676     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
677     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
678     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
679     MapScale *m_mapScale;                   ///< Instance of the map scale
680     MapView *m_mapView;                     ///< Instance of the map view
681     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
682     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
683     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
684     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
685 };
686
687 #endif // MAINWINDOW_H