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