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