Added RoutingPanel class and connected signals from/to panel.
[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         Katri Kaikkonen - katri.kaikkonen@ixonos.com
10
11     Situare is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License
13     version 2 as published by the Free Software Foundation.
14
15     Situare is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with Situare; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23     USA.
24 */
25
26 #ifndef MAINWINDOW_H
27 #define MAINWINDOW_H
28
29 #include <QtGui/QMainWindow>
30 #include <QUrl>
31
32 #include "network/networkcookiejar.h"
33
34 class QGraphicsScene;
35 class QLabel;
36 class QMessageBox;
37 class QNetworkReply;
38 class QToolButton;
39 class QWebView;
40
41 class FacebookAuthentication;
42 class FullScreenButton;
43 class FriendListPanel;
44 class IndicatorButton;
45 class GeoCoordinate;
46 class MapScale;
47 class MapScene;
48 class MapView;
49 class RoutingPanel;
50 class TabbedPanel;
51 class SettingsDialog;
52 class SceneCoordinate;
53 class SituareService;
54 class User;
55 class UserInfoPanel;
56 class ZoomButtonPanel;
57 class Location;
58
59 /**
60 * @brief Main Window Class
61 */
62 class MainWindow : public QMainWindow
63 {
64     Q_OBJECT
65
66 public:
67     /**
68      * @brief Constructor
69      *
70      * @param parent Parent
71      */
72     MainWindow(QWidget *parent = 0);
73
74     /**
75      * @brief Destructor
76      *
77      */
78     ~MainWindow();
79
80 /*******************************************************************************
81  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
82  ******************************************************************************/
83 private:
84     /**
85      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
86      */
87     void keyPressEvent(QKeyEvent* event);
88
89 /*******************************************************************************
90  * MEMBER FUNCTIONS AND SLOTS
91  ******************************************************************************/
92 public:
93     /**
94      * @brief Clears cookie jar
95      *
96      */
97     void clearCookieJar();
98
99     /**
100      * @brief
101      *
102      * @param logged
103      */
104     void loggedIn(bool logged);
105
106     /**
107      * @brief Gets the login state (logged in/logged out)
108      *
109      * @return bool Login state
110      */
111     bool loginState();
112
113     /**
114      * @brief Reads automatic location update settings.
115      */
116     void readAutomaticLocationUpdateSettings();
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 Enable / disable direction indicator button.
129      *
130      * @param enabled true if shoud be enabled, false otherwise
131      */
132     void setIndicatorButtonEnabled(bool enabled);
133
134     /**
135      * @brief Set scene for MapView
136      *
137      * @param scene Scene to be set
138      */
139     void setMapViewScene(QGraphicsScene *scene);
140
141     /**
142      * Shows dialog with enable automatic location update question.
143      *
144      * @param text text to show in dialog
145      */
146     void showEnableAutomaticUpdateLocationDialog(const QString &text);
147
148     /**
149      * @brief Gets the username from member variable for saving purposes
150      *
151      * @return QString Username
152      */
153     const QString username();
154
155 public slots:
156     /**
157      * @brief Build direction indicator button and connect slots
158      */
159     void buildIndicatorButton();
160
161     /**
162      * @brief Builds information box with message.
163      *
164      * @param message Information message
165      * @param modal Modal = true, non-modal false
166      */
167     void buildInformationBox(const QString &message, bool modal=false);
168
169     /**
170      * @brief Slot for failed login
171      */
172     void loginFailed();
173
174     /**
175      * @brief Slot to intercept signal when login with cookies is requested
176      */
177     void loginUsingCookies();
178
179     /**
180      * @brief Public slot, which open settings dialog
181      */
182     void openSettingsDialog();
183
184     /**
185      * @brief Set own location crosshair visibility
186      *
187      * @param visible
188      */
189     void setOwnLocationCrosshairVisibility(bool visible);
190
191     /**
192      * @brief Sets username to member variable for login dialog
193      *
194      * @param username Username to be set
195      */
196     void setUsername(const QString &username);
197
198     /**
199      * @brief Method to show panels
200      */
201     void showPanels();
202
203     /**
204      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
205      *        doesn't exist yet
206      *
207      */
208     void startLoginProcess();
209
210     /**
211      * @brief Toggle progress indicator.
212      *
213      * @param state true if progress indicator should be shown, false otherwise
214      */
215     void toggleProgressIndicator(bool state);
216
217     /**
218      * @brief Shows / hides Situare related UI items
219      *
220      */
221     void updateItemVisibility();
222
223 private:
224     /**
225      * @brief Build fullscreen toggle button and connect slots
226      */
227     void buildFullScreenButton();
228
229     /**
230      * @brief Build friend list panel and connect slots
231      */
232     void buildFriendListPanel();
233
234     /**
235      * @brief Build manual location setting cross hair and connect slots
236      */
237     void buildManualLocationCrosshair();
238
239     /**
240      * @brief Build map and connect slots
241      */
242     void buildMap();
243
244     /**
245      * @brief Build map scale and connect slots
246      */
247     void buildMapScale();
248
249     /**
250      * @brief Build OSM license and connect slots
251      */
252     void buildOsmLicense();
253
254     /**
255      * @brief Build application panels
256      */
257     void buildPanels();
258
259     /**
260      * @brief Build routing panel and connect slots
261      */
262     void buildRoutingPanel();
263
264     /**
265      * @brief Build user info panel and connect slots
266      */
267     void buildUserInfoPanel();
268
269     /**
270      * @brief Build webview and connect slots
271      */
272     void buildWebView();
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 for drawing the own location crosshair
349      *
350      * @param size Size of the screen
351      */
352     void drawOwnLocationCrosshair(const QSize &size);
353
354     /**
355      * @brief Slot to intercept signal when error dialog/information note is processed
356      *
357      * @param status Status of the dialog
358      */
359     void errorDialogFinished(int status);
360
361     /**
362      * @brief Slot for gps timeout.
363      *
364      * Called when request timeout occurs.
365      */
366     void gpsTimeout();
367
368     /**
369      * @brief Slot to load cookies from settings
370      */
371     void loadCookies();
372
373     /**
374      * @brief Slot to intercept signal when webview has finished loading webpage
375      *
376      * @param done Status of the loading
377      */
378     void loadDone(bool done);
379
380     /**
381      * @brief Slot to save cookies to settings
382      */
383     void saveCookies();
384
385     /**
386      * @brief Slot for settings dialog accepted.
387      */
388     void settingsDialogAccepted();
389
390     /**
391      * @brief Set correnct view port size to datamembers
392      *
393      * @param size Size of the screen
394      */
395     void setViewPortSize(const QSize &size);
396
397     /**
398      * @brief Start location search (open search dialog)
399      */
400     void startLocationSearch();
401
402     /**
403      * @brief Toggle between fullscreen and normal window mode
404      */
405     void toggleFullScreen();
406
407     /**
408      * @brief Slot to intercept signal from webview's networkaccessmanager
409      *
410      * @param reply Network reply (contains errors)
411      */
412     void webViewRequestFinished(QNetworkReply* reply);
413
414 /*******************************************************************************
415  * SIGNALS
416  ******************************************************************************/
417 signals:
418     /**
419      * @brief Automatic centering setting changed by user
420      *
421      * @param enabled True if automatic centering is enabled, otherwise false
422      */
423     void autoCenteringTriggered(bool enabled);
424
425     /**
426      * @brief Signal that indicates when user has cancelled login process
427      *
428      */
429     void cancelLoginProcess();
430
431     /**
432      * @brief View should be centered to new location
433      *
434      * @param coordinate Scene coordinates of the new center point
435      */
436     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
437
438     /**
439      * @brief Signal for enabling automatic location update.
440      *
441      * @param enabled true if enabled, false otherwise
442      * @param updateIntervalMsecs update interval in milliseconds
443      */
444     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
445
446     /**
447      * @brief Signals error
448      *
449      * @param context error context
450      * @param error error code
451      */
452     void error(const int context, const int error);
453
454     /**
455      * @brief Signal for requesting username from settings
456      *
457      */
458     void fetchUsernameFromSettings();
459
460     /**
461      * @brief Signal for finding user.
462      *
463      * @param coordinates user geo coordinates
464      */
465     void findUser(const GeoCoordinate &coordinates);
466
467     /**
468      * @brief Signals when friend's profile image is ready
469      *
470      * @param user Friend
471      */
472     void friendImageReady(User *user);
473
474     /**
475      * @brief GPS setting changed
476      *
477      * @param enabled True if GPS is enabled, otherwise false
478      */
479     void gpsTriggered(bool enabled);
480
481     /**
482      * @brief Signal for finding friend.
483      *
484      * @param coordinates friend's geo coordinates
485      */
486     void findFriend(const GeoCoordinate &coordinates);
487
488     /**
489      * @brief Signal for friend location ready.
490      *
491      * @param friendsList
492      */
493     void friendsLocationsReady(QList<User *> &friendsList);
494
495     /**
496     * @brief Emited when location request is parsed and is ready for further processing
497     *
498     * @param result List of Location items
499     */
500     void locationDataParsed(QList<Location> &result);
501
502     /**
503      * @brief Signal is emitted when location item is clicked on map.
504      *
505      * @param userIDs list of friends user IDs in the group
506      */
507     void locationItemClicked(const QList<QString> &userIDs);
508
509     /**
510      * @brief Signal is emitted when location item is clicked in list.
511      *
512      * @param swBound south-west bound in GeoCoorinate
513      * @param neBound north-east bound in GeoCoordinate
514      */
515     void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
516
517     /**
518      * @brief Signals when Login/Logout action is pressed
519      *
520      */
521     void loginActionPressed();
522
523     /**
524      * @brief MapView has been resized
525      *
526      * @param size view size
527      */
528     void mapViewResized(const QSize &size);
529
530     /**
531      * @brief Forwarding signal from MapView to MapEngine
532      *
533      * @param coordinate
534      */
535     void mapViewScrolled(const SceneCoordinate &coordinate);
536
537     /**
538      * @brief Forwarding signal from MapEngine to MapView
539      */
540     void maxZoomLevelReached();
541
542     /**
543      * @brief Forwarding signal from MapEngine to MapView
544      */
545     void minZoomLevelReached();
546
547     /**
548      * @brief Forwarding signal from MapEngine to MapScale
549      */
550     void newMapResolution(qreal scale);
551
552     /**
553      * @brief Signal for refreshing user data.
554      *
555      */
556     void refreshUserData();
557
558     /**
559      * @brief Signal for requesting reverseGeo from SituareEngine
560      *
561      */
562     void requestReverseGeo();
563
564     /**
565      * @brief Signals, when address data is ready
566      *
567      * @param address Street address
568      */
569     void reverseGeoReady(const QString &address);
570
571     /**
572      * @brief Signal to save username to settings
573      *
574      * @param username Username
575      */
576     void saveUsername(const QString &username);
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 for requestLocationUpdate from SituareEngine
587      *
588      * @param status Status message
589      * @param publish Publish on Facebook
590      */
591     void statusUpdate(const QString &status, const bool &publish);
592
593     /**
594      * @brief Signals when webview's urlChanged signal is emitted
595      *
596      * @param url New url
597      */
598     void updateCredentials(const QUrl &url);
599
600     /**
601      * @brief Signals when updateLocationDialog's data must be cleared
602      *
603      */
604     void clearUpdateLocationDialogData();
605
606     /**
607     * @brief Dragging mode triggered.
608     */
609     void draggingModeTriggered();
610
611     /**
612      * @brief MapView has finished zooming
613      */
614     void viewZoomFinished();
615
616     /**
617      * @brief Signal for use location ready.
618      *
619      * @param user User object
620      */
621     void userLocationReady(User *user);
622
623     /**
624      * @brief Map zoom in request
625      */
626     void zoomIn();
627
628     /**
629      * @brief Forwarding signal from MapEngine to MapView
630      */
631     void zoomLevelChanged(int zoomLevel);
632
633     /**
634      * @brief Map zoom out request
635      */
636     void zoomOut();
637
638 /*******************************************************************************
639  * DATA MEMBERS
640  ******************************************************************************/
641 private:
642     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
643     bool m_loggedIn;                        ///< Indicates login state
644     bool m_refresh;                         ///< Indicates when webpage is refreshed
645
646     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
647
648     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
649     QAction *m_loginAct;                    ///< Action to Login/Logout
650     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
651     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
652
653     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
654     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
655
656     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
657     QList<QDialog *> m_queue;               ///< QList type dialog queue
658
659     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
660
661     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
662
663     QSize m_viewPortSize;                 ///< Size of the viewport
664
665     QString m_email;                        ///< Placeholder for email
666     QString m_password;                     ///< Placeholder for password
667
668     QWebView *m_webView;                    ///< Shows facebook login page
669
670     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
671     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
672     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
673     MapScale *m_mapScale;                   ///< Instance of the map scale
674     MapView *m_mapView;                     ///< Instance of the map view
675     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
676     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
677     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
678     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
679     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
680 };
681
682 #endif // MAINWINDOW_H