1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
test_keylister.cpp
This file is part of libkleopatra's test suite.
SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
SPDX-License-Identifier: GPL-2.0-only
*/
#include "test_keylister.h"
#include <qgpgme/keylistjob.h>
#include <qgpgme/protocol.h>
#include <gpgme++/key.h>
#include <gpgme++/keylistresult.h>
#include <KAboutData>
#include <QDebug>
#include <QMessageBox>
#include <QStringList>
#include <QTimer>
#include <KLocalizedString>
#include <QApplication>
#include <QCommandLineParser>
#include <chrono>
using namespace std::chrono_literals;
namespace
{
class TestColumnStrategy : public Kleo::KeyListView::ColumnStrategy
{
public:
~TestColumnStrategy() override
{
}
QString title(int col) const override;
QString toolTip(const GpgME::Key &key, int col) const override;
QString text(const GpgME::Key &key, int col) const override;
QString accessibleText(const GpgME::Key &key, int col) const override;
};
QString TestColumnStrategy::title(int col) const
{
switch (col) {
case 0:
return QStringLiteral("Subject");
case 1:
return QStringLiteral("EMail");
case 2:
return QStringLiteral("Issuer");
case 3:
return QStringLiteral("Serial");
case 4:
return QStringLiteral("Protocol");
case 5:
return QStringLiteral("Validity");
default:
return QString();
}
}
QString TestColumnStrategy::toolTip(const GpgME::Key &key, int) const
{
return QStringLiteral("Fingerprint: ") + QString::fromUtf8(key.primaryFingerprint());
}
QString TestColumnStrategy::text(const GpgME::Key &key, int col) const
{
if (key.isNull()) {
return QStringLiteral("<null>");
}
switch (col) {
case 0:
return QString::fromUtf8(key.userID(0).id());
case 1:
return QString::fromUtf8(key.userID(0).email());
case 2:
return QString::fromUtf8(key.issuerName());
case 3:
return QString::fromLatin1(key.issuerSerial());
case 4:
return QString::fromLatin1(key.protocolAsString());
case 5:
return QString(QLatin1Char(key.userID(0).validityAsString()));
default:
return QString();
}
}
QString TestColumnStrategy::accessibleText(const GpgME::Key &, int) const
{
return {};
}
}
CertListView::CertListView(QWidget *parent, Qt::WindowFlags f)
: Kleo::KeyListView(new TestColumnStrategy(), nullptr, parent, f)
{
setHierarchical(true);
setRootIsDecorated(true);
}
CertListView::~CertListView()
{
}
void CertListView::slotResult(const GpgME::KeyListResult &result)
{
qDebug() << "CertListView::slotResult()";
if (result.isNull()) {
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("KeyListResult is null!"));
} else if (result.error()) {
QMessageBox::critical(this,
QStringLiteral("Key Listing Result"),
QStringLiteral("KeyListResult Error: %1").arg(QString::fromLatin1(result.error().asString())));
} else if (result.isTruncated()) {
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("KeyListResult is truncated!"));
} else {
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("Key listing successful"));
}
}
void CertListView::slotStart()
{
qDebug() << "CertListView::slotStart()";
QGpgME::KeyListJob *job = QGpgME::smime()->keyListJob(false);
Q_ASSERT(job);
QObject::connect(job, &QGpgME::KeyListJob::nextKey, this, &CertListView::slotAddKey);
QObject::connect(job, &QGpgME::KeyListJob::result, this, &CertListView::slotResult);
#if 0
QStringList l;
l << "Marc";
job->start(l, false);
#else
job->start(QStringList(), false);
#endif
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
KAboutData aboutData(QStringLiteral("test_keylister"), i18n("KeyLister Test"), QStringLiteral("0.1"));
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
auto clv = new CertListView;
clv->show();
QTimer::singleShot(5s, clv, &CertListView::slotStart);
return app.exec();
}
|