Added missing comments to engine.h, liblocationwrapper.h, mainwindow.h
[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
9    Situare is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as published by the Free Software Foundation.
12
13    Situare is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Situare; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21    USA.
22 */
23
24 #ifndef MAINWINDOW_H
25 #define MAINWINDOW_H
26
27 #include <QtGui/QMainWindow>
28 #include <QUrl>
29
30 #include "network/networkcookiejar.h"
31 #include "panelsidebar.h"
32
33 class QGraphicsScene;
34 class QLabel;
35 class QWebView;
36 class QNetworkReply;
37
38 class FacebookAuthentication;
39 class FriendListPanel;
40 class MapScale;
41 class MapScene;
42 class MapView;
43 class SituareService;
44 class User;
45 class UserInfoPanel;
46 class ZoomButtonPanel;
47 class SettingsDialog;
48 class QToolButton;
49 class QMessageBox;
50
51 /**
52 * @brief Main Window Class
53 */
54 class MainWindow : public QMainWindow
55 {
56     Q_OBJECT
57
58 public:
59     /**
60     * @brief Constructor
61     *
62     * @param parent Parent
63     */
64     MainWindow(QWidget *parent = 0);
65
66     /**
67     * @brief Destructor
68     *
69     */
70     ~MainWindow();
71
72 /*******************************************************************************
73  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
74  ******************************************************************************/
75 private:
76     /**
77       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
78       */
79     void keyPressEvent(QKeyEvent* event);
80
81 /*******************************************************************************
82  * MEMBER FUNCTIONS AND SLOTS
83  ******************************************************************************/
84 public:
85     /**
86     * @brief Builds information box with message.
87     *
88     * @param message Information message
89     * @param modal Modal = true, non-modal false
90     */
91     void buildInformationBox(const QString &message, bool modal=false);
92
93     /**
94     * @brief Clears cookie jar
95     *
96     */
97     void clearCookieJar();
98
99     /**
100     * @brief
101     *
102     * @param logged
103     */
104     void loggedIn(bool logged);
105
106     /**
107     * @brief Requests automatic location update settings.
108     */
109     void requestAutomaticLocationUpdateSettings();
110
111
112     /**
113     * @brief Enable / disable auto centering button.
114     *
115     * @param enabled true if shoud be enabled, false otherwise
116     */
117     void setAutoCenteringButtonEnabled(bool enabled);
118
119     /**
120     * @brief Enable / disable GPS button.
121     *
122     * Does set visibilities for manual location cursor and auto centering menu button.
123     *
124     * @param enabled true if enabled, false otherwise
125     */
126     void setGPSButtonEnabled(bool enabled);
127
128     /**
129       * @brief Set scene for MapView
130       *
131       * @param scene Scene to be set
132       */
133     void setMapViewScene(QGraphicsScene *scene);
134
135     /**
136     * Shows dialog with enable automatic location update question.
137     *
138     * @param text text to show in dialog
139     */
140     void showEnableAutomaticUpdateLocationDialog(const QString &text);
141
142     /**
143     * @brief Gets the username from member variable for saving purposes
144     *
145     * @return QString Username
146     */
147     const QString username();
148
149 public slots:
150     /**
151     * @brief Slot to intercept signal when login has failed (loginFailure signal)
152     *
153     */
154     void loginFailed();
155
156     /**
157     * @brief Slot to intercept signal when login with cookies is requested
158     *
159     */
160     void loginUsingCookies();
161
162     /**
163     * @brief Public slot, which open settings dialog
164     */
165     void openSettingsDialog();
166
167     /**
168     * @brief Sets username to member variable for login dialog
169     *
170     * @param username Username to be set
171     */
172     void setUsername(const QString &username);
173
174     /**
175     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
176     *        doesn't exist yet
177     *
178     */
179     void startLoginProcess();
180
181     /**
182     * @brief Toggle progress indicator.
183     *
184     * @param state true if progress indicator should be shown, false otherwise
185     */
186     void toggleProgressIndicator(bool state);
187
188     /**
189     * @brief Shows / hides Situare related UI items
190     *
191     * @param show
192     */
193     void updateItemVisibility(bool show);
194
195 private:
196     /**
197       * @brief Build fullscreen toggle button and connect slots
198       */
199     void buildFullScreenButton();
200
201     /**
202       * @brief Build friend list panel and connect slots
203       */
204     void buildFriendListPanel();
205
206     /**
207       * @brief Build manual location setting cross hair and connect slots
208       */
209     void buildManualLocationCrosshair();
210
211     /**
212       * @brief Build map and connect slots
213       */
214     void buildMap();
215
216     /**
217      * @brief Build map scale and connect slots
218      */
219     void buildMapScale();
220
221     /**
222       * @brief Build OSM license and connect slots
223       */
224     void buildOsmLicense();
225
226     /**
227       * @brief Build user info panel and connect slots
228       */
229     void buildUserInfoPanel();
230
231     /**
232     * @brief Build webview and connect slots
233     *
234     */
235     void buildWebView();
236
237     /**
238       * @brief Build zoom button panel and connect slots
239       */
240     void buildZoomButtonPanel();
241
242     /**
243     * @brief Private method to create the Menu items
244     */
245     void createMenus();
246
247     /**
248       * @brief Grab or release HW increase and decrease buttons.
249       *
250       * @param grab Use true for grabbing and false for releasing the keys
251       */
252     void grabZoomKeys(bool grab);
253
254     /**
255     * @brief Queues dialog/information box
256     *
257     * @param dialog Dialog to be added into queue
258     */
259     void queueDialog(QDialog *dialog);
260
261     /**
262       * @brief Set own location crosshair visibility
263       *
264       * @param visible
265       */
266     void setOwnLocationCrosshairVisibility(bool visible);
267
268     /**
269     * @brief Shows queued error information box
270     *
271     */
272     void showErrorInformationBox();
273
274     /**
275     * @brief Shows queued information box
276     *
277     * @fn showInformationBox
278     */
279     void showInformationBox();
280
281 private slots:
282     /**
283     * @brief Slot for automatic update dialog finished.
284     *
285     * @result result code
286     */
287     void automaticUpdateDialogFinished(int result);
288
289     /**
290     * @brief Slot to intercept signal when dialog/information note is processed
291     *
292     * @param status Status of the dialog
293     */
294     void dialogFinished(int status);
295
296     /**
297     * @brief Slot for drawing the fullscreen toggle button
298     *
299     * @param size Size of the screen
300     */
301     void drawFullScreenButton(const QSize &size);
302
303     /**
304     * @brief Slot for drawing the map distance scale
305     *
306     * @param size Size of the screen
307     */
308     void drawMapScale(const QSize &size);
309
310     /**
311     * @brief Slot for drawing the Open Street Map license text
312     *
313     * @param size Size of the screen
314     */
315     void drawOsmLicense(const QSize &size);
316
317     /**
318     * @brief Slot for drawing the own location crosshair
319     *
320     * @param size Size of the screen
321     */
322     void drawOwnLocationCrosshair(const QSize &size);
323
324     /**
325     * @brief Slot to intercept signal when error dialog/information note is processed
326     *
327     * @param status Status of the dialog
328     */
329     void errorDialogFinished(int status);
330
331     /**
332     * @brief Slot for gps timeout.
333     *
334     * Called when request timeout occurs.
335     */
336     void gpsTimeout();
337
338     /**
339     * @brief Slot to load cookies from settings
340     *
341     */
342     void loadCookies();
343
344     /**
345     * @brief Slot to intercept signal when webview has finished loading webpage
346     *
347     * @param done Status of the loading
348     */
349     void loadDone(bool done);
350
351     /**
352     * @brief Slot to save cookies to settings
353     *
354     */
355     void saveCookies();
356
357     /**
358     * @brief Set correnct view port size to datamembers
359     *
360     * @param size Size of the screen
361     */
362     void setViewPortSize(const QSize &size);
363
364     /**
365     * @brief Toggle between fullscreen and normal window mode
366     */
367     void toggleFullScreen();
368
369     /**
370     * @brief Slot to intercept signal from webview's networkaccessmanager
371     *
372     * @param reply Network reply (contains errors)
373     */
374     void webViewRequestFinished(QNetworkReply* reply);
375
376 /*******************************************************************************
377  * SIGNALS
378  ******************************************************************************/
379 signals:
380     /**
381     * @brief Automatic centering setting changed by user
382     *
383     * @param enabled True if automatic centering is enabled, otherwise false
384     */
385     void autoCenteringTriggered(bool enabled);
386
387     /**
388     * @brief Signal that indicates when user has cancelled login process
389     *
390     */
391     void cancelLoginProcess();
392
393     /**
394     * @brief View should be centered to new location
395     *
396     * @param sceneCoordinate Scene coordinates of the new center point
397     */
398     void centerToSceneCoordinates(QPoint sceneCoordinate);
399
400     /**
401     * @brief Signal for enabling automatic location update.
402     *
403     * @param enabled true if enabled, false otherwise
404     * @param updateIntervalMsecs update interval in milliseconds
405     */
406     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs);
407
408     /**
409     * @brief Signal for requesting username from settings
410     *
411     */
412     void fetchUsernameFromSettings();
413
414     /**
415     * @brief Signal for finding user.
416     *
417     * @param coordinates user geo coordinates
418     */
419     void findUser(const QPointF &coordinates);
420
421     /**
422     * @brief GPS setting changed
423     *
424     * @param enabled True if GPS is enabled, otherwise false
425     */
426     void gpsTriggered(bool enabled);
427
428     /**
429     * @brief Signal for finding friend.
430     *
431     * @param coordinates friend's geo coordinates
432     */
433     void findFriend(const QPointF &coordinates);
434
435     /**
436     * @brief Signal for friend location ready.
437     *
438     * @param friendsList
439     */
440     void friendsLocationsReady(QList<User *> &friendsList);
441
442     /**
443     * @brief Signal is emitted when location item is clicked.
444     *
445     * @param userIDs list of friends user IDs in the group
446     */
447     void locationItemClicked(const QList<QString> &userIDs);
448
449     /**
450     * @brief Signals when Login/Logout action is pressed
451     *
452     */
453     void loginActionPressed();
454
455     /**
456     * @brief MapView has been resized
457     *
458     * @param size view size
459     */
460     void mapViewResized(const QSize &size);
461
462     /**
463       * @brief Forwarding signal from MapView to MapEngine
464       *
465       * @param sceneCoordinate
466       */
467     void mapViewScrolled(QPoint sceneCoordinate);
468
469     /**
470       * @brief Forwarding signal from MapEngine to MapView
471       */
472     void maxZoomLevelReached();
473
474     /**
475     * @brief Signal that informs that user's message/location failed to update on Situare server
476     *        This signal is originally sended from SituareService with name error
477     *        Signal is renamed on MainWindow
478     */
479     void messageSendingFailed(const QString &error);
480
481     /**
482       * @brief Forwarding signal from MapEngine to MapView
483       */
484     void minZoomLevelReached();
485
486     /**
487     * @brief Signal that used to inform user that his message/location update tp Situare server
488     *        was failed.
489     *        This signal is originally sended from UserInfo
490     */
491     void notificateUpdateFailing(const QString &message);
492
493     /**
494      * @brief Forwarding signal from MapEngine to MapScale
495      */
496     void newMapResolution(qreal scale);
497
498     /**
499     * @brief Signal for refreshing user data.
500     *
501     */
502     void refreshUserData();
503
504     /**
505     * @brief Signal for requesting reverseGeo from SituareEngine
506     *
507     */
508     void requestReverseGeo();
509
510     /**
511     * @brief Signals, when address data is ready
512     *
513     * @param address Street address
514     */
515     void reverseGeoReady(const QString &address);
516
517     /**
518     * @brief Signal to save username to settings
519     *
520     * @param username Username
521     */
522     void saveUsername(const QString &username);
523
524     /**
525     * @brief Signal for requestLocationUpdate from SituareEngine
526     *
527     * @param status Status message
528     * @param publish Publish on Facebook
529     */
530     void statusUpdate(const QString &status, const bool &publish);
531
532     /**
533     * @brief Signals when webview's urlChanged signal is emitted
534     *
535     * @param url New url
536     */
537     void updateCredentials(const QUrl &url);
538
539     /**
540     * @brief Signals when updateLocation request finished successfully
541     *
542     */
543     void updateWasSuccessful();
544
545     /**
546     * @brief MapView has finished zooming
547     */
548     void viewZoomFinished();
549
550     /**
551     * @brief Signal for use location ready.
552     *
553     * @param user User object
554     */
555     void userLocationReady(User *user);
556
557     /**
558     * @brief Map zoom in request
559     */
560     void zoomIn();
561
562     /**
563       * @brief Forwarding signal from MapEngine to MapView
564       */
565     void zoomLevelChanged(int zoomLevel);
566
567     /**
568     * @brief Map zoom out request
569     */
570     void zoomOut();
571
572 /*******************************************************************************
573  * DATA MEMBERS
574  ******************************************************************************/
575 private:
576     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
577     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
578     bool m_loggedIn;                        ///< Indicates login state
579     bool m_refresh;                         ///< Indicates when webpage is refreshed
580
581     int m_viewPortHeight;                   ///< Height of view port
582     int m_viewPortWidth;                    ///< Width of view port
583
584     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
585     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
586     QAction *m_loginAct;                    ///< Action to Login/Logout
587     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
588
589     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
590     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
591
592     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
593     QList<QDialog *> m_queue;               ///< QList type dialog queue
594
595     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
596
597     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
598
599     QString m_email;                        ///< Placeholder for email
600     QString m_password;                     ///< Placeholder for password
601
602     QToolButton *m_fullScreenButton;        ///< Instance of the fullscreen toggle button
603
604     QWebView *m_webView;                    ///< Shows facebook login page
605
606     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
607     MapScale *m_mapScale;                   ///< Instance of the map scale
608     MapView *m_mapView;                     ///< Instance of the map view
609     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
610     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
611     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
612     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
613     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
614
615     SettingsDialog *m_settingsDialog;       ///< Settings dialog
616 };
617
618 #endif // MAINWINDOW_H