diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-22 18:51:12 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-03-29 22:22:25 +0000 |
| commit | b1ad938c37f4e175e5509f727d1033b074b134d4 (patch) | |
| tree | 702b41a851550c14104599905907fa659c0d39b7 /src/widgets/aooptionsdialog.cpp | |
| parent | 4274f5036004ae6d3db0e88c8e28eb78c6e37d27 (diff) | |
Integrate the keyring into UI
Add "Keyring" tab to the options dialog. The tab displays the keys from
the table model (notes and certificates) and lets users create and
delete keys.
Key generation dialog includes passphare confirmation and a note.
Diffstat (limited to 'src/widgets/aooptionsdialog.cpp')
| -rw-r--r-- | src/widgets/aooptionsdialog.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/widgets/aooptionsdialog.cpp b/src/widgets/aooptionsdialog.cpp index 760dccf..d9cbcb8 100644 --- a/src/widgets/aooptionsdialog.cpp +++ b/src/widgets/aooptionsdialog.cpp @@ -8,10 +8,13 @@ #include "networkmanager.h" #include "options.h" +// Hopefully temporary. +#include "widgets/key_generate_dialog.h" #include <QCollator> #include <QDoubleSpinBox> #include <QGroupBox> +#include <QHeaderView> #include <QResource> #include <QUiLoader> #include <QVBoxLayout> @@ -594,7 +597,49 @@ void AOOptionsDialog::setupUI() FROM_UI(QTextBrowser, privacy_policy); ui_privacy_policy->setPlainText(tr("Getting privacy policy...")); FROM_UI(QCheckBox, privacy_optout_cb); - registerOption<QCheckBox, bool>("privacy_optout", &Options::playerCountOptout, &Options::setPlayerCountOptout); + registerOption<QCheckBox, bool>("privacy_optout_cb", &Options::playerCountOptout, &Options::setPlayerCountOptout); + + // Keyring tab + + FROM_UI(QPushButton, key_generate); + connect(ui_key_generate, &QPushButton::clicked, this, [=, this] { + // this should be coupled + KeyGenerateDialog keygen_dialog(this); + if (keygen_dialog.exec() == QDialog::Accepted) + { + int err = generate_key(keygen_dialog.key_name(), keygen_dialog.key_password()); + if (err) + { + QMessageBox::warning(this, "Error", QString("Key generation failed, code %1").arg(err)); + } + ao_app->keyring_model.load_keys(); + } + }); + FROM_UI(QPushButton, key_delete); + + FROM_UI(QTableView, keyring_table); + ui_keyring_table->setModel(&ao_app->keyring_model); + ui_keyring_table->setSelectionMode(QAbstractItemView::SingleSelection); + ui_keyring_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + // This assumes something is selected, and emptiness of selection is thus + // unchecked. + connect(ui_key_delete, &QPushButton::clicked, this, [=, this] { + int row = ui_keyring_table->selectionModel()->selectedIndexes().first().row(); + QString key_note = ao_app->keyring_model.data(ao_app->keyring_model.index(row, 0)).toString(); + QString del_text = QString("Are you sure you want to delete the key pair \"%1\"? If it's an active key that you use to authenticate on a server, and you want to delete it due to suspected compromise (or otherwise want it to never be used for authentication by anyone), revoke it on the server first.").arg(key_note); + if (QMessageBox::question(this, "Confirm deletion", del_text, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) + { + QByteArray key_id = ao_app->keyring_model.data(ao_app->keyring_model.index(row, 0), 0x0100).toByteArray(); + delete_key(key_id); + ao_app->keyring_model.load_keys(); + } + }); + + connect(ui_keyring_table->selectionModel(), &QItemSelectionModel::selectionChanged, this, [=, this] { + bool selected = !ui_keyring_table->selectionModel()->selectedIndexes().isEmpty(); + ui_key_delete->setEnabled(selected); + }); updateValues(); } |
