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