diff ui/mainwindow.cpp @ 486:fa56a9403939

Lookup the last modified date for software installer after first installation.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 24 Apr 2014 14:55:22 +0200
parents 9be337ea1e3c
children 077b4342d69b ca583ffe728a
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Thu Apr 24 14:54:24 2014 +0200
+++ b/ui/mainwindow.cpp	Thu Apr 24 14:55:22 2014 +0200
@@ -36,6 +36,11 @@
 #define SERVER_URL "https://files.intevation.de:443"
 #define LIST_RESOURCE "/users/aheinecke/zertifikatsliste_1.txt"
 #define SW_RESOURCE   "/users/aheinecke/zertifikatsliste_1.txt"
+#ifdef Q_OS_WIN
+#define SW_RESOURCE_VERSION "/users/aheinecke/trustbridge-%1.exe"
+#else
+#define SW_RESOURCE_VERSION "/users/aheinecke/trustbridge-%1.sh"
+#endif
 
 #include "certificatelist.h"
 #include "downloader.h"
@@ -185,6 +190,10 @@
 {
     verifyAvailableData();
 
+    if (!mSettings.contains("Software/installedDate")) {
+        lookUpDateForVersion();
+        return;
+    }
     QDateTime listInstalledLastMod = mSettings.value("List/installedDate").toDateTime();
     QDateTime swInstalledLastMod = mSettings.value("Software/installedDate").toDateTime();
 
@@ -224,6 +233,37 @@
     downloader->start();
 }
 
+void MainWindow::lookUpDateForVersion()
+{
+    QString softwareVersion = QString::fromLatin1(SW_RESOURCE_VERSION).arg(
+        QApplication::applicationVersion());
+    qDebug() << softwareVersion;
+    QString listResource = QString::fromLatin1(LIST_RESOURCE);
+    Downloader* downloader = new Downloader(this,
+                                            QString::fromLatin1(SERVER_URL),
+                                            QByteArray(),
+                                            QDateTime::currentDateTime(),
+                                            QDateTime::currentDateTime(),
+                                            softwareVersion,
+                                            listResource,
+                                            false);
+    connect(downloader, SIGNAL(finished()), downloader, SLOT(deleteLater()));
+    connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)),
+            this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode)));
+    connect(downloader, SIGNAL(lastModifiedDate(const QDateTime&)),
+        this, SLOT(setLastModifiedDate(const QDateTime&)));
+
+    downloader->start();
+}
+
+void MainWindow::setLastModifiedDate(const QDateTime &date)
+{
+    mSettings.beginGroup("Software");
+    mSettings.setValue("installedDate", date);
+    mSettings.endGroup();
+    checkUpdates();
+}
+
 void MainWindow::newSWAvailable(const QString &fileName, const QDateTime &date) {
     QMessageBox msgBox;
     msgBox.setIcon(QMessageBox::Information);

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