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