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