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
|
/*
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "selectsecretkey.h"
#include "kgpgsettings.h"
#include "core/images.h"
#include "core/KGpgRootNode.h"
#include "model/kgpgitemmodel.h"
#include "model/selectkeyproxymodel.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QPushButton>
#include <QTableView>
#include <QVBoxLayout>
using namespace KgpgCore;
KgpgSelectSecretKey::KgpgSelectSecretKey(QWidget *parent, KGpgItemModel *model, const int countkey, const bool allowLocal, const bool allowTerminal)
: QDialog(parent),
m_localsign(nullptr),
m_terminalsign(nullptr),
m_signtrust(nullptr),
m_proxy(new SelectSecretKeyProxyModel(this))
{
setWindowTitle(i18n("Private Key List"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
setLayout(mainLayout);
mainLayout->addWidget(mainWidget);
m_okButton = buttonBox->button(QDialogButtonBox::Ok);
m_okButton->setDefault(true);
m_okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &KgpgSelectSecretKey::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &KgpgSelectSecretKey::reject);
m_okButton->setDefault(true);
QWidget *page = new QWidget(this);
QLabel *label = new QLabel(i18n("Choose secret key for signing:"), page);
m_proxy->setKeyModel(model);
m_keyslist = new QTableView(page);
m_keyslist->setModel(m_proxy);
m_keyslist->setSortingEnabled(true);
m_keyslist->setSelectionBehavior(QAbstractItemView::SelectRows);
m_keyslist->resizeColumnsToContents();
QVBoxLayout *vbox = new QVBoxLayout(page);
vbox->addWidget(label);
vbox->addWidget(m_keyslist);
if (countkey > 0) {
QLabel *signchecklabel = new QLabel(i18np("How carefully have you checked that the key really "
"belongs to the person with whom you wish to communicate:",
"How carefully have you checked that the %1 keys really "
"belong to the people with whom you wish to communicate:", countkey), page);
signchecklabel->setWordWrap(true);
m_signtrust = new QComboBox(page);
m_signtrust->addItem(i18n("I Will Not Answer"));
m_signtrust->addItem(i18n("I Have Not Checked at All"));
m_signtrust->addItem(i18n("I Have Done Casual Checking"));
m_signtrust->addItem(i18n("I Have Done Very Careful Checking"));
vbox->addWidget(signchecklabel);
vbox->addWidget(m_signtrust);
if (allowLocal){
m_localsign = new QCheckBox(i18n("Local signature (cannot be exported)"), page);
vbox->addWidget(m_localsign);
}
if (allowTerminal && (countkey == 1)) {
m_terminalsign = new QCheckBox(i18n("Do not sign all user id's (open terminal)"), page);
vbox->addWidget(m_terminalsign);
}
}
KGpgNode *nd = model->getRootNode()->findKey(KGpgSettings::defaultKey());
if (nd != nullptr) {
QModelIndex sidx = model->nodeIndex(nd);
QModelIndex pidx = m_proxy->mapFromSource(sidx);
m_keyslist->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
setMinimumSize(550, 200);
slotSelectionChanged();
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
connect(m_keyslist->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KgpgSelectSecretKey::slotSelectionChanged);
connect(m_keyslist, &QTableView::doubleClicked, this, &KgpgSelectSecretKey::slotOk);
}
QString KgpgSelectSecretKey::getKeyID() const
{
if (!m_keyslist->selectionModel()->hasSelection())
return QString();
return m_proxy->nodeForIndex(m_keyslist->selectionModel()->selectedIndexes().at(0))->getId();
}
QString KgpgSelectSecretKey::getKeyMail() const
{
if (!m_keyslist->selectionModel()->hasSelection())
return QString();
return m_proxy->nodeForIndex(m_keyslist->selectionModel()->selectedIndexes().at(0))->getEmail();
}
int KgpgSelectSecretKey::getSignTrust() const
{
if (m_signtrust)
return m_signtrust->currentIndex();
return -1;
}
bool KgpgSelectSecretKey::isLocalSign() const
{
return m_localsign && m_localsign->isChecked();
}
bool KgpgSelectSecretKey::isTerminalSign() const
{
return m_terminalsign && m_terminalsign->isChecked();
}
void KgpgSelectSecretKey::slotSelectionChanged()
{
m_okButton->setEnabled(m_keyslist->selectionModel()->hasSelection());
}
void KgpgSelectSecretKey::slotOk()
{
if (m_keyslist->selectionModel()->hasSelection())
accept();
}
#include "moc_selectsecretkey.cpp"
|