Direction indicator triange updating
[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     */
441     void directionIndicatorValuesUpdate(qreal direction, qreal distance);
442
443     /**
444      * @brief Signal for enabling automatic location update.
445      *
446      * @param enabled true if enabled, false otherwise
447      * @param updateIntervalMsecs update interval in milliseconds
448      */
449     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
450
451     /**
452      * @brief Signals error
453      *
454      * @param context error context
455      * @param error error code
456      */
457     void error(const int context, const int error);
458
459     /**
460      * @brief Signal for requesting username from settings
461      *
462      */
463     void fetchUsernameFromSettings();
464
465     /**
466      * @brief Signal for finding user.
467      *
468      * @param coordinates user geo coordinates
469      */
470     void findUser(const GeoCoordinate &coordinates);
471
472     /**
473      * @brief Signals when friend's profile image is ready
474      *
475      * @param user Friend
476      */
477     void friendImageReady(User *user);
478
479     /**
480      * @brief GPS setting changed
481      *
482      * @param enabled True if GPS is enabled, otherwise false
483      */
484     void gpsTriggered(bool enabled);
485
486     /**
487      * @brief Signal for finding friend.
488      *
489      * @param coordinates friend's geo coordinates
490      */
491     void findFriend(const GeoCoordinate &coordinates);
492
493     /**
494      * @brief Signal for friend location ready.
495      *
496      * @param friendsList
497      */
498     void friendsLocationsReady(QList<User *> &friendsList);
499
500     /**
501      * @brief Signal is emitted when location item is clicked.
502      *
503      * @param userIDs list of friends user IDs in the group
504      */
505     void locationItemClicked(const QList<QString> &userIDs);
506
507     /**
508      * @brief Signals when Login/Logout action is pressed
509      *
510      */
511     void loginActionPressed();
512
513     /**
514      * @brief MapView has been resized
515      *
516      * @param size view size
517      */
518     void mapViewResized(const QSize &size);
519
520     /**
521      * @brief Forwarding signal from MapView to MapEngine
522      *
523      * @param coordinate
524      */
525     void mapViewScrolled(const SceneCoordinate &coordinate);
526
527     /**
528      * @brief Forwarding signal from MapEngine to MapView
529      */
530     void maxZoomLevelReached();
531
532     /**
533      * @brief Forwarding signal from MapEngine to MapView
534      */
535     void minZoomLevelReached();
536
537     /**
538      * @brief Forwarding signal from MapEngine to MapScale
539      */
540     void newMapResolution(qreal scale);
541
542     /**
543      * @brief Signal for refreshing user data.
544      *
545      */
546     void refreshUserData();
547
548     /**
549      * @brief Signal for requesting reverseGeo from SituareEngine
550      *
551      */
552     void requestReverseGeo();
553
554     /**
555      * @brief Signals, when address data is ready
556      *
557      * @param address Street address
558      */
559     void reverseGeoReady(const QString &address);
560
561     /**
562      * @brief Signal to save username to settings
563      *
564      * @param username Username
565      */
566     void saveUsername(const QString &username);
567
568     /**
569      * @brief Signal for location search
570      *
571      * @param location QString location
572      */
573     void searchForLocation(QString location);
574
575     /**
576      * @brief Signal for requestLocationUpdate from SituareEngine
577      *
578      * @param status Status message
579      * @param publish Publish on Facebook
580      */
581     void statusUpdate(const QString &status, const bool &publish);
582
583     /**
584      * @brief Signals when webview's urlChanged signal is emitted
585      *
586      * @param url New url
587      */
588     void updateCredentials(const QUrl &url);
589
590     /**
591      * @brief Signals when updateLocationDialog's data must be cleared
592      *
593      */
594     void clearUpdateLocationDialogData();
595
596     /**
597      * @brief MapView has finished zooming
598      */
599     void viewZoomFinished();
600
601     /**
602      * @brief Signal for use location ready.
603      *
604      * @param user User object
605      */
606     void userLocationReady(User *user);
607
608     /**
609      * @brief Map zoom in request
610      */
611     void zoomIn();
612
613     /**
614      * @brief Forwarding signal from MapEngine to MapView
615      */
616     void zoomLevelChanged(int zoomLevel);
617
618     /**
619      * @brief Map zoom out request
620      */
621     void zoomOut();
622
623 /*******************************************************************************
624  * DATA MEMBERS
625  ******************************************************************************/
626 private:
627     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
628     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
629     bool m_loggedIn;                        ///< Indicates login state
630     bool m_refresh;                         ///< Indicates when webpage is refreshed
631
632     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
633
634     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
635     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
636     QAction *m_loginAct;                    ///< Action to Login/Logout
637     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
638     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
639
640     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
641     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
642
643     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
644     QList<QDialog *> m_queue;               ///< QList type dialog queue
645
646     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
647
648     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
649
650     QSize m_viewPortSize;                 ///< Size of the viewport
651
652     QString m_email;                        ///< Placeholder for email
653     QString m_password;                     ///< Placeholder for password
654
655     QWebView *m_webView;                    ///< Shows facebook login page
656
657     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
658     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
659     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
660     MapScale *m_mapScale;                   ///< Instance of the map scale
661     MapView *m_mapView;                     ///< Instance of the map view
662     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
663     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
664     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
665     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
666     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
667 };
668
669 #endif // MAINWINDOW_H