Merge branch 'master' into indicator
[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         Sami Rämö - sami.ramo@ixonos.com
8         Katri Kaikkonen - katri.kaikkonen@ixonos.com
9
10     Situare is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     version 2 as published by the Free Software Foundation.
13
14     Situare is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with Situare; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22     USA.
23 */
24
25 #ifndef MAINWINDOW_H
26 #define MAINWINDOW_H
27
28 #include <QtGui/QMainWindow>
29 #include <QUrl>
30
31 #include "network/networkcookiejar.h"
32 #include "panelsidebar.h"
33
34 class QGraphicsScene;
35 class QLabel;
36 class QMessageBox;
37 class QNetworkReply;
38 class QToolButton;
39 class QWebView;
40
41 class FacebookAuthentication;
42 class FullScreenButton;
43 class FriendListPanel;
44 class IndicatorButton;
45 class GeoCoordinate;
46 class MapScale;
47 class MapScene;
48 class MapView;
49 class SettingsDialog;
50 class SceneCoordinate;
51 class SituareService;
52 class User;
53 class UserInfoPanel;
54 class ZoomButtonPanel;
55
56
57 /**
58 * @brief Main Window Class
59 */
60 class MainWindow : public QMainWindow
61 {
62     Q_OBJECT
63
64 public:
65     /**
66      * @brief Constructor
67      *
68      * @param parent Parent
69      */
70     MainWindow(QWidget *parent = 0);
71
72     /**
73      * @brief Destructor
74      *
75      */
76     ~MainWindow();
77
78 /*******************************************************************************
79  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
80  ******************************************************************************/
81 private:
82     /**
83      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
84      */
85     void keyPressEvent(QKeyEvent* event);
86
87 /*******************************************************************************
88  * MEMBER FUNCTIONS AND SLOTS
89  ******************************************************************************/
90 public:
91     /**
92      * @brief Clears cookie jar
93      *
94      */
95     void clearCookieJar();
96
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
155     /**
156      * @brief Build direction indicator button and connect slots
157      */
158     void buildIndicatorButton();
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 user info panel and connect slots
255      */
256     void buildUserInfoPanel();
257
258     /**
259      * @brief Build webview and connect slots
260      */
261     void buildWebView();
262
263     /**
264      * @brief Build zoom button panel and connect slots
265      */
266     void buildZoomButtonPanel();
267
268     /**
269      * @brief Private method to create the Menu items
270      */
271     void createMenus();
272
273     /**
274      * @brief Grab or release HW increase and decrease buttons.
275      *
276      * @param grab Use true for grabbing and false for releasing the keys
277      */
278     void grabZoomKeys(bool grab);
279
280     /**
281      * @brief Queues dialog/information box
282      *
283      * @param dialog Dialog to be added into queue
284      */
285     void queueDialog(QDialog *dialog);
286
287     /**
288      * @brief Shows queued error information box
289      *
290      */
291     void showErrorInformationBox();
292
293     /**
294      * @brief Shows queued information box
295      *
296      * @fn showInformationBox
297      */
298     void showInformationBox();
299
300 private slots:
301     /**
302      * @brief Slot for automatic update dialog finished.
303      *
304      * @result result code
305      */
306     void automaticUpdateDialogFinished(int result);
307
308     /**
309      * @brief Slot to intercept signal when dialog/information note is processed
310      *
311      * @param status Status of the dialog
312      */
313     void dialogFinished(int status);
314
315     /**
316      * @brief Slot for drawing the fullscreen toggle button
317      *
318      * @param size Size of the screen
319      */
320     void drawFullScreenButton(const QSize &size);
321
322     /**
323      * @brief Slot for drawing the map distance scale
324      *
325      * @param size Size of the screen
326      */
327     void drawMapScale(const QSize &size);
328
329     /**
330      * @brief Slot for drawing the Open Street Map license text
331      *
332      * @param size Size of the screen
333      */
334     void drawOsmLicense(const QSize &size);
335
336     /**
337      * @brief Slot for drawing the own location crosshair
338      *
339      * @param size Size of the screen
340      */
341     void drawOwnLocationCrosshair(const QSize &size);
342
343     /**
344      * @brief Slot to intercept signal when error dialog/information note is processed
345      *
346      * @param status Status of the dialog
347      */
348     void errorDialogFinished(int status);
349
350     /**
351      * @brief Slot for gps timeout.
352      *
353      * Called when request timeout occurs.
354      */
355     void gpsTimeout();
356
357     /**
358      * @brief Slot to load cookies from settings
359      */
360     void loadCookies();
361
362     /**
363      * @brief Slot to intercept signal when webview has finished loading webpage
364      *
365      * @param done Status of the loading
366      */
367     void loadDone(bool done);
368
369     /**
370      * @brief Slot to save cookies to settings
371      */
372     void saveCookies();
373
374     /**
375      * @brief Slot for settings dialog accepted.
376      */
377     void settingsDialogAccepted();
378
379     /**
380      * @brief Set correnct view port size to datamembers
381      *
382      * @param size Size of the screen
383      */
384     void setViewPortSize(const QSize &size);
385
386     /**
387      * @brief Start location search (open search dialog)
388      */
389     void startLocationSearch();
390
391     /**
392      * @brief Toggle between fullscreen and normal window mode
393      */
394     void toggleFullScreen();
395
396     /**
397      * @brief Slot to intercept signal from webview's networkaccessmanager
398      *
399      * @param reply Network reply (contains errors)
400      */
401     void webViewRequestFinished(QNetworkReply* reply);
402
403 /*******************************************************************************
404  * SIGNALS
405  ******************************************************************************/
406 signals:
407     /**
408      * @brief Automatic centering setting changed by user
409      *
410      * @param enabled True if automatic centering is enabled, otherwise false
411      */
412     void autoCenteringTriggered(bool enabled);
413
414     /**
415      * @brief Signal that indicates when user has cancelled login process
416      *
417      */
418     void cancelLoginProcess();
419
420     /**
421      * @brief View should be centered to new location
422      *
423      * @param coordinate Scene coordinates of the new center point
424      */
425     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
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 kilometers
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 Signal for finding user.
461      *
462      * @param coordinates user geo coordinates
463      */
464     void findUser(const GeoCoordinate &coordinates);
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 for finding friend.
482      *
483      * @param coordinates friend's geo coordinates
484      */
485     void findFriend(const GeoCoordinate &coordinates);
486
487     /**
488      * @brief Signal for friend location ready.
489      *
490      * @param friendsList
491      */
492     void friendsLocationsReady(QList<User *> &friendsList);
493
494     /**
495      * @brief Signal is emitted when location item is clicked.
496      *
497      * @param userIDs list of friends user IDs in the group
498      */
499     void locationItemClicked(const QList<QString> &userIDs);
500
501     /**
502      * @brief Signals when Login/Logout action is pressed
503      *
504      */
505     void loginActionPressed();
506
507     /**
508      * @brief MapView has been resized
509      *
510      * @param size view size
511      */
512     void mapViewResized(const QSize &size);
513
514     /**
515      * @brief Forwarding signal from MapView to MapEngine
516      *
517      * @param coordinate
518      */
519     void mapViewScrolled(const SceneCoordinate &coordinate);
520
521     /**
522      * @brief Forwarding signal from MapEngine to MapView
523      */
524     void maxZoomLevelReached();
525
526     /**
527      * @brief Forwarding signal from MapEngine to MapView
528      */
529     void minZoomLevelReached();
530
531     /**
532      * @brief Forwarding signal from MapEngine to MapScale
533      */
534     void newMapResolution(qreal scale);
535
536     /**
537      * @brief Signal for refreshing user data.
538      *
539      */
540     void refreshUserData();
541
542     /**
543      * @brief Signal for requesting reverseGeo from SituareEngine
544      *
545      */
546     void requestReverseGeo();
547
548     /**
549      * @brief Signals, when address data is ready
550      *
551      * @param address Street address
552      */
553     void reverseGeoReady(const QString &address);
554
555     /**
556      * @brief Signal to save username to settings
557      *
558      * @param username Username
559      */
560     void saveUsername(const QString &username);
561
562     /**
563      * @brief Signal for location search
564      *
565      * @param location QString location
566      */
567     void searchForLocation(QString location);
568
569     /**
570      * @brief Signal for requestLocationUpdate from SituareEngine
571      *
572      * @param status Status message
573      * @param publish Publish on Facebook
574      */
575     void statusUpdate(const QString &status, const bool &publish);
576
577     /**
578      * @brief Signals when webview's urlChanged signal is emitted
579      *
580      * @param url New url
581      */
582     void updateCredentials(const QUrl &url);
583
584     /**
585      * @brief Signals when updateLocationDialog's data must be cleared
586      *
587      */
588     void clearUpdateLocationDialogData();
589
590     /**
591      * @brief MapView has finished zooming
592      */
593     void viewZoomFinished();
594
595     /**
596      * @brief Signal for use location ready.
597      *
598      * @param user User object
599      */
600     void userLocationReady(User *user);
601
602     /**
603      * @brief Map zoom in request
604      */
605     void zoomIn();
606
607     /**
608      * @brief Forwarding signal from MapEngine to MapView
609      */
610     void zoomLevelChanged(int zoomLevel);
611
612     /**
613      * @brief Map zoom out request
614      */
615     void zoomOut();
616
617 /*******************************************************************************
618  * DATA MEMBERS
619  ******************************************************************************/
620 private:
621     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
622     bool m_loggedIn;                        ///< Indicates login state
623     bool m_refresh;                         ///< Indicates when webpage is refreshed
624
625     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
626
627     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
628     QAction *m_loginAct;                    ///< Action to Login/Logout
629     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
630     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
631
632     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
633     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
634
635     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
636     QList<QDialog *> m_queue;               ///< QList type dialog queue
637
638     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
639
640     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
641
642     QSize m_viewPortSize;                 ///< Size of the viewport
643
644     QString m_email;                        ///< Placeholder for email
645     QString m_password;                     ///< Placeholder for password
646
647     QWebView *m_webView;                    ///< Shows facebook login page
648
649     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
650     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
651     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
652     MapScale *m_mapScale;                   ///< Instance of the map scale
653     MapView *m_mapView;                     ///< Instance of the map view
654     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
655     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
656     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
657     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
658     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
659 };
660
661 #endif // MAINWINDOW_H