Ignore SSL errors from the network reply
[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 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     /**
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 Builds information box with message.
161      *
162      * @param message Information message
163      * @param modal Modal = true, non-modal false
164      */
165     void buildInformationBox(const QString &message, bool modal=false);
166
167     /**
168      * @brief Slot for failed login
169      */
170     void loginFailed();
171
172     /**
173      * @brief Slot to intercept signal when login with cookies is requested
174      */
175     void loginUsingCookies();
176
177     /**
178      * @brief Public slot, which open settings dialog
179      */
180     void openSettingsDialog();
181
182     /**
183      * @brief Set own location crosshair visibility
184      *
185      * @param visible
186      */
187     void setCrosshairVisibility(bool visible);
188
189     /**
190      * @brief Sets username to member variable for login dialog
191      *
192      * @param username Username to be set
193      */
194     void setUsername(const QString &username);
195
196     /**
197     * @brief Shows contact dialog.
198     *
199     * Shows contact dialog with contact's information.
200     * @param guid globally unique ID of a contact
201     */
202     void showContactDialog(const QString &guid);
203
204     /**
205      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
206      *        doesn't exist yet
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 manual location setting cross hair and connect slots
226      */
227     void buildCrosshair();
228
229     /**
230      * @brief Build friend list panel and connect slots
231      */
232     void buildFriendListPanel();
233
234     /**
235      * @brief Build fullscreen toggle button and connect slots
236      */
237     void buildFullScreenButton();
238
239     /**
240      * @brief Build direction indicator button panel and connect signals
241      */
242     void buildIndicatorButtonPanel();
243
244
245     /**
246      * @brief Build location search panel and connect signals
247      */
248     void buildLocationSearchPanel();
249
250     /**
251      * @brief Build map and connect slots
252      */
253     void buildMap();
254
255     /**
256      * @brief Build map scale and connect slots
257      */
258     void buildMapScale();
259
260     /**
261      * @brief Build OSM license and connect slots
262      */
263     void buildOsmLicense();
264
265     /**
266      * @brief Build application panels
267      */
268     void buildPanels();
269
270     /**
271      * @brief Build routing panel and connect slots
272      */
273     void buildRoutingPanel();
274
275     /**
276      * @brief Build user info panel and connect slots
277      */
278     void buildUserInfoPanel();
279
280     /**
281      * @brief Build webview and connect slots
282      */
283     void buildWebView();
284
285     /**
286      * @brief Build zoom button panel and connect slots
287      */
288     void buildZoomButtonPanel();
289
290     /**
291      * @brief Private method to create the Menu items
292      */
293     void createMenus();
294
295     /**
296      * @brief Grab or release HW increase and decrease buttons.
297      *
298      * @param grab Use true for grabbing and false for releasing the keys
299      */
300     void grabZoomKeys(bool grab);
301
302     /**
303      * @brief Queues dialog/information box
304      *
305      * @param dialog Dialog to be added into queue
306      */
307     void queueDialog(QDialog *dialog);
308
309     /**
310      * @brief Shows queued error information box
311      *
312      */
313     void showErrorInformationBox();
314
315     /**
316      * @brief Shows queued information box
317      *
318      * @fn showInformationBox
319      */
320     void showInformationBox();
321
322 private slots:
323     /**
324      * @brief Slot for automatic update dialog finished.
325      *
326      * @result result code
327      */
328     void automaticUpdateDialogFinished(int result);
329
330     /**
331      * @brief Slot to intercept signal when dialog/information note is processed
332      *
333      * @param status Status of the dialog
334      */
335     void dialogFinished(int status);
336
337     /**
338      * @brief Slot for drawing the fullscreen toggle button
339      *
340      * @param size Size of the screen
341      */
342     void drawFullScreenButton(const QSize &size);
343
344     /**
345      * @brief Slot for drawing the map distance scale
346      *
347      * @param size Size of the screen
348      */
349     void drawMapScale(const QSize &size);
350
351     /**
352      * @brief Slot for drawing the Open Street Map license text
353      *
354      * @param size Size of the screen
355      */
356     void drawOsmLicense(const QSize &size);
357
358     /**
359      * @brief Slot to intercept signal when error dialog/information note is processed
360      *
361      * @param status Status of the dialog
362      */
363     void errorDialogFinished(int status);
364
365     /**
366      * @brief Slot for gps timeout.
367      *
368      * Called when request timeout occurs.
369      */
370     void gpsTimeout();
371
372     /**
373      * @brief Slot to load cookies from settings
374      */
375     void loadCookies();
376
377     /**
378      * @brief Slot to intercept signal when webview has finished loading webpage
379      *
380      * @param done Status of the loading
381      */
382     void loadDone(bool done);
383
384     /**
385     * @brief Called when map center point horizontal shifting is changed
386     *
387     * @param shifting New shifting value
388     */
389     void mapCenterHorizontalShiftingChanged(int shifting);
390
391     /**
392      * @brief Move the crosshair
393      */
394     void moveCrosshair();
395
396     /**
397      * @brief Slot to save cookies to settings
398      */
399     void saveCookies();
400
401     /**
402      * @brief Slot for settings dialog accepted.
403      */
404     void settingsDialogAccepted();
405
406     /**
407      * @brief Ignore SSL error from the reply
408      */
409     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
410
411     /**
412      * @brief Start location search (open search dialog)
413      */
414     void startLocationSearch();
415
416     /**
417      * @brief Toggle between fullscreen and normal window mode
418      */
419     void toggleFullScreen();
420
421     /**
422      * @brief Slot to intercept signal from webview's networkaccessmanager
423      *
424      * @param reply Network reply (contains errors)
425      */
426     void webViewRequestFinished(QNetworkReply* reply);
427
428 /*******************************************************************************
429  * SIGNALS
430  ******************************************************************************/
431 signals:
432     /**
433      * @brief Automatic centering setting changed by user
434      *
435      * @param enabled True if automatic centering is enabled, otherwise false
436      */
437     void autoCenteringTriggered(bool enabled);
438
439     /**
440      * @brief Signal that indicates when user has cancelled login process
441      *
442      */
443     void cancelLoginProcess();
444
445     /**
446      * @brief Signal for centering to coordinates.
447      *
448      * @param coordinates geo coordinates to center to.
449      */
450     void centerToCoordinates(const GeoCoordinate &coordinates);
451
452     /**
453      * @brief View should be centered to new location
454      *
455      * @param coordinate Scene coordinates of the new center point
456      */
457     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
458
459     /**
460     * @brief Emitted when route is cleared
461     */
462     void clearRoute();
463
464     /**
465     * @brief Signal when direction and distance from current map center point to current GPS
466     *        location is changed
467     *
468     * @param direction Direction in degrees
469     * @param distance Distance in meters
470     * @param draw Should the indicator triangle be drawn or not
471     */
472     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
473
474     /**
475      * @brief Signal for enabling automatic location update.
476      *
477      * @param enabled true if enabled, false otherwise
478      * @param updateIntervalMsecs update interval in milliseconds
479      */
480     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
481
482     /**
483      * @brief Signals error
484      *
485      * @param context error context
486      * @param error error code
487      */
488     void error(const int context, const int error);
489
490     /**
491      * @brief Signal for requesting username from settings
492      *
493      */
494     void fetchUsernameFromSettings();
495
496     /**
497      * @brief Signals when friend's profile image is ready
498      *
499      * @param user Friend
500      */
501     void friendImageReady(User *user);
502
503     /**
504      * @brief GPS setting changed
505      *
506      * @param enabled True if GPS is enabled, otherwise false
507      */
508     void gpsTriggered(bool enabled);
509
510     /**
511      * @brief Signal for friend location ready.
512      *
513      * @param friendsList
514      */
515     void friendsLocationsReady(QList<User *> &friendsList);
516
517     /**
518     * @brief Emited when location request is parsed and is ready for further processing
519     *
520     * @param result List of Location items
521     */
522     void locationDataParsed(const QList<Location> &result);
523
524     /**
525      * @brief Signal is emitted when location item is clicked on map.
526      *
527      * @param userIDs list of friends user IDs in the group
528      */
529     void locationItemClicked(const QList<QString> &userIDs);
530
531     /**
532      * @brief Signal is emitted when location item is clicked in list.
533      *
534      * @param swBound south-west bound in GeoCoorinate
535      * @param neBound north-east bound in GeoCoordinate
536      */
537     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
538
539     /**
540      * @brief Signals when Login/Logout action is pressed
541      *
542      */
543     void loginActionPressed();
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 to save username to settings
621      *
622      * @param username Username
623      */
624     void saveUsername(const QString &username);
625
626     /**
627      * @brief Signal for location search
628      *
629      * @param location QString location
630      */
631     void searchForLocation(QString location);
632
633     /**
634     * @brief Signal is emitted when search history item is clicked.
635     *
636     * @param searchString search string used
637     */
638     void searchHistoryItemClicked(const QString &searchString);
639
640     /**
641      * @brief Signal for requestLocationUpdate from SituareEngine
642      *
643      * @param status Status message
644      * @param publish Publish on Facebook
645      */
646     void statusUpdate(const QString &status, const bool &publish);
647
648     /**
649      * @brief Signals when webview's urlChanged signal is emitted
650      *
651      * @param url New url
652      */
653     void updateCredentials(const QUrl &url);
654
655     /**
656      * @brief Signals when updateLocationDialog's data must be cleared
657      *
658      */
659     void clearUpdateLocationDialogData();
660
661     /**
662     * @brief Dragging mode triggered.
663     */
664     void draggingModeTriggered();
665
666     /**
667      * @brief MapView has finished zooming
668      */
669     void viewZoomFinished();
670
671     /**
672      * @brief Signal for use location ready.
673      *
674      * @param user User object
675      */
676     void userLocationReady(User *user);
677
678     /**
679      * @brief Map zoom in request
680      */
681     void zoomIn();
682
683     /**
684      * @brief Forwarding signal from MapEngine to MapView
685      */
686     void zoomLevelChanged(int zoomLevel);
687
688     /**
689      * @brief Map zoom out request
690      */
691     void zoomOut();
692
693 /*******************************************************************************
694  * DATA MEMBERS
695  ******************************************************************************/
696 private:
697     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
698     bool m_loggedIn;                        ///< Indicates login state
699     bool m_refresh;                         ///< Indicates when webpage is refreshed
700
701     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
702     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
703
704     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
705     QAction *m_loginAct;                    ///< Action to Login/Logout
706     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
707
708     QLabel *m_crosshair;                    ///< Label for center point crosshair
709     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
710
711     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
712     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
713     QList<QDialog *> m_queue;               ///< QList type dialog queue
714
715     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
716
717     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
718
719     QString m_email;                        ///< Placeholder for email
720     QString m_password;                     ///< Placeholder for password
721
722     QWebView *m_webView;                    ///< Shows facebook login page
723
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