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