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