Fixed GPS/manual states when logging in
[situare] / src / ui / mainwindow.h
index 1475146..c8b1231 100644 (file)
@@ -4,6 +4,7 @@
 
       Henri Lampela - henri.lampela@ixonos.com
       Kaj Wallin - kaj.wallin@ixonos.com
+      Sami Rämö - sami.ramo@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    USA.
 */
 
-
 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H
 
 #include <QtGui/QMainWindow>
-#include <QWidget>
-#include <QDebug>
+#include <QUrl>
+
+#include "network/networkcookiejar.h"
+#include "panelsidebar.h"
 
+class QGraphicsScene;
 class QLabel;
-class QStackedWidget;
+class QWebView;
+
+class FacebookAuthentication;
+class FriendListPanel;
+class MapScene;
+class MapView;
+class SituareService;
+class User;
+class UserInfoPanel;
+class ZoomButtonPanel;
 
 /**
-* @Main Window Class
-*
-* @class MainWindow mainwindow.h "src/ui/mainwindow.h"
+* @brief Main Window Class
 */
 class MainWindow : public QMainWindow
 {
     Q_OBJECT
 
 public:
+    /**
+    * @brief Constructor
+    *
+    * @param parent Parent
+    */
     MainWindow(QWidget *parent = 0);
-    ~MainWindow();
 
     /**
-    * @brief Public method to get current index of the view. Used for Unit testing
+    * @brief Destructor
     *
-    * @fn getViewIndex
     */
-    int getViewIndex();
+    ~MainWindow();
 
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
 private:
     /**
-    * @brief Private method to create List and Map views as a stacked widget
+      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
+      */
+    void keyPressEvent(QKeyEvent* event);
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    /**
+    * @brief Clears cookie jar
     *
-    * @fn createViews
     */
-    void createViews();
+    void clearCookieJar();
+
     /**
-    * @brief Widget Stack object for the List and Map Views
+    * @brief
     *
-    * @var situareViews
+    * @param logged
     */
-    QStackedWidget *situareViews;
+    void loggedIn(bool logged);
 
     /**
-    * @brief Private method to create the Menu items
+    * @brief Enable / disable auto centering button.
     *
-    * @fn createMenus
+    * @param enabled true if shoud be enabled, false otherwise
     */
-    void createMenus();
-    QMenu *viewMenu;
+    void setAutoCenteringButtonEnabled(bool enabled);
 
     /**
-    * @brief Action item for changing view to List View
+    * @brief Enable / disable GPS button.
+    *
+    * Does set visibilities for manual location cursor and auto centering menu button.
     *
-    * @var toListViewAct
+    * @param enabled true if enabled, false otherwise
     */
-    QAction *toListViewAct;
+    void setGPSButtonEnabled(bool enabled);
+
+    /**
+      * @brief Set scene for MapView
+      *
+      * @param scene Scene to be set
+      */
+    void setMapViewScene(QGraphicsScene *scene);
+
     /**
-    * @brief Action item for changing view to Map View
+    * @brief Show Maemo information box with message.
     *
-    * @var toMapViewAct
+    * @param message Information message
+    * @param modal Modal = true, non-modal false
     */
-    QAction *toMapViewAct;
+    void showMaemoInformationBox(const QString &message, bool modal=false);
 
     /**
-    * @brief DUMMY LABEL, REMOVE WHEN BOTH VIEWS ARE COMPLETE
+    * @brief Gets the username from member variable for saving purposes
     *
-    * @var infoLabel
-    * @todo REMOVE THIS
+    * @return QString Username
     */
-    QLabel *infoLabel;
+    const QString username();
 
 public slots:
+
+    /**
+    * @brief Slot to intercept signal when login has failed (loginFailure signal)
+    *
+    */
+    void loginFailed();
+
+    /**
+    * @brief Slot to intercept signal when login with cookies is requested
+    *
+    */
+    void loginUsingCookies();
+
+    /**
+    * @brief Public slot, which open settings dialog
+    */
+    void openSettingsDialog();
+
+    /**
+    * @brief Sets username to member variable for login dialog
+    *
+    * @param username Username to be set
+    */
+    void setUsername(const QString &username);
+
+    /**
+    * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
+    *        doesn't exist yet
+    *
+    * @param url Login page url
+    */
+    void startLoginProcess(const QUrl &url);
+
+    /**
+    * @brief Toggle progress indicator.
+    *
+    * @param state true if progress indicator should be shown, false otherwise
+    */
+    void toggleProgressIndicator(bool state);
+
+    /**
+    * @brief Shows / hides Situare related UI items
+    *
+    * @param show
+    */
+    void updateItemVisibility(bool show);
+
+private:
+    /**
+      * @brief Build friend list panel and connect slots
+      */
+    void buildFriendListPanel();
+
+    /**
+      * @brief Build manual location setting cross hair and connect slots
+      */
+    void buildManualLocationCrosshair();
+
+    /**
+      * @brief Build map and connect slots
+      */
+    void buildMap();
+
+    /**
+      * @brief Build OSM license and connect slots
+      */
+    void buildOsmLicense();
+
+    /**
+      * @brief Build user info panel and connect slots
+      */
+    void buildUserInfoPanel();
+
+    /**
+    * @brief Build webview and connect slots
+    *
+    */
+    void buildWebView();
+
+    /**
+      * @brief Build zoom button panel and connect slots
+      */
+    void buildZoomButtonPanel();
+
+    /**
+    * @brief Private method to create the Menu items
+    */
+    void createMenus();
+
+    /**
+      * @brief Grab or release HW increase and decrease buttons.
+      *
+      * @param grab Use true for grabbing and false for releasing the keys
+      */
+    void grabZoomKeys(bool grab);
+
+    /**
+      * @brief Set own location crosshair visibility
+      *
+      * @param visible
+      */
+    void setOwnLocationCrosshairVisibility(bool visible);
+
+private slots:
+    /**
+    * @brief Slot for drawing the Open Street Map license text
+    *
+    * @param size Size of the screen
+    */
+    void drawOsmLicense(const QSize &size);
+
+    /**
+    * @brief Slot for drawing the own location crosshair
+    *
+    * @param width Width of the viewport
+    * @param height Height of the viewport
+    */
+    void drawOwnLocationCrosshair(int width, int height);
+
+    /**
+    * @brief Slot for gps error.
+    *
+    * @param message error message
+    */
+    void gpsError(const QString &message);
+
+    /**
+    * @brief Slot for gps timeout.
+    *
+    * Called when request timeout occurs.
+    */
+    void gpsTimeout();
+
+    /**
+    * @brief Slot to load cookies from settings
+    *
+    */
+    void loadCookies();
+
+    /**
+    * @brief Slot to intercept signal when webview has finished loading webpage
+    *
+    * @param done Status of the loading
+    */
+    void loadDone(bool done);
+
     /**
-    * @brief Public slot, which initiates toListViewAct action to switch view
+    * @brief Slot to save cookies to settings
     *
-    * @fn toListView
     */
-    void toListView();
+    void saveCookies();
+
+    /**
+    * @brief Set correnct view port size to datamembers
+    *
+    * @param width Width of the viewport
+    * @param height Height of the viewport
+    */
+    void setViewPortSize(const int width, const int height);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+    /**
+    * @brief Automatic centering setting changed by user
+    *
+    * @param enabled True if automatic centering is enabled, otherwise false
+    */
+    void autoCenteringTriggered(bool enabled);
+
+    /**
+    * @brief Signal that indicates when user has cancelled login process
+    *
+    */
+    void cancelLoginProcess();
+
+    /**
+    * @brief View should be centered to new location
+    *
+    * @param sceneCoordinate Scene coordinates of the new center point
+    */
+    void centerToSceneCoordinates(QPoint sceneCoordinate);
+
+    /**
+    * @brief Signal for requesting username from settings
+    *
+    */
+    void fetchUsernameFromSettings();
+
+    /**
+    * @brief Signal for finding user.
+    *
+    * @param coordinates user geo coordinates
+    */
+    void findUser(const QPointF &coordinates);
+
+    /**
+    * @brief GPS setting changed
+    *
+    * @param enabled True if GPS is enabled, otherwise false
+    */
+    void gpsTriggered(bool enabled);
+
+    /**
+    * @brief Signal for finding friend.
+    *
+    * @param coordinates friend's geo coordinates
+    */
+    void findFriend(const QPointF &coordinates);
+
+    /**
+    * @brief Signal for friend location ready.
+    *
+    * @param friendsList
+    */
+    void friendsLocationsReady(QList<User *> &friendsList);
+
+    /**
+    * @brief Signal is emitted when location item is clicked.
+    *
+    * @param userIDs list of friends user IDs in the group
+    */
+    void locationItemClicked(const QList<QString> &userIDs);
+
+    /**
+    * @brief Signals when Login/Logout action is pressed
+    *
+    */
+    void loginActionPressed();
+
+    /**
+    * @brief MapView has been resized
+    *
+    * @param size view size
+    */
+    void mapViewResized(const QSize &size);
+
+    /**
+      * @brief Forwarding signal from MapView to MapEngine
+      *
+      * @param sceneCoordinate
+      */
+    void mapViewScrolled(QPoint sceneCoordinate);
+
+    /**
+      * @brief Forwarding signal from MapEngine to MapView
+      */
+    void maxZoomLevelReached();
+
+    /**
+      * @brief Forwarding signal from MapEngine to MapView
+      */
+    void minZoomLevelReached();
+
+    /**
+    * @brief Signal for refreshing user data.
+    *
+    */
+    void refreshUserData();
+
+    /**
+    * @brief Signal for requesting reverseGeo from SituareEngine
+    *
+    */
+    void requestReverseGeo();
+
+    /**
+    * @brief Signals, when address data is ready
+    *
+    * @param address Street address
+    */
+    void reverseGeoReady(const QString &address);
+
+    /**
+    * @brief Signal for requestLocationUpdate from SituareEngine
+    *
+    * @param status Status message
+    * @param publish Publish on Facebook
+    */
+    void statusUpdate(const QString &status, const bool &publish);
+
+    /**
+    * @brief Signals when webview's urlChanged signal is emitted
+    *
+    * @param url New url
+    */
+    void updateCredentials(const QUrl &url);
+
+    /**
+    * @brief MapView has finished zooming
+    */
+    void viewZoomFinished();
+
     /**
-    * @brief Public slot, which initiates toMapViewAct action to switch view
+    * @brief Signal for use location ready.
     *
-    * @fn toMapView
+    * @param user User object
+    */
+    void userLocationReady(User *user);
+
+    /**
+    * @brief Map zoom in request
+    */
+    void zoomIn();
+
+    /**
+      * @brief Forwarding signal from MapEngine to MapView
+      */
+    void zoomLevelChanged(int zoomLevel);
+
+    /**
+    * @brief Map zoom out request
     */
-    void toMapView();
+    void zoomOut();
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+
+    bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
+    bool m_loggedIn;                        ///< Indicates login state
+    bool m_refresh;                         ///< Indicates when webpage is refreshed
+
+    int m_viewPortHeight;                   ///< Height of view port
+    int m_viewPortWidth;                    ///< Width of view port
+
+    QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
+    QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
+    QAction *m_loginAct;                    ///< Action to Login/Logout
+    QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
+
+    QLabel *m_osmLicense;                   ///< Label for Open Street Map license
+    QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
+
+    QMenu *m_viewMenu;                      ///< Object that hold the view menu items
+
+    QString m_email;                        ///< Placeholder for email
+    QString m_password;                     ///< Placeholder for password
+
+    QWebView *m_webView;                    ///< Shows facebook login page
+
+    FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
+    MapView *m_mapView;                     ///< Instance of the map view
+    NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
+    PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
+    PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
+    UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
+    ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
 };
 
 #endif // MAINWINDOW_H