287f7f0af222ae3a2c6c73b18fbb94e03022ba4b
[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 interestingPeople list of interesting people
548     */
549     void interestingPeopleReceived(QList<User> &interestingPeople);
550
551     /**
552      * @brief Signal for friend location ready.
553      *
554      * @param friendsList
555      */
556     void friendsLocationsReady(QList<User *> &friendsList);
557
558     /**
559     * @brief Signals when image is downloaded
560     *
561     * @param id image ID
562     * @param image image pixmap
563     */
564     void friendImageReady(const QString &id, const QPixmap &image);
565
566     /**
567     * @brief Emited when location request is parsed and is ready for further processing
568     *
569     * @param result List of Location items
570     */
571     void locationDataParsed(const QList<Location> &result);
572
573     /**
574      * @brief Signal is emitted when location item is clicked on map.
575      *
576      * @param userIDs list of friends user IDs in the group
577      */
578     void locationItemClicked(const QList<QString> &userIDs);
579
580     /**
581      * @brief Signal is emitted when location item is clicked in list.
582      *
583      * @param swBound south-west bound in GeoCoorinate
584      * @param neBound north-east bound in GeoCoordinate
585      */
586     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
587
588     /**
589      * @brief Signals when Login/Logout action is pressed
590      *
591      */
592     void loginActionPressed();
593
594     /**
595      * @brief MapView has been resized
596      *
597      * @param size view size
598      */
599     void mapViewResized(const QSize &size);
600
601     /**
602      * @brief Forwarding signal from MapView to MapEngine
603      *
604      * @param coordinate New center point coordinate
605      */
606     void mapViewScrolled(const SceneCoordinate &coordinate);
607
608     /**
609      * @brief Forwarding signal from MapEngine to MapView
610      */
611     void maxZoomLevelReached();
612
613     /**
614      * @brief Forwarding signal from MapEngine to MapView
615      */
616     void minZoomLevelReached();
617
618     /**
619      * @brief Forwarding signal from MapEngine to MapScale
620      */
621     void newMapResolution(qreal scale);
622
623     /**
624     * @brief Signal when fetchMessages request is finished
625     *
626     * @param messages list of messages sent to user
627     */
628     void messagesReceived(QList<Message> &messages);
629
630     /**
631      * @brief Signal for refreshing user data.
632      *
633      */
634     void refreshUserData();
635
636     /**
637     * @brief Signal for removing tags.
638     *
639     * @param tags tags to add
640     */
641     void removeTags(const QStringList &tags);
642
643     /**
644     * @brief Requests contact dialog.
645     *
646     * @param facebookId contact's facebookId
647     */
648     void requestContactDialog(const QString &facebookId);
649
650     /**
651     * @brief Requests message remove.
652     *
653     * @param id message ID
654     */
655     void requestRemoveMessage(const QString &id);
656
657     /**
658     * @brief Requests message dialog.
659     * @param receiver receiver facebook ID and name
660     */
661     void requestMessageDialog(const QPair<QString, QString> &receiver);
662
663     /**
664      * @brief Signal for requesting reverseGeo from SituareEngine
665      *
666      */
667     void requestReverseGeo();
668
669     /**
670     * @brief Requests search people by tag name.
671     *
672     * @param tag tag name
673     */
674     void requestSearchPeopleByTag(const QString &tag);
675
676     /**
677      * @brief Signals, when address data is ready
678      *
679      * @param address Street address
680      */
681     void reverseGeoReady(const QString &address);
682
683     /**
684     * @brief Emited when route is parsed and is ready for further processing
685     *
686     * @param route Route item containing parsed route details
687     */
688     void routeParsed(Route &route);
689
690     /**
691     * @brief Signal for routing to geo coordinates.
692     *
693     * @param coordinates destination geo coordinates
694     */
695     void routeTo(const GeoCoordinate &coordinates);
696
697     /**
698     * @brief Request routing to current cursor position
699     */
700     void routeToCursor();
701
702     /**
703      * @brief Signal to save username to settings
704      *
705      * @param username Username
706      */
707     void saveUsername(const QString &username);
708
709     /**
710      * @brief Signal for location search
711      *
712      * @param location QString location
713      */
714     void searchForLocation(QString location);
715
716     /**
717     * @brief Signal is emitted when search history item is clicked.
718     *
719     * @param searchString search string used
720     */
721     void searchHistoryItemClicked(const QString &searchString);
722
723     /**
724     * @brief Sends a message to a person.
725     *
726     * @param receiverId Facebook user ID
727     * @param message message text
728     * @param addCoordinates true if coordinates should be added, false otherwise
729     */
730     void sendMessage(const QString &receiverId, const QString &message, bool addCoordinates);
731
732     /**
733      * @brief Signal for requestLocationUpdate from SituareEngine
734      *
735      * @param status Status message
736      * @param publish Publish on Facebook
737      */
738     void statusUpdate(const QString &status, const bool &publish);
739
740     /**
741      * @brief Signals when webview's urlChanged signal is emitted
742      *
743      * @param url New url
744      */
745     void updateCredentials(const QUrl &url);
746
747     /**
748     * @brief Signals when image is downloaded
749     *
750     * @param id image ID
751     * @param image image pixmap
752     */
753     void userImageReady(const QString &id, const QPixmap &image);
754
755     /**
756      * @brief Signals when updateLocationDialog's data must be cleared
757      *
758      */
759     void clearUpdateLocationDialogData();
760
761     /**
762     * @brief Dragging mode triggered.
763     */
764     void draggingModeTriggered();
765
766     /**
767      * @brief MapView has finished zooming
768      */
769     void viewZoomFinished();
770
771     /**
772     * @brief Requests interesting people from current map viewport.
773     *
774     * Interesting people is defined by people with same tags as user has.
775     */
776     void requestInterestingPeople();
777
778     /**
779     * @brief Requests messages sent to the user.
780     */
781     void requestMessages();
782
783     /**
784      * @brief Signal for use location ready.
785      *
786      * @param user User object
787      */
788     void userLocationReady(User *user);
789
790     /**
791      * @brief Map zoom in request
792      */
793     void zoomIn();
794
795     /**
796      * @brief Forwarding signal from MapEngine to MapView
797      */
798     void zoomLevelChanged(int zoomLevel);
799
800     /**
801      * @brief Map zoom out request
802      */
803     void zoomOut();
804
805 /*******************************************************************************
806  * DATA MEMBERS
807  ******************************************************************************/
808 private:
809     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
810     bool m_loggedIn;                        ///< Indicates login state
811     bool m_refresh;                         ///< Indicates when webpage is refreshed
812
813     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
814     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
815
816     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
817     QAction *m_loginAct;                    ///< Action to Login/Logout
818     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
819
820     QLabel *m_crosshair;                    ///< Label for center point crosshair
821     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
822
823     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
824     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
825     QList<QDialog *> m_queue;               ///< QList type dialog queue
826
827     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
828
829     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
830
831     QString m_email;                        ///< Placeholder for email
832     QString m_password;                     ///< Placeholder for password
833
834     QWebView *m_webView;                    ///< Shows facebook login page
835
836     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
837     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
838     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
839     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
840     MapScale *m_mapScale;                   ///< Instance of the map scale
841     MapView *m_mapView;                     ///< Instance of the map view
842     MeetPeoplePanel *m_meetPeoplePanel;     ///< Instance of MeetPeoplePanel
843     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
844     MessagePanel *m_messagePanel;          ///< Instance of MessagePanel
845     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
846     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
847     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
848     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
849 };
850
851 #endif // MAINWINDOW_H