aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/keypair_details/KeyPairUIDTab.cpp
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2021-12-05 08:14:53 +0000
committerGitHub <[email protected]>2021-12-05 08:14:53 +0000
commitab7e3bac8b5f1d1fdd8367bdb1a185be36b281c2 (patch)
tree234892f5ae225d67b24619209cf57636ec9d9b2d /src/ui/keypair_details/KeyPairUIDTab.cpp
parentMerge branch 'main' of github.com:saturneric/GpgFrontend (diff)
parentRemove rapidjson and Improve update ploicy. (diff)
downloadGpgFrontend-ab7e3bac8b5f1d1fdd8367bdb1a185be36b281c2.tar.gz
GpgFrontend-ab7e3bac8b5f1d1fdd8367bdb1a185be36b281c2.zip
Merge pull request #25 from saturneric/develop
Merge version 2.0.1 beta
Diffstat (limited to 'src/ui/keypair_details/KeyPairUIDTab.cpp')
-rw-r--r--src/ui/keypair_details/KeyPairUIDTab.cpp791
1 files changed, 407 insertions, 384 deletions
diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp
index 2954aadb..3d56699a 100644
--- a/src/ui/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/keypair_details/KeyPairUIDTab.cpp
@@ -1,7 +1,7 @@
/**
- * This file is part of GPGFrontend.
+ * This file is part of GpgFrontend.
*
- * GPGFrontend is free software: you can redistribute it and/or modify
+ * GpgFrontend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@@ -24,488 +24,511 @@
#include "ui/keypair_details/KeyPairUIDTab.h"
-KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : QWidget(parent), mKey(key) {
+#include "gpg/function/GpgKeyGetter.h"
+#include "gpg/function/GpgKeyManager.h"
+#include "gpg/function/UidOperator.h"
+#include "ui/SignalStation.h"
- mCtx = ctx;
+namespace GpgFrontend::UI {
- createUIDList();
- createSignList();
- createManageUIDMenu();
- createUIDPopupMenu();
- createSignPopupMenu();
+KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent)
+ : QWidget(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)) {
+ createUIDList();
+ createSignList();
+ createManageUIDMenu();
+ createUIDPopupMenu();
+ createSignPopupMenu();
- auto uidButtonsLayout = new QGridLayout();
+ auto uidButtonsLayout = new QGridLayout();
- auto addUIDButton = new QPushButton(tr("New UID"));
- auto manageUIDButton = new QPushButton(tr("UID Management"));
+ auto addUIDButton = new QPushButton(_("New UID"));
+ auto manageUIDButton = new QPushButton(_("UID Management"));
- if(mKey.has_master_key) {
- manageUIDButton->setMenu(manageSelectedUIDMenu);
- } else {
- manageUIDButton->setDisabled(true);
- }
+ if (mKey.has_master_key()) {
+ manageUIDButton->setMenu(manageSelectedUIDMenu);
+ } else {
+ manageUIDButton->setDisabled(true);
+ }
+
+ uidButtonsLayout->addWidget(addUIDButton, 0, 1);
+ uidButtonsLayout->addWidget(manageUIDButton, 0, 2);
- uidButtonsLayout->addWidget(addUIDButton, 0, 1);
- uidButtonsLayout->addWidget(manageUIDButton, 0, 2);
+ auto gridLayout = new QGridLayout();
- auto gridLayout = new QGridLayout();
+ gridLayout->addWidget(uidList, 0, 0);
+ gridLayout->addLayout(uidButtonsLayout, 1, 0);
+ gridLayout->setContentsMargins(0, 10, 0, 0);
- gridLayout->addWidget(uidList, 0, 0);
- gridLayout->addLayout(uidButtonsLayout, 1, 0);
- gridLayout->setContentsMargins(0, 10, 0, 0);
+ auto uidGroupBox = new QGroupBox();
+ uidGroupBox->setLayout(gridLayout);
+ uidGroupBox->setTitle(_("UIDs"));
- auto uidGroupBox = new QGroupBox();
- uidGroupBox->setLayout(gridLayout);
- uidGroupBox->setTitle(tr("UIDs"));
+ auto signGridLayout = new QGridLayout();
+ signGridLayout->addWidget(sigList, 0, 0);
+ signGridLayout->setContentsMargins(0, 10, 0, 0);
- auto signGridLayout = new QGridLayout();
- signGridLayout->addWidget(sigList, 0, 0);
- signGridLayout->setContentsMargins(0, 10, 0, 0);
+ auto signGroupBox = new QGroupBox();
+ signGroupBox->setLayout(signGridLayout);
+ signGroupBox->setTitle(_("Signature of Selected UID"));
- auto signGroupBox = new QGroupBox();
- signGroupBox->setLayout(signGridLayout);
- signGroupBox->setTitle(tr("Signature of Selected UID"));
+ auto vboxLayout = new QVBoxLayout();
+ vboxLayout->addWidget(uidGroupBox);
+ vboxLayout->addWidget(signGroupBox);
+ vboxLayout->setContentsMargins(0, 0, 0, 0);
- auto vboxLayout = new QVBoxLayout();
- vboxLayout->addWidget(uidGroupBox);
- vboxLayout->addWidget(signGroupBox);
- vboxLayout->setContentsMargins(0, 0, 0, 0);
+ connect(addUIDButton, SIGNAL(clicked(bool)), this, SLOT(slotAddUID()));
+ connect(uidList, SIGNAL(itemSelectionChanged()), this,
+ SLOT(slotRefreshSigList()));
- connect(addUIDButton, SIGNAL(clicked(bool)), this, SLOT(slotAddUID()));
- connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshUIDList()));
- connect(uidList, SIGNAL(itemSelectionChanged()), this, SLOT(slotRefreshSigList()));
+ // Key Database Refresh
+ connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this,
+ SLOT(slotRefreshKey()));
- setLayout(vboxLayout);
- setAttribute(Qt::WA_DeleteOnClose, true);
+ connect(this, SIGNAL(signalUpdateUIDInfo()), SignalStation::GetInstance(),
+ SIGNAL(KeyDatabaseRefresh()));
- slotRefreshUIDList();
+ setLayout(vboxLayout);
+ setAttribute(Qt::WA_DeleteOnClose, true);
+
+ slotRefreshUIDList();
}
void KeyPairUIDTab::createUIDList() {
-
- uidList = new QTableWidget(this);
- uidList->setColumnCount(4);
- uidList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
- uidList->verticalHeader()->hide();
- uidList->setShowGrid(false);
- uidList->setSelectionBehavior(QAbstractItemView::SelectRows);
- uidList->setSelectionMode( QAbstractItemView::SingleSelection );
-
- // tableitems not editable
- uidList->setEditTriggers(QAbstractItemView::NoEditTriggers);
-
- // no focus (rectangle around tableitems)
- // may be it should focus on whole row
- uidList->setFocusPolicy(Qt::NoFocus);
- uidList->setAlternatingRowColors(true);
-
- QStringList labels;
- labels << tr("Select") << tr("Name") << tr("Email") << tr("Comment");
- uidList->setHorizontalHeaderLabels(labels);
- uidList->horizontalHeader()->setStretchLastSection(true);
+ uidList = new QTableWidget(this);
+ uidList->setColumnCount(4);
+ uidList->horizontalHeader()->setSectionResizeMode(
+ QHeaderView::ResizeToContents);
+ uidList->verticalHeader()->hide();
+ uidList->setShowGrid(false);
+ uidList->setSelectionBehavior(QAbstractItemView::SelectRows);
+ uidList->setSelectionMode(QAbstractItemView::SingleSelection);
+
+ // tableitems not editable
+ uidList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+ // no focus (rectangle around tableitems)
+ // may be it should focus on whole row
+ uidList->setFocusPolicy(Qt::NoFocus);
+ uidList->setAlternatingRowColors(true);
+
+ QStringList labels;
+ labels << _("Select") << _("Name") << _("Email") << _("Comment");
+ uidList->setHorizontalHeaderLabels(labels);
+ uidList->horizontalHeader()->setStretchLastSection(true);
}
void KeyPairUIDTab::createSignList() {
-
- sigList = new QTableWidget(this);
- sigList->setColumnCount(5);
- sigList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
- sigList->verticalHeader()->hide();
- sigList->setShowGrid(false);
- sigList->setSelectionBehavior(QAbstractItemView::SelectRows);
-
- // table items not editable
- sigList->setEditTriggers(QAbstractItemView::NoEditTriggers);
-
- // no focus (rectangle around table items)
- // may be it should focus on whole row
- sigList->setFocusPolicy(Qt::NoFocus);
- sigList->setAlternatingRowColors(true);
-
- QStringList labels;
- labels << tr("Key ID") << tr("Name") << tr("Email") << tr("Create Date") << tr("Expired Date");
- sigList->setHorizontalHeaderLabels(labels);
- sigList->horizontalHeader()->setStretchLastSection(false);
-
+ sigList = new QTableWidget(this);
+ sigList->setColumnCount(5);
+ sigList->horizontalHeader()->setSectionResizeMode(
+ QHeaderView::ResizeToContents);
+ sigList->verticalHeader()->hide();
+ sigList->setShowGrid(false);
+ sigList->setSelectionBehavior(QAbstractItemView::SelectRows);
+
+ // table items not editable
+ sigList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+ // no focus (rectangle around table items)
+ // may be it should focus on whole row
+ sigList->setFocusPolicy(Qt::NoFocus);
+ sigList->setAlternatingRowColors(true);
+
+ QStringList labels;
+ labels << _("Key ID") << _("Name") << _("Email") << _("Create Date")
+ << _("Expired Date");
+ sigList->setHorizontalHeaderLabels(labels);
+ sigList->horizontalHeader()->setStretchLastSection(false);
}
void KeyPairUIDTab::slotRefreshUIDList() {
+ int row = 0;
- int row = 0;
+ uidList->setSelectionMode(QAbstractItemView::SingleSelection);
- uidList->setSelectionMode(QAbstractItemView::SingleSelection);
+ this->buffered_uids.clear();
- this->buffered_uids.clear();
-
- for(const auto &uid : mKey.uids) {
- if(uid.invalid || uid.revoked) {
- continue;
- }
- this->buffered_uids.push_back(&uid);
+ auto uids = mKey.uids();
+ for (auto& uid : *uids) {
+ if (uid.invalid() || uid.revoked()) {
+ continue;
}
+ this->buffered_uids.push_back(std::move(uid));
+ }
- uidList->setRowCount(buffered_uids.size());
-
- for(const auto& uid : buffered_uids) {
+ uidList->setRowCount(buffered_uids.size());
- auto *tmp0 = new QTableWidgetItem(uid->name);
- uidList->setItem(row, 1, tmp0);
+ for (const auto& uid : buffered_uids) {
+ auto* tmp0 = new QTableWidgetItem(QString::fromStdString(uid.name()));
+ uidList->setItem(row, 1, tmp0);
- auto *tmp1 = new QTableWidgetItem(uid->email);
- uidList->setItem(row, 2, tmp1);
+ auto* tmp1 = new QTableWidgetItem(QString::fromStdString(uid.email()));
+ uidList->setItem(row, 2, tmp1);
- auto *tmp2 = new QTableWidgetItem(uid->comment);
- uidList->setItem(row, 3, tmp2);
+ auto* tmp2 = new QTableWidgetItem(QString::fromStdString(uid.comment()));
+ uidList->setItem(row, 3, tmp2);
- auto *tmp3 = new QTableWidgetItem(QString::number(row));
- tmp3->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
- tmp3->setTextAlignment(Qt::AlignCenter);
- tmp3->setCheckState(Qt::Unchecked);
- uidList->setItem(row, 0, tmp3);
+ auto* tmp3 = new QTableWidgetItem(QString::number(row));
+ tmp3->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
+ Qt::ItemIsSelectable);
+ tmp3->setTextAlignment(Qt::AlignCenter);
+ tmp3->setCheckState(Qt::Unchecked);
+ uidList->setItem(row, 0, tmp3);
- row++;
+ if (!row) {
+ for (auto i = 0; i < uidList->columnCount(); i++) {
+ uidList->item(row, i)->setForeground(QColor(65, 105, 255));
+ }
}
- if(uidList->rowCount() > 0) {
- uidList->selectRow(0);
- }
+ row++;
+ }
- slotRefreshSigList();
+ if (uidList->rowCount() > 0) {
+ uidList->selectRow(0);
+ }
+
+ slotRefreshSigList();
}
void KeyPairUIDTab::slotRefreshSigList() {
+ int uidRow = 0, sigRow = 0;
+ for (const auto& uid : buffered_uids) {
+ // Only Show Selected UID Signatures
+ if (!uidList->item(uidRow++, 0)->isSelected()) {
+ continue;
+ }
- int uidRow = 0, sigRow = 0;
- for(const auto& uid : buffered_uids) {
-
- // Only Show Selected UID Signatures
- if(!uidList->item(uidRow++, 0)->isSelected()) {
- continue;
- }
-
- buffered_signatures.clear();
-
- for(const auto &sig : uid->signatures) {
- if(sig.invalid || sig.revoked) {
- continue;
- }
- buffered_signatures.push_back(&sig);
- }
-
- sigList->setRowCount(buffered_signatures.size());
-
- for(const auto &sig : buffered_signatures) {
+ buffered_signatures.clear();
+ auto signatures = uid.signatures();
+ for (auto& sig : *signatures) {
+ if (sig.invalid() || sig.revoked()) {
+ continue;
+ }
+ buffered_signatures.push_back(std::move(sig));
+ }
- auto *tmp0 = new QTableWidgetItem(sig->keyid);
- sigList->setItem(sigRow, 0, tmp0);
+ sigList->setRowCount(buffered_signatures.size());
- if(gpgme_err_code(sig->status) == GPG_ERR_NO_PUBKEY) {
- auto *tmp2 = new QTableWidgetItem("<Unknown>");
- sigList->setItem(sigRow, 1, tmp2);
+ for (const auto& sig : buffered_signatures) {
+ auto* tmp0 = new QTableWidgetItem(QString::fromStdString(sig.keyid()));
+ sigList->setItem(sigRow, 0, tmp0);
- auto *tmp3 = new QTableWidgetItem("<Unknown>");
- sigList->setItem(sigRow, 2, tmp3);
- } else {
- auto *tmp2 = new QTableWidgetItem(sig->name);
- sigList->setItem(sigRow, 1, tmp2);
+ if (gpgme_err_code(sig.status()) == GPG_ERR_NO_PUBKEY) {
+ auto* tmp2 = new QTableWidgetItem("<Unknown>");
+ sigList->setItem(sigRow, 1, tmp2);
- auto *tmp3 = new QTableWidgetItem(sig->email);
- sigList->setItem(sigRow, 2, tmp3);
- }
+ auto* tmp3 = new QTableWidgetItem("<Unknown>");
+ sigList->setItem(sigRow, 2, tmp3);
+ } else {
+ auto* tmp2 = new QTableWidgetItem(QString::fromStdString(sig.name()));
+ sigList->setItem(sigRow, 1, tmp2);
- auto *tmp4 = new QTableWidgetItem(sig->create_time.toString());
- sigList->setItem(sigRow, 3, tmp4);
+ auto* tmp3 = new QTableWidgetItem(QString::fromStdString(sig.email()));
+ sigList->setItem(sigRow, 2, tmp3);
+ }
- auto *tmp5 = new QTableWidgetItem(sig->expire_time.toTime_t() == 0 ? tr("Never Expires") : sig->expire_time.toString());
- tmp5->setTextAlignment(Qt::AlignCenter);
- sigList->setItem(sigRow, 4, tmp5);
+ auto* tmp4 = new QTableWidgetItem(QString::fromStdString(
+ boost::gregorian::to_iso_string(sig.create_time())));
+ sigList->setItem(sigRow, 3, tmp4);
- sigRow++;
- }
+ auto* tmp5 = new QTableWidgetItem(
+ boost::posix_time::to_time_t(
+ boost::posix_time::ptime(sig.expire_time())) == 0
+ ? _("Never Expires")
+ : QString::fromStdString(
+ boost::gregorian::to_iso_string(sig.expire_time())));
+ tmp5->setTextAlignment(Qt::AlignCenter);
+ sigList->setItem(sigRow, 4, tmp5);
- break;
+ sigRow++;
}
+
+ break;
+ }
}
void KeyPairUIDTab::slotAddSign() {
-
- QVector<GpgUID> selected_uids;
- getUIDChecked(selected_uids);
-
- if(selected_uids.isEmpty()) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("Please select one or more UIDs before doing this operation."));
- return;
- }
-
- auto keySignDialog = new KeyUIDSignDialog(mCtx, mKey, selected_uids, this);
- keySignDialog->show();
+ auto selected_uids = getUIDChecked();
+
+ if (selected_uids->empty()) {
+ QMessageBox::information(
+ nullptr, _("Invalid Operation"),
+ _("Please select one or more UIDs before doing this operation."));
+ return;
+ }
+
+ auto keySignDialog =
+ new KeyUIDSignDialog(mKey, std::move(selected_uids), this);
+ keySignDialog->show();
}
-
-
-void KeyPairUIDTab::getUIDChecked(QVector<GpgUID> &selected_uids) {
-
- auto &uids = buffered_uids;
-
- for (int i = 0; i < uidList->rowCount(); i++) {
- if (uidList->item(i, 0)->checkState() == Qt::Checked) {
- selected_uids.push_back(*uids[i]);
- }
- }
+UIDArgsListPtr KeyPairUIDTab::getUIDChecked() {
+ auto selected_uids = std::make_unique<UIDArgsList>();
+ for (int i = 0; i < uidList->rowCount(); i++) {
+ if (uidList->item(i, 0)->checkState() == Qt::Checked)
+ selected_uids->push_back(buffered_uids[i].uid());
+ }
+ return selected_uids;
}
void KeyPairUIDTab::createManageUIDMenu() {
+ manageSelectedUIDMenu = new QMenu(this);
- manageSelectedUIDMenu = new QMenu(this);
-
- auto *signUIDAct = new QAction(tr("Sign Selected UID(s)"), this);
- connect(signUIDAct, SIGNAL(triggered()), this, SLOT(slotAddSign()));
- auto *delUIDAct = new QAction(tr("Delete Selected UID(s)"), this);
- connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUID()));
+ auto* signUIDAct = new QAction(_("Sign Selected UID(s)"), this);
+ connect(signUIDAct, SIGNAL(triggered()), this, SLOT(slotAddSign()));
+ auto* delUIDAct = new QAction(_("Delete Selected UID(s)"), this);
+ connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUID()));
- if(mKey.has_master_key) {
- manageSelectedUIDMenu->addAction(signUIDAct);
- manageSelectedUIDMenu->addAction(delUIDAct);
- }
+ if (mKey.has_master_key()) {
+ manageSelectedUIDMenu->addAction(signUIDAct);
+ manageSelectedUIDMenu->addAction(delUIDAct);
+ }
}
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();
+ auto keyNewUIDDialog = new KeyNewUIDDialog(mKey.id(), 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 == 1) {
- QMessageBox::information(nullptr,
- tr("Successful Operation"),
- tr("Successfully added a new UID."));
- } else if (result == -1) {
- QMessageBox::critical(nullptr,
- tr("Operation Failed"),
- tr("An error occurred during the operation."));
- }
+ if (result == 1) {
+ QMessageBox::information(nullptr, _("Successful Operation"),
+ _("Successfully added a new UID."));
+ } else if (result == -1) {
+ QMessageBox::critical(nullptr, _("Operation Failed"),
+ _("An error occurred during the operation."));
+ }
}
void KeyPairUIDTab::slotDelUID() {
-
- QVector<GpgUID> selected_uids;
- getUIDChecked(selected_uids);
-
- if(selected_uids.isEmpty()) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("Please select one or more UIDs before doing this operation."));
- return;
- }
-
- QString keynames;
- for (const auto &uid : selected_uids) {
- keynames.append(uid.name);
- keynames.append("<i> &lt;");
- keynames.append(uid.email);
- keynames.append("&gt; </i><br/>");
- }
-
- int ret = QMessageBox::warning(this, tr("Deleting UIDs"),
- "<b>"+tr("Are you sure that you want to delete the following uids?")+"</b><br/><br/>"+keynames+
- +"<br/>"+tr("The action can not be undone."),
- QMessageBox::No | QMessageBox::Yes);
-
-
- bool if_success = true;
-
- if (ret == QMessageBox::Yes) {
- for(const auto &uid : selected_uids) {
- if(!mCtx->revUID(mKey, uid)) {
- if_success = false;
- }
- }
-
- if(!if_success) {
- QMessageBox::critical(nullptr,
- tr("Operation Failed"),
- tr("An error occurred during the operation."));
- }
-
+ auto selected_uids = getUIDChecked();
+
+ if (selected_uids->empty()) {
+ QMessageBox::information(
+ nullptr, _("Invalid Operation"),
+ _("Please select one or more UIDs before doing this operation."));
+ return;
+ }
+
+ QString keynames;
+ for (auto& uid : *selected_uids) {
+ keynames.append(QString::fromStdString(uid));
+ keynames.append("<br/>");
+ }
+
+ int ret = QMessageBox::warning(
+ this, _("Deleting UIDs"),
+ "<b>" +
+ QString(
+ _("Are you sure that you want to delete the following UIDs?")) +
+ "</b><br/><br/>" + keynames + +"<br/>" +
+ _("The action can not be undone."),
+ QMessageBox::No | QMessageBox::Yes);
+
+ if (ret == QMessageBox::Yes) {
+ for (const auto& uid : *selected_uids) {
+ LOG(INFO) << "KeyPairUIDTab::slotDelUID UID" << uid;
+ if (!UidOperator::GetInstance().revUID(mKey, uid)) {
+ QMessageBox::critical(
+ nullptr, _("Operation Failed"),
+ QString(_("An error occurred during the delete %1 operation."))
+ .arg(uid.c_str()));
+ }
}
+ emit signalUpdateUIDInfo();
+ }
}
void KeyPairUIDTab::slotSetPrimaryUID() {
-
- GpgUID selected_uid;
-
- if(!getUIDSelected(selected_uid)) {
- auto emptyUIDMsg = new QMessageBox();
- emptyUIDMsg->setText("Please select one UID before doing this operation.");
- emptyUIDMsg->exec();
- return;
- }
-
- QString keynames;
-
- keynames.append(selected_uid.name);
- keynames.append("<i> &lt;");
- keynames.append(selected_uid.email);
- keynames.append("&gt; </i><br/>");
-
- int ret = QMessageBox::warning(this, tr("Set Primary UID"),
- "<b>"+tr("Are you sure that you want to set the Primary UID to?")+"</b><br/><br/>"+keynames+
- +"<br/>"+tr("The action can not be undone."),
- QMessageBox::No | QMessageBox::Yes);
-
- if (ret == QMessageBox::Yes) {
- if(!mCtx->setPrimaryUID(mKey, selected_uid)) {
- QMessageBox::critical(nullptr,
- tr("Operation Failed"),
- tr("An error occurred during the operation."));
- }
+ auto selected_uids = getUIDSelected();
+
+ if (selected_uids->empty()) {
+ auto emptyUIDMsg = new QMessageBox();
+ emptyUIDMsg->setText("Please select one UID before doing this operation.");
+ emptyUIDMsg->exec();
+ return;
+ }
+
+ QString keynames;
+
+ keynames.append(QString::fromStdString(selected_uids->front()));
+ keynames.append("<br/>");
+
+ int ret = QMessageBox::warning(
+ this, _("Set Primary UID"),
+ "<b>" +
+ QString(_("Are you sure that you want to set the Primary UID to?")) +
+ "</b><br/><br/>" + keynames + +"<br/>" +
+ _("The action can not be undone."),
+ QMessageBox::No | QMessageBox::Yes);
+
+ if (ret == QMessageBox::Yes) {
+ if (!UidOperator::GetInstance().setPrimaryUID(mKey,
+ selected_uids->front())) {
+ QMessageBox::critical(nullptr, _("Operation Failed"),
+ _("An error occurred during the operation."));
+ } else {
+ emit signalUpdateUIDInfo();
}
+ }
}
-bool KeyPairUIDTab::getUIDSelected(GpgUID &uid) {
- auto &uids = buffered_uids;
- for (int i = 0; i < uidList->rowCount(); i++) {
- if (uidList->item(i, 0)->isSelected()) {
- uid = *uids[i];
- return true;
- }
+UIDArgsListPtr KeyPairUIDTab::getUIDSelected() {
+ auto uids = std::make_unique<UIDArgsList>();
+ for (int i = 0; i < uidList->rowCount(); i++) {
+ if (uidList->item(i, 0)->isSelected()) {
+ uids->push_back(buffered_uids[i].uid());
}
- return false;
+ }
+ return uids;
}
-bool KeyPairUIDTab::getSignSelected(GpgKeySignature &signature) {
- auto &signatures = buffered_signatures;
- for (int i = 0; i < sigList->rowCount(); i++) {
- if (sigList->item(i, 0)->isSelected()) {
- signature = *signatures[i];
- return true;
- }
+SignIdArgsListPtr KeyPairUIDTab::getSignSelected() {
+ auto signatures = std::make_unique<SignIdArgsList>();
+ for (int i = 0; i < sigList->rowCount(); i++) {
+ if (sigList->item(i, 0)->isSelected()) {
+ auto& sign = buffered_signatures[i];
+ signatures->push_back({sign.keyid(), sign.uid()});
}
- return false;
+ }
+ return signatures;
}
void KeyPairUIDTab::createUIDPopupMenu() {
-
- uidPopupMenu = new QMenu(this);
-
- auto *serPrimaryUIDAct = new QAction(tr("Set As Primary"), this);
- connect(serPrimaryUIDAct, SIGNAL(triggered()), this, SLOT(slotSetPrimaryUID()));
- auto *signUIDAct = new QAction(tr("Sign UID"), this);
- connect(signUIDAct, SIGNAL(triggered()), this, SLOT(slotAddSignSingle()));
- auto *delUIDAct = new QAction(tr("Delete UID"), this);
- connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUIDSingle()));
-
- if(mKey.has_master_key) {
- uidPopupMenu->addAction(serPrimaryUIDAct);
- uidPopupMenu->addAction(signUIDAct);
- uidPopupMenu->addAction(delUIDAct);
- }
+ uidPopupMenu = new QMenu(this);
+
+ auto* serPrimaryUIDAct = new QAction(_("Set As Primary"), this);
+ connect(serPrimaryUIDAct, SIGNAL(triggered()), this,
+ SLOT(slotSetPrimaryUID()));
+ auto* signUIDAct = new QAction(_("Sign UID"), this);
+ connect(signUIDAct, SIGNAL(triggered()), this, SLOT(slotAddSignSingle()));
+ auto* delUIDAct = new QAction(_("Delete UID"), this);
+ connect(delUIDAct, SIGNAL(triggered()), this, SLOT(slotDelUIDSingle()));
+
+ if (mKey.has_master_key()) {
+ uidPopupMenu->addAction(serPrimaryUIDAct);
+ uidPopupMenu->addAction(signUIDAct);
+ uidPopupMenu->addAction(delUIDAct);
+ }
}
-void KeyPairUIDTab::contextMenuEvent(QContextMenuEvent *event) {
- if (uidList->selectedItems().length() > 0 && sigList->selectedItems().isEmpty()) {
- uidPopupMenu->exec(event->globalPos());
- }
+void KeyPairUIDTab::contextMenuEvent(QContextMenuEvent* event) {
+ if (uidList->selectedItems().length() > 0 &&
+ sigList->selectedItems().isEmpty()) {
+ uidPopupMenu->exec(event->globalPos());
+ }
- if (!sigList->selectedItems().isEmpty()) {
- signPopupMenu->exec(event->globalPos());
- }
+ if (!sigList->selectedItems().isEmpty()) {
+ signPopupMenu->exec(event->globalPos());
+ }
}
void KeyPairUIDTab::slotAddSignSingle() {
-
- GpgUID selected_uid;
-
- if(!getUIDSelected(selected_uid)) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("Please select one UID before doing this operation."));
- return;
- }
-
- auto selected_uids = QVector<GpgUID>({selected_uid });
- auto keySignDialog = new KeyUIDSignDialog(mCtx, mKey, selected_uids, this);
- keySignDialog->show();
+ auto selected_uids = getUIDSelected();
+
+ if (selected_uids->empty()) {
+ QMessageBox::information(
+ nullptr, _("Invalid Operation"),
+ _("Please select one UID before doing this operation."));
+ return;
+ }
+
+ auto keySignDialog =
+ new KeyUIDSignDialog(mKey, std::move(selected_uids), this);
+ keySignDialog->show();
}
void KeyPairUIDTab::slotDelUIDSingle() {
- GpgUID selected_uid;
-
- if(!getUIDSelected(selected_uid)) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("Please select one UID before doing this operation."));
- return;
- }
-
- QString keynames;
-
- keynames.append(selected_uid.name);
- keynames.append("<i> &lt;");
- keynames.append(selected_uid.email);
- keynames.append("&gt; </i><br/>");
-
- int ret = QMessageBox::warning(this, tr("Deleting UID"),
- "<b>"+tr("Are you sure that you want to delete the following uid?")+"</b><br/><br/>"+keynames+
- +"<br/>"+tr("The action can not be undone."),
- QMessageBox::No | QMessageBox::Yes);
-
- if (ret == QMessageBox::Yes) {
- if(!mCtx->revUID(mKey, selected_uid)) {
- QMessageBox::critical(nullptr,
- tr("Operation Failed"),
- tr("An error occurred during the operation."));
- }
+ auto selected_uids = getUIDSelected();
+ if (selected_uids->empty()) {
+ QMessageBox::information(
+ nullptr, _("Invalid Operation"),
+ _("Please select one UID before doing this operation."));
+ return;
+ }
+
+ QString keynames;
+
+ keynames.append(QString::fromStdString(selected_uids->front()));
+ keynames.append("<br/>");
+
+ int ret = QMessageBox::warning(
+ this, _("Deleting UID"),
+ "<b>" +
+ QString(
+ _("Are you sure that you want to delete the following uid?")) +
+ "</b><br/><br/>" + keynames + +"<br/>" +
+ _("The action can not be undone."),
+ QMessageBox::No | QMessageBox::Yes);
+
+ if (ret == QMessageBox::Yes) {
+ if (!UidOperator::GetInstance().revUID(mKey, selected_uids->front())) {
+ QMessageBox::critical(nullptr, _("Operation Failed"),
+ _("An error occurred during the operation."));
+ } else {
+ emit signalUpdateUIDInfo();
}
+ }
}
void KeyPairUIDTab::createSignPopupMenu() {
- signPopupMenu = new QMenu(this);
+ signPopupMenu = new QMenu(this);
- auto *delSignAct = new QAction(tr("Delete(Revoke) Key Signature"), this);
- connect(delSignAct, SIGNAL(triggered()), this, SLOT(slotDelSign()));
+ auto* delSignAct = new QAction(_("Delete(Revoke) Key Signature"), this);
+ connect(delSignAct, SIGNAL(triggered()), this, SLOT(slotDelSign()));
- signPopupMenu->addAction(delSignAct);
+ signPopupMenu->addAction(delSignAct);
}
void KeyPairUIDTab::slotDelSign() {
- GpgKeySignature selected_sign;
-
- if(!getSignSelected(selected_sign)) {
- QMessageBox::information(nullptr,
- tr("Invalid Operation"),
- tr("Please select one Key Signature before doing this operation."));
- return;
- }
-
- if(gpgme_err_code(selected_sign.status) == GPG_ERR_NO_PUBKEY) {
- QMessageBox::critical(nullptr,
- tr("Invalid Operation"),
- tr("To delete the signature, you need to have its corresponding public key in the local database."));
- return;
- }
-
- QString keynames;
-
- keynames.append(selected_sign.name);
- keynames.append("<i> &lt;");
- keynames.append(selected_sign.email);
- keynames.append("&gt; </i><br/>");
-
- int ret = QMessageBox::warning(this, tr("Deleting Key Signature"),
- "<b>"+tr("Are you sure that you want to delete the following signature?")+"</b><br/><br/>"+keynames+
- +"<br/>"+tr("The action can not be undone."),
- QMessageBox::No | QMessageBox::Yes);
-
- if (ret == QMessageBox::Yes) {
- if(!mCtx->revSign(mKey, selected_sign)) {
- QMessageBox::critical(nullptr,
- tr("Operation Failed"),
- tr("An error occurred during the operation."));
- }
+ auto selected_signs = getSignSelected();
+ if (selected_signs->empty()) {
+ QMessageBox::information(
+ nullptr, _("Invalid Operation"),
+ _("Please select one Key Signature before doing this operation."));
+ return;
+ }
+
+ if (!GpgKeyGetter::GetInstance()
+ .GetKey(selected_signs->front().first)
+ .good()) {
+ QMessageBox::critical(
+ nullptr, _("Invalid Operation"),
+ _("To delete the signature, you need to have its corresponding public "
+ "key in the local database."));
+ return;
+ }
+
+ QString keynames;
+
+ keynames.append(QString::fromStdString(selected_signs->front().second));
+ keynames.append("<br/>");
+
+ int ret =
+ QMessageBox::warning(this, _("Deleting Key Signature"),
+ "<b>" +
+ QString(_("Are you sure that you want to delete "
+ "the following signature?")) +
+ "</b><br/><br/>" + keynames + +"<br/>" +
+ _("The action can not be undone."),
+ QMessageBox::No | QMessageBox::Yes);
+
+ if (ret == QMessageBox::Yes) {
+ if (!GpgKeyManager::GetInstance().revSign(mKey, selected_signs)) {
+ QMessageBox::critical(nullptr, _("Operation Failed"),
+ _("An error occurred during the operation."));
}
+ }
}
+void KeyPairUIDTab::slotRefreshKey() {
+ this->mKey = GpgKeyGetter::GetInstance().GetKey(this->mKey.id());
+ this->slotRefreshUIDList();
+ this->slotRefreshSigList();
+}
+
+} // namespace GpgFrontend::UI