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