diff options
author | Saturneric <[email protected]> | 2021-05-26 18:56:05 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-05-26 18:56:05 +0000 |
commit | 2f1b0b6af6c7c21134030d990a36f458d8a9600e (patch) | |
tree | e1ee1f16a0a03fe341156d2e1db3e42015fffce6 /src | |
parent | Improve the key information update mechanism (diff) | |
download | GpgFrontend-2f1b0b6af6c7c21134030d990a36f458d8a9600e.tar.gz GpgFrontend-2f1b0b6af6c7c21134030d990a36f458d8a9600e.zip |
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 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpg/GpgContext.cpp | 6 | ||||
-rw-r--r-- | src/ui/KeygenDialog.cpp | 4 | ||||
-rw-r--r-- | src/ui/KeygenThread.cpp | 6 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyDetailsDialog.cpp | 10 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairDetailTab.cpp | 1 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairSubkeyTab.cpp | 2 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.cpp | 12 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyUIDSignDialog.cpp (renamed from src/ui/keypair_details/KeySignDialog.cpp) | 30 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 22 |
9 files changed, 59 insertions, 34 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 3e6a9350..17347a57 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -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(); } } diff --git a/src/ui/KeygenDialog.cpp b/src/ui/KeygenDialog.cpp index 435194e1..ef07dc14 100644 --- a/src/ui/KeygenDialog.cpp +++ b/src/ui/KeygenDialog.cpp @@ -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 { diff --git a/src/ui/KeygenThread.cpp b/src/ui/KeygenThread.cpp index dcd8dd77..defc20bb 100644 --- a/src/ui/KeygenThread.cpp +++ b/src/ui/KeygenThread.cpp @@ -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({}); } diff --git a/src/ui/keypair_details/KeyDetailsDialog.cpp b/src/ui/keypair_details/KeyDetailsDialog.cpp index 7b09471b..b93244e1 100644 --- a/src/ui/keypair_details/KeyDetailsDialog.cpp +++ b/src/ui/keypair_details/KeyDetailsDialog.cpp @@ -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); diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index f0819b1f..366abf27 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -159,6 +159,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW mvbox->addWidget(buttonBox); + setAttribute(Qt::WA_DeleteOnClose, true); setLayout(mvbox); } diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 1c112609..2f2a49cf 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -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() { diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 9e045daf..ce4256b8 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -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(); } diff --git a/src/ui/keypair_details/KeySignDialog.cpp b/src/ui/keypair_details/KeyUIDSignDialog.cpp index e9ac9476..64a15865 100644 --- a/src/ui/keypair_details/KeySignDialog.cpp +++ b/src/ui/keypair_details/KeyUIDSignDialog.cpp @@ -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) { - 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(); - } + // Sign For mKey + if (!mCtx->signKey(mKey, uid.uid, &expires)) { + 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(); } diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 0e59c9a0..d8e4a094 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -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); + } +} |