aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gpg/GpgContext.cpp14
-rw-r--r--src/ui/KeygenDialog.cpp112
-rw-r--r--src/ui/keypair_details/KeyNewUIDDialog.cpp82
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp33
-rw-r--r--src/ui/keypair_details/KeyPairUIDTab.cpp72
5 files changed, 206 insertions, 107 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index 17347a57..b72eda73 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -968,6 +968,20 @@ namespace GpgME {
}
}
+ bool GpgContext::addUID(const GpgKey &key, const UID &uid) {
+ QString userid = QString("%1 (%3) <%2>").arg(uid.name, uid.email, uid.comment);
+ auto gpgmeError = gpgme_op_adduid(mCtx, key.key_refer, userid.toUtf8().constData(), 0);
+ if(gpgmeError == GPG_ERR_NO_ERROR) {
+ emit signalKeyUpdated(key.id);
+ return true;
+ }
+ else {
+ checkErr(gpgmeError);
+ return false;
+ }
+
+ }
+
}
diff --git a/src/ui/KeygenDialog.cpp b/src/ui/KeygenDialog.cpp
index ef07dc14..d930fffe 100644
--- a/src/ui/KeygenDialog.cpp
+++ b/src/ui/KeygenDialog.cpp
@@ -26,6 +26,7 @@
KeyGenDialog::KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent)
: QDialog(parent), mCtx(ctx) {
+
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
this->setWindowTitle(tr("Generate Key"));
@@ -37,57 +38,8 @@ void KeyGenDialog::generateKeyDialog() {
keyUsageGroupBox = create_key_usage_group_box();
- errorLabel = new QLabel(tr(""));
- nameEdit = new QLineEdit(this);
- emailEdit = new QLineEdit(this);
- commentEdit = new QLineEdit(this);
- keySizeSpinBox = new QSpinBox(this);
- keyTypeComboBox = new QComboBox(this);
-
- for(auto &algo : GenKeyInfo::SupportedKeyAlgo) {
- keyTypeComboBox->addItem(algo);
- }
- if(!GenKeyInfo::SupportedKeyAlgo.isEmpty()) {
- keyTypeComboBox->setCurrentIndex(0);
- }
-
- QDateTime maxDateTime = QDateTime::currentDateTime().addYears(2);
-
- dateEdit = new QDateTimeEdit(maxDateTime, this);
- dateEdit->setMinimumDateTime(QDateTime::currentDateTime());
- dateEdit->setMaximumDateTime(maxDateTime);
- dateEdit->setDisplayFormat("dd/MM/yyyy hh:mm:ss");
- dateEdit->setCalendarPopup(true);
- dateEdit->setEnabled(true);
-
- expireCheckBox = new QCheckBox(this);
- expireCheckBox->setCheckState(Qt::Unchecked);
-
- noPassPhraseCheckBox = new QCheckBox(this);
- noPassPhraseCheckBox->setCheckState(Qt::Unchecked);
-
- auto *vbox1 = new QGridLayout;
-
- vbox1->addWidget(new QLabel(tr("Name:")), 0, 0);
- vbox1->addWidget(new QLabel(tr("Email Address:")), 1, 0);
- vbox1->addWidget(new QLabel(tr("Comment:")), 2, 0);
- vbox1->addWidget(new QLabel(tr("Expiration Date:")), 3, 0);
- vbox1->addWidget(new QLabel(tr("Never Expire")), 3, 3);
- vbox1->addWidget(new QLabel(tr("KeySize (in Bit):")), 4, 0);
- vbox1->addWidget(new QLabel(tr("Key Type:")), 5, 0);
- vbox1->addWidget(new QLabel(tr("Non Pass Phrase")), 6, 0);
-
- vbox1->addWidget(nameEdit, 0, 1, 1, 3);
- vbox1->addWidget(emailEdit, 1, 1, 1, 3);
- vbox1->addWidget(commentEdit, 2, 1, 1, 3);
- vbox1->addWidget(dateEdit, 3, 1);
- vbox1->addWidget(expireCheckBox, 3, 2);
- vbox1->addWidget(keySizeSpinBox, 4, 1);
- vbox1->addWidget(keyTypeComboBox, 5, 1);
- vbox1->addWidget(noPassPhraseCheckBox, 6, 1);
-
auto *groupGrid = new QGridLayout(this);
- groupGrid->addLayout(vbox1, 0, 0);
+ groupGrid->addWidget(create_basic_info_group_box(), 0, 0);
groupGrid->addWidget(keyUsageGroupBox, 1, 0);
auto *nameList = new QWidget(this);
@@ -131,7 +83,7 @@ void KeyGenDialog::slotKeyGenAccept() {
* create the string for key generation
*/
- genKeyInfo.setUserid(QString("%1 <%2>").arg(nameEdit->text(), emailEdit->text()));
+ genKeyInfo.setUserid(QString("%1 (%3) <%2>").arg(nameEdit->text(), emailEdit->text(), commentEdit->text()));
genKeyInfo.setKeySize(keySizeSpinBox->value());
@@ -362,3 +314,61 @@ void KeyGenDialog::slotKeyGenResult(bool success) {
else
QMessageBox::critical(nullptr, tr("Failure"), tr("An error occurred during key generation."));
}
+
+QGroupBox *KeyGenDialog::create_basic_info_group_box() {
+
+ errorLabel = new QLabel(tr(""));
+ nameEdit = new QLineEdit(this);
+ emailEdit = new QLineEdit(this);
+ commentEdit = new QLineEdit(this);
+ keySizeSpinBox = new QSpinBox(this);
+ keyTypeComboBox = new QComboBox(this);
+
+ for(auto &algo : GenKeyInfo::SupportedKeyAlgo) {
+ keyTypeComboBox->addItem(algo);
+ }
+ if(!GenKeyInfo::SupportedKeyAlgo.isEmpty()) {
+ keyTypeComboBox->setCurrentIndex(0);
+ }
+
+ QDateTime maxDateTime = QDateTime::currentDateTime().addYears(2);
+
+ dateEdit = new QDateTimeEdit(maxDateTime, this);
+ dateEdit->setMinimumDateTime(QDateTime::currentDateTime());
+ dateEdit->setMaximumDateTime(maxDateTime);
+ dateEdit->setDisplayFormat("dd/MM/yyyy hh:mm:ss");
+ dateEdit->setCalendarPopup(true);
+ dateEdit->setEnabled(true);
+
+ expireCheckBox = new QCheckBox(this);
+ expireCheckBox->setCheckState(Qt::Unchecked);
+
+ noPassPhraseCheckBox = new QCheckBox(this);
+ noPassPhraseCheckBox->setCheckState(Qt::Unchecked);
+
+ auto *vbox1 = new QGridLayout;
+
+ vbox1->addWidget(new QLabel(tr("Name:")), 0, 0);
+ vbox1->addWidget(new QLabel(tr("Email Address:")), 1, 0);
+ vbox1->addWidget(new QLabel(tr("Comment:")), 2, 0);
+ vbox1->addWidget(new QLabel(tr("Expiration Date:")), 3, 0);
+ vbox1->addWidget(new QLabel(tr("Never Expire")), 3, 3);
+ vbox1->addWidget(new QLabel(tr("KeySize (in Bit):")), 4, 0);
+ vbox1->addWidget(new QLabel(tr("Key Type:")), 5, 0);
+ vbox1->addWidget(new QLabel(tr("Non Pass Phrase")), 6, 0);
+
+ vbox1->addWidget(nameEdit, 0, 1, 1, 3);
+ vbox1->addWidget(emailEdit, 1, 1, 1, 3);
+ vbox1->addWidget(commentEdit, 2, 1, 1, 3);
+ vbox1->addWidget(dateEdit, 3, 1);
+ vbox1->addWidget(expireCheckBox, 3, 2);
+ vbox1->addWidget(keySizeSpinBox, 4, 1);
+ vbox1->addWidget(keyTypeComboBox, 5, 1);
+ vbox1->addWidget(noPassPhraseCheckBox, 6, 1);
+
+ auto basicInfoGroupBox = new QGroupBox();
+ basicInfoGroupBox->setLayout(vbox1);
+ basicInfoGroupBox->setTitle(tr("Basic Information"));
+
+ return basicInfoGroupBox;
+}
diff --git a/src/ui/keypair_details/KeyNewUIDDialog.cpp b/src/ui/keypair_details/KeyNewUIDDialog.cpp
new file mode 100644
index 00000000..9a70b102
--- /dev/null
+++ b/src/ui/keypair_details/KeyNewUIDDialog.cpp
@@ -0,0 +1,82 @@
+//
+// Created by eric on 2021/5/28.
+//
+
+#include "ui/keypair_details/KeyNewUIDDialog.h"
+
+KeyNewUIDDialog::KeyNewUIDDialog(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) :
+ mCtx(ctx), mKey(key), QDialog(parent) {
+
+ name = new QLineEdit();
+ name->setMinimumWidth(240);
+ email = new QLineEdit();
+ email->setMinimumWidth(240);
+ comment = new QLineEdit();
+ comment->setMinimumWidth(240);
+ createButton = new QPushButton("Create");
+ errorLabel = new QLabel();
+
+ auto gridLayout = new QGridLayout();
+ gridLayout->addWidget(new QLabel(tr("Name")), 0, 0);
+ gridLayout->addWidget(new QLabel(tr("Email")), 1, 0);
+ gridLayout->addWidget(new QLabel(tr("Comment")), 2, 0);
+
+
+ gridLayout->addWidget(name, 0 ,1);
+ gridLayout->addWidget(email, 1 ,1);
+ gridLayout->addWidget(comment, 2 ,1);
+
+ gridLayout->addWidget(createButton, 3, 0, 1, 2);
+ gridLayout->addWidget(errorLabel, 4, 0, 1, 2);
+
+ connect(createButton, SIGNAL(clicked(bool)), this, SLOT(slotCreateNewUID()));
+
+ this->setLayout(gridLayout);
+ this->setWindowTitle(tr("Create New UID"));
+ this->setAttribute(Qt::WA_DeleteOnClose, true);
+ this->setModal(true);
+}
+
+void KeyNewUIDDialog::slotCreateNewUID() {
+
+ QString errorString = "";
+
+ /**
+ * check for errors in keygen dialog input
+ */
+ if ((name->text()).size() < 5) {
+ errorString.append(tr(" Name must contain at least five characters. \n"));
+ } if(email->text().isEmpty() || !check_email_address(email->text())) {
+ errorString.append(tr(" Please give a email address. \n"));
+ }
+
+ if (errorString.isEmpty()) {
+ UID uid;
+ uid.name = name->text();
+ uid.email = email->text();
+ uid.comment = comment->text();
+
+ if(mCtx->addUID(mKey, uid)) {
+ emit finished(1);
+
+ } else {
+ emit finished(0);
+ }
+
+ } else {
+ /**
+ * create error message
+ */
+ errorLabel->setAutoFillBackground(true);
+ QPalette error = errorLabel->palette();
+ error.setColor(QPalette::Background, "#ff8080");
+ errorLabel->setPalette(error);
+ errorLabel->setText(errorString);
+
+ this->show();
+ }
+}
+
+bool KeyNewUIDDialog::check_email_address(const QString &str) {
+ return re_email.match(str).hasMatch();
+}
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index 366abf27..873b478c 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -13,8 +13,6 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
keyBox = new QGroupBox(tr("Key details"));
fingerprintBox = new QGroupBox(tr("Fingerprint"));
additionalUidBox = new QGroupBox(tr("Additional Uids"));
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
nameVarLabel = new QLabel(key.name);
nameVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
@@ -90,38 +88,21 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
fingerPrintVarLabel = new QLabel(beautifyFingerprint(key.fpr));
fingerPrintVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- fingerPrintVarLabel->setStyleSheet("margin-left: 20; margin-right: 20;");
+ fingerPrintVarLabel->setStyleSheet("margin-left: 5; margin-right: 5;");
auto *hboxFP = new QHBoxLayout();
hboxFP->addWidget(fingerPrintVarLabel);
- QIcon ico(":button_copy.png");
- QPushButton copyFingerprintButton(QIcon(ico.pixmap(12, 12)), "");
- //copyFingerprintButton.setStyleSheet("QPushButton {border: 0px; } QPushButton:Pressed {} ");
- copyFingerprintButton.setFlat(true);
- copyFingerprintButton.setToolTip(tr("copy fingerprint to clipboard"));
- connect(&copyFingerprintButton, SIGNAL(clicked()), this, SLOT(slotCopyFingerprint()));
+ auto *copyFingerprintButton = new QPushButton(tr("Copy"));
+ copyFingerprintButton->setFlat(true);
+ copyFingerprintButton->setToolTip(tr("copy fingerprint to clipboard"));
+ connect(copyFingerprintButton, SIGNAL(clicked()), this, SLOT(slotCopyFingerprint()));
- hboxFP->addWidget(&copyFingerprintButton);
+ hboxFP->addWidget(copyFingerprintButton);
fingerprintBox->setLayout(hboxFP);
mvbox->addWidget(fingerprintBox);
- // If key has more than primary uid, also show the other uids
-// gpgme_user_id_t addUserIds = key->uids->next;
-// if (addUserIds != nullptr) {
-// auto *vboxUID = new QVBoxLayout();
-// while (addUserIds != nullptr) {
-// addUserIdsVarLabel = new QLabel(
-// QString::fromUtf8(addUserIds->name) + QString(" <") + addUserIds->email + ">");
-// addUserIdsVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
-// vboxUID->addWidget(addUserIdsVarLabel);
-// addUserIds = addUserIds->next;
-// }
-// additionalUidBox->setLayout(vboxUID);
-// mvbox->addWidget(additionalUidBox);
-// }
-
if (key.is_private_key) {
auto *privKeyBox = new QGroupBox(tr("Private Key"));
auto *vboxPK = new QVBoxLayout();
@@ -157,8 +138,6 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
mvbox->addLayout(expBox);
}
- mvbox->addWidget(buttonBox);
-
setAttribute(Qt::WA_DeleteOnClose, true);
setLayout(mvbox);
}
diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp
index ce4256b8..82d27262 100644
--- a/src/ui/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/keypair_details/KeyPairUIDTab.cpp
@@ -15,42 +15,35 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget
auto uidButtonsLayout = new QGridLayout();
auto addUIDButton = new QPushButton(tr("New UID"));
- auto manageUIDButton = new QPushButton(tr("Manage UID"));
+ auto manageUIDButton = new QPushButton(tr("UID Management"));
manageUIDButton->setMenu(manageUIDMenu);
uidButtonsLayout->addWidget(addUIDButton, 0, 1);
uidButtonsLayout->addWidget(manageUIDButton, 0, 2);
-
-// auto sigButtonsLayout = new QGridLayout();
-// auto manageSigButton = new QPushButton(tr("Manage Signature"));
-//
-// sigButtonsLayout->addWidget(addSigButton, 0, 1);
-// sigButtonsLayout->addWidget(manageSigButton, 0, 2);
-
auto gridLayout = new QGridLayout();
gridLayout->addWidget(uidList, 0, 0);
gridLayout->addLayout(uidButtonsLayout, 1, 0);
gridLayout->addWidget(sigList, 2, 0);
-// gridLayout->addLayout(sigButtonsLayout, 3, 0);
setLayout(gridLayout);
+ connect(addUIDButton, SIGNAL(clicked(bool)), this, SLOT(slotAddUID()));
+
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() {
+
uidList = new QTableWidget(this);
- uidList->setColumnCount(3);
+ uidList->setColumnCount(4);
uidList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
uidList->verticalHeader()->hide();
uidList->setShowGrid(false);
@@ -66,14 +59,15 @@ void KeyPairUIDTab::createUIDList() {
uidList->setAlternatingRowColors(true);
QStringList labels;
- labels << tr("Operate") << tr("Name") << tr("Email") << tr("Comment");
+ labels << tr("Select") << tr("Name") << tr("Email") << tr("Comment");
uidList->setHorizontalHeaderLabels(labels);
uidList->horizontalHeader()->setStretchLastSection(true);
}
void KeyPairUIDTab::createSignList() {
+
sigList = new QTableWidget(this);
- sigList->setColumnCount(4);
+ sigList->setColumnCount(5);
sigList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
sigList->verticalHeader()->hide();
sigList->setShowGrid(false);
@@ -88,7 +82,7 @@ void KeyPairUIDTab::createSignList() {
sigList->setAlternatingRowColors(true);
QStringList labels;
- labels << tr("Type") << tr("Pubkey Id") << tr("Create Time") << tr("Valid Time");
+ labels << tr("Type") << tr("Name") << tr("Email") << tr("Create Time") << tr("Valid Time");
sigList->setHorizontalHeaderLabels(labels);
sigList->horizontalHeader()->setStretchLastSection(true);
@@ -98,7 +92,6 @@ void KeyPairUIDTab::slotRefreshUIDList() {
int row = 0;
- uidList->clearContents();
uidList->setRowCount(mKey.uids.size());
uidList->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -121,39 +114,41 @@ void KeyPairUIDTab::slotRefreshUIDList() {
row++;
}
+ slotRefreshSigList();
}
void KeyPairUIDTab::slotRefreshSigList() {
- sigList->clearContents();
-
- int row = 0;
+ int uidRow = 0, sigRow = 0;
for(const auto& uid : mKey.uids) {
// Only Show Selected UID's Signatures
- if(!uidList->item(row, 0)->isSelected())
+ if(!uidList->item(uidRow++, 0)->isSelected()) {
continue;
+ }
sigList->setRowCount(uid.signatures.size());
for(const auto &sig : uid.signatures) {
auto *tmp0 = new QTableWidgetItem(sig.pubkey_algo);
- sigList->setItem(row, 0, tmp0);
+ sigList->setItem(sigRow, 0, tmp0);
+
+ auto *tmp2 = new QTableWidgetItem(sig.name);
+ sigList->setItem(sigRow, 1, tmp2);
- auto *tmp2 = new QTableWidgetItem(sig.uid);
- sigList->setItem(row, 1, tmp2);
+ auto *tmp3 = new QTableWidgetItem(sig.email);
+ sigList->setItem(sigRow, 2, tmp3);
- auto *tmp3 = new QTableWidgetItem(sig.create_time.toString());
- sigList->setItem(row, 2, tmp3);
+ auto *tmp4 = new QTableWidgetItem(sig.create_time.toString());
+ sigList->setItem(sigRow, 3, tmp4);
- auto *tmp4 = new QTableWidgetItem(sig.expire_time.toString());
- sigList->setItem(row, 3, tmp4);
+ auto *tmp5 = new QTableWidgetItem(sig.expire_time.toString());
+ sigList->setItem(sigRow, 4, tmp5);
- row++;
+ sigRow++;
}
break;
-
}
}
@@ -194,3 +189,22 @@ void KeyPairUIDTab::createManageUIDMenu() {
manageUIDMenu->addAction(signUIDAct);
}
+
+void KeyPairUIDTab::slotAddUID() {
+ auto keyNewUIDDialog = new KeyNewUIDDialog(mCtx, mKey, this);
+ connect(keyNewUIDDialog, SIGNAL(finished(int)), this, SLOT(slotAddUIDResult(int)));
+ connect(keyNewUIDDialog, SIGNAL(finished(int)), keyNewUIDDialog, SLOT(deleteLater()));
+ keyNewUIDDialog->show();
+}
+
+void KeyPairUIDTab::slotAddUIDResult(int result) {
+ if(result) {
+ QMessageBox::information(nullptr,
+ tr("Successful Operation"),
+ tr("Successfully added a new UID."));
+ } else {
+ QMessageBox::critical(nullptr,
+ tr("Operation Failed"),
+ tr("An error occurred during the operation."));
+ }
+}