58edfaec68ee64a7c54f8c49981b8829780eb9f9
[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 <QUrl>
32
33 //Remove this
34 #include <QNetworkReply>
35 #include <QSslError>
36
37 #include "situareservice/message.h"
38 #include "network/networkcookiejar.h"
39
40 class QGraphicsScene;
41 class QLabel;
42 class QMessageBox;
43 class QNetworkReply;
44 class QToolButton;
45 class QWebView;
46
47 class FacebookAuthentication;
48 class FriendListPanel;
49 class FullScreenButton;
50 class GeoCoordinate;
51 class IndicatorButtonPanel;
52 class Location;
53 class LocationSearchPanel;
54 class MapScale;
55 class MapScene;
56 class MapView;
57 class MeetPeoplePanel;
58 class MessagePanel;
59 class Route;
60 class RoutingPanel;
61 class SceneCoordinate;
62 class SettingsDialog;
63 class SituareService;
64 class TabbedPanel;
65 class User;
66 class UserInfoPanel;
67 class ZoomButtonPanel;
68
69 /**
70  * @brief Main Window Class
71  */
72 class MainWindow : public QMainWindow
73 {
74     Q_OBJECT
75
76 public:
77     /**
78      * @brief Constructor
79      *
80      * @param parent Parent
81      */
82     MainWindow(QWidget *parent = 0);
83
84     /**
85      * @brief Destructor
86      */
87     ~MainWindow();
88
89 /*******************************************************************************
90  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
91  ******************************************************************************/
92 private:
93     /**
94      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
95      */
96     void keyPressEvent(QKeyEvent* event);
97
98 /*******************************************************************************
99  * MEMBER FUNCTIONS AND SLOTS
100  ******************************************************************************/
101 public:
102     /**
103      * @brief Clears cookie jar
104      *
105      */
106     void clearCookieJar();
107
108     /**
109      * @brief
110      *
111      * @param logged
112      */
113     void loggedIn(bool logged);
114
115     /**
116      * @brief Gets the login state (logged in/logged out)
117      *
118      * @return bool Login state
119      */
120     bool loginState();
121
122     /**
123      * @brief Reads automatic location update settings.
124      */
125     void readAutomaticLocationUpdateSettings();
126
127     /**
128      * @brief Enable / disable GPS button.
129      *
130      * Does set visibilities for manual location cursor and auto centering menu button.
131      *
132      * @param enabled true if enabled, false otherwise
133      */
134     void setGPSButtonEnabled(bool enabled);
135
136     /**
137      * @brief Enable / disable direction indicator button.
138      *
139      * @param enabled true if shoud be enabled, false otherwise
140      */
141     void setIndicatorButtonEnabled(bool enabled);
142
143     /**
144      * @brief Set scene for MapView
145      *
146      * @param scene Scene to be set
147      */
148     void setMapViewScene(QGraphicsScene *scene);
149
150     /**
151      * Shows dialog with enable automatic location update question.
152      *
153      * @param text text to show in dialog
154      */
155     void showEnableAutomaticUpdateLocationDialog(const QString &text);
156
157     /**
158      * @brief Gets the username from member variable for saving purposes
159      *
160      * @return QString Username
161      */
162     const QString username();
163
164 public slots:
165     /**
166      * @brief Builds information box with message.
167      *
168      * @param message Information message
169      * @param modal Modal = true, non-modal false
170      */
171     void buildInformationBox(const QString &message, bool modal=false);
172
173     /**
174      * @brief Slot for failed login
175      */
176     void loginFailed();
177
178     /**
179      * @brief Slot to intercept signal when login with cookies is requested
180      */
181     void loginUsingCookies();
182
183     /**
184      * @brief Public slot, which open settings dialog
185      */
186     void openSettingsDialog();
187
188     /**
189      * @brief Set own location crosshair visibility
190      *
191      * @param visible
192      */
193     void setCrosshairVisibility(bool visible);
194
195     /**
196      * @brief Sets username to member variable for login dialog
197      *
198      * @param username Username to be set
199      */
200     void setUsername(const QString &username);
201
202     /**
203     * @brief Shows contact dialog.
204     *
205     * Shows contact dialog with contact's information.
206     * @param guid globally unique ID of a contact
207     */
208     void showContactDialog(const QString &guid);
209
210     /**
211     * @brief Shows message dialog.
212     *
213     * @param receiver receiver ID and name
214     */
215     void showMessageDialog(const QPair<QString, QString> &receiver);
216
217     /**
218      * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
219      *        doesn't exist yet
220      */
221     void startLoginProcess();
222
223     /**
224      * @brief Toggle progress indicator.
225      *
226      * @param state true if progress indicator should be shown, false otherwise
227      */
228     void toggleProgressIndicator(bool state);
229
230     /**
231      * @brief Shows / hides Situare related UI items
232      *
233      */
234     void updateItemVisibility();
235
236 private:
237     /**
238      * @brief Build manual location setting cross hair and connect slots
239      */
240     void buildCrosshair();
241
242     /**
243      * @brief Build friend list panel and connect slots
244      */
245     void buildFriendListPanel();
246
247     /**
248      * @brief Build fullscreen toggle button and connect slots
249      */
250     void buildFullScreenButton();
251
252     /**
253      * @brief Build direction indicator button panel and connect signals
254      */
255     void buildIndicatorButtonPanel();
256
257     /**
258      * @brief Build location search panel and connect signals
259      */
260     void buildLocationSearchPanel();
261
262     /**
263      * @brief Build map and connect slots
264      */
265     void buildMap();
266
267     /**
268      * @brief Build map scale and connect slots
269      */
270     void buildMapScale();
271
272     /**
273      * @brief Build meet people panel and connect slots
274      */
275     void buildMeetPeoplePanel();
276
277     /**
278      * @brief Build message panel and connect slots
279      */
280     void buildMessagePanel();
281
282     /**
283      * @brief Build OSM license and connect slots
284      */
285     void buildOsmLicense();
286
287     /**
288      * @brief Build application panels
289      */
290     void buildPanels();
291
292     /**
293      * @brief Build routing panel and connect slots
294      */
295     void buildRoutingPanel();
296
297     /**
298      * @brief Build user info panel and connect slots
299      */
300     void buildUserInfoPanel();
301
302     /**
303      * @brief Build webview and connect slots
304      */
305     void buildWebView();
306
307     /**
308      * @brief Build zoom button panel and connect slots
309      */
310     void buildZoomButtonPanel();
311
312     /**
313      * @brief Private method to create the Menu items
314      */
315     void createMenus();
316
317     /**
318      * @brief Grab or release HW increase and decrease buttons.
319      *
320      * @param grab Use true for grabbing and false for releasing the keys
321      */
322     void grabZoomKeys(bool grab);
323
324     /**
325      * @brief Queues dialog/information box
326      *
327      * @param dialog Dialog to be added into queue
328      */
329     void queueDialog(QDialog *dialog);
330
331     /**
332      * @brief Shows queued error information box
333      *
334      */
335     void showErrorInformationBox();
336
337     /**
338      * @brief Shows queued information box
339      *
340      * @fn showInformationBox
341      */
342     void showInformationBox();
343
344 private slots:
345     /**
346      * @brief Slot for automatic update dialog finished.
347      *
348      * @result result code
349      */
350     void automaticUpdateDialogFinished(int result);
351
352     /**
353      * @brief Slot to intercept signal when dialog/information note is processed
354      *
355      * @param status Status of the dialog
356      */
357     void dialogFinished(int status);
358
359     /**
360      * @brief Slot for drawing the fullscreen toggle button
361      *
362      * @param size Size of the screen
363      */
364     void drawFullScreenButton(const QSize &size);
365
366     /**
367      * @brief Slot for drawing the map distance scale
368      *
369      * @param size Size of the screen
370      */
371     void drawMapScale(const QSize &size);
372
373     /**
374      * @brief Slot for drawing the Open Street Map license text
375      *
376      * @param size Size of the screen
377      */
378     void drawOsmLicense(const QSize &size);
379
380     /**
381      * @brief Slot to intercept signal when error dialog/information note is processed
382      *
383      * @param status Status of the dialog
384      */
385     void errorDialogFinished(int status);
386
387     /**
388      * @brief Slot for gps timeout.
389      *
390      * Called when request timeout occurs.
391      */
392     void gpsTimeout();
393
394     /**
395      * @brief Slot to load cookies from settings
396      */
397     void loadCookies();
398
399     /**
400      * @brief Slot to intercept signal when webview has finished loading webpage
401      *
402      * @param done Status of the loading
403      */
404     void loadDone(bool done);
405
406     /**
407     * @brief Called when map center point horizontal shifting is changed
408     *
409     * @param shifting New shifting value
410     */
411     void mapCenterHorizontalShiftingChanged(int shifting);
412
413     /**
414      * @brief Move the crosshair
415      */
416     void moveCrosshair();
417
418     /**
419      * @brief Slot to save cookies to settings
420      */
421     void saveCookies();
422
423     /**
424      * @brief Slot for settings dialog accepted.
425      */
426     void settingsDialogAccepted();
427
428     /**
429      * @brief Start location search (open search dialog)
430      */
431     void startLocationSearch();
432
433     /**
434     * @brief Start people search (open search dialog)
435     */
436     void startPeopleSearch();
437
438     /**
439      * @brief Toggle between fullscreen and normal window mode
440      */
441     void toggleFullScreen();
442
443     /**
444      * @brief Slot to intercept signal from webview's networkaccessmanager
445      *
446      * @param reply Network reply (contains errors)
447      */
448     void webViewRequestFinished(QNetworkReply* reply);
449
450     /**
451      * REMOVE THIS, FIXES WEBVIEW BUG IN SCRATCHBOX
452      */
453     void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
454
455 /*******************************************************************************
456  * SIGNALS
457  ******************************************************************************/
458 signals:
459     /**
460      * @brief Automatic centering setting changed by user
461      *
462      * @param enabled True if automatic centering is enabled, otherwise false
463      */
464     void autoCenteringTriggered(bool enabled);
465
466     /**
467      * @brief Signal that indicates when user has cancelled login process
468      *
469      */
470     void cancelLoginProcess();
471
472     /**
473      * @brief Signal for centering to coordinates.
474      *
475      * @param coordinates geo coordinates to center to.
476      */
477     void centerToCoordinates(const GeoCoordinate &coordinates);
478
479     /**
480      * @brief View should be centered to new location
481      *
482      * @param coordinate Scene coordinates of the new center point
483      */
484     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
485
486     /**
487     * @brief Emitted when route is cleared
488     */
489     void clearRoute();
490
491     /**
492     * @brief Signal when direction and distance from current map center point to current GPS
493     *        location is changed
494     *
495     * @param direction Direction in degrees
496     * @param distance Distance in meters
497     * @param draw Should the indicator triangle be drawn or not
498     */
499     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
500
501     /**
502      * @brief Signal for enabling automatic location update.
503      *
504      * @param enabled true if enabled, false otherwise
505      * @param updateIntervalMsecs update interval in milliseconds
506      */
507     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
508
509     /**
510      * @brief Signals error
511      *
512      * @param context error context
513      * @param error error code
514      */
515     void error(const int context, const int error);
516
517     /**
518      * @brief Signal for requesting username from settings
519      *
520      */
521     void fetchUsernameFromSettings();
522
523     /**
524      * @brief Signals when friend's profile image is ready
525      *
526      * @param user Friend
527      */
528     void friendImageReady(User *user);
529
530     /**
531      * @brief GPS setting changed
532      *
533      * @param enabled True if GPS is enabled, otherwise false
534      */
535     void gpsTriggered(bool enabled);
536
537     /**
538     * @brief Signal when fetchPeopleWithSimilarInterest request is finished
539     *
540     * @param interestingPeople list of interesting people
541     */
542     void interestingPeopleReceived(QList<User> &interestingPeople);
543
544     /**
545      * @brief Signal for friend location ready.
546      *
547      * @param friendsList
548      */
549     void friendsLocationsReady(QList<User *> &friendsList);
550
551     /**
552     * @brief Signals when image is downloaded
553     *
554     * @param id image ID
555     * @param image image pixmap
556     */
557     void friendImageReady(const QString &id, const QPixmap &image);
558
559     /**
560     * @brief Emited when location request is parsed and is ready for further processing
561     *
562     * @param result List of Location items
563     */
564     void locationDataParsed(const QList<Location> &result);
565
566     /**
567      * @brief Signal is emitted when location item is clicked on map.
568      *
569      * @param userIDs list of friends user IDs in the group
570      */
571     void locationItemClicked(const QList<QString> &userIDs);
572
573     /**
574      * @brief Signal is emitted when location item is clicked in list.
575      *
576      * @param swBound south-west bound in GeoCoorinate
577      * @param neBound north-east bound in GeoCoordinate
578      */
579     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
580
581     /**
582      * @brief Signals when Login/Logout action is pressed
583      *
584      */
585     void loginActionPressed();
586
587     /**
588      * @brief MapView has been resized
589      *
590      * @param size view size
591      */
592     void mapViewResized(const QSize &size);
593
594     /**
595      * @brief Forwarding signal from MapView to MapEngine
596      *
597      * @param coordinate New center point coordinate
598      */
599     void mapViewScrolled(const SceneCoordinate &coordinate);
600
601     /**
602      * @brief Forwarding signal from MapEngine to MapView
603      */
604     void maxZoomLevelReached();
605
606     /**
607      * @brief Forwarding signal from MapEngine to MapView
608      */
609     void minZoomLevelReached();
610
611     /**
612      * @brief Forwarding signal from MapEngine to MapScale
613      */
614     void newMapResolution(qreal scale);
615
616     /**
617     * @brief Signal when fetchMessages request is finished
618     *
619     * @param messages list of messages sent to user
620     */
621     void messagesReceived(QList<Message> &messages);
622
623     /**
624      * @brief Signal for refreshing user data.
625      *
626      */
627     void refreshUserData();
628
629     /**
630     * @brief Requests contact dialog.
631     *
632     * @param facebookId contact's facebookId
633     */
634     void requestContactDialog(const QString &facebookId);
635
636     /**
637     * @brief Requests message dialog.
638     * @param receiver receiver facebook ID and name
639     */
640     void requestMessageDialog(const QPair<QString, QString> &receiver);
641
642     /**
643      * @brief Signal for requesting reverseGeo from SituareEngine
644      *
645      */
646     void requestReverseGeo();
647
648     /**
649      * @brief Signals, when address data is ready
650      *
651      * @param address Street address
652      */
653     void reverseGeoReady(const QString &address);
654
655     /**
656     * @brief Emited when route is parsed and is ready for further processing
657     *
658     * @param route Route item containing parsed route details
659     */
660     void routeParsed(Route &route);
661
662     /**
663     * @brief Signal for routing to geo coordinates.
664     *
665     * @param coordinates destination geo coordinates
666     */
667     void routeTo(const GeoCoordinate &coordinates);
668
669     /**
670     * @brief Request routing to current cursor position
671     */
672     void routeToCursor();
673
674     /**
675      * @brief Signal to save username to settings
676      *
677      * @param username Username
678      */
679     void saveUsername(const QString &username);
680
681     /**
682      * @brief Signal for location search
683      *
684      * @param location QString location
685      */
686     void searchForLocation(QString location);
687
688     /**
689     * @brief Signal is emitted when search history item is clicked.
690     *
691     * @param searchString search string used
692     */
693     void searchHistoryItemClicked(const QString &searchString);
694
695     /**
696     * @brief Sends a message to a person.
697     *
698     * @param receiverId Facebook user ID
699     * @param message message text
700     */
701     void sendMessage(const QString &receiverId, const QString &message);
702
703     /**
704      * @brief Signal for requestLocationUpdate from SituareEngine
705      *
706      * @param status Status message
707      * @param publish Publish on Facebook
708      */
709     void statusUpdate(const QString &status, const bool &publish);
710
711     /**
712      * @brief Signals when webview's urlChanged signal is emitted
713      *
714      * @param url New url
715      */
716     void updateCredentials(const QUrl &url);
717
718     /**
719     * @brief Signals when image is downloaded
720     *
721     * @param id image ID
722     * @param image image pixmap
723     */
724     void userImageReady(const QString &id, const QPixmap &image);
725
726     /**
727      * @brief Signals when updateLocationDialog's data must be cleared
728      *
729      */
730     void clearUpdateLocationDialogData();
731
732     /**
733     * @brief Dragging mode triggered.
734     */
735     void draggingModeTriggered();
736
737     /**
738      * @brief MapView has finished zooming
739      */
740     void viewZoomFinished();
741
742     /**
743     * @brief Requests interesting people from current map viewport.
744     *
745     * Interesting people is defined by people with same tags as user has.
746     */
747     void requestInterestingPeople();
748
749     /**
750     * @brief Requests messages sent to the user.
751     */
752     void requestMessages();
753
754     /**
755      * @brief Signal for use location ready.
756      *
757      * @param user User object
758      */
759     void userLocationReady(User *user);
760
761     /**
762      * @brief Map zoom in request
763      */
764     void zoomIn();
765
766     /**
767      * @brief Forwarding signal from MapEngine to MapView
768      */
769     void zoomLevelChanged(int zoomLevel);
770
771     /**
772      * @brief Map zoom out request
773      */
774     void zoomOut();
775
776 /*******************************************************************************
777  * DATA MEMBERS
778  ******************************************************************************/
779 private:
780     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
781     bool m_loggedIn;                        ///< Indicates login state
782     bool m_refresh;                         ///< Indicates when webpage is refreshed
783
784     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
785     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
786
787     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
788     QAction *m_loginAct;                    ///< Action to Login/Logout
789     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
790
791     QLabel *m_crosshair;                    ///< Label for center point crosshair
792     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
793
794     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
795     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
796     QList<QDialog *> m_queue;               ///< QList type dialog queue
797
798     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
799
800     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
801
802     QString m_email;                        ///< Placeholder for email
803     QString m_password;                     ///< Placeholder for password
804
805     QWebView *m_webView;                    ///< Shows facebook login page
806
807     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
808     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
809     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
810     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
811     MapScale *m_mapScale;                   ///< Instance of the map scale
812     MapView *m_mapView;                     ///< Instance of the map view
813     MeetPeoplePanel *m_meetPeoplePanel;     ///< Instance of MeetPeoplePanel
814     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
815     MessagePanel *m_messsagePanel;          ///< Instance of MessagePanel
816     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
817     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
818     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
819     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
820 };
821
822 #endif // MAINWINDOW_H