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