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