aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2025-04-18 23:23:15 +0000
committersaturneric <[email protected]>2025-04-18 23:23:15 +0000
commit0b91f3575db5fd191dd137053bd6bd8b6db03405 (patch)
treee60875ba1ae67772ad5f95808f2e68665faa4c39
parentchore: update appstream configures (diff)
downloadGpgFrontend-0b91f3575db5fd191dd137053bd6bd8b6db03405.tar.gz
GpgFrontend-0b91f3575db5fd191dd137053bd6bd8b6db03405.zip
fix: operations of subkey
-rw-r--r--src/core/function/gpg/GpgAutomatonHandler.cpp6
-rw-r--r--src/core/function/gpg/GpgKeyManager.cpp6
-rw-r--r--src/core/function/gpg/GpgUIDOperator.cpp4
-rw-r--r--src/ui/dialog/ADSKsPicker.cpp98
4 files changed, 73 insertions, 41 deletions
diff --git a/src/core/function/gpg/GpgAutomatonHandler.cpp b/src/core/function/gpg/GpgAutomatonHandler.cpp
index afa55299..c0ce853d 100644
--- a/src/core/function/gpg/GpgAutomatonHandler.cpp
+++ b/src/core/function/gpg/GpgAutomatonHandler.cpp
@@ -110,13 +110,13 @@ auto InteratorCbFunc(void* handle, const char* status, const char* args,
}
auto DoInteractImpl(GpgContext& ctx_, const GpgKeyPtr& key, bool card_edit,
- const QString& id,
+ const QString& fpr,
AutomatonNextStateHandler next_state_handler,
AutomatonActionHandler action_handler,
int flags) -> std::tuple<GpgError, bool> {
gpgme_key_t p_key = key == nullptr ? nullptr : static_cast<gpgme_key_t>(*key);
- AutomatonHandelStruct handel(card_edit, id);
+ AutomatonHandelStruct handel(card_edit, fpr);
handel.SetHandler(std::move(next_state_handler), std::move(action_handler));
GpgData data_out;
@@ -133,7 +133,7 @@ auto GpgAutomatonHandler::DoInteract(
int flags) -> std::tuple<GpgError, bool> {
assert(key != nullptr);
if (key == nullptr) return {GPG_ERR_USER_1, false};
- return DoInteractImpl(ctx_, key, false, key->ID(),
+ return DoInteractImpl(ctx_, key, false, key->Fingerprint(),
std::move(next_state_handler),
std::move(action_handler), flags);
}
diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp
index 5fca4ed4..b2337659 100644
--- a/src/core/function/gpg/GpgKeyManager.cpp
+++ b/src/core/function/gpg/GpgKeyManager.cpp
@@ -168,7 +168,7 @@ auto GpgKeyManager::SetOwnerTrustLevel(const GpgKeyPtr& key,
};
auto [err, succ] = auto_.DoInteract(key, next_state_handler, action_handler);
- return err == GPG_ERR_NO_ERROR && !succ;
+ return err == GPG_ERR_NO_ERROR && succ;
}
auto GpgKeyManager::DeleteSubkey(const GpgKeyPtr& key,
@@ -246,7 +246,7 @@ auto GpgKeyManager::DeleteSubkey(const GpgKeyPtr& key,
};
auto [err, succ] = auto_.DoInteract(key, next_state_handler, action_handler);
- return err == GPG_ERR_NO_ERROR && !succ;
+ return err == GPG_ERR_NO_ERROR && succ;
}
auto GpgKeyManager::RevokeSubkey(const GpgKeyPtr& key, int subkey_index,
@@ -362,7 +362,7 @@ auto GpgKeyManager::RevokeSubkey(const GpgKeyPtr& key, int subkey_index,
};
auto [err, succ] = auto_.DoInteract(key, next_state_handler, action_handler);
- return err == GPG_ERR_NO_ERROR && !succ;
+ return err == GPG_ERR_NO_ERROR && succ;
}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/function/gpg/GpgUIDOperator.cpp b/src/core/function/gpg/GpgUIDOperator.cpp
index ca056be0..e1b8b8af 100644
--- a/src/core/function/gpg/GpgUIDOperator.cpp
+++ b/src/core/function/gpg/GpgUIDOperator.cpp
@@ -130,7 +130,7 @@ auto GpgUIDOperator::DeleteUID(const GpgKeyPtr& key, int uid_index) -> bool {
};
auto [err, succ] = auto_.DoInteract(key, next_state_handler, action_handler);
- return err == GPG_ERR_NO_ERROR && !succ;
+ return err == GPG_ERR_NO_ERROR && succ;
}
auto GpgUIDOperator::RevokeUID(const GpgKeyPtr& key, int uid_index,
@@ -245,7 +245,7 @@ auto GpgUIDOperator::RevokeUID(const GpgKeyPtr& key, int uid_index,
};
auto [err, succ] = auto_.DoInteract(key, next_state_handler, action_handler);
- return err == GPG_ERR_NO_ERROR && !succ;
+ return err == GPG_ERR_NO_ERROR && succ;
}
} // namespace GpgFrontend
diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp
index 56039a15..501c2276 100644
--- a/src/ui/dialog/ADSKsPicker.cpp
+++ b/src/ui/dialog/ADSKsPicker.cpp
@@ -29,6 +29,7 @@
#include "ADSKsPicker.h"
#include "core/function/gpg/GpgKeyOpera.h"
+#include "core/thread/TaskRunnerGetter.h"
#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
#include "ui/widgets/KeyTreeView.h"
@@ -62,8 +63,11 @@ ADSKsPicker::ADSKsPicker(int channel, GpgKeyPtr key,
return;
}
+
+ confirm_button->setDisabled(true);
+ cancel_button->setDisabled(true);
+
slot_add_adsk(tree_view_->GetAllCheckedSubKey());
- accept();
});
connect(cancel_button, &QPushButton::clicked, this, &QDialog::reject);
@@ -99,37 +103,65 @@ ADSKsPicker::ADSKsPicker(int channel, GpgKeyPtr key,
}
void ADSKsPicker::slot_add_adsk(const QContainer<GpgSubKey>& s_keys) {
- QContainer<QString> err_sub_key_infos;
- for (const auto& s_key : s_keys) {
- auto [err, data_object] =
- GpgKeyOpera::GetInstance(channel_).AddADSKSync(key_, s_key);
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue;
-
- err_sub_key_infos.append(tr("Key ID: %1 Reason: %2")
- .arg(s_key.ID())
- .arg(DescribeGpgErrCode(err).second));
- }
-
- if (!err_sub_key_infos.isEmpty()) {
- QStringList failed_info;
- for (const auto& info : err_sub_key_infos) {
- failed_info.append(info);
- }
- auto details = failed_info.join("\n\n");
- auto* msg_box = new QMessageBox(nullptr);
- msg_box->setIcon(QMessageBox::Warning);
- msg_box->setWindowTitle(err_sub_key_infos.size() == s_keys.size()
- ? tr("Failed")
- : tr("Partially Failed"));
- msg_box->setText(err_sub_key_infos.size() == s_keys.size()
- ? tr("Failed to add all selected subkeys.")
- : tr("Some subkeys failed to be added as ADSKs."));
- msg_box->setDetailedText(details);
- msg_box->show();
-
- return;
- }
-
- emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh();
+ auto* task = new Thread::Task(
+ [=, channel = channel_,
+ key = key_](const DataObjectPtr& data_object) -> int {
+ QStringList err_sub_key_infos;
+ for (const auto& s_key : s_keys) {
+ auto [err, _] =
+ GpgKeyOpera::GetInstance(channel).AddADSKSync(key, s_key);
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue;
+
+ err_sub_key_infos.append(tr("Key ID: %1 Reason: %2")
+ .arg(s_key.ID())
+ .arg(DescribeGpgErrCode(err).second));
+ }
+ data_object->Swap({err_sub_key_infos});
+ return 0;
+ },
+ "add_adsk", TransferParams(),
+ [=, self = QPointer<ADSKsPicker>(this)](
+ int ret, const DataObjectPtr& data_object) {
+ if (ret < 0) {
+ QMessageBox::critical(
+ self, tr("Unknown Error"),
+ tr("Caught unknown error while exporting the key."));
+ return;
+ }
+
+ if (!data_object->Check<QStringList>()) return;
+ auto err_sub_key_infos = ExtractParams<QStringList>(data_object, 0);
+
+ if (!err_sub_key_infos.isEmpty()) {
+ QStringList failed_info;
+ for (const auto& info : err_sub_key_infos) {
+ failed_info.append(info);
+ }
+ auto details = failed_info.join("\n\n");
+
+ auto* msg_box = new QMessageBox(self);
+ msg_box->setIcon(QMessageBox::Warning);
+ msg_box->setWindowTitle(err_sub_key_infos.size() == s_keys.size()
+ ? tr("Failed")
+ : tr("Partially Failed"));
+ msg_box->setText(
+ err_sub_key_infos.size() == s_keys.size()
+ ? tr("Failed to add all selected subkeys.")
+ : tr("Some subkeys failed to be added as ADSKs."));
+ msg_box->setDetailedText(details);
+ msg_box->exec();
+ }
+
+ emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh();
+
+ if (self != nullptr) {
+ self->accept();
+ self->close();
+ }
+ });
+
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
+ ->PostTask(task);
}
} // namespace GpgFrontend::UI