diff ui/mainwindow.cpp @ 708:bd48fae793b6

(Issue25) Log update check success, change header labels.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 02 Jul 2014 12:49:11 +0200
parents 2c63bb63de76
children 8f110e6b8295
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Wed Jul 02 12:39:28 2014 +0200
+++ b/ui/mainwindow.cpp	Wed Jul 02 12:49:11 2014 +0200
@@ -345,14 +345,17 @@
     connect(downloader, SIGNAL(newListAvailable(const QString&, const QDateTime&)),
             this, SLOT(handleNewList(const QString&, const QDateTime&)));
     if (!downloadSW) {
+        setState(BeforeDownload);
         connect(downloader, SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)),
                 this, SLOT(handleNewSW(const QString&, const QDateTime&)));
     } else {
+        setState(DownloadingSW);
         connect(downloader, SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)),
                 this, SLOT(installNewSW(const QString&, const QDateTime&)));
     }
 
     connect(downloader, SIGNAL(finished()), downloader, SLOT(deleteLater()));
+    connect(downloader, SIGNAL(finished()), this, SLOT(updateCheckSuccess()));
     connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)),
             this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode)));
     downloader->start();
@@ -393,6 +396,7 @@
 void MainWindow::downloaderError(const QString &message, SSLConnection::ErrorCode error)
 {
     /* TODO logging and handle error according to a plan */
+    syslog_error_printf ("Failed to check for updates: %s", message.toUtf8().constData());
     mCurMessage = message;
     showMessage();
     setState(TransferError);
@@ -535,16 +539,27 @@
     mUpdatesHeader =
         new QLabel("<h2>" + tr("Certificates unchanged")+ "</h2>");
     mLastCertUpdate =
-        new QLabel(tr("Last update of certificates: %1").arg(""));
-    mLastSWupdate =
-        new QLabel(tr("Last update of TrustBridge: %1").arg(""));
+        new QLabel("");
+    mLastCertUpdate->hide();
+    mSoftwareVersionLabel =
+        new QLabel(tr("TrustBridge Version: %1").arg(QApplication::applicationVersion()));
+    const QDateTime lastCheck = mSettings.value("lastUpdateCheck").toDateTime();
+    if (lastCheck.isValid()) {
+        const QString lastUpdateCheck = QLocale::system().toString(lastCheck);
+        mLastUpdateCheck =
+            new QLabel(tr("Last sucessful update check: %1").arg(lastUpdateCheck));
+    } else {
+        mLastUpdateCheck = new QLabel("");
+        mLastUpdateCheck->hide();
+    }
     QLabel *updatesTip =
         new QLabel(tr("You should apply the following changes to your root certificates:"));
     updatesTip->setWordWrap(true);
 
     updatesHeaderTextLayout->addWidget(mUpdatesHeader);
     updatesHeaderTextLayout->addWidget(mLastCertUpdate);
-    updatesHeaderTextLayout->addWidget(mLastSWupdate);
+    updatesHeaderTextLayout->addWidget(mLastUpdateCheck);
+    updatesHeaderTextLayout->addWidget(mSoftwareVersionLabel);
     updatesHeaderTextLayout->addSpacing(10);
     updatesHeaderTextLayout->addWidget(updatesTip);
 
@@ -912,8 +927,11 @@
         }
     }
 
-    mLastCertUpdate->setText(tr("Last update of certificates: %1")
-            .arg(mInstalledList.date().toString()));
+    if (mInstalledList.date().isValid()) {
+        mLastCertUpdate->setText(tr("Installed certificates from: %1")
+                .arg(QLocale::system().toString(mInstalledList.date())));
+        mLastCertUpdate->show();
+    }
     mUpdatesManualCertificates->setText("<h3>" +
             tr("Manually changed certificates (%1)").arg(0) +
             "</h3>");
@@ -1159,3 +1177,15 @@
     }
     return closeApp();
 }
+
+void MainWindow::updateCheckSuccess()
+{
+    if (getState() != TransferError) {
+        const QDateTime now = QDateTime::currentDateTime();
+        mSettings.setValue("lastUpdateCheck", now);
+        mLastUpdateCheck->setText(tr("Last sucessful update check: %1").arg(
+                        QLocale::system().toString(now)));
+        mLastUpdateCheck->show();
+        syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData());
+    }
+}

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