diff ui/processhelp_linux.cpp @ 1371:23df332b2a4c

(issue179) Read install signature timestamp from config This also changes the way the sigDt is propgated to the MainWindow. It no longer uses the settings but hands it over as a parameter directly.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 24 Nov 2014 15:48:49 +0100
parents 2a1aa9df8f11
children 96f640c88d10
line wrap: on
line diff
--- a/ui/processhelp_linux.cpp	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/processhelp_linux.cpp	Mon Nov 24 15:48:49 2014 +0100
@@ -9,6 +9,7 @@
 
 #include "processhelp.h"
 #include "linuxlockfile.h"
+#include "util.h"
 
 #include <fcntl.h>
 #include <semaphore.h>
@@ -16,6 +17,7 @@
 #include <QDebug>
 #include <QDir>
 #include <QStandardPaths>
+#include <QApplication>
 
 int lockFileFD = -1;
 
@@ -47,4 +49,50 @@
     close_lockfile(lockFileFD);
 }
 
+QDateTime ProcessHelp::getSigDtFromInstSettings() {
+    QString pathCandidate;
+    QDateTime retval;
+    if (is_system_install()) {
+        pathCandidate = "/etc/" + qApp->applicationName() + "/" +
+          qApp->applicationName() + "-inst.cfg";
+    } else {
+        qDebug() << "Application name is : " << qApp->applicationName();
+        pathCandidate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) +
+          + "/" + qApp->organizationName() + "/" +  qApp->applicationName() + "-inst.cfg";
+    }
+    QFileInfo fi(pathCandidate);
+    if (!fi.isReadable()) {
+        qDebug() << "Failed to find install config: " << pathCandidate;
+        return retval;
+    }
+    QFile instcfg(pathCandidate);
+    if (!instcfg.open(QIODevice::ReadOnly)) {
+        qDebug() << "Failed to open install config";
+        return retval;
+    }
+    QByteArray data;
+    int readLines = 0;
+    while (readLines < 100) {
+        readLines++;
+        data = instcfg.readLine();
+        if (data.isEmpty()) {
+            qDebug() << "Failed to read install config";
+            break;
+        }
+        QString line = QString::fromLocal8Bit(data);
+        if (line.startsWith("SIG_DATE=")) {
+            bool ok = false;
+            QString sigDate = line.replace("SIG_DATE=","");
+            long sigSecs = sigDate.toLong(&ok);
+            if (!ok) {
+                qDebug() << "Failed to convert sig date to long";
+            }
+            retval = QDateTime::fromTime_t(sigSecs);
+            break;
+        }
+    }
+    qDebug() << "Sig time is: " << retval;
+    instcfg.close();
+    return retval;
+}
 #endif /* Not WIN32 */

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