changeset 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 64c8c6350e60
children 7e304573ebd1
files ui/CMakeLists.txt ui/listupdatedialog.cpp ui/listupdatedialog.h ui/main.cpp ui/mainwindow.cpp ui/mainwindow.h
diffstat 6 files changed, 84 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ui/CMakeLists.txt	Wed Mar 19 11:31:08 2014 +0000
+++ b/ui/CMakeLists.txt	Wed Mar 19 11:32:25 2014 +0000
@@ -20,6 +20,7 @@
 set(M13UI_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/listupdatedialog.cpp
     ${CERTIFICATELIST_SOURCES}
     ${DOWNLOADER_SOURCES}
 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/listupdatedialog.cpp	Wed Mar 19 11:32:25 2014 +0000
@@ -0,0 +1,16 @@
+#include "listupdatedialog.h"
+#include <QDebug>
+
+ListUpdateDialog::ListUpdateDialog(QDialog *parent,
+                                   const CertificateList &listToInstall) :
+    QDialog(parent),
+    mCertificateList(listToInstall)
+{
+    qDebug() << "I am a happy list update dialog";
+    setupGUI();
+}
+
+void ListUpdateDialog::setupGUI()
+{
+    return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/listupdatedialog.h	Wed Mar 19 11:32:25 2014 +0000
@@ -0,0 +1,22 @@
+#ifndef LISTUPDATEDIALOG_H
+#define LISTUPDATEDIALOG_H
+
+#include "certificatelist.h"
+#include <QDialog>
+/**
+ * @file listupdatedialog.h
+ * @brief The dialog for certificate selection.
+ */
+
+class ListUpdateDialog : public QDialog
+{
+public:
+    /** @brief Create a list update dialog for the listToInstall */
+    ListUpdateDialog(QDialog *parent, const CertificateList &listToInstall);
+
+private:
+    CertificateList mCertificateList;
+    void setupGUI();
+};
+
+#endif // LISTUPDATEDIALOG_H
--- a/ui/main.cpp	Wed Mar 19 11:31:08 2014 +0000
+++ b/ui/main.cpp	Wed Mar 19 11:32:25 2014 +0000
@@ -43,7 +43,6 @@
     QSettings::setDefaultFormat(QSettings::IniFormat);
 
     MainWindow mainWin;
-    mainWin.show();
 
     return app.exec();
 }
--- 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()));
 }
--- a/ui/mainwindow.h	Wed Mar 19 11:31:08 2014 +0000
+++ b/ui/mainwindow.h	Wed Mar 19 11:32:25 2014 +0000
@@ -1,11 +1,17 @@
 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H
 
+/**
+ * @file mainwindow.h
+ * @brief Main UI controller
+ */
+
 #include <QSystemTrayIcon>
 #include <QDialog>
 #include <QSettings>
 
 #include "downloader.h"
+#include "certificatelist.h"
 class QMenu;
 class QAction;
 class QTimer;
@@ -37,8 +43,18 @@
     void handleNewList(const QString& fileName, const QDateTime& modDate);
     void handleNewSW(const QString& fileName, const QDateTime& modDate);
     void downloaderError(const QString &message, SSLConnection::ErrorCode error);
+    /** @brief Trigger the appropiate action depending on the state */
+    void messageClicked();
 
 private:
+    /** @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 verifyAvailableData();
     void createTrayIcon();
     void createActions();
@@ -55,6 +71,8 @@
     QAction *mCheckUpdates;
     QAction *mQuitAction;
     CurrentState mCurState;
+
+    CertificateList mListToInstall;
 };
 
 #endif // MAINWINDOW_H

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