d34d0ad3748c2d21a4d972ffee55aa8c809b21ef
[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
46 /**
47 * @brief Main Window Class
48 */
49 class MainWindow : public QMainWindow
50 {
51     Q_OBJECT
52
53 public:
54     /**
55     * @brief Constructor
56     *
57     * @param parent Parent
58     */
59     MainWindow(QWidget *parent = 0);
60
61     /**
62     * @brief Destructor
63     *
64     */
65     ~MainWindow();
66
67 /*******************************************************************************
68  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
69  ******************************************************************************/
70 private:
71     /**
72       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
73       */
74     void keyPressEvent(QKeyEvent* event);
75
76 /*******************************************************************************
77  * MEMBER FUNCTIONS AND SLOTS
78  ******************************************************************************/
79 public:    
80     /**
81     * @brief
82     *
83     * @param logged
84     */
85     void loggedIn(bool logged);
86
87     /**
88     * @brief Enable / disable auto centering button.
89     *
90     * @param enabled true if shoud be enabled, false otherwise
91     */
92     void setAutoCenteringButtonEnabled(bool enabled);
93
94     /**
95     * @brief Enable / disable GPS button.
96     *
97     * Does set visibilities for manual location cursor and auto centering menu button.
98     *
99     * @param enabled true if enabled, false otherwise
100     */
101     void setGPSButtonEnabled(bool enabled);
102
103     /**
104       * @brief Set scene for MapView
105       *
106       * @param scene Scene to be set
107       */
108     void setMapViewScene(QGraphicsScene *scene);
109
110     /**
111     * @brief Show Maemo information box with message.
112     *
113     * @brief message information message
114     */
115     void showMaemoInformationBox(const QString &message);
116
117     /**
118     * @brief Gets the username from member variable for saving purposes
119     *
120     * @return QString Username
121     */
122     const QString username();
123
124 public slots:
125     /**
126     * @brief Slot to intercept signal when user has pressed connect button from loginDialog
127     *
128     * @param email E-mail
129     * @param password Password
130     */
131     void loginDialogDone(const QString &email, const QString &password);
132
133     /**
134     * @brief Slot to intercept signal when login has failed (loginFailure signal)
135     *
136     */
137     void loginFailed();
138
139     /**
140     * @brief Public slot, which open settings dialog
141     */
142     void openSettingsDialog();
143
144     /**
145     * @brief Sets username to member variable for login dialog
146     *
147     * @param username Username to be set
148     */
149     void setUsername(const QString &username);
150
151     /**
152     * @brief
153     *
154     * @param show
155     */
156     void showPanels(bool show);
157
158     /**
159     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
160     *        doesn't exist yet
161     *
162     * @param url Login page url
163     */
164     void startLoginProcess(const QUrl &url);
165
166     /**
167     * @brief Toggle progress indicator.
168     *
169     * @param state true if progress indicator should be shown, false otherwise
170     */
171     void toggleProgressIndicator(bool state);
172
173 private:
174     /**
175       * @brief Build friend list panel and connect slots
176       */
177     void buildFriendListPanel();
178
179     /**
180       * @brief Build manual location setting cross hair and connect slots
181       */
182     void buildManualLocationCrosshair();
183
184     /**
185       * @brief Build map and connect slots
186       */
187     void buildMap();
188
189     /**
190       * @brief Build OSM license and connect slots
191       */
192     void buildOsmLicense();
193
194     /**
195       * @brief Build user info panel and connect slots
196       */
197     void buildUserInfoPanel();
198
199     /**
200       * @brief Build zoom button panel and connect slots
201       */
202     void buildZoomButtonPanel();
203
204     /**
205     * @brief Private method to create the Menu items
206     */
207     void createMenus();
208
209     /**
210       * @brief Grab or release HW increase and decrease buttons.
211       *
212       * @param grab Use true for grabbing and false for releasing the keys
213       */
214     void grabZoomKeys(bool grab);
215
216     /**
217       * @brief Set own location crosshair visibility
218       *
219       * @param visible
220       */
221     void setOwnLocationCrosshairVisibility(bool visible);
222
223 private slots:
224     /**
225     * @brief Slot for drawing the Open Street Map license text
226     *
227     * @param size Size of the screen
228     */
229     void drawOsmLicense(const QSize &size);
230
231     /**
232     * @brief Slot for drawing the own location crosshair
233     *
234     * @param width Width of the viewport
235     * @param height Height of the viewport
236     */
237     void drawOwnLocationCrosshair(int width, int height);
238
239     /**
240     * @brief Slot for gps error.
241     *
242     * @param message error message
243     */
244     void gpsError(const QString &message);
245
246     /**
247     * @brief Slot for gps timeout.
248     *
249     * Called when request timeout occurs.
250     */
251     void gpsTimeout();
252
253     /**
254     * @brief Slot to intercept signal when webview has finished loading webpage
255     *
256     * @param done Status of the loading
257     */
258     void loadDone(bool done);
259
260     /**
261     * @brief Set correnct view port size to datamembers
262     *
263     * @param width Width of the viewport
264     * @param height Height of the viewport
265     */
266     void setViewPortSize(const int width, const int height);
267
268 /*******************************************************************************
269  * SIGNALS
270  ******************************************************************************/
271 signals:
272     /**
273     * @brief Automatic centering setting changed by user
274     *
275     * @param enabled True if automatic centering is enabled, otherwise false
276     */
277     void autoCenteringTriggered(bool enabled);
278
279     /**
280     * @brief Signal that indicates when user has cancelled login process
281     *
282     */
283     void cancelLoginProcess();
284
285     /**
286     * @brief View should be centered to new location
287     *
288     * @param sceneCoordinate Scene coordinates of the new center point
289     */
290     void centerToSceneCoordinates(QPoint sceneCoordinate);
291
292     /**
293     * @brief Signal for requesting username from settings
294     *
295     */
296     void fetchUsernameFromSettings();
297
298     /**
299     * @brief GPS setting changed
300     *
301     * @param enabled True if GPS is enabled, otherwise false
302     */
303     void gpsTriggered(bool enabled);
304
305     /**
306     * @brief Signal for finding friend.
307     *
308     * @param coordinates friend's geo coordinates
309     */
310     void findFriend(const QPointF &coordinates);
311
312     /**
313     * @brief Signal for friend location ready.
314     *
315     * @param friendsList
316     */
317     void friendsLocationsReady(QList<User *> &friendsList);
318
319     /**
320     * @brief Signal is emitted when location item is clicked.
321     *
322     * @param userIDs list of friends user IDs in the group
323     */
324     void locationItemClicked(const QList<QString> &userIDs);
325
326     /**
327     * @brief Signals when Login/Logout action is pressed
328     *
329     */
330     void loginActionPressed();
331
332     /**
333     * @brief MapView has been resized
334     *
335     * @param size view size
336     */
337     void mapViewResized(const QSize &size);
338
339     /**
340       * @brief Forwarding signal from MapView to MapEngine
341       *
342       * @param sceneCoordinate
343       */
344     void mapViewScrolled(QPoint sceneCoordinate);
345
346     /**
347       * @brief Forwarding signal from MapEngine to MapView
348       */
349     void maxZoomLevelReached();
350
351     /**
352       * @brief Forwarding signal from MapEngine to MapView
353       */
354     void minZoomLevelReached();
355
356     /**
357     * @brief Signal for refreshing user data.
358     *
359     */
360     void refreshUserData();
361
362     /**
363     * @brief Signal for requesting reverseGeo from SituareEngine
364     *
365     */
366     void requestReverseGeo();
367
368     /**
369     * @brief Signals, when address data is ready
370     *
371     * @param address Street address
372     */
373     void reverseGeoReady(const QString &address);
374
375     /**
376     * @brief Signal for requestLocationUpdate from SituareEngine
377     *
378     * @param status Status message
379     * @param publish Publish on Facebook
380     */
381     void statusUpdate(const QString &status, const bool &publish);
382
383     /**
384     * @brief Signals when webview's urlChanged signal is emitted
385     *
386     * @param url New url
387     */
388     void updateCredentials(const QUrl &url);
389
390     /**
391     * @brief MapView has finished zooming
392     */
393     void viewZoomFinished();
394
395     /**
396     * @brief Signal for use location ready.
397     *
398     * @param user User object
399     */
400     void userLocationReady(User *user);
401
402     /**
403     * @brief Map zoom in request
404     */
405     void zoomIn();
406
407     /**
408       * @brief Forwarding signal from MapEngine to MapView
409       */
410     void zoomLevelChanged(int zoomLevel);
411
412     /**
413     * @brief Map zoom out request
414     */
415     void zoomOut();
416
417 /*******************************************************************************
418  * DATA MEMBERS
419  ******************************************************************************/
420 private:
421
422     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
423     bool m_loggedIn;                        ///< Indicates login state
424     bool m_refresh;                         ///< Indicates when webpage is refreshed
425
426     int m_viewPortHeight;                   ///< Height of view port
427     int m_viewPortWidth;                    ///< Width of view port
428
429     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
430     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
431     QAction *m_loginAct;                    ///< Action to Login/Logout
432     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
433
434     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
435     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
436
437     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
438
439     QString m_email;                        ///< Placeholder for email
440     QString m_password;                     ///< Placeholder for password
441
442     QUrl m_loginUrl;                        ///< Placeholder for login page url
443
444     QWebView *m_webView;                    ///< Shows facebook login page
445
446     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
447     LoginDialog *m_loginDialog;             ///< Login dialog
448     MapView *m_mapView;                     ///< Instance of the map view
449     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
450     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
451     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
452     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
453 };
454
455 #endif // MAINWINDOW_H