aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-05-26 18:56:05 +0000
committerSaturneric <[email protected]>2021-05-26 18:56:05 +0000
commit2f1b0b6af6c7c21134030d990a36f458d8a9600e (patch)
treee1ee1f16a0a03fe341156d2e1db3e42015fffce6
parentImprove the key information update mechanism (diff)
downloadGpgFrontend-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]>
-rw-r--r--include/gpg/GpgContext.h2
-rw-r--r--include/ui/keypair_details/KeyPairUIDTab.h2
-rw-r--r--include/ui/keypair_details/KeyUIDSignDialog.h (renamed from include/ui/keypair_details/KeySignDialog.h)10
-rw-r--r--include/ui/widgets/KeyList.h3
-rw-r--r--src/gpg/GpgContext.cpp6
-rw-r--r--src/ui/KeygenDialog.cpp4
-rw-r--r--src/ui/KeygenThread.cpp6
-rw-r--r--src/ui/keypair_details/KeyDetailsDialog.cpp10
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp1
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.cpp2
-rw-r--r--src/ui/keypair_details/KeyPairUIDTab.cpp12
-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.cpp22
13 files changed, 70 insertions, 40 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index 1c47b0f6..21099b63 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -148,6 +148,8 @@ namespace GpgME {
void signalKeyUpdated(QString key_id);
+ void signalKeyInfoChanged();
+
private slots:
void slotRefreshKeyList();
diff --git a/include/ui/keypair_details/KeyPairUIDTab.h b/include/ui/keypair_details/KeyPairUIDTab.h
index 679803d3..0db02e5e 100644
--- a/include/ui/keypair_details/KeyPairUIDTab.h
+++ b/include/ui/keypair_details/KeyPairUIDTab.h
@@ -28,7 +28,7 @@
#include "GpgFrontend.h"
#include "gpg/GpgContext.h"
-#include "KeySignDialog.h"
+#include "KeyUIDSignDialog.h"
class KeyPairUIDTab : public QWidget {
Q_OBJECT
diff --git a/include/ui/keypair_details/KeySignDialog.h b/include/ui/keypair_details/KeyUIDSignDialog.h
index 21c8470b..56ec8541 100644
--- a/include/ui/keypair_details/KeySignDialog.h
+++ b/include/ui/keypair_details/KeyUIDSignDialog.h
@@ -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
diff --git a/include/ui/widgets/KeyList.h b/include/ui/widgets/KeyList.h
index c4169f4a..4bdafc17 100644
--- a/include/ui/widgets/KeyList.h
+++ b/include/ui/widgets/KeyList.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:
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);
+ }
+}