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