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