c9e4caf3db9251f950ec6700650214b81dfd8ddb
[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 UpdateLocationDialog;
60 class User;
61 class UserInfoPanel;
62 class ZoomButtonPanel;
63
64 /**
65  * @brief Main Window Class
66  */
67 class MainWindow : public QMainWindow
68 {
69     Q_OBJECT
70
71 public:
72     /**
73      * @brief Constructor
74      *
75      * @param parent Parent
76      */
77     MainWindow(QWidget *parent = 0);
78
79     /**
80      * @brief Destructor
81      */
82     ~MainWindow();
83
84 /*******************************************************************************
85  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
86  ******************************************************************************/
87 private:
88     /**
89      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
90      */
91     void keyPressEvent(QKeyEvent* event);
92
93 /*******************************************************************************
94  * MEMBER FUNCTIONS AND SLOTS
95  ******************************************************************************/
96 public:
97     /**
98       * @brief Build and show login dialog with login browser
99       *
100       * @param browser Login browser instance
101       */
102     void buildLoginDialog(QWebView *browser);
103
104     /**
105      * @brief
106      *
107      * @param logged
108      */
109     void loggedIn(bool logged);
110
111     /**
112      * @brief Reads automatic location update settings.
113      */
114     void readAutomaticLocationUpdateSettings();
115
116     /**
117      * @brief Enable / disable GPS button.
118      *
119      * Does set visibilities for manual location cursor and auto centering menu button.
120      *
121      * @param enabled true if enabled, false otherwise
122      */
123     void setGPSButtonEnabled(bool enabled);
124
125     /**
126      * @brief Enable / disable direction indicator button.
127      *
128      * @param enabled true if shoud be enabled, false otherwise
129      */
130     void setIndicatorButtonEnabled(bool enabled);
131
132     /**
133      * @brief Set scene for MapView
134      *
135      * @param scene Scene to be set
136      */
137     void setMapViewScene(QGraphicsScene *scene);
138
139     /**
140      * Shows dialog with enable automatic location update question.
141      *
142      * @param text text to show in dialog
143      */
144     void showEnableAutomaticUpdateLocationDialog(const QString &text);
145
146 public slots:
147     /**
148      * @brief Saves status message and Facebook publish setting
149      *
150      * @param status message that user sends. Message is stored to m_backupMessage data member
151      * @param publish setting that determines whether the user status message is published on
152      *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
153      */
154     void backupUpdateLocationDialogData(const QString &status, bool publish);
155
156     /**
157      * @brief Builds information box with message.
158      *
159      * @param message Information message
160      * @param modal Modal = true, non-modal false
161      */
162     void buildInformationBox(const QString &message, bool modal=false);
163
164     /**
165      * @brief Clears backups of message and publish on Facebook setting
166      */
167     void clearUpdateLocationDialogData();
168
169     /**
170       * @brief Hides and deletes login dialog
171       */
172     void destroyLoginDialog();
173
174     /**
175      * @brief Public slot, which open settings dialog
176      */
177     void openSettingsDialog();
178
179     /**
180      * @brief Set own location crosshair visibility
181      *
182      * @param visible
183      */
184     void setCrosshairVisibility(bool visible);
185
186     /**
187     * @brief Shows contact dialog.
188     *
189     * Shows contact dialog with contact's information.
190     * @param guid globally unique ID of a contact
191     */
192     void showContactDialog(const QString &guid);
193
194     /**
195      * @brief Toggle progress indicator.
196      *
197      * @param state true if progress indicator should be shown, false otherwise
198      */
199     void toggleProgressIndicator(bool state);
200
201     /**
202      * @brief Shows / hides Situare related UI items based on login state
203      *
204      * @param loggedIn Is the user currently logged in
205      */
206     void updateItemVisibility(bool loggedIn);
207
208 private:
209     /**
210      * @brief Build manual location setting cross hair and connect slots
211      */
212     void buildCrosshair();
213
214     /**
215      * @brief Build friend list panel and connect slots
216      */
217     void buildFriendListPanel();
218
219     /**
220      * @brief Build fullscreen toggle button and connect slots
221      */
222     void buildFullScreenButton();
223
224     /**
225      * @brief Build direction indicator button panel and connect signals
226      */
227     void buildIndicatorButtonPanel();
228
229
230     /**
231      * @brief Build location search panel and connect signals
232      */
233     void buildLocationSearchPanel();
234
235     /**
236      * @brief Build map and connect slots
237      */
238     void buildMap();
239
240     /**
241      * @brief Build map scale and connect slots
242      */
243     void buildMapScale();
244
245     /**
246      * @brief Build OSM license and connect slots
247      */
248     void buildOsmLicense();
249
250     /**
251      * @brief Build application panels
252      */
253     void buildPanels();
254
255     /**
256      * @brief Build routing panel and connect slots
257      */
258     void buildRoutingPanel();
259
260     /**
261      * @brief Build user info panel and connect slots
262      */
263     void buildUserInfoPanel();
264
265     /**
266      * @brief Build zoom button panel and connect slots
267      */
268     void buildZoomButtonPanel();
269
270     /**
271      * @brief Private method to create the Menu items
272      */
273     void createMenus();
274
275     /**
276      * @brief Grab or release HW increase and decrease buttons.
277      *
278      * @param grab Use true for grabbing and false for releasing the keys
279      */
280     void grabZoomKeys(bool grab);
281
282     /**
283      * @brief Queues dialog/information box
284      *
285      * @param dialog Dialog to be added into queue
286      */
287     void queueDialog(QDialog *dialog);
288
289     /**
290      * @brief reads Unsend message from settings at startup
291      */
292     void restoreUnsendMessage();
293
294     /**
295      * @brief Shows queued error information box
296      *
297      */
298     void showErrorInformationBox();
299
300     /**
301      * @brief Shows queued information box
302      *
303      * @fn showInformationBox
304      */
305     void showInformationBox();
306
307 private slots:
308     /**
309      * @brief Slot for automatic update dialog finished.
310      *
311      * @result result code
312      */
313     void automaticUpdateDialogFinished(int result);
314
315     /**
316      * @brief Slot to intercept signal when dialog/information note is processed
317      *
318      * @param status Status of the dialog
319      */
320     void dialogFinished(int status);
321
322     /**
323      * @brief Slot for drawing the fullscreen toggle button
324      *
325      * @param size Size of the screen
326      */
327     void drawFullScreenButton(const QSize &size);
328
329     /**
330      * @brief Slot for drawing the map distance scale
331      *
332      * @param size Size of the screen
333      */
334     void drawMapScale(const QSize &size);
335
336     /**
337      * @brief Slot for drawing the Open Street Map license text
338      *
339      * @param size Size of the screen
340      */
341     void drawOsmLicense(const QSize &size);
342
343     /**
344      * @brief Slot to intercept signal when error dialog/information note is processed
345      *
346      * @param status Status of the dialog
347      */
348     void errorDialogFinished(int status);
349
350     /**
351      * @brief Slot for gps timeout.
352      *
353      * Called when request timeout occurs.
354      */
355     void gpsTimeout();
356
357     /**
358     * @brief Called when map center point horizontal shifting is changed
359     *
360     * @param shifting New shifting value
361     */
362     void mapCenterHorizontalShiftingChanged(int shifting);
363
364     /**
365      * @brief Move the crosshair
366      */
367     void moveCrosshair();
368
369     /**
370      * @brief Slot for settings dialog accepted.
371      */
372     void settingsDialogAccepted();
373
374     /**
375      * @brief Show update location dialog
376      */
377     void showUpdateLocationDialog();
378
379     /**
380      * @brief Ignore SSL error from the reply
381      */
382     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
383
384     /**
385      * @brief Start location search (open search dialog)
386      */
387     void startLocationSearch();
388
389     /**
390      * @brief Toggle between fullscreen and normal window mode
391      */
392     void toggleFullScreen();
393
394     /**
395      * @brief Slot function to get indication when dialog is finished
396      */
397     void updateLocationDialogFinished(int reason);
398
399 /*******************************************************************************
400  * SIGNALS
401  ******************************************************************************/
402 signals:
403     /**
404      * @brief Automatic centering setting changed by user
405      *
406      * @param enabled True if automatic centering is enabled, otherwise false
407      */
408     void autoCenteringTriggered(bool enabled);
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 Signals when friend's profile image is ready
457      *
458      * @param user Friend
459      */
460     void friendImageReady(User *user);
461
462     /**
463      * @brief GPS setting changed
464      *
465      * @param enabled True if GPS is enabled, otherwise false
466      */
467     void gpsTriggered(bool enabled);
468
469     /**
470      * @brief Signal for friend location ready.
471      *
472      * @param friendsList
473      */
474     void friendsLocationsReady(QList<User *> &friendsList);
475
476     /**
477     * @brief Emited when location request is parsed and is ready for further processing
478     *
479     * @param result List of Location items
480     */
481     void locationDataParsed(const QList<Location> &result);
482
483     /**
484      * @brief Signal is emitted when location item is clicked on map.
485      *
486      * @param userIDs list of friends user IDs in the group
487      */
488     void locationItemClicked(const QList<QString> &userIDs);
489
490     /**
491      * @brief Signal is emitted when location item is clicked in list.
492      *
493      * @param swBound south-west bound in GeoCoorinate
494      * @param neBound north-east bound in GeoCoordinate
495      */
496     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
497
498     /**
499      * @brief Signals when Login/Logout action is pressed
500      *
501      */
502     void loginActionPressed();
503
504     /**
505      * @brief MapView has been resized
506      *
507      * @param size view size
508      */
509     void mapViewResized(const QSize &size);
510
511     /**
512      * @brief Forwarding signal from MapView to MapEngine
513      *
514      * @param coordinate New center point coordinate
515      */
516     void mapViewScrolled(const SceneCoordinate &coordinate);
517
518     /**
519      * @brief Forwarding signal from MapEngine to MapView
520      */
521     void maxZoomLevelReached();
522
523     /**
524      * @brief Forwarding signal from MapEngine to MapView
525      */
526     void minZoomLevelReached();
527
528     /**
529      * @brief Forwarding signal from MapEngine to MapScale
530      */
531     void newMapResolution(qreal scale);
532
533     /**
534      * @brief Signal for refreshing user data.
535      *
536      */
537     void refreshUserData();
538
539     /**
540     * @brief Requests contact dialog.
541     *
542     * @param facebookId contact's facebookId
543     */
544     void requestContactDialog(const QString &facebookId);
545
546     /**
547      * @brief Signal for requesting reverseGeo from SituareEngine
548      *
549      */
550     void requestReverseGeo();
551
552     /**
553      * @brief Signals, when address data is ready
554      *
555      * @param address Street address
556      */
557     void reverseGeoReady(const QString &address);
558
559     /**
560     * @brief Emited when route is parsed and is ready for further processing
561     *
562     * @param route Route item containing parsed route details
563     */
564     void routeParsed(Route &route);
565
566     /**
567     * @brief Signal for routing to geo coordinates.
568     *
569     * @param coordinates destination geo coordinates
570     */
571     void routeTo(const GeoCoordinate &coordinates);
572
573     /**
574     * @brief Request routing to current cursor position
575     */
576     void routeToCursor();
577
578     /**
579      * @brief Signal for location search
580      *
581      * @param location QString location
582      */
583     void searchForLocation(QString location);
584
585     /**
586     * @brief Signal is emitted when search history item is clicked.
587     *
588     * @param searchString search string used
589     */
590     void searchHistoryItemClicked(const QString &searchString);
591
592     /**
593      * @brief Signal for requestLocationUpdate from SituareEngine
594      *
595      * @param status Status message
596      * @param publish Publish on Facebook
597      */
598     void statusUpdate(const QString &status, const bool &publish);
599
600     /**
601     * @brief Dragging mode triggered.
602     */
603     void draggingModeTriggered();
604
605     /**
606      * @brief MapView has finished zooming
607      */
608     void viewZoomFinished();
609
610     /**
611      * @brief Signal for use location ready.
612      *
613      * @param user User object
614      */
615     void userLocationReady(User *user);
616
617     /**
618      * @brief Map zoom in request
619      */
620     void zoomIn();
621
622     /**
623      * @brief Forwarding signal from MapEngine to MapView
624      */
625     void zoomLevelChanged(int zoomLevel);
626
627     /**
628      * @brief Map zoom out request
629      */
630     void zoomOut();
631
632 /*******************************************************************************
633  * DATA MEMBERS
634  ******************************************************************************/
635 private:
636     bool m_backupFacebookPublishPolicity;   ///< Backup of publish on Facebook checkbox value
637     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
638     bool m_loggedIn;                        ///< Indicates login state
639     bool m_refresh;                         ///< Indicates when webpage is refreshed
640
641     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
642     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
643
644     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
645     QAction *m_loginAct;                    ///< Action to Login/Logout
646     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
647
648     QDialog *m_loginDialog;                 ///< Login dialog
649
650     QLabel *m_crosshair;                    ///< Label for center point crosshair
651     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
652
653     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
654     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
655     QList<QDialog *> m_queue;               ///< QList type dialog queue
656
657     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
658
659     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
660
661     QString m_backupMessage;                ///< Backup of users message
662
663     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
664     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
665     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
666     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
667     MapScale *m_mapScale;                   ///< Instance of the map scale
668     MapView *m_mapView;                     ///< Instance of the map view
669     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
670     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
671     UpdateLocationDialog *m_updateLocation; ///< Update location dialog
672     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
673     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
674 };
675
676 #endif // MAINWINDOW_H