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