Changeset View
Changeset View
Standalone View
Standalone View
src/dialogs/trustchainwidget.cpp
- This file was added.
1 | /* Copyright (c) 2016 Klarälvdalens Datakonsult AB | ||||
---|---|---|---|---|---|
2 | | ||||
3 | Kleopatra is free software; you can redistribute it and/or modify | ||||
4 | it under the terms of the GNU General Public License as published by | ||||
5 | the Free Software Foundation; either version 2 of the License, or | ||||
6 | (at your option) any later version. | ||||
7 | | ||||
8 | Kleopatra is distributed in the hope that it will be useful, | ||||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
11 | General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU General Public License | ||||
14 | along with this program; if not, write to the Free Software | ||||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
16 | */ | ||||
17 | | ||||
18 | #include "trustchainwidget.h" | ||||
19 | #include "ui_trustchainwidget.h" | ||||
20 | | ||||
21 | #include "kleopatra_debug.h" | ||||
22 | | ||||
23 | #include <QTreeWidgetItem> | ||||
24 | #include <QTreeWidget> | ||||
25 | #include <QDialogButtonBox> | ||||
26 | #include <QPushButton> | ||||
27 | | ||||
28 | #include <gpgme++/key.h> | ||||
29 | | ||||
30 | #include <libkleo/dn.h> | ||||
31 | #include <libkleo/keycache.h> | ||||
32 | | ||||
33 | class TrustChainWidget::Private | ||||
34 | { | ||||
35 | public: | ||||
36 | Private(TrustChainWidget *qq) | ||||
37 | : q(qq) | ||||
38 | {} | ||||
39 | | ||||
40 | GpgME::Key key; | ||||
41 | Ui::TrustChainWidget ui; | ||||
42 | | ||||
43 | private: | ||||
44 | TrustChainWidget *q; | ||||
45 | }; | ||||
46 | | ||||
47 | TrustChainWidget::TrustChainWidget(QWidget *parent) | ||||
48 | : QWidget(parent) | ||||
49 | , d(new Private(this)) | ||||
50 | { | ||||
51 | d->ui.setupUi(this); | ||||
52 | } | ||||
53 | | ||||
54 | TrustChainWidget::~TrustChainWidget() | ||||
55 | { | ||||
56 | } | ||||
57 | | ||||
58 | void TrustChainWidget::setKey(const GpgME::Key &key) | ||||
59 | { | ||||
60 | if (key.protocol() != GpgME::CMS) { | ||||
61 | qCDebug(KLEOPATRA_LOG) << "Trust chain is only supported for CMS keys"; | ||||
62 | return; | ||||
63 | } | ||||
64 | | ||||
65 | d->key = key; | ||||
66 | d->ui.treeWidget->clear(); | ||||
67 | const auto chain = Kleo::KeyCache::instance()->findIssuers(key, | ||||
68 | Kleo::KeyCache::RecursiveSearch | Kleo::KeyCache::IncludeSubject); | ||||
69 | if (chain.empty()) { | ||||
70 | return; | ||||
71 | } | ||||
72 | QTreeWidgetItem *last = 0; | ||||
73 | if (!chain.back().isRoot()) { | ||||
74 | last = new QTreeWidgetItem(d->ui.treeWidget); | ||||
75 | last->setText(0, i18n("Issuer Certificate Not Found (%1)", | ||||
76 | Kleo::DN(chain.back().issuerName()).prettyDN())); | ||||
77 | const QBrush &fg = d->ui.treeWidget->palette().brush(QPalette::Disabled, QPalette::WindowText); | ||||
78 | last->setForeground(0, fg); | ||||
79 | } | ||||
80 | for (auto it = chain.rbegin(), end = chain.rend(); it != end; ++it) { | ||||
81 | last = last ? new QTreeWidgetItem(last) : new QTreeWidgetItem(d->ui.treeWidget); | ||||
82 | last->setText(0, Kleo::DN(it->userID(0).id()).prettyDN()); | ||||
83 | } | ||||
84 | d->ui.treeWidget->expandAll(); | ||||
85 | } | ||||
86 | | ||||
87 | GpgME::Key TrustChainWidget::key() const | ||||
88 | { | ||||
89 | return d->key; | ||||
90 | } | ||||
91 | | ||||
92 | | ||||
93 | | ||||
94 | TrustChainDialog::TrustChainDialog(QWidget *parent) | ||||
95 | : QDialog(parent) | ||||
96 | { | ||||
97 | resize(650, 330); | ||||
98 | setWindowTitle(i18n("Trust Chain")); | ||||
99 | | ||||
100 | auto l = new QVBoxLayout(this); | ||||
101 | l->setMargin(0); | ||||
102 | l->addWidget(new TrustChainWidget(this)); | ||||
103 | | ||||
104 | auto bbox = new QDialogButtonBox(this); | ||||
105 | auto btn = bbox->addButton(QDialogButtonBox::Close); | ||||
106 | connect(btn, &QPushButton::pressed, this, &QDialog::accept); | ||||
107 | l->addWidget(bbox); | ||||
108 | } | ||||
109 | | ||||
110 | TrustChainDialog::~TrustChainDialog() | ||||
111 | { | ||||
112 | } | ||||
113 | | ||||
114 | void TrustChainDialog::setKey(const GpgME::Key &key) | ||||
115 | { | ||||
116 | auto w = findChild<TrustChainWidget*>(); | ||||
117 | Q_ASSERT(w); | ||||
118 | w->setKey(key); | ||||
119 | } | ||||
120 | | ||||
121 | GpgME::Key TrustChainDialog::key() const | ||||
122 | { | ||||
123 | auto w = findChild<TrustChainWidget*>(); | ||||
124 | Q_ASSERT(w); | ||||
125 | return w->key(); | ||||
126 | } | ||||
127 | |