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