a056ae48f4ceffddfdcb63d3befbac44570c4868
[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 Signal for adding tags.
461     *
462     * @param tags tags to add
463     */
464     void addTags(const QStringList &tags);
465
466     /**
467      * @brief Automatic centering setting changed by user
468      *
469      * @param enabled True if automatic centering is enabled, otherwise false
470      */
471     void autoCenteringTriggered(bool enabled);
472
473     /**
474      * @brief Signal that indicates when user has cancelled login process
475      *
476      */
477     void cancelLoginProcess();
478
479     /**
480      * @brief Signal for centering to coordinates.
481      *
482      * @param coordinates geo coordinates to center to.
483      */
484     void centerToCoordinates(const GeoCoordinate &coordinates);
485
486     /**
487      * @brief View should be centered to new location
488      *
489      * @param coordinate Scene coordinates of the new center point
490      */
491     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
492
493     /**
494     * @brief Emitted when route is cleared
495     */
496     void clearRoute();
497
498     /**
499     * @brief Signal when direction and distance from current map center point to current GPS
500     *        location is changed
501     *
502     * @param direction Direction in degrees
503     * @param distance Distance in meters
504     * @param draw Should the indicator triangle be drawn or not
505     */
506     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
507
508     /**
509      * @brief Signal for enabling automatic location update.
510      *
511      * @param enabled true if enabled, false otherwise
512      * @param updateIntervalMsecs update interval in milliseconds
513      */
514     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
515
516     /**
517      * @brief Signals error
518      *
519      * @param context error context
520      * @param error error code
521      */
522     void error(const int context, const int error);
523
524     /**
525      * @brief Signal for requesting username from settings
526      *
527      */
528     void fetchUsernameFromSettings();
529
530     /**
531      * @brief Signals when friend's profile image is ready
532      *
533      * @param user Friend
534      */
535     void friendImageReady(User *user);
536
537     /**
538      * @brief GPS setting changed
539      *
540      * @param enabled True if GPS is enabled, otherwise false
541      */
542     void gpsTriggered(bool enabled);
543
544     /**
545     * @brief Signal when fetchPeopleWithSimilarInterest request is finished
546     *
547     * @param friends list of friends
548     * @param others list of other people
549     */
550     void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
551
552     /**
553      * @brief Signal for friend location ready.
554      *
555      * @param friendsList
556      */
557     void friendsLocationsReady(QList<User *> &friendsList);
558
559     /**
560     * @brief Signals when image is downloaded
561     *
562     * @param id image ID
563     * @param image image pixmap
564     */
565     void friendImageReady(const QString &id, const QPixmap &image);
566
567     /**
568     * @brief Emited when location request is parsed and is ready for further processing
569     *
570     * @param result List of Location items
571     */
572     void locationDataParsed(const QList<Location> &result);
573
574     /**
575      * @brief Signal is emitted when location item is clicked on map.
576      *
577      * @param userIDs list of friends user IDs in the group
578      */
579     void locationItemClicked(const QList<QString> &userIDs);
580
581     /**
582      * @brief Signal is emitted when location item is clicked in list.
583      *
584      * @param swBound south-west bound in GeoCoorinate
585      * @param neBound north-east bound in GeoCoordinate
586      */
587     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
588
589     /**
590      * @brief Signals when Login/Logout action is pressed
591      *
592      */
593     void loginActionPressed();
594
595     /**
596      * @brief MapView has been resized
597      *
598      * @param size view size
599      */
600     void mapViewResized(const QSize &size);
601
602     /**
603      * @brief Forwarding signal from MapView to MapEngine
604      *
605      * @param coordinate New center point coordinate
606      */
607     void mapViewScrolled(const SceneCoordinate &coordinate);
608
609     /**
610      * @brief Forwarding signal from MapEngine to MapView
611      */
612     void maxZoomLevelReached();
613
614     /**
615      * @brief Forwarding signal from MapEngine to MapView
616      */
617     void minZoomLevelReached();
618
619     /**
620      * @brief Forwarding signal from MapEngine to MapScale
621      */
622     void newMapResolution(qreal scale);
623
624     /**
625     * @brief Signal when fetchMessages request is finished
626     *
627     * @param messages list of messages sent to user
628     */
629     void messagesReceived(QList<Message> &received, QList<Message> &sent);
630
631     /**
632     * @brief Signals when fetchPopularTags request is finished
633     *
634     * @param popularTags list of popular tags
635     */
636     void popularTagsReceived(QHash<QString, QString> &popularTags);
637
638     /**
639     * @brief Signal for requesting popular tags
640     */
641     void requestPopularTags();
642
643     /**
644      * @brief Signal for refreshing user data.
645      *
646      */
647     void refreshUserData();
648
649     /**
650     * @brief Signal for removing tags.
651     *
652     * @param tags tags to add
653     */
654     void removeTags(const QStringList &tags);
655
656     /**
657     * @brief Requests contact dialog.
658     *
659     * @param facebookId contact's facebookId
660     */
661     void requestContactDialog(const QString &facebookId);
662
663     /**
664     * @brief Requests message remove.
665     *
666     * @param id message ID
667     */
668     void requestRemoveMessage(const QString &id);
669
670     /**
671     * @brief Requests message dialog.
672     * @param receiver receiver facebook ID and name
673     */
674     void requestMessageDialog(const QPair<QString, QString> &receiver);
675
676     /**
677      * @brief Signal for requesting reverseGeo from SituareEngine
678      *
679      */
680     void requestReverseGeo();
681
682     /**
683     * @brief Requests search people by tag name.
684     *
685     * @param tag tag name
686     */
687     void requestSearchPeopleByTag(const QString &tag);
688
689     /**
690      * @brief Signals, when address data is ready
691      *
692      * @param address Street address
693      */
694     void reverseGeoReady(const QString &address);
695
696     /**
697     * @brief Emited when route is parsed and is ready for further processing
698     *
699     * @param route Route item containing parsed route details
700     */
701     void routeParsed(Route &route);
702
703     /**
704     * @brief Signal for routing to geo coordinates.
705     *
706     * @param coordinates destination geo coordinates
707     */
708     void routeTo(const GeoCoordinate &coordinates);
709
710     /**
711     * @brief Request routing to current cursor position
712     */
713     void routeToCursor();
714
715     /**
716      * @brief Signal to save username to settings
717      *
718      * @param username Username
719      */
720     void saveUsername(const QString &username);
721
722     /**
723      * @brief Signal for location search
724      *
725      * @param location QString location
726      */
727     void searchForLocation(QString location);
728
729     /**
730     * @brief Signal is emitted when search history item is clicked.
731     *
732     * @param searchString search string used
733     */
734     void searchHistoryItemClicked(const QString &searchString);
735
736     /**
737     * @brief Sends a message to a person.
738     *
739     * @param receiverId Facebook user ID
740     * @param message message text
741     * @param addCoordinates true if coordinates should be added, false otherwise
742     */
743     void sendMessage(const QString &receiverId, const QString &message, bool addCoordinates);
744
745     /**
746      * @brief Signal for requestLocationUpdate from SituareEngine
747      *
748      * @param status Status message
749      * @param publish Publish on Facebook
750      */
751     void statusUpdate(const QString &status, const bool &publish);
752
753     /**
754      * @brief Signals when webview's urlChanged signal is emitted
755      *
756      * @param url New url
757      */
758     void updateCredentials(const QUrl &url);
759
760     /**
761     * @brief Signals when image is downloaded
762     *
763     * @param id image ID
764     * @param image image pixmap
765     */
766     void userImageReady(const QString &id, const QPixmap &image);
767
768     /**
769      * @brief Signals when updateLocationDialog's data must be cleared
770      *
771      */
772     void clearUpdateLocationDialogData();
773
774     /**
775     * @brief Dragging mode triggered.
776     */
777     void draggingModeTriggered();
778
779     /**
780      * @brief MapView has finished zooming
781      */
782     void viewZoomFinished();
783
784     /**
785     * @brief Requests interesting people from current map viewport.
786     *
787     * Interesting people is defined by people with same tags as user has.
788     */
789     void requestInterestingPeople();
790
791     /**
792     * @brief Requests messages sent to the user.
793     */
794     void requestMessages();
795
796     /**
797      * @brief Signal for use location ready.
798      *
799      * @param user User object
800      */
801     void userLocationReady(User *user);
802
803     /**
804      * @brief Map zoom in request
805      */
806     void zoomIn();
807
808     /**
809      * @brief Forwarding signal from MapEngine to MapView
810      */
811     void zoomLevelChanged(int zoomLevel);
812
813     /**
814      * @brief Map zoom out request
815      */
816     void zoomOut();
817
818 /*******************************************************************************
819  * DATA MEMBERS
820  ******************************************************************************/
821 private:
822     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
823     bool m_loggedIn;                        ///< Indicates login state
824     bool m_refresh;                         ///< Indicates when webpage is refreshed
825
826     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
827     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
828
829     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
830     QAction *m_loginAct;                    ///< Action to Login/Logout
831     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
832
833     QLabel *m_crosshair;                    ///< Label for center point crosshair
834     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
835
836     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
837     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
838     QList<QDialog *> m_queue;               ///< QList type dialog queue
839
840     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
841
842     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
843
844     QString m_email;                        ///< Placeholder for email
845     QString m_password;                     ///< Placeholder for password
846
847     QWebView *m_webView;                    ///< Shows facebook login page
848
849     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
850     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
851     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
852     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
853     MapScale *m_mapScale;                   ///< Instance of the map scale
854     MapView *m_mapView;                     ///< Instance of the map view
855     MeetPeoplePanel *m_meetPeoplePanel;     ///< Instance of MeetPeoplePanel
856     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
857     MessagePanel *m_messagePanel;          ///< Instance of MessagePanel
858     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
859     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
860     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
861     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
862 };
863
864 #endif // MAINWINDOW_H