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