d24646cbb1bf756d735f0ee1a2a35bab0c09dea3
[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     void automaticLocationUpdateIntervalSet(int updateIntervalMsecs);
281
282     /**
283     * @brief Signal that indicates when user has cancelled login process
284     *
285     */
286     void cancelLoginProcess();
287
288     /**
289     * @brief View should be centered to new location
290     *
291     * @param sceneCoordinate Scene coordinates of the new center point
292     */
293     void centerToSceneCoordinates(QPoint sceneCoordinate);
294
295     /**
296     * @brief Signal for requesting username from settings
297     *
298     */
299     void fetchUsernameFromSettings();
300
301     /**
302     * @brief GPS setting changed
303     *
304     * @param enabled True if GPS is enabled, otherwise false
305     */
306     void gpsTriggered(bool enabled);
307
308     /**
309     * @brief Signal for finding friend.
310     *
311     * @param coordinates friend's geo coordinates
312     */
313     void findFriend(const QPointF &coordinates);
314
315     /**
316     * @brief Signal for friend location ready.
317     *
318     * @param friendsList
319     */
320     void friendsLocationsReady(QList<User *> &friendsList);
321
322     /**
323     * @brief Signal is emitted when location item is clicked.
324     *
325     * @param userIDs list of friends user IDs in the group
326     */
327     void locationItemClicked(const QList<QString> &userIDs);
328
329     /**
330     * @brief Signals when Login/Logout action is pressed
331     *
332     */
333     void loginActionPressed();
334
335     /**
336     * @brief MapView has been resized
337     *
338     * @param size view size
339     */
340     void mapViewResized(const QSize &size);
341
342     /**
343       * @brief Forwarding signal from MapView to MapEngine
344       *
345       * @param sceneCoordinate
346       */
347     void mapViewScrolled(QPoint sceneCoordinate);
348
349     /**
350       * @brief Forwarding signal from MapEngine to MapView
351       */
352     void maxZoomLevelReached();
353
354     /**
355       * @brief Forwarding signal from MapEngine to MapView
356       */
357     void minZoomLevelReached();
358
359     /**
360     * @brief Signal for refreshing user data.
361     *
362     */
363     void refreshUserData();
364
365     /**
366     * @brief Signal for requesting reverseGeo from SituareEngine
367     *
368     */
369     void requestReverseGeo();
370
371     /**
372     * @brief Signals, when address data is ready
373     *
374     * @param address Street address
375     */
376     void reverseGeoReady(const QString &address);
377
378     /**
379     * @brief Signal for requestLocationUpdate from SituareEngine
380     *
381     * @param status Status message
382     * @param publish Publish on Facebook
383     */
384     void statusUpdate(const QString &status, const bool &publish);
385
386     /**
387     * @brief Signals when webview's urlChanged signal is emitted
388     *
389     * @param url New url
390     */
391     void updateCredentials(const QUrl &url);
392
393     /**
394     * @brief MapView has finished zooming
395     */
396     void viewZoomFinished();
397
398     /**
399     * @brief Signal for use location ready.
400     *
401     * @param user User object
402     */
403     void userLocationReady(User *user);
404
405     /**
406     * @brief Map zoom in request
407     */
408     void zoomIn();
409
410     /**
411       * @brief Forwarding signal from MapEngine to MapView
412       */
413     void zoomLevelChanged(int zoomLevel);
414
415     /**
416     * @brief Map zoom out request
417     */
418     void zoomOut();
419
420 /*******************************************************************************
421  * DATA MEMBERS
422  ******************************************************************************/
423 private:
424
425     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
426     bool m_loggedIn;                        ///< Indicates login state
427     bool m_refresh;                         ///< Indicates when webpage is refreshed
428
429     int m_viewPortHeight;                   ///< Height of view port
430     int m_viewPortWidth;                    ///< Width of view port
431
432     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
433     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
434     QAction *m_loginAct;                    ///< Action to Login/Logout
435     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
436
437     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
438     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
439
440     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
441
442     QString m_email;                        ///< Placeholder for email
443     QString m_password;                     ///< Placeholder for password
444
445     QUrl m_loginUrl;                        ///< Placeholder for login page url
446
447     QWebView *m_webView;                    ///< Shows facebook login page
448
449     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
450     LoginDialog *m_loginDialog;             ///< Login dialog
451     MapView *m_mapView;                     ///< Instance of the map view
452     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
453     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
454     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
455     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
456
457     SettingsDialog *m_settingsDialog;       ///< Settings dialog
458 };
459
460 #endif // MAINWINDOW_H