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