changeset 1373:00fcb9c4d16b

(issue179) Handle SW verify failures and try to redownload the update
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 24 Nov 2014 16:46:08 +0100
parents 96f640c88d10
children 1bf288d17857
files ui/mainwindow.cpp ui/mainwindow.h
diffstat 2 files changed, 51 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Mon Nov 24 15:49:18 2014 +0100
+++ b/ui/mainwindow.cpp	Mon Nov 24 16:46:08 2014 +0100
@@ -128,7 +128,8 @@
     mTrayMode(trayMode),
     mManualDetailsShown(false),
     mFailedConnections(0),
-    mSigDt(sigDt)
+    mSigDt(sigDt),
+    mDownloadSWAccepted(false)
 {
     createActions();
     createTrayIcon();
@@ -175,15 +176,21 @@
 void MainWindow::messageClicked()
 {
     if (mCurState == NewSoftwareAvailable) {
+        mDownloadSWAccepted = true;
         verifySWData();
-        QString swFileName = mSettings.value("Software/available").toString();
-        if (swFileName.isEmpty()) {
-            checkUpdates(true);
-            mCurState = DownloadingSW;
-            return;
+        if (mFailedConnections == 0) {
+            /* If we have a failed connection cound verifySWData has
+             * triggered an invalid software recovery and an update is already
+             * scheduled. */
+            QString swFileName = mSettings.value("Software/available").toString();
+            if (swFileName.isEmpty()) {
+                checkUpdates();
+                mCurState = DownloadingSW;
+                return;
+            }
+            installNewSW(swFileName,
+                    mSettings.value("Software/availableDate").toDateTime());
         }
-        installNewSW(swFileName,
-                mSettings.value("Software/availableDate").toDateTime());
     } else {
         show();
     }
@@ -293,6 +300,7 @@
             if (verifyResult.fptr) {
                 fclose(verifyResult.fptr);
             }
+            scheduleFailureRetryOrClose(!isVisible());
         }
         QFile::remove(swFileName);
         mSettings.remove("Software/available");
@@ -436,6 +444,7 @@
             if (vres.fptr) {
                 fclose(vres.fptr);
             }
+            scheduleFailureRetryOrClose(!isVisible());
         }
         QFile::remove(filePath);
         mSettings.remove("Software/available");
@@ -547,9 +556,14 @@
 #endif
 }
 
-void MainWindow::checkUpdates(bool downloadSW)
+void MainWindow::checkUpdates()
 {
     verifyListData();
+    bool downloadSW = false;
+
+    if (mDownloadSWAccepted == true) {
+        downloadSW = true;
+    }
 
     /* Delete old temporary installers if they exist */
     QString oldUpdater = mSettings.value("Software/Updater").toString();
@@ -1790,6 +1804,18 @@
     return closeApp();
 }
 
+void MainWindow::scheduleFailureRetryOrClose(bool close) {
+    int waitInterval = getNextUpdateInterval(mFailedConnections++);
+    if (waitInterval <= 0 && close) {
+        qDebug() << "Shutting down after " << mFailedConnections <<
+            " tries to get an update connection.";
+        closeApp();
+    } else if (waitInterval > 0) {
+        qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
+        QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
+    }
+}
+
 void MainWindow::updateCheckSuccess()
 {
     if (getState() != TransferError) {
@@ -1802,17 +1828,8 @@
         handleLTE(lteNoConnection, true); /* Reset error state */
         handleLTE(lteInvalidCertificate, true);
         mFailedConnections = 0;
-    } else if (!isVisible()) {
-        int waitInterval = getNextUpdateInterval(mFailedConnections++);
-        if (waitInterval < 0) {
-            qDebug() << "Shutting down after " << mFailedConnections <<
-                " tries to get an update connection.";
-            closeApp();
-            return;
-        }
-        qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
-        QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
-        return;
+    } else {
+        scheduleFailureRetryOrClose(!isVisible());
     }
     if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode)
             && !isVisible()) {
--- a/ui/mainwindow.h	Mon Nov 24 15:49:18 2014 +0100
+++ b/ui/mainwindow.h	Mon Nov 24 16:46:08 2014 +0100
@@ -120,9 +120,10 @@
     void iconActivated(QSystemTrayIcon::ActivationReason reason);
     /** @brief Check if new updates are available.
      *
-     * @param[in] downloadSW wether or not new software should be downloaded.
+     * Wether the software should be downloaded or not is determined by
+     * the mDownloadSWAccepted value.
      */
-    void checkUpdates(bool downloadSW = false);
+    void checkUpdates();
     /**@brief parse a new certificate list and update the UI*/
     void handleNewList(const QString& fileName, const QDateTime& modDate);
     /**@brief handle a Software update, update state and inform the user */
@@ -294,6 +295,16 @@
      **/
     void handleLTE(LongTimeErrors lte, bool reset = false);
 
+    /** @brief schedule an update check retry or close the application.
+     *
+     * An update check retry is scheduled base on getNextUpdateInterval.
+     * If getNextUpdateInterval returns a negative value the application
+     * is closed if the parameter close is true.
+     *
+     * This function also increases the failed connection count.
+     */
+    void scheduleFailureRetryOrClose(bool close);
+
     /** @brief note a verify error in the settings and show a message
      *
      * Saves a software verify error in the settings and notifies the
@@ -386,6 +397,7 @@
     bool mManualDetailsShown;
     int mFailedConnections;
     QDateTime mSigDt;
+    bool mDownloadSWAccepted;
 };
 
 #endif // MAINWINDOW_H

http://wald.intevation.org/projects/trustbridge/