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