# HG changeset patch # User Andre Heinecke # Date 1412000645 -7200 # Node ID c2fd36cd4093f2526a64a2d2f938999ebf758d31 # Parent 13b56e9c7e7b80fd7170477f6f0b84d4af5741e1 (issue123) Use gcr-viewer to view certificate details on Linux diff -r 13b56e9c7e7b -r c2fd36cd4093 ui/certificate.cpp --- 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 #include #include +#include +#include #include @@ -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 diff -r 13b56e9c7e7b -r c2fd36cd4093 ui/certificateitemwidget.cpp --- 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 #include #include +#include void CheckLessToolBtn::paintEvent(QPaintEvent * pe) { @@ -67,7 +68,6 @@ QLabel *firstLabel = new QLabel(QString::fromLatin1("%1 ").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
%3
%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; }