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