Added comments
[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 GPS setting changed
344     *
345     * @param enabled True if GPS is enabled, otherwise false
346     */
347     void gpsTriggered(bool enabled);
348
349     /**
350     * @brief Signal for finding friend.
351     *
352     * @param coordinates friend's geo coordinates
353     */
354     void findFriend(const QPointF &coordinates);
355
356     /**
357     * @brief Signal for friend location ready.
358     *
359     * @param friendsList
360     */
361     void friendsLocationsReady(QList<User *> &friendsList);
362
363     /**
364     * @brief Signal is emitted when location item is clicked.
365     *
366     * @param userIDs list of friends user IDs in the group
367     */
368     void locationItemClicked(const QList<QString> &userIDs);
369
370     /**
371     * @brief Signals when Login/Logout action is pressed
372     *
373     */
374     void loginActionPressed();
375
376     /**
377     * @brief MapView has been resized
378     *
379     * @param size view size
380     */
381     void mapViewResized(const QSize &size);
382
383     /**
384       * @brief Forwarding signal from MapView to MapEngine
385       *
386       * @param sceneCoordinate
387       */
388     void mapViewScrolled(QPoint sceneCoordinate);
389
390     /**
391       * @brief Forwarding signal from MapEngine to MapView
392       */
393     void maxZoomLevelReached();
394
395     /**
396       * @brief Forwarding signal from MapEngine to MapView
397       */
398     void minZoomLevelReached();
399
400     /**
401     * @brief Signal for refreshing user data.
402     *
403     */
404     void refreshUserData();
405
406     /**
407     * @brief Signal for requesting reverseGeo from SituareEngine
408     *
409     */
410     void requestReverseGeo();
411
412     /**
413     * @brief Signals, when address data is ready
414     *
415     * @param address Street address
416     */
417     void reverseGeoReady(const QString &address);
418
419     /**
420     * @brief Signal for requestLocationUpdate from SituareEngine
421     *
422     * @param status Status message
423     * @param publish Publish on Facebook
424     */
425     void statusUpdate(const QString &status, const bool &publish);
426
427     /**
428     * @brief Signals when webview's urlChanged signal is emitted
429     *
430     * @param url New url
431     */
432     void updateCredentials(const QUrl &url);
433
434     /**
435     * @brief MapView has finished zooming
436     */
437     void viewZoomFinished();
438
439     /**
440     * @brief Signal for use location ready.
441     *
442     * @param user User object
443     */
444     void userLocationReady(User *user);
445
446     /**
447     * @brief Map zoom in request
448     */
449     void zoomIn();
450
451     /**
452       * @brief Forwarding signal from MapEngine to MapView
453       */
454     void zoomLevelChanged(int zoomLevel);
455
456     /**
457     * @brief Map zoom out request
458     */
459     void zoomOut();
460
461 /*******************************************************************************
462  * DATA MEMBERS
463  ******************************************************************************/
464 private:
465
466     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
467     bool m_loggedIn;                        ///< Indicates login state
468     bool m_refresh;                         ///< Indicates when webpage is refreshed
469
470     int m_viewPortHeight;                   ///< Height of view port
471     int m_viewPortWidth;                    ///< Width of view port
472
473     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
474     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
475     QAction *m_loginAct;                    ///< Action to Login/Logout
476     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
477
478     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
479     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
480
481     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
482
483     QString m_email;                        ///< Placeholder for email
484     QString m_password;                     ///< Placeholder for password
485
486     QWebView *m_webView;                    ///< Shows facebook login page
487
488     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
489     LoginDialog *m_loginDialog;             ///< Login dialog
490     MapView *m_mapView;                     ///< Instance of the map view
491     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
492     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
493     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
494     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
495     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
496 };
497
498 #endif // MAINWINDOW_H