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 signalKeyUpdated(QString key_id);
|
||||||
|
|
||||||
|
void signalKeyInfoChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void slotRefreshKeyList();
|
void slotRefreshKeyList();
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "GpgFrontend.h"
|
#include "GpgFrontend.h"
|
||||||
#include "gpg/GpgContext.h"
|
#include "gpg/GpgContext.h"
|
||||||
|
|
||||||
#include "KeySignDialog.h"
|
#include "KeyUIDSignDialog.h"
|
||||||
|
|
||||||
class KeyPairUIDTab : public QWidget {
|
class KeyPairUIDTab : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
// Created by eric on 2021/5/24.
|
// Created by eric on 2021/5/24.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef GPGFRONTEND_KEYSIGNDIALOG_H
|
#ifndef GPGFRONTEND_KEYUIDSIGNDIALOG_H
|
||||||
#define GPGFRONTEND_KEYSIGNDIALOG_H
|
#define GPGFRONTEND_KEYUIDSIGNDIALOG_H
|
||||||
|
|
||||||
#include "GpgFrontend.h"
|
#include "GpgFrontend.h"
|
||||||
|
|
||||||
#include "gpg/GpgContext.h"
|
#include "gpg/GpgContext.h"
|
||||||
#include "ui/widgets/KeyList.h"
|
#include "ui/widgets/KeyList.h"
|
||||||
|
|
||||||
class KeySignDialog : public QDialog {
|
class KeyUIDSignDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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:
|
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,
|
KeyListColumn::InfoType infoType = KeyListColumn::ALL,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setExcludeKeys(std::initializer_list<QString> key_ids);
|
||||||
|
|
||||||
void setColumnWidth(int row, int size);
|
void setColumnWidth(int row, int size);
|
||||||
|
|
||||||
void addMenuAction(QAction *act);
|
void addMenuAction(QAction *act);
|
||||||
@ -100,6 +102,7 @@ private:
|
|||||||
QVector<GpgKey> buffered_keys;
|
QVector<GpgKey> buffered_keys;
|
||||||
KeyListRow::KeyType mSelectType;
|
KeyListRow::KeyType mSelectType;
|
||||||
KeyListColumn::InfoType mInfoType;
|
KeyListColumn::InfoType mInfoType;
|
||||||
|
QVector<QString> excluded_key_ids;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -859,6 +859,7 @@ namespace GpgME {
|
|||||||
void GpgContext::slotRefreshKeyList() {
|
void GpgContext::slotRefreshKeyList() {
|
||||||
qDebug() << "Refreshing Keys";
|
qDebug() << "Refreshing Keys";
|
||||||
this->fetch_keys();
|
this->fetch_keys();
|
||||||
|
emit signalKeyInfoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -881,7 +882,7 @@ namespace GpgME {
|
|||||||
auto it = mKeyMap.find(id);
|
auto it = mKeyMap.find(id);
|
||||||
|
|
||||||
if(it != mKeyMap.end()) {
|
if(it != mKeyMap.end()) {
|
||||||
return *it.value();
|
return *(it.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error("key not found");
|
throw std::runtime_error("key not found");
|
||||||
@ -935,11 +936,9 @@ namespace GpgME {
|
|||||||
|
|
||||||
void GpgContext::setSigners(const QVector<GpgKey> &keys) {
|
void GpgContext::setSigners(const QVector<GpgKey> &keys) {
|
||||||
gpgme_signers_clear(mCtx);
|
gpgme_signers_clear(mCtx);
|
||||||
unsigned int count = 0;
|
|
||||||
for (const auto &key : keys) {
|
for (const auto &key : keys) {
|
||||||
auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
|
auto gpgmeError = gpgme_signers_add(mCtx, key.key_refer);
|
||||||
checkErr(gpgmeError);
|
checkErr(gpgmeError);
|
||||||
gpgme_key_unref(key.key_refer);
|
|
||||||
}
|
}
|
||||||
if (keys.length() != gpgme_signers_count(mCtx)) {
|
if (keys.length() != gpgme_signers_count(mCtx)) {
|
||||||
qDebug() << "No All Keys Added";
|
qDebug() << "No All Keys Added";
|
||||||
@ -963,6 +962,7 @@ namespace GpgME {
|
|||||||
|
|
||||||
if(new_key_refer != nullptr) {
|
if(new_key_refer != nullptr) {
|
||||||
it.value()->swapKeyRefer(new_key_refer);
|
it.value()->swapKeyRefer(new_key_refer);
|
||||||
|
emit signalKeyInfoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -142,9 +142,7 @@ void KeyGenDialog::slotKeyGenAccept() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kg = new KeyGenThread(&genKeyInfo, mCtx);
|
kg = new KeyGenThread(&genKeyInfo, mCtx);
|
||||||
|
|
||||||
connect(kg, SIGNAL(signalKeyGenerated(bool)), this, SLOT(slotKeyGenResult(bool)));
|
connect(kg, SIGNAL(signalKeyGenerated(bool)), this, SLOT(slotKeyGenResult(bool)));
|
||||||
|
|
||||||
kg->start();
|
kg->start();
|
||||||
|
|
||||||
this->accept();
|
this->accept();
|
||||||
@ -169,8 +167,6 @@ void KeyGenDialog::slotKeyGenAccept() {
|
|||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(kg, true);
|
|
||||||
|
|
||||||
dialog->close();
|
dialog->close();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,15 +24,15 @@
|
|||||||
|
|
||||||
#include "ui/KeygenThread.h"
|
#include "ui/KeygenThread.h"
|
||||||
|
|
||||||
KeyGenThread::KeyGenThread(GenKeyInfo* keyGenParams, GpgME::GpgContext *ctx) {
|
KeyGenThread::KeyGenThread(GenKeyInfo* keyGenParams, GpgME::GpgContext *ctx): QThread(nullptr) {
|
||||||
this->keyGenParams = keyGenParams;
|
this->keyGenParams = keyGenParams;
|
||||||
this->mCtx = ctx;
|
this->mCtx = ctx;
|
||||||
abort = false;
|
abort = false;
|
||||||
|
connect(this, &KeyGenThread::finished, this, &KeyGenThread::deleteLater);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyGenThread::run() {
|
void KeyGenThread::run() {
|
||||||
bool success = mCtx->generateKey(keyGenParams);
|
bool success = mCtx->generateKey(keyGenParams);
|
||||||
|
|
||||||
emit signalKeyGenerated(success);
|
emit signalKeyGenerated(success);
|
||||||
|
emit finished({});
|
||||||
}
|
}
|
||||||
|
@ -27,15 +27,15 @@
|
|||||||
KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent)
|
KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent)
|
||||||
: QDialog(parent) {
|
: QDialog(parent) {
|
||||||
|
|
||||||
|
tabWidget = new QTabWidget();
|
||||||
tabWidget = new QTabWidget(this);
|
tabWidget->addTab(new KeyPairDetailTab(ctx, key, tabWidget), tr("KeyPair"));
|
||||||
tabWidget->addTab(new KeyPairDetailTab(ctx, key, this), tr("KeyPair"));
|
tabWidget->addTab(new KeyPairUIDTab(ctx, key, tabWidget), tr("UIDs"));
|
||||||
tabWidget->addTab(new KeyPairUIDTab(ctx, key, this), tr("UIDs"));
|
tabWidget->addTab(new KeyPairSubkeyTab(ctx, key, tabWidget), tr("Subkeys"));
|
||||||
tabWidget->addTab(new KeyPairSubkeyTab(ctx, key, this), tr("Subkeys"));
|
|
||||||
|
|
||||||
auto *mainLayout = new QVBoxLayout;
|
auto *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(tabWidget);
|
mainLayout->addWidget(tabWidget);
|
||||||
|
|
||||||
|
this->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
this->setLayout(mainLayout);
|
this->setLayout(mainLayout);
|
||||||
this->setWindowTitle(tr("Key Details"));
|
this->setWindowTitle(tr("Key Details"));
|
||||||
this->setModal(true);
|
this->setModal(true);
|
||||||
|
@ -159,6 +159,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
|
|||||||
|
|
||||||
mvbox->addWidget(buttonBox);
|
mvbox->addWidget(buttonBox);
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
setLayout(mvbox);
|
setLayout(mvbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), key(key), QWidget(parent) {
|
KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), key(key), QWidget(parent) {
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyPairSubkeyTab::creatSubkeyList() {
|
void KeyPairSubkeyTab::creatSubkeyList() {
|
||||||
|
@ -38,16 +38,14 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget
|
|||||||
|
|
||||||
setLayout(gridLayout);
|
setLayout(gridLayout);
|
||||||
|
|
||||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefreshUIDList()));
|
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshUIDList()));
|
||||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefreshSigList()));
|
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshSigList()));
|
||||||
|
|
||||||
connect(mCtx, SIGNAL(signalKeyUpdated(QString)), this, SLOT(slotRefreshUIDList()));
|
|
||||||
connect(mCtx, SIGNAL(signalKeyUpdated(QString)), this, SLOT(slotRefreshSigList()));
|
|
||||||
|
|
||||||
connect(uidList, SIGNAL(itemSelectionChanged()), this, SLOT(slotRefreshSigList()));
|
connect(uidList, SIGNAL(itemSelectionChanged()), this, SLOT(slotRefreshSigList()));
|
||||||
|
|
||||||
slotRefreshUIDList();
|
slotRefreshUIDList();
|
||||||
slotRefreshSigList();
|
slotRefreshSigList();
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyPairUIDTab::createUIDList() {
|
void KeyPairUIDTab::createUIDList() {
|
||||||
@ -172,7 +170,7 @@ void KeyPairUIDTab::slotAddSign() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto keySignDialog = new KeySignDialog(mCtx, mKey, selected_uids, this);
|
auto keySignDialog = new KeyUIDSignDialog(mCtx, mKey, selected_uids, this);
|
||||||
keySignDialog->show();
|
keySignDialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
// Created by eric on 2021/5/24.
|
// 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) {
|
mKey(key), mCtx(ctx), mUids(uid), QDialog(parent) {
|
||||||
|
|
||||||
mKeyList = new KeyList(ctx,
|
mKeyList = new KeyList(ctx,
|
||||||
@ -12,6 +12,9 @@ KeySignDialog::KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QV
|
|||||||
KeyListColumn::NAME | KeyListColumn::EmailAddress,
|
KeyListColumn::NAME | KeyListColumn::EmailAddress,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
mKeyList->setExcludeKeys({key.id});
|
||||||
|
mKeyList->slotRefresh();
|
||||||
|
|
||||||
signKeyButton = new QPushButton("Sign");
|
signKeyButton = new QPushButton("Sign");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,24 +56,33 @@ KeySignDialog::KeySignDialog(GpgME::GpgContext *ctx, const GpgKey &key, const QV
|
|||||||
this->setModal(true);
|
this->setModal(true);
|
||||||
this->setWindowTitle(tr("Sign For Key's UID(s)"));
|
this->setWindowTitle(tr("Sign For Key's UID(s)"));
|
||||||
this->adjustSize();
|
this->adjustSize();
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySignDialog::slotSignKey(bool clicked) {
|
void KeyUIDSignDialog::slotSignKey(bool clicked) {
|
||||||
|
|
||||||
|
// Set Signers
|
||||||
QVector<GpgKey> keys;
|
QVector<GpgKey> keys;
|
||||||
mKeyList->getCheckedKeys(keys);
|
mKeyList->getCheckedKeys(keys);
|
||||||
mCtx->setSigners(keys);
|
mCtx->setSigners(keys);
|
||||||
|
|
||||||
const auto expires = expiresEdit->dateTime();
|
const auto expires = expiresEdit->dateTime();
|
||||||
|
|
||||||
for(const auto &uid : mUids) {
|
for(const auto &uid : mUids) {
|
||||||
for(const auto &key : keys) {
|
// Sign For mKey
|
||||||
if (!mCtx->signKey(mKey, uid.uid, &expires)) {
|
if (!mCtx->signKey(mKey, uid.uid, &expires)) {
|
||||||
auto msg = QMessageBox();
|
QMessageBox::critical(nullptr,
|
||||||
msg.setText(QString("%1 <%2> failed to sign.").arg(key.name, key.email));
|
tr("Operation Unsuccessful"),
|
||||||
msg.exec();
|
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();
|
this->close();
|
||||||
}
|
}
|
@ -85,7 +85,7 @@ KeyList::KeyList(GpgME::GpgContext *ctx,
|
|||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
popupMenu = new QMenu(this);
|
popupMenu = new QMenu(this);
|
||||||
connect(mCtx, SIGNAL(signalKeyDBChanged()), this, SLOT(slotRefresh()));
|
connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefresh()));
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
slotRefresh();
|
slotRefresh();
|
||||||
}
|
}
|
||||||
@ -105,6 +105,17 @@ void KeyList::slotRefresh()
|
|||||||
int row_count = 0;
|
int row_count = 0;
|
||||||
|
|
||||||
while (it != keys.end()) {
|
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) {
|
if (mSelectType == KeyListRow::ONLY_SECRET_KEY && !it->is_private_key) {
|
||||||
it = keys.erase(it);
|
it = keys.erase(it);
|
||||||
continue;
|
continue;
|
||||||
@ -398,12 +409,17 @@ void KeyList::uploadFinished()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KeyList::getCheckedKeys(QVector<GpgKey> &keys) {
|
void KeyList::getCheckedKeys(QVector<GpgKey> &keys) {
|
||||||
|
|
||||||
keys.clear();
|
keys.clear();
|
||||||
|
|
||||||
for (int i = 0; i < mKeyList->rowCount(); i++) {
|
for (int i = 0; i < mKeyList->rowCount(); i++) {
|
||||||
if (mKeyList->item(i, 0)->checkState() == Qt::Checked) {
|
if (mKeyList->item(i, 0)->checkState() == Qt::Checked) {
|
||||||
keys.push_back(buffered_keys[i]);
|
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