From b1ad938c37f4e175e5509f727d1033b074b134d4 Mon Sep 17 00:00:00 2001 From: Osmium Sorcerer Date: Sun, 22 Mar 2026 18:51:12 +0000 Subject: 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. --- src/widgets/aooptionsdialog.cpp | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/widgets/aooptionsdialog.cpp') 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 #include #include +#include #include #include #include @@ -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("privacy_optout", &Options::playerCountOptout, &Options::setPlayerCountOptout); + registerOption("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(); } -- cgit