Draw direction indicator triangle only when GPS location item is not visible
[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         Sami Rämö - sami.ramo@ixonos.com
8         Katri Kaikkonen - katri.kaikkonen@ixonos.com
9
10     Situare is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     version 2 as published by the Free Software Foundation.
13
14     Situare is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with Situare; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22     USA.
23 */
24
25 #ifndef MAINWINDOW_H
26 #define MAINWINDOW_H
27
28 #include <QtGui/QMainWindow>
29 #include <QUrl>
30
31 #include "network/networkcookiejar.h"
32 #include "panelsidebar.h"
33
34 class QGraphicsScene;
35 class QLabel;
36 class QMessageBox;
37 class QNetworkReply;
38 class QToolButton;
39 class QWebView;
40
41 class FacebookAuthentication;
42 class FullScreenButton;
43 class FriendListPanel;
44 class IndicatorButton;
45 class GeoCoordinate;
46 class MapScale;
47 class MapScene;
48 class MapView;
49 class SettingsDialog;
50 class SceneCoordinate;
51 class SituareService;
52 class User;
53 class UserInfoPanel;
54 class ZoomButtonPanel;
55
56
57 /**
58 * @brief Main Window Class
59 */
60 class MainWindow : public QMainWindow
61 {
62     Q_OBJECT
63
64 public:
65     /**
66      * @brief Constructor
67      *
68      * @param parent Parent
69      */
70     MainWindow(QWidget *parent = 0);
71
72     /**
73      * @brief Destructor
74      *
75      */
76     ~MainWindow();
77
78 /*******************************************************************************
79  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
80  ******************************************************************************/
81 private:
82     /**
83      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
84      */
85     void keyPressEvent(QKeyEvent* event);
86
87 /*******************************************************************************
88  * MEMBER FUNCTIONS AND SLOTS
89  ******************************************************************************/
90 public:
91     /**
92      * @brief Clears cookie jar
93      *
94      */
95     void clearCookieJar();
96
97     /**
98      * @brief
99      *
100      * @param logged
101      */
102     void loggedIn(bool logged);
103
104     /**
105      * @brief Gets the login state (logged in/logged out)
106      *
107      * @return bool Login state
108      */
109     bool loginState();
110
111     /**
112      * @brief Reads automatic location update settings.
113      */
114     void readAutomaticLocationUpdateSettings();
115
116 //    /**
117 //     * @brief Enable / disable auto centering button.
118 //     *
119 //     * @param enabled true if shoud be enabled, false otherwise
120 //     */
121 //    void setAutoCenteringButtonEnabled(bool enabled);
122
123     /**
124      * @brief Enable / disable GPS button.
125      *
126      * Does set visibilities for manual location cursor and auto centering menu button.
127      *
128      * @param enabled true if enabled, false otherwise
129      */
130     void setGPSButtonEnabled(bool enabled);
131
132     /**
133      * @brief Enable / disable direction indicator button.
134      *
135      * @param enabled true if shoud be enabled, false otherwise
136      */
137     void setIndicatorButtonEnabled(bool enabled);
138
139     /**
140      * @brief Set scene for MapView
141      *
142      * @param scene Scene to be set
143      */
144     void setMapViewScene(QGraphicsScene *scene);
145
146     /**
147      * Shows dialog with enable automatic location update question.
148      *
149      * @param text text to show in dialog
150      */
151     void showEnableAutomaticUpdateLocationDialog(const QString &text);
152
153     /**
154      * @brief Gets the username from member variable for saving purposes
155      *
156      * @return QString Username
157      */
158     const QString username();
159
160 public slots:
161
162     /**
163      * @brief Build direction indicator button and connect slots
164      */
165     void buildIndicatorButton();
166
167     /**
168      * @brief Builds information box with message.
169      *
170      * @param message Information message
171      * @param modal Modal = true, non-modal false
172      */
173     void buildInformationBox(const QString &message, bool modal=false);
174
175     /**
176      * @brief Slot for failed login
177      */
178     void loginFailed();
179
180     /**
181      * @brief Slot to intercept signal when login with cookies is requested
182      */
183     void loginUsingCookies();
184
185     /**
186      * @brief Public slot, which open settings dialog
187      */
188     void openSettingsDialog();
189
190     /**
191      * @brief Set own location crosshair visibility
192      *
193      * @param visible
194      */
195     void setOwnLocationCrosshairVisibility(bool visible);
196
197     /**
198      * @brief Sets username to member variable for login dialog
199      *
200      * @param username Username to be set
201      */
202     void setUsername(const QString &username);
203
204     /**
205      * @brief Method to show panels
206      */
207     void showPanels();
208
209     /**
210      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
211      *        doesn't exist yet
212      *
213      */
214     void startLoginProcess();
215
216     /**
217      * @brief Toggle progress indicator.
218      *
219      * @param state true if progress indicator should be shown, false otherwise
220      */
221     void toggleProgressIndicator(bool state);
222
223     /**
224      * @brief Shows / hides Situare related UI items
225      *
226      */
227     void updateItemVisibility();
228
229 private:
230     /**
231      * @brief Build fullscreen toggle button and connect slots
232      */
233     void buildFullScreenButton();
234
235     /**
236      * @brief Build friend list panel and connect slots
237      */
238     void buildFriendListPanel();
239
240     /**
241      * @brief Build manual location setting cross hair and connect slots
242      */
243     void buildManualLocationCrosshair();
244
245     /**
246      * @brief Build map and connect slots
247      */
248     void buildMap();
249
250     /**
251      * @brief Build map scale and connect slots
252      */
253     void buildMapScale();
254
255     /**
256      * @brief Build OSM license and connect slots
257      */
258     void buildOsmLicense();
259
260     /**
261      * @brief Build user info panel and connect slots
262      */
263     void buildUserInfoPanel();
264
265     /**
266      * @brief Build webview and connect slots
267      */
268     void buildWebView();
269
270     /**
271      * @brief Build zoom button panel and connect slots
272      */
273     void buildZoomButtonPanel();
274
275     /**
276      * @brief Private method to create the Menu items
277      */
278     void createMenus();
279
280     /**
281      * @brief Grab or release HW increase and decrease buttons.
282      *
283      * @param grab Use true for grabbing and false for releasing the keys
284      */
285     void grabZoomKeys(bool grab);
286
287     /**
288      * @brief Queues dialog/information box
289      *
290      * @param dialog Dialog to be added into queue
291      */
292     void queueDialog(QDialog *dialog);
293
294     /**
295      * @brief Shows queued error information box
296      *
297      */
298     void showErrorInformationBox();
299
300     /**
301      * @brief Shows queued information box
302      *
303      * @fn showInformationBox
304      */
305     void showInformationBox();
306
307 private slots:
308     /**
309      * @brief Slot for automatic update dialog finished.
310      *
311      * @result result code
312      */
313     void automaticUpdateDialogFinished(int result);
314
315     /**
316      * @brief Slot to intercept signal when dialog/information note is processed
317      *
318      * @param status Status of the dialog
319      */
320     void dialogFinished(int status);
321
322     /**
323      * @brief Slot for drawing the fullscreen toggle button
324      *
325      * @param size Size of the screen
326      */
327     void drawFullScreenButton(const QSize &size);
328
329     /**
330      * @brief Slot for drawing the map distance scale
331      *
332      * @param size Size of the screen
333      */
334     void drawMapScale(const QSize &size);
335
336     /**
337      * @brief Slot for drawing the Open Street Map license text
338      *
339      * @param size Size of the screen
340      */
341     void drawOsmLicense(const QSize &size);
342
343     /**
344      * @brief Slot for drawing the own location crosshair
345      *
346      * @param size Size of the screen
347      */
348     void drawOwnLocationCrosshair(const QSize &size);
349
350     /**
351      * @brief Slot to intercept signal when error dialog/information note is processed
352      *
353      * @param status Status of the dialog
354      */
355     void errorDialogFinished(int status);
356
357     /**
358      * @brief Slot for gps timeout.
359      *
360      * Called when request timeout occurs.
361      */
362     void gpsTimeout();
363
364     /**
365      * @brief Slot to load cookies from settings
366      */
367     void loadCookies();
368
369     /**
370      * @brief Slot to intercept signal when webview has finished loading webpage
371      *
372      * @param done Status of the loading
373      */
374     void loadDone(bool done);
375
376     /**
377      * @brief Slot to save cookies to settings
378      */
379     void saveCookies();
380
381     /**
382      * @brief Slot for settings dialog accepted.
383      */
384     void settingsDialogAccepted();
385
386     /**
387      * @brief Set correnct view port size to datamembers
388      *
389      * @param size Size of the screen
390      */
391     void setViewPortSize(const QSize &size);
392
393     /**
394      * @brief Start location search (open search dialog)
395      */
396     void startLocationSearch();
397
398     /**
399      * @brief Toggle between fullscreen and normal window mode
400      */
401     void toggleFullScreen();
402
403     /**
404      * @brief Slot to intercept signal from webview's networkaccessmanager
405      *
406      * @param reply Network reply (contains errors)
407      */
408     void webViewRequestFinished(QNetworkReply* reply);
409
410 /*******************************************************************************
411  * SIGNALS
412  ******************************************************************************/
413 signals:
414     /**
415      * @brief Automatic centering setting changed by user
416      *
417      * @param enabled True if automatic centering is enabled, otherwise false
418      */
419     void autoCenteringTriggered(bool enabled);
420
421     /**
422      * @brief Signal that indicates when user has cancelled login process
423      *
424      */
425     void cancelLoginProcess();
426
427     /**
428      * @brief View should be centered to new location
429      *
430      * @param coordinate Scene coordinates of the new center point
431      */
432     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
433
434     /**
435     * @brief Signal when direction and distance from current map center point to current GPS
436     *        location is changed
437     *
438     * @param direction Direction in degrees
439     * @param distance Distance in kilometers
440     * @param draw Should the indicator triangle be drawn or not
441     */
442     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
443
444     /**
445      * @brief Signal for enabling automatic location update.
446      *
447      * @param enabled true if enabled, false otherwise
448      * @param updateIntervalMsecs update interval in milliseconds
449      */
450     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
451
452     /**
453      * @brief Signals error
454      *
455      * @param context error context
456      * @param error error code
457      */
458     void error(const int context, const int error);
459
460     /**
461      * @brief Signal for requesting username from settings
462      *
463      */
464     void fetchUsernameFromSettings();
465
466     /**
467      * @brief Signal for finding user.
468      *
469      * @param coordinates user geo coordinates
470      */
471     void findUser(const GeoCoordinate &coordinates);
472
473     /**
474      * @brief Signals when friend's profile image is ready
475      *
476      * @param user Friend
477      */
478     void friendImageReady(User *user);
479
480     /**
481      * @brief GPS setting changed
482      *
483      * @param enabled True if GPS is enabled, otherwise false
484      */
485     void gpsTriggered(bool enabled);
486
487     /**
488      * @brief Signal for finding friend.
489      *
490      * @param coordinates friend's geo coordinates
491      */
492     void findFriend(const GeoCoordinate &coordinates);
493
494     /**
495      * @brief Signal for friend location ready.
496      *
497      * @param friendsList
498      */
499     void friendsLocationsReady(QList<User *> &friendsList);
500
501     /**
502      * @brief Signal is emitted when location item is clicked.
503      *
504      * @param userIDs list of friends user IDs in the group
505      */
506     void locationItemClicked(const QList<QString> &userIDs);
507
508     /**
509      * @brief Signals when Login/Logout action is pressed
510      *
511      */
512     void loginActionPressed();
513
514     /**
515      * @brief MapView has been resized
516      *
517      * @param size view size
518      */
519     void mapViewResized(const QSize &size);
520
521     /**
522      * @brief Forwarding signal from MapView to MapEngine
523      *
524      * @param coordinate
525      */
526     void mapViewScrolled(const SceneCoordinate &coordinate);
527
528     /**
529      * @brief Forwarding signal from MapEngine to MapView
530      */
531     void maxZoomLevelReached();
532
533     /**
534      * @brief Forwarding signal from MapEngine to MapView
535      */
536     void minZoomLevelReached();
537
538     /**
539      * @brief Forwarding signal from MapEngine to MapScale
540      */
541     void newMapResolution(qreal scale);
542
543     /**
544      * @brief Signal for refreshing user data.
545      *
546      */
547     void refreshUserData();
548
549     /**
550      * @brief Signal for requesting reverseGeo from SituareEngine
551      *
552      */
553     void requestReverseGeo();
554
555     /**
556      * @brief Signals, when address data is ready
557      *
558      * @param address Street address
559      */
560     void reverseGeoReady(const QString &address);
561
562     /**
563      * @brief Signal to save username to settings
564      *
565      * @param username Username
566      */
567     void saveUsername(const QString &username);
568
569     /**
570      * @brief Signal for location search
571      *
572      * @param location QString location
573      */
574     void searchForLocation(QString location);
575
576     /**
577      * @brief Signal for requestLocationUpdate from SituareEngine
578      *
579      * @param status Status message
580      * @param publish Publish on Facebook
581      */
582     void statusUpdate(const QString &status, const bool &publish);
583
584     /**
585      * @brief Signals when webview's urlChanged signal is emitted
586      *
587      * @param url New url
588      */
589     void updateCredentials(const QUrl &url);
590
591     /**
592      * @brief Signals when updateLocationDialog's data must be cleared
593      *
594      */
595     void clearUpdateLocationDialogData();
596
597     /**
598      * @brief MapView has finished zooming
599      */
600     void viewZoomFinished();
601
602     /**
603      * @brief Signal for use location ready.
604      *
605      * @param user User object
606      */
607     void userLocationReady(User *user);
608
609     /**
610      * @brief Map zoom in request
611      */
612     void zoomIn();
613
614     /**
615      * @brief Forwarding signal from MapEngine to MapView
616      */
617     void zoomLevelChanged(int zoomLevel);
618
619     /**
620      * @brief Map zoom out request
621      */
622     void zoomOut();
623
624 /*******************************************************************************
625  * DATA MEMBERS
626  ******************************************************************************/
627 private:
628     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
629     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
630     bool m_loggedIn;                        ///< Indicates login state
631     bool m_refresh;                         ///< Indicates when webpage is refreshed
632
633     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
634
635     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
636     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
637     QAction *m_loginAct;                    ///< Action to Login/Logout
638     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
639     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
640
641     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
642     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
643
644     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
645     QList<QDialog *> m_queue;               ///< QList type dialog queue
646
647     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
648
649     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
650
651     QSize m_viewPortSize;                 ///< Size of the viewport
652
653     QString m_email;                        ///< Placeholder for email
654     QString m_password;                     ///< Placeholder for password
655
656     QWebView *m_webView;                    ///< Shows facebook login page
657
658     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
659     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
660     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
661     MapScale *m_mapScale;                   ///< Instance of the map scale
662     MapView *m_mapView;                     ///< Instance of the map view
663     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
664     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
665     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
666     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
667     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
668 };
669
670 #endif // MAINWINDOW_H