diff ui/mainwindow.cpp @ 71:f22a99f7cb69

Add certificatelist to install as member. Look for updates on startup
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 19 Mar 2014 11:32:25 +0000
parents c6125d73faf4
children 7e304573ebd1
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Wed Mar 19 11:31:08 2014 +0000
+++ b/ui/mainwindow.cpp	Wed Mar 19 11:32:25 2014 +0000
@@ -16,6 +16,7 @@
 
 #include "certificatelist.h"
 #include "downloader.h"
+#include "listupdatedialog.h"
 
 MainWindow::MainWindow() {
     createActions();
@@ -29,6 +30,7 @@
     connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage()));
     mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000);
     mMessageTimer->start();
+    checkUpdates();
 }
 
 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
@@ -46,6 +48,16 @@
     }
 }
 
+void MainWindow::messageClicked()
+{
+    if (mCurState == NewListAvailable) {
+        ListUpdateDialog *listUpdateDialog = new ListUpdateDialog(this,
+                mListToInstall);
+        listUpdateDialog->show();
+        qDebug() << "NewListAvailable";
+    }
+}
+
 void MainWindow::showMessage()
 {
     if (!mCurMessage.isEmpty()) {
@@ -55,25 +67,14 @@
     }
 }
 
-/** @brief check the integrity of available files.
- *
- * Do not use this as a trust check as this only works on
- * FileNames where the underlying files can change. This
- * is just meant to check if the downloaded data was somehow
- * removed or corrupted.
- *
- */
 void MainWindow::verifyAvailableData()
 {
     QString listFileName = mSettings.value("List/available").toString();
     QString swFileName = mSettings.value("Software/available").toString();
 
     if (!listFileName.isEmpty()) {
-        const char *cFileName = listFileName.toLocal8Bit().constData();
-        char *data = NULL;
-        size_t size;
-
-        if (read_and_verify_list(cFileName, &data, &size) != Valid) {
+        mListToInstall.readList(listFileName.toLocal8Bit().constData());
+        if (!mListToInstall.isValid()) {
             // Probably a bug when Qt fileName is encoded and cFileName
             // fails because of this. This needs a unit test!
             // Maybe check that the file is in our data directory
@@ -81,8 +82,6 @@
             mSettings.remove("List/available");
             mSettings.remove("List/availableDate");
         }
-
-        free(data); // We only needed verify
     } else {
         // Make sure the available notation is also removed
         mSettings.remove("List/available");
@@ -98,11 +97,20 @@
 }
 
 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) {
+    mSettings.setValue("List/available", fileName);
+    mSettings.setValue("List/availableDate", modDate);
 
+    verifyAvailableData();
+    if (!mListToInstall.isValid()) {
+        /* Downloader provided invalid files */
+        /* TODO: Error count. Error handling. Otherwise
+         * we can go into an endless loop here */
+
+        /* Retry the download again in 10 - 20 minutes */
+        QTimer::singleShot(600000 + (qrand() % 60000), this, SLOT(checkUpdates()));
+    }
     mCurMessage = tr("An updated certificate list is available. Click here to install.");
     setState(NewListAvailable);
-    mSettings.setValue("List/available", fileName);
-    mSettings.setValue("List/availableDate", modDate);
     showMessage();
 }
 
@@ -168,4 +176,6 @@
     setWindowIcon(trayImg);
     mTrayIcon->show();
     mTrayIcon->setToolTip(tr("m13ui"));
+
+    connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
 }

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