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