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