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