Merge branch 'master' into settings_auto_update
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 8 Jun 2010 11:30:11 +0000 (14:30 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 8 Jun 2010 11:30:11 +0000 (14:30 +0300)
Conflicts:
doc/testing/functionality-tests.doc
src/ui/mainwindow.cpp
src/ui/mainwindow.h

13 files changed:
src/engine/engine.cpp
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/situareservice/situareservice.cpp
src/src.pro
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userinfopanel.cpp
src/ui/userinfopanel.h

index a83ff1e..02d8597 100644 (file)
@@ -39,6 +39,7 @@ const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Au
 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12;  ///< Default zoom level when GPS available
 const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
+const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
 
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
@@ -86,8 +87,6 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
-    initializeGpsAndAutocentering();
-
     // signals connected, now it's time to show the main window
     // but init the MapEngine before so starting location is set
     m_mapEngine->init();
@@ -95,6 +94,8 @@ SituareEngine::SituareEngine(QMainWindow *parent)
 
     m_facebookAuthenticator->start();
 
+    initializeGpsAndAutocentering();
+
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
             this, SLOT(automaticUpdateIntervalTimerTimeout()));
@@ -136,7 +137,7 @@ void SituareEngine::disableAutoCentering()
     qDebug() << __PRETTY_FUNCTION__;
 
     changeAutoCenteringSetting(false);
-    m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
+    m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
 void SituareEngine::enableAutoCentering(bool enabled)
@@ -189,7 +190,10 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
         if (m_automaticUpdateIntervalTimer) {
 
             if (enabled && m_gps->isRunning()) {
-                m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+                if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
+                    m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
+                else
+                    m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
                 m_automaticUpdateIntervalTimer->start();
             }
             else
@@ -201,8 +205,9 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
 void SituareEngine::error(const QString &error)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << "ERROR MESSAGE: " << error;
 
-    m_ui->showMaemoInformationBox(error, true);
+    m_ui->buildInformationBox(error, true);
 
     if(error.compare(SESSION_EXPIRED) == 0) {
         m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
@@ -234,18 +239,19 @@ void SituareEngine::initializeGpsAndAutocentering()
         changeAutoCenteringSetting(true);
         enableGPS(true);
 
-        m_ui->showMaemoInformationBox(tr("GPS enabled"));
-        m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
+        m_ui->buildInformationBox(tr("GPS enabled"));
+        m_ui->buildInformationBox(tr("Auto centering enabled"));
+
     } else { // Normal start
         changeAutoCenteringSetting(autoCenteringEnabled.toBool());
         enableGPS(gpsEnabled.toBool());
 
         if (gpsEnabled.toBool())
-            m_ui->showMaemoInformationBox(tr("GPS enabled"));
+            m_ui->buildInformationBox(tr("GPS enabled"));
 
         if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
-            m_ui->showMaemoInformationBox(tr("Auto centering enabled"));        
-    } 
+            m_ui->buildInformationBox(tr("Auto centering enabled"));
+    }
 }
 
 bool SituareEngine::isUserMoved()
@@ -369,8 +375,8 @@ void SituareEngine::signalsFromFacebookAuthenticator()
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
             this, SLOT(loginOk()));
 
-    connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
-            m_ui, SLOT(startLoginProcess(QUrl)));
+    connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
+            m_ui, SLOT(startLoginProcess()));
 
     connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
             m_ui, SLOT(loginFailed()));
@@ -450,12 +456,15 @@ void SituareEngine::signalsFromMainWindow()
             this, SLOT(requestUpdateLocation(QString,bool)));
 
     connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
-            this, SLOT(enableAutomaticLocationUpdate(bool, int)));
+            this, SLOT(enableAutomaticLocationUpdate(bool, int)));    
 
     // signals from user info tab
     connect(m_ui, SIGNAL(refreshUserData()),
             this, SLOT(refreshUserData()));
 
+    connect (m_ui, SIGNAL(notificateUpdateFailing(QString)),
+             this, SLOT(error(QString)));
+
     connect(m_ui, SIGNAL(findUser(QPointF)),
             m_mapEngine, SLOT(setViewLocation(QPointF)));
 
@@ -505,6 +514,12 @@ void SituareEngine::signalsFromSituareService()
 
     connect(m_situareService, SIGNAL(updateWasSuccessful()),
             this, SLOT(updateWasSuccessful()));
+
+    connect(m_situareService, SIGNAL(updateWasSuccessful()),
+            m_ui, SIGNAL(updateWasSuccessful()));
+
+    connect(m_situareService, SIGNAL(error(QString)),
+            m_ui, SIGNAL(messageSendingFailed(QString)));
 }
 
 void SituareEngine::updateWasSuccessful()
index fcd87e4..80819b6 100644 (file)
@@ -38,9 +38,7 @@
 
 FacebookAuthentication::FacebookAuthentication(QObject *parent)
     : QObject(parent),
-    m_freshLogin(false),
-    m_loginAttempts(0)
-
+    m_freshLogin(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -93,17 +91,7 @@ void FacebookAuthentication::start()
     }
     else {
         m_freshLogin = true;
-
-        QStringList list;
-        list.append(FACEBOOK_LOGINBASE);
-        list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-        list.append(INTERVAL1);
-        list.append(SITUARE_LOGIN_SUCCESS);
-        list.append(INTERVAL2);
-        list.append(SITUARE_LOGIN_FAILURE);
-        list.append(FACEBOOK_LOGIN_ENDING);
-
-        emit newLoginRequest(list.join(EMPTY));
+        emit newLoginRequest();
     }
 }
 
@@ -172,20 +160,14 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
         else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
             qWarning() << "login failure" << endl;
             qDebug() << callbackUrl;
-            ++m_loginAttempts;
-            /* emit loginFailure for every second login attemps, since webview loads login
-               error page (loadingDone() signal is emitted) and we need to avoid that because
-               at this point we don't have new login parameters */
-            if(m_loginAttempts % 2) {
-                clearAccountInformation(true);
-                if(m_freshLogin) {
-                    emit error(LOGIN_FAILED);
-                    emit loginFailure();
-                }
-                else {
-                    m_freshLogin = true;
-                    emit error(SESSION_EXPIRED);
-                }
+            clearAccountInformation(true);
+            if(m_freshLogin) {
+                emit error(LOGIN_FAILED);
+                emit loginFailure();
+            }
+            else {
+                m_freshLogin = true;
+                emit error(SESSION_EXPIRED);
             }
         }
         else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {
index 8a296da..4ffea66 100644 (file)
@@ -139,9 +139,8 @@ signals:
     /**
     * @brief Signals when credentials are invalid new login is needed
     *
-    * @param url Login page url
     */
-    void newLoginRequest(const QUrl &url);
+    void newLoginRequest();
 
     /**
     * @brief This signal is emitted when new cookies need to be saved.
@@ -157,8 +156,6 @@ private:
 
     bool m_freshLogin;
 
-    int m_loginAttempts; ///< Indicates login attempts
-
     /**
     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
     *        QStrings and setters and getters.
index 3a0c225..cdd921f 100644 (file)
@@ -249,7 +249,8 @@ void SituareService::requestFinished(QNetworkReply *reply)
         qDebug() << "BytesAvailable: " << reply->bytesAvailable();
 
         if (reply->error()) {
-            emit error(reply->errorString());
+            emit error(reply->errorString());            
+            qDebug() << "TMP MESSAGE VILLE";
         } else {
             qint64 max = reply->size();
             QByteArray replyArray = reply->read(max);
index 10e7c8a..d48615b 100644 (file)
@@ -98,7 +98,7 @@ HEADERS += ui/mainwindow.h \
 QT += network \
     webkit
 
-DEFINES += QT_NO_DEBUG_OUTPUT
+#DEFINES += QT_NO_DEBUG_OUTPUT
 
 simulator {
     SOURCES += network/networkhandlerprivatestub.cpp \
index f6bc20a..012d5e6 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QtGui>
 #include <QtWebKit>
+#include <QtAlgorithms>
 
 #include "common.h"
 #include "facebookservice/facebookauthentication.h"
@@ -52,6 +53,7 @@ const int N900_APP_HEIGHT = 449;
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
     m_drawOwnLocationCrosshair(false),
+    m_errorShown(false),
     m_loggedIn(false),
     m_refresh(false),
     m_ownLocationCrosshair(0),
@@ -109,6 +111,12 @@ MainWindow::~MainWindow()
 
     if(m_webView)
         delete m_webView;
+
+    qDeleteAll(m_queue.begin(), m_queue.end());
+    m_queue.clear();
+
+    qDeleteAll(m_error_queue.begin(), m_error_queue.end());
+    m_error_queue.clear();
 }
 
 void MainWindow::automaticLocationUpdateEnabled(bool enabled)
@@ -154,6 +162,32 @@ void MainWindow::buildFriendListPanel()
             m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
 }
 
+void MainWindow::buildInformationBox(const QString &message, bool modal)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
+    QLabel *label = new QLabel(msgBox);
+    label->setAlignment(Qt::AlignCenter);
+    label->setText(message);
+    msgBox->setWidget(label);
+
+    if(modal) {
+        msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
+    } else {
+        msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+    }
+#else
+    QMessageBox *msgBox = new QMessageBox(this);
+    msgBox->button(QMessageBox::Ok);
+    msgBox->setText(message);
+    msgBox->setModal(modal);
+#endif
+
+    queueDialog(msgBox);
+}
+
 void MainWindow::buildManualLocationCrosshair()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -248,6 +282,15 @@ void MainWindow::buildUserInfoPanel()
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_userPanel, SLOT(screenResized(QSize)));
+
+    connect(this, SIGNAL(updateWasSuccessful()),
+            m_userPanel, SIGNAL(updateWasSuccessful()));
+
+    connect(this, SIGNAL(messageSendingFailed(QString)),
+            m_userPanel, SIGNAL(messageSendingFailed(QString)));
+
+    connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString)),
+            this, SIGNAL(notificateUpdateFailing(QString)));
 }
 
 void MainWindow::buildWebView()
@@ -257,6 +300,13 @@ void MainWindow::buildWebView()
     if(!m_webView) {
         m_webView = new QWebView;
 
+        if(!m_cookieJar)
+            m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+        m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
+        connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
+                this, SLOT(webViewRequestFinished(QNetworkReply*)));
         connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
                 this, SIGNAL(updateCredentials(QUrl)));
         connect(m_webView, SIGNAL(loadFinished(bool)),
@@ -343,6 +393,46 @@ void MainWindow::createMenus()
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
+void MainWindow::dialogFinished(int status)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QDialog *dialog = m_queue.takeFirst();
+    LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
+    if(loginDialog) {
+        if(status != 0) {
+            buildWebView();
+            loginDialog->userInput(m_email, m_password);
+
+            QStringList urlParts;
+            urlParts.append(FACEBOOK_LOGINBASE);
+            urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+            urlParts.append(INTERVAL1);
+            urlParts.append(SITUARE_LOGIN_SUCCESS);
+            urlParts.append(INTERVAL2);
+            urlParts.append(SITUARE_LOGIN_FAILURE);
+            urlParts.append(FACEBOOK_LOGIN_ENDING);
+
+            emit saveUsername(m_email);
+            m_refresh = true;
+            m_webView->load(QUrl(urlParts.join(EMPTY)));
+            toggleProgressIndicator(true);
+        } else {
+            emit cancelLoginProcess();
+        }
+    }
+
+    dialog->deleteLater();
+
+    if(!m_error_queue.isEmpty() && m_errorShown == false) {
+        showErrorInformationBox();
+    } else {
+        if(!m_queue.isEmpty()) {
+            showInformationBox();
+        }
+    }
+}
+
 void MainWindow::drawFullScreenButton(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
@@ -373,11 +463,26 @@ void MainWindow::drawOwnLocationCrosshair(int width, int height)
     }
 }
 
+void MainWindow::errorDialogFinished(int status)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    qDebug() << status;
+    QDialog *dialog = m_error_queue.takeFirst();
+
+    dialog->deleteLater();
+    m_errorShown = false;
+
+    if(!m_error_queue.isEmpty()) {
+        showErrorInformationBox();
+    }
+}
+
 void MainWindow::gpsTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    showMaemoInformationBox(tr("GPS timeout"));
+    buildInformationBox(tr("GPS timeout"));
 }
 
 void MainWindow::grabZoomKeys(bool grab)
@@ -500,8 +605,7 @@ void MainWindow::loggedIn(bool logged)
 
     if(logged) {
         m_loginAct->setText(tr("Logout"));
-    }
-    else {
+    } else {
         clearCookieJar();
         m_email.clear();
         m_password.clear();
@@ -519,16 +623,7 @@ void MainWindow::loginFailed()
 
     toggleProgressIndicator(false);
 
-    QStringList urlParts;
-    urlParts.append(FACEBOOK_LOGINBASE);
-    urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-    urlParts.append(INTERVAL1);
-    urlParts.append(SITUARE_LOGIN_SUCCESS);
-    urlParts.append(INTERVAL2);
-    urlParts.append(SITUARE_LOGIN_FAILURE);
-    urlParts.append(FACEBOOK_LOGIN_ENDING);
-
-    startLoginProcess(urlParts.join(EMPTY));
+    startLoginProcess();
 }
 
 void MainWindow::loginUsingCookies()
@@ -566,6 +661,24 @@ void MainWindow::requestAutomaticLocationUpdateSettings()
     m_settingsDialog->emitAutomaticLocationUpdateSettings();
 }
 
+void MainWindow::queueDialog(QDialog *dialog)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
+    if(dialog->isModal()) {
+        m_error_queue.append(dialog);
+    } else {
+        m_queue.append(dialog);
+    }
+
+    // show error dialog if there is only one error dialog in the queue and no error dialog is shown
+    if(m_error_queue.count() == 1 && m_errorShown == false)
+        showErrorInformationBox();
+    else if(m_queue.count() == 1 && m_errorShown == false)
+        showInformationBox();
+}
+
 void MainWindow::saveCookies()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -621,8 +734,7 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
         m_ownLocationCrosshair->show();
         m_drawOwnLocationCrosshair = true;
         drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
-    }
-    else {
+    } else {
         m_ownLocationCrosshair->hide();
         m_drawOwnLocationCrosshair = false;
     }
@@ -657,23 +769,6 @@ bool MainWindow::showEnableAutomaticUpdateLocationDialog()
         return false;
 }
 
-void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-#ifdef Q_WS_MAEMO_5
-    if(modal) {
-        QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::NoTimeout);
-    }
-    else {
-        QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
-    }
-#else
-    Q_UNUSED(modal);
-    QMessageBox::information(this, tr("Situare"), message, QMessageBox::Ok);
-#endif
-}
-
 void MainWindow::toggleFullScreen()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -684,39 +779,45 @@ void MainWindow::toggleFullScreen()
         showNormal();
 }
 
-void MainWindow::startLoginProcess(const QUrl &url)
+void MainWindow::showErrorInformationBox()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    buildWebView();
+    if(m_error_queue.count()) {
+        m_errorShown = true;
+        QDialog *dialog = m_error_queue.first();
+        connect(dialog, SIGNAL(finished(int)),
+                this, SLOT(errorDialogFinished(int)));
+        dialog->show();
+    }
+}
 
-    LoginDialog loginDialog;
+void MainWindow::showInformationBox()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    emit fetchUsernameFromSettings();
+    if(m_queue.count()) {
+        QDialog *dialog = m_queue.first();
+        connect(dialog, SIGNAL(finished(int)),
+                this, SLOT(dialogFinished(int)));
+        dialog->show();
+    }
+}
 
-    if(!m_cookieJar)
-        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+void MainWindow::startLoginProcess()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+    LoginDialog *loginDialog = new LoginDialog();
+
+    emit fetchUsernameFromSettings();
 
-    loginDialog.clearTextFields();
+    loginDialog->clearTextFields();
 
     if(!m_email.isEmpty())
-        loginDialog.setEmailField(m_email);
-
-    if(loginDialog.exec() != QDialog::Accepted) {
-        // if login dialog was canceled we need to stop processing webview
-        m_webView->stop();
+        loginDialog->setEmailField(m_email);
 
-        emit cancelLoginProcess();
-    }
-    else {
-        loginDialog.userInput(m_email, m_password);
-        emit saveUsername(m_email);
-        m_webView->load(url);
-        toggleProgressIndicator(true);
-        m_refresh = true;
-    }
+    queueDialog(loginDialog);
 }
 
 void MainWindow::toggleProgressIndicator(bool value)
@@ -745,8 +846,7 @@ void MainWindow::updateItemVisibility(bool show)
             setGPSButtonEnabled(false);
             emit gpsTriggered(false);
         }
-    }
-    else {
+    } else {
         m_friendsListPanel->closePanel();
         m_friendsListPanel->hide();
         m_friendsListPanelSidebar->hide();
@@ -763,3 +863,14 @@ const QString MainWindow::username()
     
     return m_email;
 }
+
+void MainWindow::webViewRequestFinished(QNetworkReply *reply)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(reply->error()) {
+        qDebug() << reply->error() << reply->errorString();
+        toggleProgressIndicator(false);
+    }
+}
+
index 68ce6a6..ba7a8bd 100644 (file)
@@ -33,6 +33,7 @@
 class QGraphicsScene;
 class QLabel;
 class QWebView;
+class QNetworkReply;
 
 class FacebookAuthentication;
 class FriendListPanel;
@@ -87,6 +88,14 @@ public:
     void automaticLocationUpdateEnabled(bool enabled);
 
     /**
+    * @brief Builds information box with message.
+    *
+    * @param message Information message
+    * @param modal Modal = true, non-modal false
+    */
+    void buildInformationBox(const QString &message, bool modal=false);
+
+    /**
     * @brief Clears cookie jar
     *
     */
@@ -136,14 +145,6 @@ public:
     bool showEnableAutomaticUpdateLocationDialog();
 
     /**
-    * @brief Show Maemo information box with message.
-    *
-    * @param message Information message
-    * @param modal Modal = true, non-modal false
-    */
-    void showMaemoInformationBox(const QString &message, bool modal=false);
-
-    /**
     * @brief Gets the username from member variable for saving purposes
     *
     * @return QString Username
@@ -179,9 +180,8 @@ public slots:
     * @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);
+    void startLoginProcess();
 
     /**
     * @brief Toggle progress indicator.
@@ -252,14 +252,41 @@ private:
     void grabZoomKeys(bool grab);
 
     /**
+    * @brief Queues dialog/information box
+    *
+    * @param dialog Dialog to be added into queue
+    */
+    void queueDialog(QDialog *dialog);
+
+    /**
       * @brief Set own location crosshair visibility
       *
       * @param visible
       */
     void setOwnLocationCrosshairVisibility(bool visible);
 
+    /**
+    * @brief Shows queued error information box
+    *
+    */
+    void showErrorInformationBox();
+
+    /**
+    * @brief Shows queued information box
+    *
+    * @fn showInformationBox
+    */
+    void showInformationBox();
+
 private slots:
     /**
+    * @brief Slot to intercept signal when dialog/information note is processed
+    *
+    * @param status Status of the dialog
+    */
+    void dialogFinished(int status);
+
+    /**
     * @brief Slot for drawing the fullscreen toggle button
     *
     * @param size Size of the screen
@@ -282,6 +309,13 @@ private slots:
     void drawOwnLocationCrosshair(int width, int height);
 
     /**
+    * @brief Slot to intercept signal when error dialog/information note is processed
+    *
+    * @param status Status of the dialog
+    */
+    void errorDialogFinished(int status);
+
+    /**
     * @brief Slot for gps timeout.
     *
     * Called when request timeout occurs.
@@ -320,6 +354,13 @@ private slots:
     */
     void toggleFullScreen();
 
+    /**
+    * @brief Slot to intercept signal from webview's networkaccessmanager
+    *
+    * @param reply Network reply (contains errors)
+    */
+    void webViewRequestFinished(QNetworkReply* reply);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -419,11 +460,25 @@ signals:
     void maxZoomLevelReached();
 
     /**
+    * @brief Signal that informs that user's message/location failed to update on Situare server
+    *        This signal is originally sended from SituareService with name error
+    *        Signal is renamed on MainWindow
+    */
+    void messageSendingFailed(const QString &error);
+
+    /**
       * @brief Forwarding signal from MapEngine to MapView
       */
     void minZoomLevelReached();
 
     /**
+    * @brief Signal that used to inform user that his message/location update tp Situare server
+    *        was failed.
+    *        This signal is originally sended from UserInfo
+    */
+    void notificateUpdateFailing(const QString &message);
+
+    /**
     * @brief Signal for refreshing user data.
     *
     */
@@ -465,6 +520,12 @@ signals:
     void updateCredentials(const QUrl &url);
 
     /**
+    * @brief Signals when updateLocation request finished successfully
+    *
+    */
+    void updateWasSuccessful();
+
+    /**
     * @brief MapView has finished zooming
     */
     void viewZoomFinished();
@@ -496,6 +557,7 @@ signals:
  ******************************************************************************/
 private:
     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
+    bool m_errorShown;                      ///< Indicates if error dialog/note is shown
     bool m_loggedIn;                        ///< Indicates login state
     bool m_refresh;                         ///< Indicates when webpage is refreshed
 
@@ -510,6 +572,9 @@ private:
     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
 
+    QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
+    QList<QDialog *> m_queue;               ///< QList type dialog queue
+
     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
 
     QString m_email;                        ///< Placeholder for email
@@ -528,6 +593,7 @@ private:
     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
 
     SettingsDialog *m_settingsDialog;       ///< Settings dialog
+
 };
 
 #endif // MAINWINDOW_H
index a578bb5..cbf79cb 100755 (executable)
@@ -23,7 +23,8 @@
 #include <QDebug>
 #include "updatelocationdialog.h"
 
-UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
+UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook,
+                                           QWidget *parent)
     : QDialog(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -34,9 +35,13 @@ UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
     QGroupBox *groupBox = new QGroupBox(scrollArea);
 
     m_textEdit = new QTextEdit;
+    m_textEdit->setText(userMessage);
+
     m_locationLabel = new QLabel;
     m_locationLabel->setWordWrap(true);
+
     m_checkBox = new QCheckBox(tr("Publish on Facebook"));
+    m_checkBox->setChecked(publishOnFacebook);
 
     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
     QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok);
@@ -60,12 +65,7 @@ UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
     connect(sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 
-    scrollArea->show();
-}
-
-UpdateLocationDialog::~UpdateLocationDialog()
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    scrollArea->show();    
 }
 
 void UpdateLocationDialog::setAddress(const QString &address)
@@ -76,10 +76,11 @@ void UpdateLocationDialog::setAddress(const QString &address)
 
 void UpdateLocationDialog::sendUpdate()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;   
 
     // coordinates for this call will be get from somewhere, map etc...
-    emit statusUpdate(m_textEdit->toPlainText(), m_checkBox->isChecked());
+    emit statusUpdate(m_textEdit->toPlainText(), m_checkBox->isChecked());    
+    m_textEdit->clear();
 
-    this->close();
+    close();
 }
index 1464886..af57d5b 100755 (executable)
@@ -53,10 +53,12 @@ public:
     /**
     * @brief Default constructor
     *
+    * @param userMessage update location dialog message
+    * @param publishOnFacebook update location dialog Facebook publish policity
     * @param parent
     */
-    UpdateLocationDialog(QWidget *parent = 0);
-    ~UpdateLocationDialog();
+    UpdateLocationDialog(const QString &userMessage = "", bool publishOnFacebook = false,
+                         QWidget *parent = 0);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
@@ -84,7 +86,6 @@ private slots:
  ******************************************************************************/
 
 signals:
-
     /**
     * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class
     *
@@ -98,9 +99,8 @@ signals:
  ******************************************************************************/
 
 private:
-
-    QCheckBox *m_checkBox; ///< Pointer to CheckBox
     QLabel *m_locationLabel; ///< Pointer to locationLabel
+    QCheckBox *m_checkBox; ///< Pointer to CheckBox
     QTextEdit *m_textEdit; ///< Pointer to TextEdit
 };
 
index f0bec2f..a97f499 100644 (file)
@@ -6,6 +6,7 @@
        Jussi Laitinen - jussi.laitinen@ixonos.com
        Katri Kaikkonen - katri.kaikkonen@ixonos.com
        Henri Lampela - henri.lampela@ixonos.com
+       Ville Tiensuu - ville.tiensuu@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -22,6 +23,7 @@
    USA.
 */
 
+#include "common.h"
 #include "imagebutton.h"
 #include "../user/user.h"
 #include "userinfo.h"
 const int BACKGROUND_WIDTH = 240; ///< Width for item
 const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
 const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
-const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);  ///< Small font
 const int ICON_HEIGHT = 24; ///< Icon height
 const int ICON_WIDTH = 24;  ///< Icon width
-const int IMAGE_HEIGHT = 60;    ///< Profile image height
-const int IMAGE_WIDTH = 60;     ///< Profile image width
 const int MARGIN = 5; ///< Icon margin
 const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
+const QString USER_UNSEND_MESSAGE = "User_unsend_message_content";
+const QString USER_UNSEND_MESSAGE_PUBLISH_POLICITY = "User_unsend_message_publish";
 
 /**
 * @var LABEL_MAX_WIDTH
@@ -110,10 +109,12 @@ UserInfo::UserInfo(QWidget *parent)
 
     connect(updateStatusMessageButton,SIGNAL(clicked()),
             this,SLOT(messageUpdate()));
+
     connect(updateFriendsButton,SIGNAL(clicked()),
             this, SIGNAL(refreshUserData()));
+
     connect(m_findButton, SIGNAL(clicked()),
-        this, SLOT(findButtonClicked()));
+        this, SLOT(findButtonClicked()));    
 
     setFixedWidth(BACKGROUND_WIDTH);
 
@@ -129,6 +130,23 @@ UserInfo::UserInfo(QWidget *parent)
     m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
     m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
     m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
+
+    restoreUnsendMessage();
+}
+
+UserInfo::~UserInfo()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+    if (!m_backupMessage.isEmpty()) {        
+        settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
+        settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
+    } else {
+        settings.remove(USER_UNSEND_MESSAGE);
+        settings.remove(USER_UNSEND_MESSAGE_PUBLISH_POLICITY);
+    }
 }
 
 void UserInfo::setAddress(const QString &address)
@@ -175,23 +193,6 @@ void UserInfo::setUserName(const QString &name)
     setText(false);
 }
 
-QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QFontMetrics labelMetrics = label->fontMetrics();
-
-    QString textParam = text;
-    int index = textParam.indexOf('\n');
-
-    if (index > 0) {
-        textParam.truncate(index);
-        textParam.append("...");
-    }
-
-   return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
-}
-
 void UserInfo::setText(bool expanded)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -207,6 +208,31 @@ void UserInfo::setText(bool expanded)
     }
 }
 
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_backupMessage = status;
+    m_backupFacebookPublishPolicity = publish;
+
+    m_messageUpdateVerified = false;
+}
+
+void UserInfo::clearUpdateLocationDialogData()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_backupMessage.clear();
+    m_backupFacebookPublishPolicity = false;
+}
+
+void UserInfo::findButtonClicked()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit findUser(m_coordinates);
+}
+
 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
@@ -224,6 +250,42 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
     }
 }
 
+void UserInfo::mousePressEvent(QMouseEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+
+    m_mousePosition = event->pos();
+}
+
+void UserInfo::messageUpdate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit requestReverseGeo();
+
+    UpdateLocationDialog updateLocation(m_backupMessage, m_backupFacebookPublishPolicity, this);
+
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            &updateLocation, SLOT(setAddress(QString)));
+
+    connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+            this, SIGNAL(statusUpdate(QString,bool)));
+
+    connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+            this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+
+    updateLocation.exec();
+
+    disconnect(this, SIGNAL(reverseGeoReady(QString)),
+            &updateLocation, SLOT(setAddress(QString)));
+
+    disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+            this, SIGNAL(statusUpdate(QString,bool)));
+
+    disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+            this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+}
+
 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
@@ -241,33 +303,45 @@ void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
     painter.drawPixmap(bottomRect, m_backgroundBottomImage);
 }
 
-void UserInfo::mousePressEvent(QMouseEvent *event)
+void UserInfo::restoreUnsendMessage()
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+    qDebug() << __PRETTY_FUNCTION__;
 
-    m_mousePosition = event->pos();
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    m_backupMessage = settings.value(USER_UNSEND_MESSAGE, "").toString();
+    m_backupFacebookPublishPolicity =
+            settings.value(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, false).toBool();
 }
 
-void UserInfo::findButtonClicked()
+QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    emit findUser(m_coordinates);
+    QFontMetrics labelMetrics = label->fontMetrics();
+
+    QString textParam = text;
+    int index = textParam.indexOf('\n');
+
+    if (index > 0) {
+        textParam.truncate(index);
+        textParam.append("...");
+    }
+
+   return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
 }
 
-void UserInfo::messageUpdate()
+void UserInfo::verifyMessageUpdateFailure(const QString &errorMessage)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    UpdateLocationDialog updateLocationDialog(this);
+    Q_UNUSED(errorMessage);
 
-    emit requestReverseGeo();
+    if (!m_messageUpdateVerified) {
 
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            &updateLocationDialog, SLOT(setAddress(QString)));
-    connect(&updateLocationDialog, SIGNAL(statusUpdate(QString, bool)),
-            this, SIGNAL(statusUpdate(QString, bool)));
+        if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
+            emit notificateUpdateFailing(tr("Location update failed\n\nYour message is saved to "
+                                            "textbox until sending will succeed"));
+    }
 
-    updateLocationDialog.exec();
+    m_messageUpdateVerified = true;
 }
-
index 7e3684f..c404217 100644 (file)
@@ -6,6 +6,7 @@
        Jussi Laitinen - jussi.laitinen@ixonos.com
        Katri Kaikkonen - katri.kaikkonen@ixonos.com
        Henri Lampela - henri.lampela@ixonos.com
+       Ville Tiensuu - ville.tiensuu@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -46,6 +47,13 @@ public:
     */
     UserInfo(QWidget *parent=0);
 
+    /**
+    * @brief Desctructor
+    * saves unsend user message to settings
+    *
+    */
+    ~UserInfo();
+
 /*******************************************************************************
 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
 *******************************************************************************/
@@ -88,14 +96,7 @@ public:
     *
     * @param coordinates Reference to users current coordinates
     */
-    void setCoordinates(const QPointF &coordinates);
-
-    /**
-    * @brief Sets the message text
-    *
-    * @param text Reference to user message
-    */
-    void setMessageText(const QString &text);
+    void setCoordinates(const QPointF &coordinates);    
 
     /**
     * @brief Sets the user picture
@@ -118,7 +119,46 @@ public:
     */
     void setUserName(const QString &name);
 
+public slots:
+
+    /**
+    * @brief Clears backups of message and publish on Facebook setting
+    */
+    void clearUpdateLocationDialogData();
+
+    /**
+    * @brief Saves status message and Facebook publish setting
+    *
+    * @param status message that user sends. Message is stored to m_backupMessage data member
+    * @param publish setting that determines whether the user status message is published on
+    *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
+    */
+    void backupUpdateLocationDialogData(const QString &status, bool publish);
+
+    /**
+    * @brief Sets the message text
+    *
+    * @param text Reference to user message
+    */
+    void setMessageText(const QString &text);
+
+
+    /**
+    * @brief Emits signal to inform user about failed message/location update.
+    *        Contains logic to send signal only after failed message/location update.
+    *
+    * @param errorMessage from Situare server. Message is not used in this function
+    */
+    void verifyMessageUpdateFailure(const QString &errorMessage);
+
 private:
+
+    /**
+    * @brief reads Unsend message from settings at startup
+    *
+    */
+    void restoreUnsendMessage();
+
     /**
     * @brief Set shortened or full-length text to labels.
     *
@@ -143,7 +183,7 @@ private slots:
     * @brief Slot function to forward messageUpdate launch signal
     *
     */
-    void messageUpdate();
+    void messageUpdate();    
 
 /******************************************************************************
 * SIGNALS
@@ -157,6 +197,20 @@ signals:
     void findUser(const QPointF &coordinates);
 
     /**
+    * @brief Signal that informs that user's message/location failed to update on Situare server
+    *        This signal is originally sended from SituareService with name error
+    *        Signal is renamed on MainWindow
+    */
+    void messageSendingFailed(const QString &error);
+
+    /**
+    * @brief Signal that used to inform user that his message/location update tp Situare server
+    *        was failed.
+    *        This signal is originally sended from UserInfo
+    */
+    void notificateUpdateFailing(const QString &message);
+
+    /**
     * @brief Signal for refreshing user data.
     *
     */
@@ -182,12 +236,13 @@ signals:
     * @param publish Publish on Facebook
     */
     void statusUpdate(const QString &status, const bool &publish);
-
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    bool m_expanded;                    ///< Item expanded state
+    bool m_backupFacebookPublishPolicity; ///< Backup of publish on Facebook checkbox value
+    bool m_expanded;                    ///< Item expanded state   
+    bool m_messageUpdateVerified;       ///< Place for message/location update check
     QLabel *m_locationLabel;            ///< Location label
     QLabel *m_nameLabel;                ///< Name label
     QLabel *m_statusTextLabel;          ///< Status text label
@@ -197,11 +252,12 @@ private:
     QPixmap m_backgroundTopImage;       ///< Top background image
     QPoint m_mousePosition;             ///< Current mouse press position
     QPointF m_coordinates;              ///< User current coordinates
-    QString m_address;                  ///< Address from where the new message was sent.
+    QString m_address;                  ///< Address from where the new message was sent
+    QString m_backupMessage;            ///< Backup of users message
     QString m_messageText;              ///< User's message
     QString m_time;                     ///< Time when the new message was sent
     QString m_userName;                 ///< User's name
-    ImageButton *m_findButton;          ///< User find button
+    ImageButton *m_findButton;          ///< User find button   
 };
 
 #endif // USERINFO_H
index e98d064..639d3a7 100644 (file)
@@ -63,6 +63,18 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
 
     connect(m_userInfo, SIGNAL(refreshUserData()),
             this, SIGNAL(refreshUserData()));
+
+    connect(this, SIGNAL(updateWasSuccessful()),
+            m_userInfo, SLOT(clearUpdateLocationDialogData()));
+
+    connect(this, SIGNAL(messageSendingFailed(QString)),
+            m_userInfo, SIGNAL(messageSendingFailed(QString)));
+
+    connect (this, SIGNAL(messageSendingFailed(QString)),
+             m_userInfo, SLOT(verifyMessageUpdateFailure(QString)));
+
+    connect (m_userInfo, SIGNAL(notificateUpdateFailing(QString)),
+             this, SIGNAL(notificateUpdateFailing(QString)));
 }
 
 void UserInfoPanel::userDataReceived(User *user)
index c0ab604..b23c915 100644 (file)
@@ -70,6 +70,20 @@ signals:
     void findUser(const QPointF &coordinates);
 
     /**
+    * @brief Signal that informs that user's message/location failed to update on Situare server
+    *        This signal is originally sended from SituareService with name error
+    *        Signal is renamed on MainWindow
+    */
+    void messageSendingFailed(const QString &error);
+
+    /**
+    * @brief Signal that used to inform user that his message/location update tp Situare server
+    *        was failed.
+    *        This signal is originally sended from UserInfo
+    */
+    void notificateUpdateFailing(const QString &message);
+
+    /**
     * @brief Signal for refreshing user data.
     *
     */
@@ -96,6 +110,11 @@ signals:
     */
     void statusUpdate(const QString &status, const bool &publish);
 
+    /**
+    * @brief Signals when updateLocation request finished successfully
+    *
+    */
+    void updateWasSuccessful();
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/