48f383712ab415677477d98e974f777e198d5fd1
[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 MeetPeoplePanel;
51 class Route;
52 class RoutingPanel;
53 class TabbedPanel;
54 class SettingsDialog;
55 class SceneCoordinate;
56 class SituareService;
57 class TabbedPanel;
58 class User;
59 class UserInfoPanel;
60 class ZoomButtonPanel;
61 class Location;
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 Clears cookie jar
98      *
99      */
100     void clearCookieJar();
101
102     /**
103      * @brief
104      *
105      * @param logged
106      */
107     void loggedIn(bool logged);
108
109     /**
110      * @brief Gets the login state (logged in/logged out)
111      *
112      * @return bool Login state
113      */
114     bool loginState();
115
116     /**
117      * @brief Reads automatic location update settings.
118      */
119     void readAutomaticLocationUpdateSettings();
120
121     /**
122      * @brief Enable / disable GPS button.
123      *
124      * Does set visibilities for manual location cursor and auto centering menu button.
125      *
126      * @param enabled true if enabled, false otherwise
127      */
128     void setGPSButtonEnabled(bool enabled);
129
130     /**
131      * @brief Enable / disable direction indicator button.
132      *
133      * @param enabled true if shoud be enabled, false otherwise
134      */
135     void setIndicatorButtonEnabled(bool enabled);
136
137     /**
138      * @brief Set scene for MapView
139      *
140      * @param scene Scene to be set
141      */
142     void setMapViewScene(QGraphicsScene *scene);
143
144     /**
145      * Shows dialog with enable automatic location update question.
146      *
147      * @param text text to show in dialog
148      */
149     void showEnableAutomaticUpdateLocationDialog(const QString &text);
150
151     /**
152      * @brief Gets the username from member variable for saving purposes
153      *
154      * @return QString Username
155      */
156     const QString username();
157
158 public slots:
159     /**
160      * @brief Build direction indicator button panel and connect signals
161      */
162     void buildIndicatorButtonPanel();
163
164     /**
165      * @brief Builds information box with message.
166      *
167      * @param message Information message
168      * @param modal Modal = true, non-modal false
169      */
170     void buildInformationBox(const QString &message, bool modal=false);
171
172     /**
173      * @brief Slot for failed login
174      */
175     void loginFailed();
176
177     /**
178      * @brief Slot to intercept signal when login with cookies is requested
179      */
180     void loginUsingCookies();
181
182     /**
183      * @brief Public slot, which open settings dialog
184      */
185     void openSettingsDialog();
186
187     /**
188      * @brief Set own location crosshair visibility
189      *
190      * @param visible
191      */
192     void setOwnLocationCrosshairVisibility(bool visible);
193
194     /**
195      * @brief Sets username to member variable for login dialog
196      *
197      * @param username Username to be set
198      */
199     void setUsername(const QString &username);
200
201     /**
202      * @brief Method to show panels
203      */
204     void showPanels();
205
206     /**
207      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
208      *        doesn't exist yet
209      */
210     void startLoginProcess();
211
212     /**
213      * @brief Toggle progress indicator.
214      *
215      * @param state true if progress indicator should be shown, false otherwise
216      */
217     void toggleProgressIndicator(bool state);
218
219     /**
220      * @brief Shows / hides Situare related UI items
221      *
222      */
223     void updateItemVisibility();
224
225 private:
226     /**
227      * @brief Build fullscreen toggle button and connect slots
228      */
229     void buildFullScreenButton();
230
231     /**
232      * @brief Build friend list panel and connect slots
233      */
234     void buildFriendListPanel();
235
236     /**
237      * @brief Build manual location setting cross hair and connect slots
238      */
239     void buildManualLocationCrosshair();
240
241     /**
242      * @brief Build meet people panel and connect slots
243      */
244     void buildMeetPeoplePanel();
245
246     /**
247      * @brief Build map and connect slots
248      */
249     void buildMap();
250
251     /**
252      * @brief Build map scale and connect slots
253      */
254     void buildMapScale();
255
256     /**
257      * @brief Build OSM license and connect slots
258      */
259     void buildOsmLicense();
260
261     /**
262      * @brief Build application panels
263      */
264     void buildPanels();
265
266     /**
267      * @brief Build routing panel and connect slots
268      */
269     void buildRoutingPanel();
270
271     /**
272      * @brief Build user info panel and connect slots
273      */
274     void buildUserInfoPanel();
275
276     /**
277      * @brief Build webview and connect slots
278      */
279     void buildWebView();
280
281     /**
282      * @brief Build zoom button panel and connect slots
283      */
284     void buildZoomButtonPanel();
285
286     /**
287      * @brief Private method to create the Menu items
288      */
289     void createMenus();
290
291     /**
292      * @brief Grab or release HW increase and decrease buttons.
293      *
294      * @param grab Use true for grabbing and false for releasing the keys
295      */
296     void grabZoomKeys(bool grab);
297
298     /**
299      * @brief Queues dialog/information box
300      *
301      * @param dialog Dialog to be added into queue
302      */
303     void queueDialog(QDialog *dialog);
304
305     /**
306      * @brief Shows queued error information box
307      *
308      */
309     void showErrorInformationBox();
310
311     /**
312      * @brief Shows queued information box
313      *
314      * @fn showInformationBox
315      */
316     void showInformationBox();
317
318 private slots:
319     /**
320      * @brief Slot for automatic update dialog finished.
321      *
322      * @result result code
323      */
324     void automaticUpdateDialogFinished(int result);
325
326     /**
327      * @brief Slot to intercept signal when dialog/information note is processed
328      *
329      * @param status Status of the dialog
330      */
331     void dialogFinished(int status);
332
333     /**
334      * @brief Slot for drawing the fullscreen toggle button
335      *
336      * @param size Size of the screen
337      */
338     void drawFullScreenButton(const QSize &size);
339
340     /**
341      * @brief Slot for drawing the map distance scale
342      *
343      * @param size Size of the screen
344      */
345     void drawMapScale(const QSize &size);
346
347     /**
348      * @brief Slot for drawing the Open Street Map license text
349      *
350      * @param size Size of the screen
351      */
352     void drawOsmLicense(const QSize &size);
353
354     /**
355      * @brief Slot for drawing the own location crosshair
356      *
357      * @param size Size of the screen
358      */
359     void drawOwnLocationCrosshair(const QSize &size);
360
361     /**
362      * @brief Slot to intercept signal when error dialog/information note is processed
363      *
364      * @param status Status of the dialog
365      */
366     void errorDialogFinished(int status);
367
368     /**
369      * @brief Slot for gps timeout.
370      *
371      * Called when request timeout occurs.
372      */
373     void gpsTimeout();
374
375     /**
376      * @brief Slot to load cookies from settings
377      */
378     void loadCookies();
379
380     /**
381      * @brief Slot to intercept signal when webview has finished loading webpage
382      *
383      * @param done Status of the loading
384      */
385     void loadDone(bool done);
386
387     /**
388      * @brief Slot to save cookies to settings
389      */
390     void saveCookies();
391
392     /**
393      * @brief Slot for settings dialog accepted.
394      */
395     void settingsDialogAccepted();
396
397     /**
398      * @brief Set correnct view port size to datamembers
399      *
400      * @param size Size of the screen
401      */
402     void setViewPortSize(const QSize &size);
403
404     /**
405      * @brief Start location search (open search dialog)
406      */
407     void startLocationSearch();
408
409     /**
410      * @brief Toggle between fullscreen and normal window mode
411      */
412     void toggleFullScreen();
413
414     /**
415      * @brief Slot to intercept signal from webview's networkaccessmanager
416      *
417      * @param reply Network reply (contains errors)
418      */
419     void webViewRequestFinished(QNetworkReply* reply);
420
421 /*******************************************************************************
422  * SIGNALS
423  ******************************************************************************/
424 signals:
425     /**
426      * @brief Automatic centering setting changed by user
427      *
428      * @param enabled True if automatic centering is enabled, otherwise false
429      */
430     void autoCenteringTriggered(bool enabled);
431
432     /**
433      * @brief Signal that indicates when user has cancelled login process
434      *
435      */
436     void cancelLoginProcess();
437
438     /**
439      * @brief Signal for centering to coordinates.
440      *
441      * @param coordinates geo coordinates to center to.
442      */
443     void centerToCoordinates(const GeoCoordinate &coordinates);
444
445     /**
446      * @brief View should be centered to new location
447      *
448      * @param coordinate Scene coordinates of the new center point
449      */
450     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
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
544      */
545     void mapViewScrolled(const SceneCoordinate &coordinate);
546
547     /**
548      * @brief Forwarding signal from MapEngine to MapView
549      */
550     void maxZoomLevelReached();
551
552     /**
553      * @brief Forwarding signal from MapEngine to MapView
554      */
555     void minZoomLevelReached();
556
557     /**
558      * @brief Forwarding signal from MapEngine to MapScale
559      */
560     void newMapResolution(qreal scale);
561
562     /**
563      * @brief Signal for refreshing user data.
564      *
565      */
566     void refreshUserData();
567
568     /**
569      * @brief Signal for requesting reverseGeo from SituareEngine
570      *
571      */
572     void requestReverseGeo();
573
574     /**
575      * @brief Signals, when address data is ready
576      *
577      * @param address Street address
578      */
579     void reverseGeoReady(const QString &address);
580
581     /**
582     * @brief Emited when route is parsed and is ready for further processing
583     *
584     * @param route Route item containing parsed route details
585     */
586     void routeParsed(Route &route);
587
588     /**
589     * @brief Signal for routing to geo coordinates.
590     *
591     * @param coordinates destination geo coordinates
592     */
593     void routeTo(const GeoCoordinate &coordinates);
594
595     /**
596      * @brief Signal to save username to settings
597      *
598      * @param username Username
599      */
600     void saveUsername(const QString &username);
601
602     /**
603      * @brief Signal for location search
604      *
605      * @param location QString location
606      */
607     void searchForLocation(QString location);
608
609     /**
610      * @brief Signal for requestLocationUpdate from SituareEngine
611      *
612      * @param status Status message
613      * @param publish Publish on Facebook
614      */
615     void statusUpdate(const QString &status, const bool &publish);
616
617     /**
618      * @brief Signals when webview's urlChanged signal is emitted
619      *
620      * @param url New url
621      */
622     void updateCredentials(const QUrl &url);
623
624     /**
625      * @brief Signals when updateLocationDialog's data must be cleared
626      *
627      */
628     void clearUpdateLocationDialogData();
629
630     /**
631     * @brief Dragging mode triggered.
632     */
633     void draggingModeTriggered();
634
635     /**
636      * @brief MapView has finished zooming
637      */
638     void viewZoomFinished();
639
640     /**
641      * @brief Signal for use location ready.
642      *
643      * @param user User object
644      */
645     void userLocationReady(User *user);
646
647     /**
648      * @brief Map zoom in request
649      */
650     void zoomIn();
651
652     /**
653      * @brief Forwarding signal from MapEngine to MapView
654      */
655     void zoomLevelChanged(int zoomLevel);
656
657     /**
658      * @brief Map zoom out request
659      */
660     void zoomOut();
661
662 /*******************************************************************************
663  * DATA MEMBERS
664  ******************************************************************************/
665 private:
666     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
667     bool m_loggedIn;                        ///< Indicates login state
668     bool m_refresh;                         ///< Indicates when webpage is refreshed
669
670     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
671
672     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
673     QAction *m_loginAct;                    ///< Action to Login/Logout
674     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
675
676     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
677     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
678
679     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
680     QList<QDialog *> m_queue;               ///< QList type dialog queue
681
682     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
683
684     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
685
686     QSize m_viewPortSize;                 ///< Size of the viewport
687
688     QString m_email;                        ///< Placeholder for email
689     QString m_password;                     ///< Placeholder for password
690
691     QWebView *m_webView;                    ///< Shows facebook login page
692
693     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
694     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
695     IndicatorButtonPanel *m_indicatorButtonPanel;     ///< Instance of direction indicator button
696     MapScale *m_mapScale;                   ///< Instance of the map scale
697     MapView *m_mapView;                     ///< Instance of the map view
698     MeetPeoplePanel *m_meetPeoplePanel;     ///< Instance of MeetPeoplePanel
699     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
700     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
701     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
702     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
703     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
704 };
705
706 #endif // MAINWINDOW_H