diff options
Diffstat (limited to '')
-rw-r--r-- | src/gpg/function/GpgKeyGetter.cpp | 17 | ||||
-rw-r--r-- | src/gpg/function/GpgKeyOpera.cpp | 25 | ||||
-rw-r--r-- | src/gpg/function/GpgKeyOpera.h | 8 | ||||
-rw-r--r-- | src/gpg/function/UidOperator.cpp | 3 | ||||
-rw-r--r-- | src/ui/KeyImportDetailDialog.cpp | 8 | ||||
-rwxr-xr-x | src/ui/KeyMgmt.cpp | 24 | ||||
-rwxr-xr-x | src/ui/KeyMgmt.h | 2 | ||||
-rw-r--r-- | src/ui/KeyServerImportDialog.cpp | 34 | ||||
-rw-r--r-- | src/ui/KeyServerImportDialog.h | 3 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyNewUIDDialog.cpp | 14 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyNewUIDDialog.h | 3 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairDetailTab.cpp | 40 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairDetailTab.h | 7 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairSubkeyTab.cpp | 5 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.cpp | 16 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.h | 2 | ||||
-rw-r--r-- | src/ui/keypair_details/KeySetExpireDateDialog.cpp | 33 | ||||
-rw-r--r-- | src/ui/keypair_details/KeySetExpireDateDialog.h | 6 | ||||
-rw-r--r-- | src/ui/widgets/GroupKeyList.cpp | 25 | ||||
-rw-r--r-- | src/ui/widgets/GroupKeyList.h | 34 |
20 files changed, 232 insertions, 77 deletions
diff --git a/src/gpg/function/GpgKeyGetter.cpp b/src/gpg/function/GpgKeyGetter.cpp index ce4c9899..18fbe649 100644 --- a/src/gpg/function/GpgKeyGetter.cpp +++ b/src/gpg/function/GpgKeyGetter.cpp @@ -23,16 +23,20 @@ */ #include "gpg/function/GpgKeyGetter.h" + #include <gpg-error.h> + #include "GpgConstants.h" GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetKey(const std::string& fpr) { gpgme_key_t _p_key; gpgme_get_key(ctx, fpr.c_str(), &_p_key, 1); - if (_p_key == nullptr) - DLOG(WARNING) << "GpgKeyGetter GetKey _p_key Null"; - assert(_p_key != nullptr); - return GpgKey(std::move(_p_key)); + if (_p_key == nullptr) { + DLOG(WARNING) << "GpgKeyGetter GetKey Private _p_key Null fpr" << fpr; + return GetPubkey(fpr); + } else { + return GpgKey(std::move(_p_key)); + } } GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetPubkey( @@ -40,7 +44,7 @@ GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetPubkey( gpgme_key_t _p_key; gpgme_get_key(ctx, fpr.c_str(), &_p_key, 0); if (_p_key == nullptr) - DLOG(WARNING) << "GpgKeyGetter GetKey _p_key Null"; + DLOG(WARNING) << "GpgKeyGetter GetKey _p_key Null" << fpr; return GpgKey(std::move(_p_key)); } @@ -66,7 +70,6 @@ GpgFrontend::KeyLinkListPtr GpgFrontend::GpgKeyGetter::FetchKey() { GpgFrontend::KeyListPtr GpgFrontend::GpgKeyGetter::GetKeys( const KeyIdArgsListPtr& ids) { auto keys = std::make_unique<KeyArgsList>(); - for (const auto& id : *ids) - keys->push_back(GetKey(id)); + for (const auto& id : *ids) keys->push_back(GetKey(id)); return keys; } diff --git a/src/gpg/function/GpgKeyOpera.cpp b/src/gpg/function/GpgKeyOpera.cpp index 0a222c3f..c7775d10 100644 --- a/src/gpg/function/GpgKeyOpera.cpp +++ b/src/gpg/function/GpgKeyOpera.cpp @@ -61,23 +61,28 @@ void GpgFrontend::GpgKeyOpera::DeleteKeys( * @param expires date and time * @return if successful */ -void GpgFrontend::GpgKeyOpera::SetExpire( - const GpgKey& key, const SubkeyId& subkey_id, +GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::SetExpire( + const GpgKey& key, const SubkeyId& subkey_fpr, std::unique_ptr<boost::gregorian::date>& expires) { unsigned long expires_time = 0; if (expires != nullptr) { using namespace boost::posix_time; - expires_time = to_time_t(ptime(*expires)); + using namespace std::chrono; + expires_time = to_time_t(ptime(*expires)) - + system_clock::to_time_t(system_clock::now()); } + LOG(INFO) << "GpgFrontend::GpgKeyOpera::SetExpire" << key.id() << subkey_fpr + << expires_time; + GpgError err; - if (subkey_id.empty()) + if (subkey_fpr.empty()) err = gpgme_op_setexpire(ctx, gpgme_key_t(key), expires_time, nullptr, 0); else err = gpgme_op_setexpire(ctx, gpgme_key_t(key), expires_time, - subkey_id.c_str(), 0); + subkey_fpr.c_str(), 0); - assert(gpg_err_code(err) != GPG_ERR_NO_ERROR); + return err; } /** @@ -124,7 +129,9 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( unsigned long expires = 0; { using namespace boost::posix_time; - expires = to_time_t(ptime(params->getExpired())); + using namespace std::chrono; + expires = to_time_t(ptime(params->getExpired())) - + system_clock::to_time_t(system_clock::now()); } unsigned int flags = 0; @@ -158,7 +165,9 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey( unsigned long expires = 0; { using namespace boost::posix_time; - expires = to_time_t(ptime(params->getExpired())); + using namespace std::chrono; + expires = to_time_t(ptime(params->getExpired())) - + system_clock::to_time_t(system_clock::now()); } unsigned int flags = 0; diff --git a/src/gpg/function/GpgKeyOpera.h b/src/gpg/function/GpgKeyOpera.h index 36864cc7..54f7f3e6 100644 --- a/src/gpg/function/GpgKeyOpera.h +++ b/src/gpg/function/GpgKeyOpera.h @@ -35,9 +35,8 @@ class GpgKeyOpera : public SingletonFunctionObject<GpgKeyOpera> { public: void DeleteKeys(KeyIdArgsListPtr key_ids); - void SetExpire(const GpgKey& key, - const SubkeyId& subkey_id, - std::unique_ptr<boost::gregorian::date>& expires); + GpgError SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr, + std::unique_ptr<boost::gregorian::date>& expires); void GenerateRevokeCert(const GpgKey& key, const std::string& output_file_name); @@ -45,8 +44,7 @@ class GpgKeyOpera : public SingletonFunctionObject<GpgKeyOpera> { GpgFrontend::GpgError GenerateKey(const std::unique_ptr<GenKeyInfo>& params); GpgFrontend::GpgError GenerateSubkey( - const GpgKey& key, - const std::unique_ptr<GenKeyInfo>& params); + const GpgKey& key, const std::unique_ptr<GenKeyInfo>& params); private: GpgContext& ctx = GpgContext::GetInstance(); diff --git a/src/gpg/function/UidOperator.cpp b/src/gpg/function/UidOperator.cpp index 5b02855b..69caf458 100644 --- a/src/gpg/function/UidOperator.cpp +++ b/src/gpg/function/UidOperator.cpp @@ -58,6 +58,7 @@ bool GpgFrontend::UidOperator::addUID(const GpgFrontend::GpgKey& key, const std::string& name, const std::string& comment, const std::string& email) { - auto uid = boost::format("%1 (%2) <%3>") % name % comment % email; + LOG(INFO) << "GpgFrontend::UidOperator::addUID" << name << comment << email; + auto uid = boost::format("%1%(%2%)<%3%>") % name % comment % email; return addUID(key, uid.str()); } diff --git a/src/ui/KeyImportDetailDialog.cpp b/src/ui/KeyImportDetailDialog.cpp index d2f33a2e..92c73f0e 100644 --- a/src/ui/KeyImportDetailDialog.cpp +++ b/src/ui/KeyImportDetailDialog.cpp @@ -28,8 +28,7 @@ namespace GpgFrontend::UI { KeyImportDetailDialog::KeyImportDetailDialog(GpgImportInformation result, - bool automatic, - QWidget* parent) + bool automatic, QWidget* parent) : QDialog(parent), mResult(std::move(result)) { // If no key for import found, just show a message if (mResult.considered == 0) { @@ -115,6 +114,8 @@ void KeyImportDetailDialog::createGeneralInfoBox() { } void KeyImportDetailDialog::createKeysTable() { + LOG(INFO) << "KeyImportDetailDialog::createKeysTable() Called"; + keysTable = new QTableWidget(this); keysTable->setRowCount(0); keysTable->setColumnCount(4); @@ -132,8 +133,7 @@ void KeyImportDetailDialog::createKeysTable() { for (const auto& imp_key : mResult.importedKeys) { keysTable->setRowCount(row + 1); GpgKey key = GpgKeyGetter::GetInstance().GetKey(imp_key.fpr); - if (!key.good()) - continue; + if (!key.good()) continue; keysTable->setItem( row, 0, new QTableWidgetItem(QString::fromStdString(key.name()))); keysTable->setItem( diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 6a070188..df476fc9 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -29,6 +29,7 @@ #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyImportExportor.h" #include "gpg/function/GpgKeyOpera.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { KeyMgmt::KeyMgmt(QWidget* parent) @@ -90,6 +91,9 @@ KeyMgmt::KeyMgmt(QWidget* parent) setWindowTitle(tr("Key Pair Management")); mKeyList->addMenuAction(deleteSelectedKeysAct); mKeyList->addMenuAction(showKeyDetailsAct); + + connect(this, SIGNAL(signalKeyStatusUpdated()), SignalStation::GetInstance(), + SIGNAL(KeyDatabaseRefresh())); } void KeyMgmt::createActions() { @@ -221,6 +225,7 @@ void KeyMgmt::createToolBars() { void KeyMgmt::slotImportKeys(const std::string& in_buffer) { GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey( std::make_unique<ByteArray>(in_buffer)); + emit signalKeyStatusUpdated(); new KeyImportDetailDialog(result, false, this); } @@ -258,13 +263,13 @@ void KeyMgmt::deleteKeysWithWarning(KeyIdArgsListPtr key_ids) { * more than one selected... compare to seahorse "delete-dialog" */ - if (key_ids->empty()) - return; + LOG(INFO) << "KeyMgmt::deleteKeysWithWarning Called"; + + if (key_ids->empty()) return; QString keynames; for (const auto& key_id : *key_ids) { auto key = GpgKeyGetter::GetInstance().GetKey(key_id); - if (!key.good()) - continue; + if (!key.good()) continue; keynames.append(QString::fromStdString(key.name())); keynames.append("<i> <"); keynames.append(QString::fromStdString(key.email())); @@ -278,14 +283,15 @@ void KeyMgmt::deleteKeysWithWarning(KeyIdArgsListPtr key_ids) { tr("The action can not be undone."), QMessageBox::No | QMessageBox::Yes); - if (ret == QMessageBox::Yes) + if (ret == QMessageBox::Yes) { GpgKeyOpera::GetInstance().DeleteKeys(std::move(key_ids)); + emit signalKeyStatusUpdated(); + } } void KeyMgmt::slotShowKeyDetails() { auto keys_selected = mKeyList->getSelected(); - if (keys_selected->empty()) - return; + if (keys_selected->empty()) return; auto key = GpgKeyGetter::GetInstance().GetKey(keys_selected->front()); @@ -337,9 +343,7 @@ void KeyMgmt::slotGenerateKeyDialog() { keyGenDialog->show(); } -void KeyMgmt::closeEvent(QCloseEvent* event) { - QMainWindow::closeEvent(event); -} +void KeyMgmt::closeEvent(QCloseEvent* event) { QMainWindow::closeEvent(event); } void KeyMgmt::slotGenerateSubKey() { auto keys_selected = mKeyList->getSelected(); diff --git a/src/ui/KeyMgmt.h b/src/ui/KeyMgmt.h index a0a4bb72..f96fbf38 100755 --- a/src/ui/KeyMgmt.h +++ b/src/ui/KeyMgmt.h @@ -75,6 +75,8 @@ class KeyMgmt : public QMainWindow { void signalStatusBarChanged(QString); + void signalKeyStatusUpdated(); + private: void createMenus(); diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index c4d2bdac..866e378a 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -27,6 +27,7 @@ #include <utility> #include "gpg/function/GpgKeyImportExportor.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { @@ -45,6 +46,7 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic, // Buttons closeButton = createButton(tr("&Close"), SLOT(close())); importButton = createButton(tr("&Import ALL"), SLOT(slotImport())); + importButton->setDisabled(true); searchButton = createButton(tr("&Search"), SLOT(slotSearch())); // Line edit for search string @@ -111,7 +113,7 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic, QPoint pos = settings.value("ImportKeyFromServer/pos", QPoint(150, 150)).toPoint(); QSize size = - settings.value("ImportKeyFromServer/size", QSize(500, 300)).toSize(); + settings.value("ImportKeyFromServer/size", QSize(800, 500)).toSize(); qDebug() << "Settings size" << size << "pos" << pos; this->setMinimumSize(size); this->move(pos); @@ -128,6 +130,9 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic, } this->setModal(true); + + connect(this, SIGNAL(signalKeyImported()), SignalStation::GetInstance(), + SIGNAL(KeyDatabaseRefresh())); } QPushButton* KeyServerImportDialog::createButton(const QString& text, @@ -189,29 +194,39 @@ void KeyServerImportDialog::slotSearch() { return; } - QUrl urlFromRemote = keyServerComboBox->currentText() + - "/pks/lookup?search=" + searchLineEdit->text() + - "&op=index&options=mr"; + QUrl url_from_remote = keyServerComboBox->currentText() + + "/pks/lookup?search=" + searchLineEdit->text() + + "&op=index&options=mr"; qnam = new QNetworkAccessManager(this); - QNetworkReply* reply = qnam->get(QNetworkRequest(urlFromRemote)); + QNetworkReply* reply = qnam->get(QNetworkRequest(url_from_remote)); connect(reply, SIGNAL(finished()), this, SLOT(slotSearchFinished())); setLoading(true); + this->searchButton->setDisabled(true); + this->keyServerComboBox->setDisabled(true); + this->searchLineEdit->setReadOnly(true); + this->importButton->setDisabled(true); while (reply->isRunning()) { QApplication::processEvents(); } + this->searchButton->setDisabled(false); + this->keyServerComboBox->setDisabled(false); + this->searchLineEdit->setReadOnly(false); + this->importButton->setDisabled(false); setLoading(false); } void KeyServerImportDialog::slotSearchFinished() { + LOG(INFO) << "KeyServerImportDialog::slotSearchFinished Called"; + auto* reply = qobject_cast<QNetworkReply*>(sender()); keysTable->clearContents(); keysTable->setRowCount(0); - QString firstLine = QString(reply->readLine(1024)); + QString first_line = QString(reply->readLine(1024)); auto error = reply->error(); if (error != QNetworkReply::NoError) { @@ -232,7 +247,7 @@ void KeyServerImportDialog::slotSearchFinished() { return; } - if (firstLine.contains("Error")) { + if (first_line.contains("Error")) { QString text = QString(reply->readLine(1024)); if (text.contains("Too many responses")) { setMessage("<h4>" + tr("Too many responses from keyserver!") + "</h4>", @@ -340,11 +355,14 @@ void KeyServerImportDialog::slotSearchFinished() { false); } keysTable->resizeColumnsToContents(); + importButton->setDisabled(keysTable->size().isEmpty()); } reply->deleteLater(); } void KeyServerImportDialog::slotImport() { + LOG(INFO) << "KeyServerImportDialog::slotImport currentRow" + << keysTable->currentRow(); if (keysTable->currentRow() > -1) { QString keyid = keysTable->item(keysTable->currentRow(), 2)->text(); slotImport(QStringList(keyid), keyServerComboBox->currentText()); @@ -434,6 +452,7 @@ void KeyServerImportDialog::slotImportFinished() { reply->deleteLater(); this->importKeys(std::make_unique<ByteArray>(key.constData(), key.length())); + if (mAutomatic) { setMessage(tr("<h4>Key Updated</h4>"), false); } else { @@ -444,6 +463,7 @@ void KeyServerImportDialog::slotImportFinished() { void KeyServerImportDialog::importKeys(ByteArrayPtr in_data) { GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey(std::move(in_data)); + emit signalKeyImported(); if (mAutomatic) { new KeyImportDetailDialog(result, true, this); this->accept(); diff --git a/src/ui/KeyServerImportDialog.h b/src/ui/KeyServerImportDialog.h index 061329b4..f768afa7 100644 --- a/src/ui/KeyServerImportDialog.h +++ b/src/ui/KeyServerImportDialog.h @@ -46,6 +46,9 @@ class KeyServerImportDialog : public QDialog { void slotImportKey(const KeyIdArgsListPtr& keys); + signals: + void signalKeyImported(); + private slots: void slotImport(); diff --git a/src/ui/keypair_details/KeyNewUIDDialog.cpp b/src/ui/keypair_details/KeyNewUIDDialog.cpp index a22250c1..00401231 100644 --- a/src/ui/keypair_details/KeyNewUIDDialog.cpp +++ b/src/ui/keypair_details/KeyNewUIDDialog.cpp @@ -26,6 +26,7 @@ #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/UidOperator.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { KeyNewUIDDialog::KeyNewUIDDialog(const KeyId& key_id, QWidget* parent) @@ -49,7 +50,10 @@ KeyNewUIDDialog::KeyNewUIDDialog(const KeyId& key_id, QWidget* parent) gridLayout->addWidget(comment, 2, 1); gridLayout->addWidget(createButton, 3, 0, 1, 2); - gridLayout->addWidget(errorLabel, 4, 0, 1, 2); + gridLayout->addWidget( + new QLabel(tr("Notice: The New UID Created will be set as Primary.")), 4, + 0, 1, 2); + gridLayout->addWidget(errorLabel, 5, 0, 1, 2); connect(createButton, SIGNAL(clicked(bool)), this, SLOT(slotCreateNewUID())); @@ -57,6 +61,9 @@ KeyNewUIDDialog::KeyNewUIDDialog(const KeyId& key_id, QWidget* parent) this->setWindowTitle(tr("Create New UID")); this->setAttribute(Qt::WA_DeleteOnClose, true); this->setModal(true); + + connect(this, SIGNAL(signalUIDCreated()), SignalStation::GetInstance(), + SIGNAL(KeyDatabaseRefresh())); } void KeyNewUIDDialog::slotCreateNewUID() { @@ -75,9 +82,10 @@ void KeyNewUIDDialog::slotCreateNewUID() { if (errorString.isEmpty()) { if (UidOperator::GetInstance().addUID(mKey, name->text().toStdString(), comment->text().toStdString(), - email->text().toStdString())) + email->text().toStdString())) { emit finished(1); - else + emit signalUIDCreated(); + } else emit finished(-1); } else { diff --git a/src/ui/keypair_details/KeyNewUIDDialog.h b/src/ui/keypair_details/KeyNewUIDDialog.h index 076a69ed..73c4aa7b 100644 --- a/src/ui/keypair_details/KeyNewUIDDialog.h +++ b/src/ui/keypair_details/KeyNewUIDDialog.h @@ -35,6 +35,9 @@ class KeyNewUIDDialog : public QDialog { public: KeyNewUIDDialog(const KeyId& key, QWidget* parent = nullptr); + signals: + void signalUIDCreated(); + private slots: void slotCreateNewUID(); diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index 65b38b84..3608ef63 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -23,14 +23,15 @@ */ #include "ui/keypair_details/KeyPairDetailTab.h" + #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyImportExportor.h" +#include "ui/SignalStation.h" #include "ui/WaitingDialog.h" namespace GpgFrontend::UI { KeyPairDetailTab::KeyPairDetailTab(const std::string& key_id, QWidget* parent) - : QWidget(parent), - mKey(std::move(GpgKeyGetter::GetInstance().GetKey(key_id))) { + : QWidget(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)) { keyid = mKey.id(); ownerBox = new QGroupBox(tr("Owner")); @@ -200,6 +201,10 @@ KeyPairDetailTab::KeyPairDetailTab(const std::string& key_id, QWidget* parent) mvbox->addLayout(expBox); } + // when key database updated + connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this, + SLOT(slotRefreshKey())); + mvbox->setContentsMargins(0, 0, 0, 0); slotRefreshKeyInfo(); @@ -212,7 +217,7 @@ void KeyPairDetailTab::slotExportPrivateKey() { int ret = QMessageBox::information( this, tr("Exporting private Key"), "<h3>" + tr("You are about to export your") + "<font color=\"red\">" + - tr("PRIVATE KEY") + "</font>!</h3>\n" + + tr(" PRIVATE KEY ") + "</font>!</h3>\n" + tr("This is NOT your Public Key, so DON'T give it away.") + "<br />" + tr("Do you REALLY want to export your PRIVATE KEY?"), QMessageBox::Cancel | QMessageBox::Ok); @@ -278,28 +283,20 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { QString usage; QTextStream usage_steam(&usage); - if (mKey.can_certify()) - usage_steam << "Cert "; - if (mKey.can_encrypt()) - usage_steam << "Encr "; - if (mKey.can_sign()) - usage_steam << "Sign "; - if (mKey.can_authenticate()) - usage_steam << "Auth "; + if (mKey.can_certify()) usage_steam << "Cert "; + if (mKey.can_encrypt()) usage_steam << "Encr "; + if (mKey.can_sign()) usage_steam << "Sign "; + if (mKey.can_authenticate()) usage_steam << "Auth "; usageVarLabel->setText(usage); QString actualUsage; QTextStream actual_usage_steam(&actualUsage); - if (mKey.CanCertActual()) - actual_usage_steam << "Cert "; - if (mKey.CanEncrActual()) - actual_usage_steam << "Encr "; - if (mKey.CanSignActual()) - actual_usage_steam << "Sign "; - if (mKey.CanAuthActual()) - actual_usage_steam << "Auth "; + if (mKey.CanCertActual()) actual_usage_steam << "Cert "; + if (mKey.CanEncrActual()) actual_usage_steam << "Encr "; + if (mKey.CanSignActual()) actual_usage_steam << "Sign "; + if (mKey.CanAuthActual()) actual_usage_steam << "Auth "; actualUsageVarLabel->setText(actualUsage); @@ -364,5 +361,10 @@ void KeyPairDetailTab::slotGenRevokeCert() { // if (!mOutputFileName.isEmpty()) // mCtx->generateRevokeCert(mKey, mOutputFileName); } +void KeyPairDetailTab::slotRefreshKey() { + LOG(INFO) << "KeyPairDetailTab::slotRefreshKey Called"; + this->mKey = GpgKeyGetter::GetInstance().GetKey(mKey.id()); + this->slotRefreshKeyInfo(); +} } // namespace GpgFrontend::UI diff --git a/src/ui/keypair_details/KeyPairDetailTab.h b/src/ui/keypair_details/KeyPairDetailTab.h index a4978568..5f6e93fe 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.h +++ b/src/ui/keypair_details/KeyPairDetailTab.h @@ -25,10 +25,9 @@ #ifndef GPGFRONTEND_KEYPAIRDETAILTAB_H #define GPGFRONTEND_KEYPAIRDETAILTAB_H +#include "KeySetExpireDateDialog.h" #include "gpg/GpgContext.h" #include "ui/GpgFrontendUI.h" - -#include "KeySetExpireDateDialog.h" #include "ui/KeyServerImportDialog.h" #include "ui/KeyUploadDialog.h" @@ -68,6 +67,8 @@ class KeyPairDetailTab : public QWidget { void slotGenRevokeCert(); + void slotRefreshKey(); + private: std::string keyid; /** The id of the key the details should be shown for */ @@ -92,7 +93,7 @@ class KeyPairDetailTab : public QWidget { QLabel* actualUsageVarLabel; QLabel* masterKeyExistVarLabel; - QMenu* keyServerOperaMenu; + QMenu* keyServerOperaMenu{}; public: explicit KeyPairDetailTab(const std::string& key_id, diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index 7703bbde..a2841f50 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -255,9 +255,10 @@ void KeyPairSubkeyTab::createSubkeyOperaMenu() { } void KeyPairSubkeyTab::slotEditSubkey() { - qDebug() << "Slot Edit Subkey"; + LOG(INFO) << "KeyPairSubkeyTab::slotEditSubkey Fpr" << getSelectedSubkey().fpr(); + auto dialog = - new KeySetExpireDateDialog(mKey.id(), getSelectedSubkey().id(), this); + new KeySetExpireDateDialog(mKey.id(), getSelectedSubkey().fpr(), this); dialog->show(); } diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 075db08e..24461011 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -23,15 +23,16 @@ */ #include "ui/keypair_details/KeyPairUIDTab.h" + #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyManager.h" #include "gpg/function/UidOperator.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent) - : QWidget(parent), - mKey(std::move(GpgKeyGetter::GetInstance().GetKey(key_id))) { + : QWidget(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)) { createUIDList(); createSignList(); createManageUIDMenu(); @@ -79,6 +80,10 @@ KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent) 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); @@ -367,7 +372,7 @@ UIDArgsListPtr KeyPairUIDTab::getUIDSelected() { uids->push_back(buffered_uids[i].uid()); } } - return std::move(uids); + return uids; } SignIdArgsListPtr KeyPairUIDTab::getSignSelected() { @@ -501,5 +506,10 @@ void KeyPairUIDTab::slotDelSign() { } } } +void KeyPairUIDTab::slotRefreshKey() { + this->mKey = GpgKeyGetter::GetInstance().GetKey(this->mKey.id()); + this->slotRefreshUIDList(); + this->slotRefreshSigList(); +} } // namespace GpgFrontend::UI diff --git a/src/ui/keypair_details/KeyPairUIDTab.h b/src/ui/keypair_details/KeyPairUIDTab.h index 0246ead2..58d0bc2a 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.h +++ b/src/ui/keypair_details/KeyPairUIDTab.h @@ -85,6 +85,8 @@ class KeyPairUIDTab : public QWidget { void slotDelSign(); + void slotRefreshKey(); + static void slotAddUIDResult(int result); protected: diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp index 7d681a6e..b6e9da6c 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp @@ -28,6 +28,7 @@ #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyOpera.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { @@ -38,15 +39,18 @@ KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, } KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, - std::string subkey_id, + std::string subkey_fpr, QWidget* parent) : QDialog(parent), mKey(GpgKeyGetter::GetInstance().GetKey(key_id)), - mSubkey(std::move(subkey_id)) { + mSubkey(std::move(subkey_fpr)) { init(); } void KeySetExpireDateDialog::slotConfirm() { + + LOG(INFO) << "KeySetExpireDateDialog::slotConfirm Called"; + std::unique_ptr<boost::gregorian::date> expires = nullptr; if (this->nonExpiredCheck->checkState() == Qt::Unchecked) { expires = std::make_unique<boost::gregorian::date>( @@ -54,7 +58,27 @@ void KeySetExpireDateDialog::slotConfirm() { this->dateTimeEdit->dateTime().toTime_t()) .date()); } - GpgKeyOpera::GetInstance().SetExpire(mKey, mSubkey, expires); + + LOG(INFO) << "KeySetExpireDateDialog::slotConfirm" << mKey.id() << mSubkey + << *expires; + + auto err = GpgKeyOpera::GetInstance().SetExpire(mKey, mSubkey, expires); + + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) { + auto* msg_box = new QMessageBox(nullptr); + msg_box->setAttribute(Qt::WA_DeleteOnClose); + msg_box->setStandardButtons(QMessageBox::Ok); + msg_box->setWindowTitle(tr("Success")); + msg_box->setText(tr("The expire date of the key pair has been updated.")); + msg_box->setModal(false); + msg_box->open(); + + emit signalKeyExpireDateUpdated(); + + } else { + QMessageBox::critical(this, tr("Failure"), tr(gpgme_strerror(err))); + } + this->close(); } @@ -81,6 +105,9 @@ void KeySetExpireDateDialog::init() { this->setWindowTitle("Edit Expire Datetime"); this->setModal(true); this->setAttribute(Qt::WA_DeleteOnClose, true); + + connect(this, SIGNAL(signalKeyExpireDateUpdated()), + SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh())); } void KeySetExpireDateDialog::slotNonExpiredChecked(int state) { diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.h b/src/ui/keypair_details/KeySetExpireDateDialog.h index 09153956..f9779005 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.h +++ b/src/ui/keypair_details/KeySetExpireDateDialog.h @@ -38,10 +38,12 @@ class KeySetExpireDateDialog : public QDialog { explicit KeySetExpireDateDialog(const KeyId& key_id, QWidget* parent = nullptr); - explicit KeySetExpireDateDialog(const KeyId& key_id, - std::string subkey_id, + explicit KeySetExpireDateDialog(const KeyId& key_id, std::string subkey_fpr, QWidget* parent = nullptr); + signals: + void signalKeyExpireDateUpdated(); + private: void init(); diff --git a/src/ui/widgets/GroupKeyList.cpp b/src/ui/widgets/GroupKeyList.cpp new file mode 100644 index 00000000..404e8faf --- /dev/null +++ b/src/ui/widgets/GroupKeyList.cpp @@ -0,0 +1,25 @@ +/** + * This file is part of GPGFrontend. + * + * 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. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#include "GroupKeyList.h" diff --git a/src/ui/widgets/GroupKeyList.h b/src/ui/widgets/GroupKeyList.h new file mode 100644 index 00000000..f0c9e2c6 --- /dev/null +++ b/src/ui/widgets/GroupKeyList.h @@ -0,0 +1,34 @@ +/** + * This file is part of GPGFrontend. + * + * 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. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_GROUPKEYLIST_H +#define GPGFRONTEND_GROUPKEYLIST_H + +#include "ui/GpgFrontendUI.h" + +class GroupKeyList : public QWidget { + Q_OBJECT +}; + +#endif // GPGFRONTEND_GROUPKEYLIST_H |