Added fibration feedback feature.
[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 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     /**
147      * @brief Gets the username from member variable for saving purposes
148      *
149      * @return QString Username
150      */
151     const QString username();
152
153 public slots:
154
155     /**
156      * @brief Build direction indicator button and connect slots
157      */
158     void buildIndicatorButton();
159
160     /**
161      * @brief Builds information box with message.
162      *
163      * @param message Information message
164      * @param modal Modal = true, non-modal false
165      */
166     void buildInformationBox(const QString &message, bool modal=false);
167
168     /**
169      * @brief Slot for failed login
170      */
171     void loginFailed();
172
173     /**
174      * @brief Slot to intercept signal when login with cookies is requested
175      */
176     void loginUsingCookies();
177
178     /**
179      * @brief Public slot, which open settings dialog
180      */
181     void openSettingsDialog();
182
183     /**
184      * @brief Set own location crosshair visibility
185      *
186      * @param visible
187      */
188     void setOwnLocationCrosshairVisibility(bool visible);
189
190     /**
191      * @brief Sets username to member variable for login dialog
192      *
193      * @param username Username to be set
194      */
195     void setUsername(const QString &username);
196
197     /**
198      * @brief Method to show panels
199      */
200     void showPanels();
201
202     /**
203      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
204      *        doesn't exist yet
205      *
206      */
207     void startLoginProcess();
208
209     /**
210      * @brief Toggle progress indicator.
211      *
212      * @param state true if progress indicator should be shown, false otherwise
213      */
214     void toggleProgressIndicator(bool state);
215
216     /**
217      * @brief Shows / hides Situare related UI items
218      *
219      */
220     void updateItemVisibility();
221
222 private:
223     /**
224      * @brief Build fullscreen toggle button and connect slots
225      */
226     void buildFullScreenButton();
227
228     /**
229      * @brief Build friend list panel and connect slots
230      */
231     void buildFriendListPanel();
232
233     /**
234      * @brief Build manual location setting cross hair and connect slots
235      */
236     void buildManualLocationCrosshair();
237
238     /**
239      * @brief Build map and connect slots
240      */
241     void buildMap();
242
243     /**
244      * @brief Build map scale and connect slots
245      */
246     void buildMapScale();
247
248     /**
249      * @brief Build OSM license and connect slots
250      */
251     void buildOsmLicense();
252
253     /**
254      * @brief Build user info panel and connect slots
255      */
256     void buildUserInfoPanel();
257
258     /**
259      * @brief Build webview and connect slots
260      */
261     void buildWebView();
262
263     /**
264      * @brief Build zoom button panel and connect slots
265      */
266     void buildZoomButtonPanel();
267
268     /**
269      * @brief Private method to create the Menu items
270      */
271     void createMenus();
272
273     /**
274      * @brief Grab or release HW increase and decrease buttons.
275      *
276      * @param grab Use true for grabbing and false for releasing the keys
277      */
278     void grabZoomKeys(bool grab);
279
280     /**
281      * @brief Queues dialog/information box
282      *
283      * @param dialog Dialog to be added into queue
284      */
285     void queueDialog(QDialog *dialog);
286
287     /**
288      * @brief Shows queued error information box
289      *
290      */
291     void showErrorInformationBox();
292
293     /**
294      * @brief Shows queued information box
295      *
296      * @fn showInformationBox
297      */
298     void showInformationBox();
299
300 private slots:
301     /**
302      * @brief Slot for automatic update dialog finished.
303      *
304      * @result result code
305      */
306     void automaticUpdateDialogFinished(int result);
307
308     /**
309      * @brief Slot to intercept signal when dialog/information note is processed
310      *
311      * @param status Status of the dialog
312      */
313     void dialogFinished(int status);
314
315     /**
316      * @brief Slot for drawing the fullscreen toggle button
317      *
318      * @param size Size of the screen
319      */
320     void drawFullScreenButton(const QSize &size);
321
322     /**
323      * @brief Slot for drawing the map distance scale
324      *
325      * @param size Size of the screen
326      */
327     void drawMapScale(const QSize &size);
328
329     /**
330      * @brief Slot for drawing the Open Street Map license text
331      *
332      * @param size Size of the screen
333      */
334     void drawOsmLicense(const QSize &size);
335
336     /**
337      * @brief Slot for drawing the own location crosshair
338      *
339      * @param size Size of the screen
340      */
341     void drawOwnLocationCrosshair(const QSize &size);
342
343     /**
344      * @brief Slot to intercept signal when error dialog/information note is processed
345      *
346      * @param status Status of the dialog
347      */
348     void errorDialogFinished(int status);
349
350     /**
351      * @brief Slot for gps timeout.
352      *
353      * Called when request timeout occurs.
354      */
355     void gpsTimeout();
356
357     /**
358      * @brief Slot to load cookies from settings
359      */
360     void loadCookies();
361
362     /**
363      * @brief Slot to intercept signal when webview has finished loading webpage
364      *
365      * @param done Status of the loading
366      */
367     void loadDone(bool done);
368
369     /**
370      * @brief Slot to save cookies to settings
371      */
372     void saveCookies();
373
374     /**
375      * @brief Slot for settings dialog accepted.
376      */
377     void settingsDialogAccepted();
378
379     /**
380      * @brief Set correnct view port size to datamembers
381      *
382      * @param size Size of the screen
383      */
384     void setViewPortSize(const QSize &size);
385
386     /**
387      * @brief Start location search (open search dialog)
388      */
389     void startLocationSearch();
390
391     /**
392      * @brief Toggle between fullscreen and normal window mode
393      */
394     void toggleFullScreen();
395
396     /**
397      * @brief Slot to intercept signal from webview's networkaccessmanager
398      *
399      * @param reply Network reply (contains errors)
400      */
401     void webViewRequestFinished(QNetworkReply* reply);
402
403 /*******************************************************************************
404  * SIGNALS
405  ******************************************************************************/
406 signals:
407     /**
408      * @brief Automatic centering setting changed by user
409      *
410      * @param enabled True if automatic centering is enabled, otherwise false
411      */
412     void autoCenteringTriggered(bool enabled);
413
414     /**
415      * @brief Signal that indicates when user has cancelled login process
416      *
417      */
418     void cancelLoginProcess();
419
420     /**
421      * @brief View should be centered to new location
422      *
423      * @param coordinate Scene coordinates of the new center point
424      */
425     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
426
427     /**
428      * @brief Signal for enabling automatic location update.
429      *
430      * @param enabled true if enabled, false otherwise
431      * @param updateIntervalMsecs update interval in milliseconds
432      */
433     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
434
435     /**
436      * @brief Signals error
437      *
438      * @param context error context
439      * @param error error code
440      */
441     void error(const int context, const int error);
442
443     /**
444      * @brief Signal for requesting username from settings
445      *
446      */
447     void fetchUsernameFromSettings();
448
449     /**
450      * @brief Signal for finding user.
451      *
452      * @param coordinates user geo coordinates
453      */
454     void findUser(const GeoCoordinate &coordinates);
455
456     /**
457      * @brief Signals when friend's profile image is ready
458      *
459      * @param user Friend
460      */
461     void friendImageReady(User *user);
462
463     /**
464      * @brief GPS setting changed
465      *
466      * @param enabled True if GPS is enabled, otherwise false
467      */
468     void gpsTriggered(bool enabled);
469
470     /**
471      * @brief Signal for finding friend.
472      *
473      * @param coordinates friend's geo coordinates
474      */
475     void findFriend(const GeoCoordinate &coordinates);
476
477     /**
478      * @brief Signal for friend location ready.
479      *
480      * @param friendsList
481      */
482     void friendsLocationsReady(QList<User *> &friendsList);
483
484     /**
485      * @brief Signal is emitted when location item is clicked.
486      *
487      * @param userIDs list of friends user IDs in the group
488      */
489     void locationItemClicked(const QList<QString> &userIDs);
490
491     /**
492      * @brief Signals when Login/Logout action is pressed
493      *
494      */
495     void loginActionPressed();
496
497     /**
498      * @brief MapView has been resized
499      *
500      * @param size view size
501      */
502     void mapViewResized(const QSize &size);
503
504     /**
505      * @brief Forwarding signal from MapView to MapEngine
506      *
507      * @param coordinate
508      */
509     void mapViewScrolled(const SceneCoordinate &coordinate);
510
511     /**
512      * @brief Forwarding signal from MapEngine to MapView
513      */
514     void maxZoomLevelReached();
515
516     /**
517      * @brief Forwarding signal from MapEngine to MapView
518      */
519     void minZoomLevelReached();
520
521     /**
522      * @brief Forwarding signal from MapEngine to MapScale
523      */
524     void newMapResolution(qreal scale);
525
526     /**
527      * @brief Signal for refreshing user data.
528      *
529      */
530     void refreshUserData();
531
532     /**
533      * @brief Signal for requesting reverseGeo from SituareEngine
534      *
535      */
536     void requestReverseGeo();
537
538     /**
539      * @brief Signals, when address data is ready
540      *
541      * @param address Street address
542      */
543     void reverseGeoReady(const QString &address);
544
545     /**
546      * @brief Signal to save username to settings
547      *
548      * @param username Username
549      */
550     void saveUsername(const QString &username);
551
552     /**
553      * @brief Signal for location search
554      *
555      * @param location QString location
556      */
557     void searchForLocation(QString location);
558
559     /**
560      * @brief Signal for requestLocationUpdate from SituareEngine
561      *
562      * @param status Status message
563      * @param publish Publish on Facebook
564      */
565     void statusUpdate(const QString &status, const bool &publish);
566
567     /**
568      * @brief Signals when webview's urlChanged signal is emitted
569      *
570      * @param url New url
571      */
572     void updateCredentials(const QUrl &url);
573
574     /**
575      * @brief Signals when updateLocationDialog's data must be cleared
576      *
577      */
578     void clearUpdateLocationDialogData();
579
580     /**
581     * @brief Dragging mode triggered.
582     */
583     void draggingModeTriggered();
584
585     /**
586      * @brief MapView has finished zooming
587      */
588     void viewZoomFinished();
589
590     /**
591      * @brief Signal for use location ready.
592      *
593      * @param user User object
594      */
595     void userLocationReady(User *user);
596
597     /**
598      * @brief Map zoom in request
599      */
600     void zoomIn();
601
602     /**
603      * @brief Forwarding signal from MapEngine to MapView
604      */
605     void zoomLevelChanged(int zoomLevel);
606
607     /**
608      * @brief Map zoom out request
609      */
610     void zoomOut();
611
612 /*******************************************************************************
613  * DATA MEMBERS
614  ******************************************************************************/
615 private:
616     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
617     bool m_loggedIn;                        ///< Indicates login state
618     bool m_refresh;                         ///< Indicates when webpage is refreshed
619
620     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
621
622     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
623     QAction *m_loginAct;                    ///< Action to Login/Logout
624     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
625     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
626
627     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
628     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
629
630     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
631     QList<QDialog *> m_queue;               ///< QList type dialog queue
632
633     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
634
635     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
636
637     QSize m_viewPortSize;                 ///< Size of the viewport
638
639     QString m_email;                        ///< Placeholder for email
640     QString m_password;                     ///< Placeholder for password
641
642     QWebView *m_webView;                    ///< Shows facebook login page
643
644     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
645     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
646     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
647     MapScale *m_mapScale;                   ///< Instance of the map scale
648     MapView *m_mapView;                     ///< Instance of the map view
649     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
650     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
651     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
652     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
653     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
654 };
655
656 #endif // MAINWINDOW_H