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