Added Progress indicator handling in error situations
authorlampehe-local <henri.lampela@ixonos.com>
Fri, 18 Jun 2010 09:54:16 +0000 (12:54 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Fri, 18 Jun 2010 09:54:16 +0000 (12:54 +0300)
Reviewed by: Jussi Laitinen

src/engine/engine.cpp
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 47771dc..91cb772 100644 (file)
@@ -214,15 +214,19 @@ void SituareEngine::error(const int error)
     switch(error)
     {
     case QNetworkReply::ConnectionRefusedError:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Connection refused by the server"), true);
         break;
     case QNetworkReply::RemoteHostClosedError:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Connection closed by the server"), true);
         break;
     case QNetworkReply::HostNotFoundError:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Remote server not found"), true);
         break;
     case QNetworkReply::TimeoutError:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Connection timed out"), true);
         break;
     case SituareError::SESSION_EXPIRED:
@@ -233,12 +237,16 @@ void SituareEngine::error(const int error)
         m_ui->loginFailed();
         break;
     case SituareError::LOGIN_FAILED:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
+        m_ui->loginFailed();
         break;
     case SituareError::UPDATE_FAILED:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Update failed, please try again"), true);
         break;
     case SituareError::DATA_RETRIEVAL_FAILED:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
         break;
     case SituareError::ADDRESS_RETRIEVAL_FAILED:
@@ -255,6 +263,7 @@ void SituareEngine::error(const int error)
         m_ui->buildInformationBox(tr("GPS initialization failed"), true);
         break;
     case SituareError::UNKNOWN_REPLY:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Unknown server response"), true);
         break;
     case SituareError::INVALID_JSON:
@@ -263,6 +272,7 @@ void SituareEngine::error(const int error)
         m_facebookAuthenticator->clearAccountInformation(false); // clean all
         break;
     default:
+        m_ui->toggleProgressIndicator(false);
         qCritical() << "QNetworkReply::NetworkError :" << error;
         break;
     }
@@ -441,9 +451,6 @@ void SituareEngine::signalsFromFacebookAuthenticator()
     connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
             m_ui, SLOT(startLoginProcess()));
 
-    connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
-            m_ui, SLOT(loginFailed()));
-
     connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
             m_ui, SLOT(saveCookies()));
 
index d238821..716b054 100644 (file)
@@ -169,7 +169,6 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
             clearAccountInformation(true);
             if(m_freshLogin) {
                 emit error(SituareError::LOGIN_FAILED);
-                emit loginFailure();
             } else {
                 m_freshLogin = true;
                 emit error(SituareError::SESSION_EXPIRED);
@@ -179,12 +178,12 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
         } else {
             qDebug() << "totally wrong webPage";
             // we should not get a wrong page at this point
-            emit loginFailure();
+            emit error(SituareError::LOGIN_FAILED);
         }
     } else {
         qDebug() << " Loading of page failed invalid URL" << endl;
         // we should not get a wrong page at this point
-        emit loginFailure();
+        emit error(SituareError::LOGIN_FAILED);
     }
     return found;
 }
index 06ec2c4..0f06828 100644 (file)
@@ -124,12 +124,6 @@ signals:
     void credentialsReady(const FacebookCredentials &credentials);
 
     /**
-    * @brief This signal is emitted if updateCredentials method can't find credentials from URL
-    *
-    */
-    void loginFailure();
-
-    /**
     * @brief This signal is emitted always when login is called. At first  the application tries
     *        to login using saved cookies
     *
index 5d54ec7..6050503 100644 (file)
@@ -55,6 +55,7 @@ MainWindow::MainWindow(QWidget *parent)
     m_errorShown(false),
     m_loggedIn(false),
     m_refresh(false),
+    m_progressIndicatorCount(0),
     m_ownLocationCrosshair(0),
     m_email(),    
     m_password(),
@@ -669,9 +670,6 @@ void MainWindow::loginFailed()
     qDebug() << __PRETTY_FUNCTION__;
 
     clearCookieJar();
-
-    toggleProgressIndicator(false);
-
     startLoginProcess();
 }
 
@@ -899,7 +897,16 @@ void MainWindow::toggleProgressIndicator(bool value)
     qDebug() << __PRETTY_FUNCTION__;
 
 #ifdef Q_WS_MAEMO_5
-    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
+    if(value) {
+        m_progressIndicatorCount++;
+        setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+    } else {
+        if(m_progressIndicatorCount > 0)
+            m_progressIndicatorCount--;
+
+        if(m_progressIndicatorCount == 0)
+            setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+    }
 #else
     Q_UNUSED(value);
 #endif // Q_WS_MAEMO_5
@@ -945,7 +952,6 @@ void MainWindow::webViewRequestFinished(QNetworkReply *reply)
     if(reply->error() != QNetworkReply::OperationCanceledError &&
        reply->error() != QNetworkReply::NoError) {
         emit error(reply->error());
-        toggleProgressIndicator(false);
     }
 }
 
index aae2e50..da80bf8 100644 (file)
@@ -155,7 +155,7 @@ public slots:
     void buildInformationBox(const QString &message, bool modal=false);
 
     /**
-    * @brief Slot to intercept signal when login has failed (loginFailure signal)
+    * @brief Slot for failed login
     *
     */
     void loginFailed();
@@ -591,6 +591,7 @@ private:
     bool m_loggedIn;                        ///< Indicates login state
     bool m_refresh;                         ///< Indicates when webpage is refreshed
 
+    int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
 
     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle