Merge branch 'note_queue'
[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 class QNetworkReply;
37
38 class FacebookAuthentication;
39 class FriendListPanel;
40 class MapScene;
41 class MapView;
42 class SituareService;
43 class User;
44 class UserInfoPanel;
45 class ZoomButtonPanel;
46 class SettingsDialog;
47 class QToolButton;
48
49 /**
50 * @brief Main Window Class
51 */
52 class MainWindow : public QMainWindow
53 {
54     Q_OBJECT
55
56 public:
57     /**
58     * @brief Constructor
59     *
60     * @param parent Parent
61     */
62     MainWindow(QWidget *parent = 0);
63
64     /**
65     * @brief Destructor
66     *
67     */
68     ~MainWindow();
69
70 /*******************************************************************************
71  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
72  ******************************************************************************/
73 private:
74     /**
75       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
76       */
77     void keyPressEvent(QKeyEvent* event);
78
79 /*******************************************************************************
80  * MEMBER FUNCTIONS AND SLOTS
81  ******************************************************************************/
82 public:
83     /**
84     * @brief Builds information box with message.
85     *
86     * @param message Information message
87     * @param modal Modal = true, non-modal false
88     */
89     void buildInformationBox(const QString &message, bool modal=false);
90
91     /**
92     * @brief Clears cookie jar
93     *
94     */
95     void clearCookieJar();
96
97     /**
98     * @brief
99     *
100     * @param logged
101     */
102     void loggedIn(bool logged);
103
104     /**
105     * @brief Enable / disable auto centering button.
106     *
107     * @param enabled true if shoud be enabled, false otherwise
108     */
109     void setAutoCenteringButtonEnabled(bool enabled);
110
111     /**
112     * @brief Enable / disable GPS button.
113     *
114     * Does set visibilities for manual location cursor and auto centering menu button.
115     *
116     * @param enabled true if enabled, false otherwise
117     */
118     void setGPSButtonEnabled(bool enabled);
119
120     /**
121       * @brief Set scene for MapView
122       *
123       * @param scene Scene to be set
124       */
125     void setMapViewScene(QGraphicsScene *scene);
126
127     /**
128     * @brief Gets the username from member variable for saving purposes
129     *
130     * @return QString Username
131     */
132     const QString username();
133
134 public slots:
135     /**
136     * @brief Slot to intercept signal when login has failed (loginFailure signal)
137     *
138     */
139     void loginFailed();
140
141     /**
142     * @brief Slot to intercept signal when login with cookies is requested
143     *
144     */
145     void loginUsingCookies();
146
147     /**
148     * @brief Public slot, which open settings dialog
149     */
150     void openSettingsDialog();
151
152     /**
153     * @brief Sets username to member variable for login dialog
154     *
155     * @param username Username to be set
156     */
157     void setUsername(const QString &username);
158
159     /**
160     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
161     *        doesn't exist yet
162     *
163     */
164     void startLoginProcess();
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     /**
174     * @brief Shows / hides Situare related UI items
175     *
176     * @param show
177     */
178     void updateItemVisibility(bool show);
179
180 private:
181     /**
182       * @brief Build fullscreen toggle button and connect slots
183       */
184     void buildFullScreenButton();
185
186     /**
187       * @brief Build friend list panel and connect slots
188       */
189     void buildFriendListPanel();
190
191     /**
192       * @brief Build manual location setting cross hair and connect slots
193       */
194     void buildManualLocationCrosshair();
195
196     /**
197       * @brief Build map and connect slots
198       */
199     void buildMap();
200
201     /**
202       * @brief Build OSM license and connect slots
203       */
204     void buildOsmLicense();
205
206     /**
207       * @brief Build user info panel and connect slots
208       */
209     void buildUserInfoPanel();
210
211     /**
212     * @brief Build webview and connect slots
213     *
214     */
215     void buildWebView();
216
217     /**
218       * @brief Build zoom button panel and connect slots
219       */
220     void buildZoomButtonPanel();
221
222     /**
223     * @brief Private method to create the Menu items
224     */
225     void createMenus();
226
227     /**
228       * @brief Grab or release HW increase and decrease buttons.
229       *
230       * @param grab Use true for grabbing and false for releasing the keys
231       */
232     void grabZoomKeys(bool grab);
233
234     /**
235     * @brief Queues dialog/information box
236     *
237     * @param dialog Dialog to be added into queue
238     */
239     void queueDialog(QDialog *dialog);
240
241     /**
242       * @brief Set own location crosshair visibility
243       *
244       * @param visible
245       */
246     void setOwnLocationCrosshairVisibility(bool visible);
247
248     /**
249     * @brief Shows queued error information box
250     *
251     */
252     void showErrorInformationBox();
253
254     /**
255     * @brief Shows queued information box
256     *
257     * @fn showInformationBox
258     */
259     void showInformationBox();
260
261 private slots:
262     /**
263     * @brief Slot to intercept signal when dialog/information note is processed
264     *
265     * @param status Status of the dialog
266     */
267     void dialogFinished(int status);
268
269     /**
270     * @brief Slot for drawing the fullscreen toggle button
271     *
272     * @param size Size of the screen
273     */
274     void drawFullScreenButton(const QSize &size);
275
276     /**
277     * @brief Slot for drawing the Open Street Map license text
278     *
279     * @param size Size of the screen
280     */
281     void drawOsmLicense(const QSize &size);
282
283     /**
284     * @brief Slot for drawing the own location crosshair
285     *
286     * @param width Width of the viewport
287     * @param height Height of the viewport
288     */
289     void drawOwnLocationCrosshair(int width, int height);
290
291     /**
292     * @brief Slot to intercept signal when error dialog/information note is processed
293     *
294     * @param status Status of the dialog
295     */
296     void errorDialogFinished(int status);
297
298     /**
299     * @brief Slot for gps timeout.
300     *
301     * Called when request timeout occurs.
302     */
303     void gpsTimeout();
304
305     /**
306     * @brief Slot to load cookies from settings
307     *
308     */
309     void loadCookies();
310
311     /**
312     * @brief Slot to intercept signal when webview has finished loading webpage
313     *
314     * @param done Status of the loading
315     */
316     void loadDone(bool done);
317
318     /**
319     * @brief Slot to save cookies to settings
320     *
321     */
322     void saveCookies();
323
324     /**
325     * @brief Set correnct view port size to datamembers
326     *
327     * @param width Width of the viewport
328     * @param height Height of the viewport
329     */
330     void setViewPortSize(const int width, const int height);
331
332     /**
333     * @brief Toggle between fullscreen and normal window mode
334     */
335     void toggleFullScreen();
336
337     /**
338     * @brief Slot to intercept signal from webview's networkaccessmanager
339     *
340     * @param reply Network reply (contains errors)
341     */
342     void webViewRequestFinished(QNetworkReply* reply);
343
344 /*******************************************************************************
345  * SIGNALS
346  ******************************************************************************/
347 signals:
348     /**
349     * @brief Automatic centering setting changed by user
350     *
351     * @param enabled True if automatic centering is enabled, otherwise false
352     */
353     void autoCenteringTriggered(bool enabled);
354
355     /**
356     * @brief Signal that indicates when user has cancelled login process
357     *
358     */
359     void cancelLoginProcess();
360
361     /**
362     * @brief View should be centered to new location
363     *
364     * @param sceneCoordinate Scene coordinates of the new center point
365     */
366     void centerToSceneCoordinates(QPoint sceneCoordinate);
367
368     /**
369     * @brief Signal for enabling automatic location update.
370     *
371     * @param enabled true if enabled, false otherwise
372     * @param updateIntervalMsecs update interval in milliseconds
373     */
374     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs);
375
376     /**
377     * @brief Signal for requesting username from settings
378     *
379     */
380     void fetchUsernameFromSettings();
381
382     /**
383     * @brief Signal for finding user.
384     *
385     * @param coordinates user geo coordinates
386     */
387     void findUser(const QPointF &coordinates);
388
389     /**
390     * @brief GPS setting changed
391     *
392     * @param enabled True if GPS is enabled, otherwise false
393     */
394     void gpsTriggered(bool enabled);
395
396     /**
397     * @brief Signal for finding friend.
398     *
399     * @param coordinates friend's geo coordinates
400     */
401     void findFriend(const QPointF &coordinates);
402
403     /**
404     * @brief Signal for friend location ready.
405     *
406     * @param friendsList
407     */
408     void friendsLocationsReady(QList<User *> &friendsList);
409
410     /**
411     * @brief Signal is emitted when location item is clicked.
412     *
413     * @param userIDs list of friends user IDs in the group
414     */
415     void locationItemClicked(const QList<QString> &userIDs);
416
417     /**
418     * @brief Signals when Login/Logout action is pressed
419     *
420     */
421     void loginActionPressed();
422
423     /**
424     * @brief MapView has been resized
425     *
426     * @param size view size
427     */
428     void mapViewResized(const QSize &size);
429
430     /**
431       * @brief Forwarding signal from MapView to MapEngine
432       *
433       * @param sceneCoordinate
434       */
435     void mapViewScrolled(QPoint sceneCoordinate);
436
437     /**
438       * @brief Forwarding signal from MapEngine to MapView
439       */
440     void maxZoomLevelReached();
441
442     /**
443     * @brief Signal that informs that user's message/location failed to update on Situare server
444     *        This signal is originally sended from SituareService with name error
445     *        Signal is renamed on MainWindow
446     */
447     void messageSendingFailed(const QString &error);
448
449     /**
450       * @brief Forwarding signal from MapEngine to MapView
451       */
452     void minZoomLevelReached();
453
454     /**
455     * @brief Signal that used to inform user that his message/location update tp Situare server
456     *        was failed.
457     *        This signal is originally sended from UserInfo
458     */
459     void notificateUpdateFailing(const QString &message);
460
461     /**
462     * @brief Signal for refreshing user data.
463     *
464     */
465     void refreshUserData();
466
467     /**
468     * @brief Signal for requesting reverseGeo from SituareEngine
469     *
470     */
471     void requestReverseGeo();
472
473     /**
474     * @brief Signals, when address data is ready
475     *
476     * @param address Street address
477     */
478     void reverseGeoReady(const QString &address);
479
480     /**
481     * @brief Signal to save username to settings
482     *
483     * @param username Username
484     */
485     void saveUsername(const QString &username);
486
487     /**
488     * @brief Signal for requestLocationUpdate from SituareEngine
489     *
490     * @param status Status message
491     * @param publish Publish on Facebook
492     */
493     void statusUpdate(const QString &status, const bool &publish);
494
495     /**
496     * @brief Signals when webview's urlChanged signal is emitted
497     *
498     * @param url New url
499     */
500     void updateCredentials(const QUrl &url);
501
502     /**
503     * @brief Signals when updateLocation request finished successfully
504     *
505     */
506     void updateWasSuccessful();
507
508     /**
509     * @brief MapView has finished zooming
510     */
511     void viewZoomFinished();
512
513     /**
514     * @brief Signal for use location ready.
515     *
516     * @param user User object
517     */
518     void userLocationReady(User *user);
519
520     /**
521     * @brief Map zoom in request
522     */
523     void zoomIn();
524
525     /**
526       * @brief Forwarding signal from MapEngine to MapView
527       */
528     void zoomLevelChanged(int zoomLevel);
529
530     /**
531     * @brief Map zoom out request
532     */
533     void zoomOut();
534
535 /*******************************************************************************
536  * DATA MEMBERS
537  ******************************************************************************/
538 private:
539     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
540     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
541     bool m_loggedIn;                        ///< Indicates login state
542     bool m_refresh;                         ///< Indicates when webpage is refreshed
543
544     int m_viewPortHeight;                   ///< Height of view port
545     int m_viewPortWidth;                    ///< Width of view port
546
547     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
548     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
549     QAction *m_loginAct;                    ///< Action to Login/Logout
550     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
551
552     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
553     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
554
555     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
556     QList<QDialog *> m_queue;               ///< QList type dialog queue
557
558     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
559
560     QString m_email;                        ///< Placeholder for email
561     QString m_password;                     ///< Placeholder for password
562
563     QToolButton *m_fullScreenButton;        ///< Instance of the fullscreen toggle button
564
565     QWebView *m_webView;                    ///< Shows facebook login page
566
567     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
568     MapView *m_mapView;                     ///< Instance of the map view
569     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
570     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
571     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
572     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
573     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
574
575     SettingsDialog *m_settingsDialog;       ///< Settings dialog
576
577 };
578
579 #endif // MAINWINDOW_H