Merge branch 'master' into login_browser
[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 QGraphicsScene;
37 class QLabel;
38 class QMessageBox;
39 class QNetworkReply;
40 class QToolButton;
41 class QWebView;
42
43 class FacebookAuthentication;
44 class FacebookLoginBrowser;
45 class FriendListPanel;
46 class FullScreenButton;
47 class GeoCoordinate;
48 class IndicatorButtonPanel;
49 class Location;
50 class LocationSearchPanel;
51 class MapScale;
52 class MapScene;
53 class MapView;
54 class Route;
55 class RoutingPanel;
56 class SceneCoordinate;
57 class SettingsDialog;
58 class SituareService;
59 class TabbedPanel;
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 Clears cookie jar
99      *
100      */
101     void clearCookieJar();
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     void buildFacebookLoginBrowser();
161
162     void destroyFacebookLoginBrowser();
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 setCrosshairVisibility(bool visible);
193
194     /**
195     * @brief Shows contact dialog.
196     *
197     * Shows contact dialog with contact's information.
198     * @param guid globally unique ID of a contact
199     */
200     void showContactDialog(const QString &guid);
201
202     /**
203      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
204      *        doesn't exist yet
205      */
206     void startLoginProcess();
207
208     /**
209      * @brief Toggle progress indicator.
210      *
211      * @param state true if progress indicator should be shown, false otherwise
212      */
213     void toggleProgressIndicator(bool state);
214
215     /**
216      * @brief Shows / hides Situare related UI items
217      *
218      */
219     void updateItemVisibility();
220
221 private:
222     /**
223      * @brief Build manual location setting cross hair and connect slots
224      */
225     void buildCrosshair();
226
227     /**
228      * @brief Build friend list panel and connect slots
229      */
230     void buildFriendListPanel();
231
232     /**
233      * @brief Build fullscreen toggle button and connect slots
234      */
235     void buildFullScreenButton();
236
237     /**
238      * @brief Build direction indicator button panel and connect signals
239      */
240     void buildIndicatorButtonPanel();
241
242
243     /**
244      * @brief Build location search panel and connect signals
245      */
246     void buildLocationSearchPanel();
247
248     /**
249      * @brief Build map and connect slots
250      */
251     void buildMap();
252
253     /**
254      * @brief Build map scale and connect slots
255      */
256     void buildMapScale();
257
258     /**
259      * @brief Build OSM license and connect slots
260      */
261     void buildOsmLicense();
262
263     /**
264      * @brief Build application panels
265      */
266     void buildPanels();
267
268     /**
269      * @brief Build routing panel and connect slots
270      */
271     void buildRoutingPanel();
272
273     /**
274      * @brief Build user info panel and connect slots
275      */
276     void buildUserInfoPanel();
277
278     /**
279      * @brief Build webview and connect slots
280      */
281     void buildWebView();
282
283     /**
284      * @brief Build zoom button panel and connect slots
285      */
286     void buildZoomButtonPanel();
287
288     /**
289      * @brief Private method to create the Menu items
290      */
291     void createMenus();
292
293     /**
294      * @brief Grab or release HW increase and decrease buttons.
295      *
296      * @param grab Use true for grabbing and false for releasing the keys
297      */
298     void grabZoomKeys(bool grab);
299
300     /**
301      * @brief Queues dialog/information box
302      *
303      * @param dialog Dialog to be added into queue
304      */
305     void queueDialog(QDialog *dialog);
306
307     /**
308      * @brief Shows queued error information box
309      *
310      */
311     void showErrorInformationBox();
312
313     /**
314      * @brief Shows queued information box
315      *
316      * @fn showInformationBox
317      */
318     void showInformationBox();
319
320 private slots:
321     /**
322      * @brief Slot for automatic update dialog finished.
323      *
324      * @result result code
325      */
326     void automaticUpdateDialogFinished(int result);
327
328     /**
329      * @brief Slot to intercept signal when dialog/information note is processed
330      *
331      * @param status Status of the dialog
332      */
333     void dialogFinished(int status);
334
335     /**
336      * @brief Slot for drawing the fullscreen toggle button
337      *
338      * @param size Size of the screen
339      */
340     void drawFullScreenButton(const QSize &size);
341
342     /**
343      * @brief Slot for drawing the map distance scale
344      *
345      * @param size Size of the screen
346      */
347     void drawMapScale(const QSize &size);
348
349     /**
350      * @brief Slot for drawing the Open Street Map license text
351      *
352      * @param size Size of the screen
353      */
354     void drawOsmLicense(const QSize &size);
355
356     /**
357      * @brief Slot to intercept signal when error dialog/information note is processed
358      *
359      * @param status Status of the dialog
360      */
361     void errorDialogFinished(int status);
362
363     /**
364      * @brief Slot for gps timeout.
365      *
366      * Called when request timeout occurs.
367      */
368     void gpsTimeout();
369
370     /**
371      * @brief Slot to load cookies from settings
372      */
373     void loadCookies();
374
375     /**
376      * @brief Slot to intercept signal when webview has finished loading webpage
377      *
378      * @param done Status of the loading
379      */
380     void loadDone(bool done);
381
382     /**
383     * @brief Called when map center point horizontal shifting is changed
384     *
385     * @param shifting New shifting value
386     */
387     void mapCenterHorizontalShiftingChanged(int shifting);
388
389     /**
390      * @brief Move the crosshair
391      */
392     void moveCrosshair();
393
394     /**
395      * @brief Slot to save cookies to settings
396      */
397     void saveCookies();
398
399     /**
400      * @brief Slot for settings dialog accepted.
401      */
402     void settingsDialogAccepted();
403
404     /**
405      * @brief Ignore SSL error from the reply
406      */
407     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
408
409     /**
410      * @brief Start location search (open search dialog)
411      */
412     void startLocationSearch();
413
414     /**
415      * @brief Toggle between fullscreen and normal window mode
416      */
417     void toggleFullScreen();
418
419     /**
420      * @brief Slot to intercept signal from webview's networkaccessmanager
421      *
422      * @param reply Network reply (contains errors)
423      */
424     void webViewRequestFinished(QNetworkReply* reply);
425
426 /*******************************************************************************
427  * SIGNALS
428  ******************************************************************************/
429 signals:
430     /**
431      * @brief Automatic centering setting changed by user
432      *
433      * @param enabled True if automatic centering is enabled, otherwise false
434      */
435     void autoCenteringTriggered(bool enabled);
436
437     /**
438      * @brief Signal that indicates when user has cancelled login process
439      *
440      */
441     void cancelLoginProcess();
442
443     /**
444      * @brief Signal for centering to coordinates.
445      *
446      * @param coordinates geo coordinates to center to.
447      */
448     void centerToCoordinates(const GeoCoordinate &coordinates);
449
450     /**
451      * @brief View should be centered to new location
452      *
453      * @param coordinate Scene coordinates of the new center point
454      */
455     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
456
457     /**
458     * @brief Emitted when route is cleared
459     */
460     void clearRoute();
461
462     /**
463     * @brief Signal when direction and distance from current map center point to current GPS
464     *        location is changed
465     *
466     * @param direction Direction in degrees
467     * @param distance Distance in meters
468     * @param draw Should the indicator triangle be drawn or not
469     */
470     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
471
472     /**
473      * @brief Signal for enabling automatic location update.
474      *
475      * @param enabled true if enabled, false otherwise
476      * @param updateIntervalMsecs update interval in milliseconds
477      */
478     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
479
480     /**
481      * @brief Signals error
482      *
483      * @param context error context
484      * @param error error code
485      */
486     void error(const int context, const int error);
487
488     /**
489      * @brief Signal for requesting username from settings
490      *
491      */
492     void fetchUsernameFromSettings();
493
494     /**
495      * @brief Signals when friend's profile image is ready
496      *
497      * @param user Friend
498      */
499     void friendImageReady(User *user);
500
501     /**
502      * @brief GPS setting changed
503      *
504      * @param enabled True if GPS is enabled, otherwise false
505      */
506     void gpsTriggered(bool enabled);
507
508     /**
509      * @brief Signal for friend location ready.
510      *
511      * @param friendsList
512      */
513     void friendsLocationsReady(QList<User *> &friendsList);
514
515     /**
516     * @brief Emited when location request is parsed and is ready for further processing
517     *
518     * @param result List of Location items
519     */
520     void locationDataParsed(const QList<Location> &result);
521
522     /**
523      * @brief Signal is emitted when location item is clicked on map.
524      *
525      * @param userIDs list of friends user IDs in the group
526      */
527     void locationItemClicked(const QList<QString> &userIDs);
528
529     /**
530      * @brief Signal is emitted when location item is clicked in list.
531      *
532      * @param swBound south-west bound in GeoCoorinate
533      * @param neBound north-east bound in GeoCoordinate
534      */
535     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
536
537     /**
538      * @brief Signals when Login/Logout action is pressed
539      *
540      */
541     void loginActionPressed();
542
543     void loginBrowserCreated(FacebookLoginBrowser *);
544
545     /**
546      * @brief MapView has been resized
547      *
548      * @param size view size
549      */
550     void mapViewResized(const QSize &size);
551
552     /**
553      * @brief Forwarding signal from MapView to MapEngine
554      *
555      * @param coordinate New center point coordinate
556      */
557     void mapViewScrolled(const SceneCoordinate &coordinate);
558
559     /**
560      * @brief Forwarding signal from MapEngine to MapView
561      */
562     void maxZoomLevelReached();
563
564     /**
565      * @brief Forwarding signal from MapEngine to MapView
566      */
567     void minZoomLevelReached();
568
569     /**
570      * @brief Forwarding signal from MapEngine to MapScale
571      */
572     void newMapResolution(qreal scale);
573
574     /**
575      * @brief Signal for refreshing user data.
576      *
577      */
578     void refreshUserData();
579
580     /**
581     * @brief Requests contact dialog.
582     *
583     * @param facebookId contact's facebookId
584     */
585     void requestContactDialog(const QString &facebookId);
586
587     /**
588      * @brief Signal for requesting reverseGeo from SituareEngine
589      *
590      */
591     void requestReverseGeo();
592
593     /**
594      * @brief Signals, when address data is ready
595      *
596      * @param address Street address
597      */
598     void reverseGeoReady(const QString &address);
599
600     /**
601     * @brief Emited when route is parsed and is ready for further processing
602     *
603     * @param route Route item containing parsed route details
604     */
605     void routeParsed(Route &route);
606
607     /**
608     * @brief Signal for routing to geo coordinates.
609     *
610     * @param coordinates destination geo coordinates
611     */
612     void routeTo(const GeoCoordinate &coordinates);
613
614     /**
615     * @brief Request routing to current cursor position
616     */
617     void routeToCursor();
618
619     /**
620      * @brief Signal for location search
621      *
622      * @param location QString location
623      */
624     void searchForLocation(QString location);
625
626     /**
627     * @brief Signal is emitted when search history item is clicked.
628     *
629     * @param searchString search string used
630     */
631     void searchHistoryItemClicked(const QString &searchString);
632
633     /**
634      * @brief Signal for requestLocationUpdate from SituareEngine
635      *
636      * @param status Status message
637      * @param publish Publish on Facebook
638      */
639     void statusUpdate(const QString &status, const bool &publish);
640
641     /**
642      * @brief Signals when webview's urlChanged signal is emitted
643      *
644      * @param url New url
645      */
646     void updateCredentials(const QUrl &url);
647
648     /**
649      * @brief Signals when updateLocationDialog's data must be cleared
650      *
651      */
652     void clearUpdateLocationDialogData();
653
654     /**
655     * @brief Dragging mode triggered.
656     */
657     void draggingModeTriggered();
658
659     /**
660      * @brief MapView has finished zooming
661      */
662     void viewZoomFinished();
663
664     /**
665      * @brief Signal for use location ready.
666      *
667      * @param user User object
668      */
669     void userLocationReady(User *user);
670
671     /**
672      * @brief Map zoom in request
673      */
674     void zoomIn();
675
676     /**
677      * @brief Forwarding signal from MapEngine to MapView
678      */
679     void zoomLevelChanged(int zoomLevel);
680
681     /**
682      * @brief Map zoom out request
683      */
684     void zoomOut();
685
686 /*******************************************************************************
687  * DATA MEMBERS
688  ******************************************************************************/
689 private:
690     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
691     bool m_loggedIn;                        ///< Indicates login state
692     bool m_refresh;                         ///< Indicates when webpage is refreshed
693
694     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
695     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
696
697     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
698     QAction *m_loginAct;                    ///< Action to Login/Logout
699     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
700
701     QLabel *m_crosshair;                    ///< Label for center point crosshair
702     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
703
704     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
705     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
706     QList<QDialog *> m_queue;               ///< QList type dialog queue
707
708     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
709
710     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
711
712     QString m_email;                        ///< Placeholder for email
713     QString m_password;                     ///< Placeholder for password
714
715     QWebView *m_webView;                    ///< Shows facebook login page
716
717     FacebookLoginBrowser *m_facebookLoginBrowser;
718     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
719     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
720     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
721     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
722     MapScale *m_mapScale;                   ///< Instance of the map scale
723     MapView *m_mapView;                     ///< Instance of the map view
724     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
725     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
726     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
727     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
728     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
729 };
730
731 #endif // MAINWINDOW_H