Fix the wrong use of the signing key interface.
Fix the problem that the window or control is not deleted after it is closed. Modify the names of some classes. Extend the function of KeyList, add exclusion list. Improve the message mechanism of GpgContext. Fix the problem caused by incorrect API calls caused by incorrect understanding of the gpgme document. Signed-off-by: Saturneric <eric.bktu@gmail.com>
This commit is contained in:
parent
f134e08858
commit
2f1b0b6af6
@ -148,6 +148,8 @@ namespace GpgME {
|
||||
|
||||
void signalKeyUpdated(QString key_id);
|
||||
|
||||
void signalKeyInfoChanged();
|
||||
|
||||
private slots:
|
||||
|
||||
void slotRefreshKeyList();
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "GpgFrontend.h"
|
||||
#include "gpg/GpgContext.h"
|
||||
|
||||
#include "KeySignDialog.h"
|
||||
#include "KeyUIDSignDialog.h"
|
||||
|
||||
class KeyPairUIDTab : public QWidget {
|
||||
Q_OBJECT
|
||||
|
@ -2,20 +2,20 @@
|
||||
// Created by eric on 2021/5/24.
|
||||
//
|
||||
|
||||
#ifndef GPGFRONTEND_KEYSIGNDIALOG_H
|
||||
#define GPGFRONTEND_KEYSIGNDIALOG_H
|
||||
#ifndef GPGFRONTEND_KEYUIDSIGNDIALOG_H
|
||||
#define GPGFRONTEND_KEYUIDSIGNDIALOG_H
|
||||
|
||||
#include "GpgFrontend.h"
|
||||
|
||||
#include "gpg/GpgContext.h"
|
||||
#include "ui/widgets/KeyList.h"
|
||||
|
||||
class KeySignDialog : public QDialog {
|
||||
class KeyUIDSignDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<UID> &uid, QWidget *parent = nullptr);
|
||||
explicit KeyUIDSignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<UID> &uid, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
|
||||
@ -41,4 +41,4 @@ private slots:
|
||||
};
|
||||
|
||||
|
||||
#endif //GPGFRONTEND_KEYSIGNDIALOG_H
|
||||
#endif //GPGFRONTEND_KEYUIDSIGNDIALOG_H
|
@ -63,6 +63,8 @@ public:
|
||||
KeyListColumn::InfoType infoType = KeyListColumn::ALL,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
void setExcludeKeys(std::initializer_list<QString> key_ids);
|
||||
|
||||
void setColumnWidth(int row, int size);
|
||||
|
||||
void addMenuAction(QAction *act);
|
||||
@ -100,6 +102,7 @@ private:
|
||||
QVector<GpgKey> buffered_keys;
|
||||
KeyListRow::KeyType mSelectType;
|
||||
KeyListColumn::InfoType mInfoType;
|
||||
QVector<QString> excluded_key_ids;
|
||||
|
||||
|
||||
private slots:
|
||||
|
@ -859,6 +859,7 @@ namespace GpgME {
|
||||
void GpgContext::slotRefreshKeyList() {
|
||||
qDebug() << "Refreshing Keys";
|
||||
this->fetch_keys();
|
||||
emit signalKeyInfoChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -881,7 +882,7 @@ namespace GpgME {
|
||||
auto it = mKeyMap.find(id);
|
||||
|
||||
if(it != mKeyMap.end()) {
|
||||
return *it.value();
|
||||
return *(it.value());
|
||||
}
|
||||
|
||||
throw std::runtime_error("key not found");
|
||||
@ -935,11 +936,9 @@ namespace GpgME {
|
||||
|
||||
void GpgContext::setSigners(const QVector<GpgKey> &keys) {
|
||||
gpgme_signers_clear(mCtx);
|
||||
unsigned int count = 0;
|
||||
for (const auto &key : keys) {
|
||||
auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
|
||||
checkErr(gpgmeError);
|
||||
gpgme_key_unref(key.key_refer);
|
||||
}
|
||||
if (keys.length() != gpgme_signers_count(mCtx)) {
|
||||
qDebug() << "No All Keys Added";
|
||||
@ -963,6 +962,7 @@ namespace GpgME {
|
||||
|
||||
if(new_key_refer != nullptr) {
|
||||
it.value()->swapKeyRefer(new_key_refer);
|
||||
emit signalKeyInfoChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,9 +142,7 @@ void KeyGenDialog::slotKeyGenAccept() {
|
||||
}
|
||||
|
||||
kg = new KeyGenThread(&genKeyInfo, mCtx);
|
||||
|
||||
connect(kg, SIGNAL(signalKeyGenerated(bool)), this, SLOT(slotKeyGenResult(bool)));
|
||||
|
||||
kg->start();
|
||||
|
||||
this->accept();
|
||||
@ -169,8 +167,6 @@ void KeyGenDialog::slotKeyGenAccept() {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
destroy(kg, true);
|
||||
|
||||
dialog->close();
|
||||
|
||||
} else {
|
||||
|
@ -24,15 +24,15 @@
|
||||
|
||||
#include "ui/KeygenThread.h"
|
||||
|
||||
KeyGenThread::KeyGenThread(GenKeyInfo* keyGenParams, GpgME::GpgContext *ctx) {
|
||||
KeyGenThread::KeyGenThread(GenKeyInfo* keyGenParams, GpgME::GpgContext *ctx): QThread(nullptr) {
|
||||
this->keyGenParams = keyGenParams;
|
||||
this->mCtx = ctx;
|
||||
abort = false;
|
||||
connect(this, &KeyGenThread::finished, this, &KeyGenThread::deleteLater);
|
||||
}
|
||||
|
||||
void KeyGenThread::run() {
|
||||
bool success = mCtx->generateKey(keyGenParams);
|
||||
|
||||
emit signalKeyGenerated(success);
|
||||
|
||||
emit finished({});
|
||||
}
|
||||
|
@ -27,15 +27,15 @@
|
||||
KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent)
|
||||
: QDialog(parent) {
|
||||
|
||||
|
||||
tabWidget = new QTabWidget(this);
|
||||
tabWidget->addTab(new KeyPairDetailTab(ctx, key, this), tr("KeyPair"));
|
||||
tabWidget->addTab(new KeyPairUIDTab(ctx, key, this), tr("UIDs"));
|
||||
tabWidget->addTab(new KeyPairSubkeyTab(ctx, key, this), tr("Subkeys"));
|
||||
tabWidget = new QTabWidget();
|
||||
tabWidget->addTab(new KeyPairDetailTab(ctx, key, tabWidget), tr("KeyPair"));
|
||||
tabWidget->addTab(new KeyPairUIDTab(ctx, key, tabWidget), tr("UIDs"));
|
||||
tabWidget->addTab(new KeyPairSubkeyTab(ctx, key, tabWidget), tr("Subkeys"));
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(tabWidget);
|
||||
|
||||
this->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
this->setLayout(mainLayout);
|
||||
this->setWindowTitle(tr("Key Details"));
|
||||
this->setModal(true);
|
||||
|
@ -159,6 +159,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
|
||||
|
||||
mvbox->addWidget(buttonBox);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setLayout(mvbox);
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), key(key), QWidget(parent) {
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
}
|
||||
|
||||
void KeyPairSubkeyTab::creatSubkeyList() {
|
||||
|
@ -38,16 +38,14 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget
|
||||
|
||||
setLayout(gridLayout);
|
||||
|
||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefreshUIDList()));
|
||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefreshSigList()));
|
||||
|
||||
connect(mCtx, SIGNAL(signalKeyUpdated(QString)), this, SLOT(slotRefreshUIDList()));
|
||||
connect(mCtx, SIGNAL(signalKeyUpdated(QString)), this, SLOT(slotRefreshSigList()));
|
||||
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshUIDList()));
|
||||
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshSigList()));
|
||||
|
||||
connect(uidList, SIGNAL(itemSelectionChanged()), this, SLOT(slotRefreshSigList()));
|
||||
|
||||
slotRefreshUIDList();
|
||||
slotRefreshSigList();
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
}
|
||||
|
||||
void KeyPairUIDTab::createUIDList() {
|
||||
@ -172,7 +170,7 @@ void KeyPairUIDTab::slotAddSign() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto keySignDialog = new KeySignDialog(mCtx, mKey, selected_uids, this);
|
||||
auto keySignDialog = new KeyUIDSignDialog(mCtx, mKey, selected_uids, this);
|
||||
keySignDialog->show();
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
// Created by eric on 2021/5/24.
|
||||
//
|
||||
|
||||
#include "ui/keypair_details/KeySignDialog.h"
|
||||
#include "ui/keypair_details/KeyUIDSignDialog.h"
|
||||
|
||||
KeySignDialog::KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<UID> &uid, QWidget *parent) :
|
||||
KeyUIDSignDialog::KeyUIDSignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QVector<UID> &uid, QWidget *parent) :
|
||||
mKey(key), mCtx(ctx), mUids(uid), QDialog(parent) {
|
||||
|
||||
mKeyList = new KeyList(ctx,
|
||||
@ -12,6 +12,9 @@ KeySignDialog::KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QV
|
||||
KeyListColumn::NAME | KeyListColumn::EmailAddress,
|
||||
this);
|
||||
|
||||
mKeyList->setExcludeKeys({key.id});
|
||||
mKeyList->slotRefresh();
|
||||
|
||||
signKeyButton = new QPushButton("Sign");
|
||||
|
||||
/**
|
||||
@ -53,24 +56,33 @@ KeySignDialog::KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QV
|
||||
this->setModal(true);
|
||||
this->setWindowTitle(tr("Sign For Key's UID(s)"));
|
||||
this->adjustSize();
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
}
|
||||
|
||||
void KeySignDialog::slotSignKey(bool clicked) {
|
||||
void KeyUIDSignDialog::slotSignKey(bool clicked) {
|
||||
|
||||
// Set Signers
|
||||
QVector<GpgKey> keys;
|
||||
mKeyList->getCheckedKeys(keys);
|
||||
mCtx->setSigners(keys);
|
||||
|
||||
const auto expires = expiresEdit->dateTime();
|
||||
|
||||
for(const auto &uid : mUids) {
|
||||
for(const auto &key : keys) {
|
||||
// Sign For mKey
|
||||
if (!mCtx->signKey(mKey, uid.uid, &expires)) {
|
||||
auto msg = QMessageBox();
|
||||
msg.setText(QString("%1 <%2> failed to sign.").arg(key.name, key.email));
|
||||
msg.exec();
|
||||
}
|
||||
QMessageBox::critical(nullptr,
|
||||
tr("Operation Unsuccessful"),
|
||||
QString("%1 <%2>"+tr(" signature operation failed for UID ") + "%3")
|
||||
.arg(mKey.name, mKey.email, uid.uid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QMessageBox::information(nullptr,
|
||||
tr("Operation Complete"),
|
||||
tr("The signature operation of the UID is complete"));
|
||||
|
||||
this->close();
|
||||
}
|
@ -85,7 +85,7 @@ KeyList::KeyList(GpgME::GpgContext *ctx,
|
||||
setLayout(layout);
|
||||
|
||||
popupMenu = new QMenu(this);
|
||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefresh()));
|
||||
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefresh()));
|
||||
setAcceptDrops(true);
|
||||
slotRefresh();
|
||||
}
|
||||
@ -105,6 +105,17 @@ void KeyList::slotRefresh()
|
||||
int row_count = 0;
|
||||
|
||||
while (it != keys.end()) {
|
||||
if(!excluded_key_ids.isEmpty()){
|
||||
bool if_find = false;
|
||||
for(const auto &key_id : excluded_key_ids) {
|
||||
if(it->id == key_id) {
|
||||
it = keys.erase(it);
|
||||
if_find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(if_find) continue;
|
||||
}
|
||||
if (mSelectType == KeyListRow::ONLY_SECRET_KEY && !it->is_private_key) {
|
||||
it = keys.erase(it);
|
||||
continue;
|
||||
@ -398,12 +409,17 @@ void KeyList::uploadFinished()
|
||||
}
|
||||
|
||||
void KeyList::getCheckedKeys(QVector<GpgKey> &keys) {
|
||||
|
||||
keys.clear();
|
||||
|
||||
for (int i = 0; i < mKeyList->rowCount(); i++) {
|
||||
if (mKeyList->item(i, 0)->checkState() == Qt::Checked) {
|
||||
keys.push_back(buffered_keys[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyList::setExcludeKeys(std::initializer_list<QString> key_ids) {
|
||||
excluded_key_ids.clear();
|
||||
for(auto &key_id : key_ids) {
|
||||
excluded_key_ids.push_back(key_id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user