Merge branch 'master' into settings_auto_update
[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 "panelsidebar.h"
31
32 class QGraphicsScene;
33 class QLabel;
34 class QWebView;
35
36 class FacebookAuthentication;
37 class FriendListPanel;
38 class LoginDialog;
39 class MapScene;
40 class MapView;
41 class SituareService;
42 class User;
43 class UserInfoPanel;
44 class ZoomButtonPanel;
45 class SettingsDialog;
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 Public slot, which open settings dialog
142     */
143     void openSettingsDialog();
144
145     /**
146     * @brief Sets username to member variable for login dialog
147     *
148     * @param username Username to be set
149     */
150     void setUsername(const QString &username);
151
152     /**
153     * @brief
154     *
155     * @param show
156     */
157     void showPanels(bool show);
158
159     /**
160     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
161     *        doesn't exist yet
162     *
163     * @param url Login page url
164     */
165     void startLoginProcess(const QUrl &url);
166
167     /**
168     * @brief Toggle progress indicator.
169     *
170     * @param state true if progress indicator should be shown, false otherwise
171     */
172     void toggleProgressIndicator(bool state);
173
174 private:
175     /**
176       * @brief Build friend list panel and connect slots
177       */
178     void buildFriendListPanel();
179
180     /**
181       * @brief Build manual location setting cross hair and connect slots
182       */
183     void buildManualLocationCrosshair();
184
185     /**
186       * @brief Build map and connect slots
187       */
188     void buildMap();
189
190     /**
191       * @brief Build OSM license and connect slots
192       */
193     void buildOsmLicense();
194
195     /**
196       * @brief Build user info panel and connect slots
197       */
198     void buildUserInfoPanel();
199
200     /**
201       * @brief Build zoom button panel and connect slots
202       */
203     void buildZoomButtonPanel();
204
205     /**
206     * @brief Private method to create the Menu items
207     */
208     void createMenus();
209
210     /**
211       * @brief Grab or release HW increase and decrease buttons.
212       *
213       * @param grab Use true for grabbing and false for releasing the keys
214       */
215     void grabZoomKeys(bool grab);
216
217     /**
218       * @brief Set own location crosshair visibility
219       *
220       * @param visible
221       */
222     void setOwnLocationCrosshairVisibility(bool visible);
223
224 private slots:
225     /**
226     * @brief Slot for drawing the Open Street Map license text
227     *
228     * @param size Size of the screen
229     */
230     void drawOsmLicense(const QSize &size);
231
232     /**
233     * @brief Slot for drawing the own location crosshair
234     *
235     * @param width Width of the viewport
236     * @param height Height of the viewport
237     */
238     void drawOwnLocationCrosshair(int width, int height);
239
240     /**
241     * @brief Slot for gps error.
242     *
243     * @param message error message
244     */
245     void gpsError(const QString &message);
246
247     /**
248     * @brief Slot for gps timeout.
249     *
250     * Called when request timeout occurs.
251     */
252     void gpsTimeout();
253
254     /**
255     * @brief Slot to intercept signal when webview has finished loading webpage
256     *
257     * @param done Status of the loading
258     */
259     void loadDone(bool done);
260
261     /**
262     * @brief Set correnct view port size to datamembers
263     *
264     * @param width Width of the viewport
265     * @param height Height of the viewport
266     */
267     void setViewPortSize(const int width, const int height);
268
269 /*******************************************************************************
270  * SIGNALS
271  ******************************************************************************/
272 signals:
273     /**
274     * @brief Automatic centering setting changed by user
275     *
276     * @param enabled True if automatic centering is enabled, otherwise false
277     */
278     void autoCenteringTriggered(bool enabled);
279
280     /**
281     * @brief Signal that indicates when user has cancelled login process
282     *
283     */
284     void cancelLoginProcess();
285
286     /**
287     * @brief View should be centered to new location
288     *
289     * @param sceneCoordinate Scene coordinates of the new center point
290     */
291     void centerToSceneCoordinates(QPoint sceneCoordinate);
292
293     /**
294     * @brief Signal for enabling automatic location update.
295     *
296     * @param enabled true if enabled, false otherwise
297     * @param updateIntervalMsecs update interval in milliseconds
298     */
299     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs);
300
301     /**
302     * @brief Signal for requesting username from settings
303     *
304     */
305     void fetchUsernameFromSettings();
306
307     /**
308     * @brief Signal for finding user.
309     *
310     * @param coordinates user geo coordinates
311     */
312     void findUser(const QPointF &coordinates);
313
314     /**
315     * @brief GPS setting changed
316     *
317     * @param enabled True if GPS is enabled, otherwise false
318     */
319     void gpsTriggered(bool enabled);
320
321     /**
322     * @brief Signal for finding friend.
323     *
324     * @param coordinates friend's geo coordinates
325     */
326     void findFriend(const QPointF &coordinates);
327
328     /**
329     * @brief Signal for friend location ready.
330     *
331     * @param friendsList
332     */
333     void friendsLocationsReady(QList<User *> &friendsList);
334
335     /**
336     * @brief Signal is emitted when location item is clicked.
337     *
338     * @param userIDs list of friends user IDs in the group
339     */
340     void locationItemClicked(const QList<QString> &userIDs);
341
342     /**
343     * @brief Signals when Login/Logout action is pressed
344     *
345     */
346     void loginActionPressed();
347
348     /**
349     * @brief MapView has been resized
350     *
351     * @param size view size
352     */
353     void mapViewResized(const QSize &size);
354
355     /**
356       * @brief Forwarding signal from MapView to MapEngine
357       *
358       * @param sceneCoordinate
359       */
360     void mapViewScrolled(QPoint sceneCoordinate);
361
362     /**
363       * @brief Forwarding signal from MapEngine to MapView
364       */
365     void maxZoomLevelReached();
366
367     /**
368       * @brief Forwarding signal from MapEngine to MapView
369       */
370     void minZoomLevelReached();
371
372     /**
373     * @brief Signal for refreshing user data.
374     *
375     */
376     void refreshUserData();
377
378     /**
379     * @brief Signal for requesting reverseGeo from SituareEngine
380     *
381     */
382     void requestReverseGeo();
383
384     /**
385     * @brief Signals, when address data is ready
386     *
387     * @param address Street address
388     */
389     void reverseGeoReady(const QString &address);
390
391     /**
392     * @brief Signal for requestLocationUpdate from SituareEngine
393     *
394     * @param status Status message
395     * @param publish Publish on Facebook
396     */
397     void statusUpdate(const QString &status, const bool &publish);
398
399     /**
400     * @brief Signals when webview's urlChanged signal is emitted
401     *
402     * @param url New url
403     */
404     void updateCredentials(const QUrl &url);
405
406     /**
407     * @brief MapView has finished zooming
408     */
409     void viewZoomFinished();
410
411     /**
412     * @brief Signal for use location ready.
413     *
414     * @param user User object
415     */
416     void userLocationReady(User *user);
417
418     /**
419     * @brief Map zoom in request
420     */
421     void zoomIn();
422
423     /**
424       * @brief Forwarding signal from MapEngine to MapView
425       */
426     void zoomLevelChanged(int zoomLevel);
427
428     /**
429     * @brief Map zoom out request
430     */
431     void zoomOut();
432
433 /*******************************************************************************
434  * DATA MEMBERS
435  ******************************************************************************/
436 private:
437
438     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
439     bool m_loggedIn;                        ///< Indicates login state
440     bool m_refresh;                         ///< Indicates when webpage is refreshed
441
442     int m_viewPortHeight;                   ///< Height of view port
443     int m_viewPortWidth;                    ///< Width of view port
444
445     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
446     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
447     QAction *m_loginAct;                    ///< Action to Login/Logout
448     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
449
450     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
451     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
452
453     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
454
455     QString m_email;                        ///< Placeholder for email
456     QString m_password;                     ///< Placeholder for password
457
458     QUrl m_loginUrl;                        ///< Placeholder for login page url
459
460     QWebView *m_webView;                    ///< Shows facebook login page
461
462     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
463     LoginDialog *m_loginDialog;             ///< Login dialog
464     MapView *m_mapView;                     ///< Instance of the map view
465     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
466     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
467     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
468     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
469
470     SettingsDialog *m_settingsDialog;       ///< Settings dialog
471 };
472
473 #endif // MAINWINDOW_H