changeset 1297:c2fd36cd4093

(issue123) Use gcr-viewer to view certificate details on Linux
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 29 Sep 2014 16:24:05 +0200
parents 13b56e9c7e7b
children 9017c524e762
files ui/certificate.cpp ui/certificateitemwidget.cpp
diffstat 2 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ui/certificate.cpp	Mon Sep 29 16:12:47 2014 +0200
+++ b/ui/certificate.cpp	Mon Sep 29 16:24:05 2014 +0200
@@ -10,6 +10,8 @@
 #include <QFile>
 #include <QStringList>
 #include <QObject>
+#include <QProcess>
+#include <QTemporaryFile>
 
 #include <polarssl/sha1.h>
 
@@ -257,7 +259,21 @@
 #else
 bool Certificate::showNativeUI(void *parent)
 {
-    qDebug() << "Not implemented.";
-    return false;
+    QTemporaryFile *tmpCert = new QTemporaryFile;
+    tmpCert->open();
+    tmpCert->write("-----BEGIN CERTIFICATE-----\n");
+    tmpCert->write(mBaseLine.right(mBaseLine.size() - 2).toLatin1());
+    tmpCert->write("-----END CERTIFICATE-----\n");
+    tmpCert->close();
+    QStringList args;
+    args << tmpCert->fileName();
+    QProcess *viewer = new QProcess();
+    viewer->setProgram("gcr-viewer");
+    viewer->setArguments(args);
+
+    QObject::connect (viewer, SIGNAL(finished(int, QProcess::ExitStatus)), tmpCert, SLOT(deleteLater()));
+    QObject::connect (viewer, SIGNAL(finished(int, QProcess::ExitStatus)), viewer, SLOT(deleteLater()));
+    viewer->start();
+    return !(!viewer->waitForStarted() || viewer->state() == QProcess::NotRunning);
 }
 #endif
--- a/ui/certificateitemwidget.cpp	Mon Sep 29 16:12:47 2014 +0200
+++ b/ui/certificateitemwidget.cpp	Mon Sep 29 16:24:05 2014 +0200
@@ -13,6 +13,7 @@
 #include <QToolButton>
 #include <QSignalBlocker>
 #include <QPushButton>
+#include <QMessageBox>
 
 void CheckLessToolBtn::paintEvent(QPaintEvent * pe) {
 
@@ -67,7 +68,6 @@
     QLabel *firstLabel = new QLabel(QString::fromLatin1("<big><b>%1</b></big> ").arg
         (mCertificate.subjectCN()));
 
-#ifdef Q_OS_WIN
     QHBoxLayout *firstLabelButtonLayout = new QHBoxLayout;
     firstLabelButtonLayout->addWidget(firstLabel);
     QPushButton *detailsBtn = new QPushButton;
@@ -78,9 +78,6 @@
     firstLabelButtonLayout->addStretch(-1);
     connect(detailsBtn, SIGNAL(clicked()), this, SLOT(showCertDlg()));
     labelLayout->addLayout(firstLabelButtonLayout);
-#else
-    labelLayout->addWidget(firstLabel);
-#endif
     QLabel *secondLabel = new QLabel(QString::fromLatin1("%2<br/>%3<br/>%4").arg
         (mCertificate.subjectO()).arg(validity).arg
         (fpstring));
@@ -114,7 +111,16 @@
 {
     /* This is a totally evil cast but legitimate on Windows
      * HANDLES are only 32 bit even on Windows 64 bit */
-    qDebug() << "Showing native ui: " <<  mCertificate.showNativeUI((void*)effectiveWinId());
+    if (!mCertificate.showNativeUI((void*)effectiveWinId())) {
+        qDebug() << "Failed to show native dialog";
+#ifdef WIN32
+        // maybe old windows version
+        QMessageBox::warning(this, tr("TrustBridge error"), tr("Failed to open native viewer."));
+#else
+        QMessageBox::warning(this, tr("TrustBridge error"), tr("Failed to open 'gcr-viewer'.") + "\n" +
+                tr("TrustBridge uses 'gcr-viewer' to show certificate details. Please ensure that 'gcr-viewer' is installed."));
+#endif
+    }
     return;
 }
 

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