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