feat: let user select keys to sync from key server

This commit is contained in:
saturneric 2024-05-11 15:42:53 +02:00
parent 50c8b159eb
commit a236f22b15
4 changed files with 58 additions and 17 deletions

View File

@ -78,7 +78,7 @@ SignersPicker::SignersPicker(QWidget* parent)
}
auto SignersPicker::GetCheckedSigners() -> GpgFrontend::KeyIdArgsListPtr {
return key_list_->GetPrivateChecked();
return key_list_->GetCheckedPrivateKey();
}
auto SignersPicker::GetStatus() const -> bool { return this->accepted_; }

View File

@ -141,7 +141,7 @@ void MainWindow::SlotEncrypt() {
void MainWindow::SlotSign() {
if (edit_->SlotCurPageTextEdit() == nullptr) return;
auto key_ids = m_key_list_->GetPrivateChecked();
auto key_ids = m_key_list_->GetCheckedPrivateKey();
if (key_ids->empty()) {
QMessageBox::critical(
this, tr("No Key Checked"),

View File

@ -231,7 +231,7 @@ auto KeyList::GetAllPrivateKeys() -> KeyIdArgsListPtr {
return ret;
}
auto KeyList::GetPrivateChecked() -> KeyIdArgsListPtr {
auto KeyList::GetCheckedPrivateKey() -> KeyIdArgsListPtr {
auto ret = std::make_unique<KeyIdArgsList>();
if (ui_->keyGroupTab->size().isEmpty()) return ret;
@ -242,7 +242,27 @@ auto KeyList::GetPrivateChecked() -> KeyIdArgsListPtr {
for (int i = 0; i < key_list->rowCount(); i++) {
if ((key_list->item(i, 0)->checkState() == Qt::Checked) &&
((key_list->item(i, 1)) != nullptr)) {
((key_list->item(i, 1)) != nullptr) &&
buffered_keys[i].IsPrivateKey()) {
ret->push_back(buffered_keys[i].GetId());
}
}
return ret;
}
auto KeyList::GetCheckedPublicKey() -> KeyIdArgsListPtr {
auto ret = std::make_unique<KeyIdArgsList>();
if (ui_->keyGroupTab->size().isEmpty()) return ret;
auto* key_list =
qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget());
const auto& buffered_keys =
m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_;
for (int i = 0; i < key_list->rowCount(); i++) {
if ((key_list->item(i, 0)->checkState() == Qt::Checked) &&
((key_list->item(i, 1)) != nullptr) &&
!buffered_keys[i].IsPrivateKey()) {
ret->push_back(buffered_keys[i].GetId());
}
}
@ -458,14 +478,28 @@ void KeyList::slot_refresh_ui() {
}
void KeyList::slot_sync_with_key_server() {
auto checked_public_keys = GetCheckedPublicKey();
KeyIdArgsList key_ids;
{
std::lock_guard<std::mutex> guard(buffered_key_list_mutex_);
for (const auto& key : *buffered_keys_list_) {
if (!(key.IsPrivateKey() && key.IsHasMasterKey())) {
key_ids.push_back(key.GetId());
if (checked_public_keys->empty()) {
QMessageBox::StandardButton const reply = QMessageBox::question(
this, QCoreApplication::tr("Sync All Public Key"),
QCoreApplication::tr("You have not checked any public keys that you "
"want to synchronize, do you want to synchronize "
"all public keys from the key server?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::No) return;
{
std::lock_guard<std::mutex> guard(buffered_key_list_mutex_);
for (const auto& key : *buffered_keys_list_) {
if (!(key.IsPrivateKey() && key.IsHasMasterKey())) {
key_ids.push_back(key.GetId());
}
}
}
} else {
key_ids = *checked_public_keys;
}
if (key_ids.empty()) return;

View File

@ -188,7 +188,7 @@ class KeyList : public QWidget {
const QString& name, const QString& id,
KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::InfoType infoType = KeyListColumn::ALL,
const KeyTable::KeyTableFilter filter =
KeyTable::KeyTableFilter filter =
[](const GpgKey&, const KeyTable&) -> bool { return true; });
/**
@ -225,7 +225,7 @@ class KeyList : public QWidget {
*
* @return KeyIdArgsListPtr
*/
KeyIdArgsListPtr GetChecked();
auto GetChecked() -> KeyIdArgsListPtr;
/**
* @brief Get the Checked object
@ -233,21 +233,28 @@ class KeyList : public QWidget {
* @param key_table
* @return KeyIdArgsListPtr
*/
static KeyIdArgsListPtr GetChecked(const KeyTable& key_table);
static auto GetChecked(const KeyTable& key_table) -> KeyIdArgsListPtr;
/**
* @brief Get the Private Checked object
*
* @return KeyIdArgsListPtr
*/
KeyIdArgsListPtr GetPrivateChecked();
auto GetCheckedPrivateKey() -> KeyIdArgsListPtr;
/**
* @brief
*
* @return KeyIdArgsListPtr
*/
auto GetCheckedPublicKey() -> KeyIdArgsListPtr;
/**
* @brief Get the All Private Keys object
*
* @return KeyIdArgsListPtr
*/
KeyIdArgsListPtr GetAllPrivateKeys();
auto GetAllPrivateKeys() -> KeyIdArgsListPtr;
/**
* @brief Set the Checked object
@ -270,14 +277,14 @@ class KeyList : public QWidget {
*
* @return KeyIdArgsListPtr
*/
KeyIdArgsListPtr GetSelected();
auto GetSelected() -> KeyIdArgsListPtr;
/**
* @brief Get the Selected Key object
*
* @return QString
*/
QString GetSelectedKey();
auto GetSelectedKey() -> QString;
/**
* @brief
@ -285,7 +292,7 @@ class KeyList : public QWidget {
* @return true
* @return false
*/
[[maybe_unused]] bool ContainsPrivateKeys();
[[maybe_unused]] auto ContainsPrivateKeys() -> bool;
signals:
/**