aboutsummaryrefslogtreecommitdiffstats
path: root/src/m_key_server_sync/KeyServerList.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2026-09-23 23:07:07 +0200
committersaturneric <[email protected]>2026-09-23 23:07:07 +0200
commitd06e0d6f50afbb8254fa228e03befcaac4511ad2 (patch)
tree0f9a1a8139b9f7c8fec5552484dcc69a99c0e760 /src/m_key_server_sync/KeyServerList.cpp
parentfeat(gpg-info): expose GnuPG details through scripted UI (diff)
downloadmodules-d06e0d6f50afbb8254fa228e03befcaac4511ad2.tar.gz
modules-d06e0d6f50afbb8254fa228e03befcaac4511ad2.zip
feat(ui): migrate modules to command mounts
- replace legacy menu and settings events with typed commands - add Lua scripts for module UI placement and native widget mounts - migrate key server, inspector, and update dialogs to host-owned views - route module settings through storage capabilities - update lifecycle hooks, event manifests, and widget interfaces - fix key server task cleanup and theme color resolution
Diffstat (limited to 'src/m_key_server_sync/KeyServerList.cpp')
-rw-r--r--src/m_key_server_sync/KeyServerList.cpp64
1 files changed, 22 insertions, 42 deletions
diff --git a/src/m_key_server_sync/KeyServerList.cpp b/src/m_key_server_sync/KeyServerList.cpp
index b4267d7..160d57c 100644
--- a/src/m_key_server_sync/KeyServerList.cpp
+++ b/src/m_key_server_sync/KeyServerList.cpp
@@ -32,28 +32,32 @@
#include <QJsonDocument>
#include <QMutex>
#include <QMutexLocker>
-#include <QSettings>
#include "GFModule.h"
#include "GFSDKUI.h"
namespace {
-constexpr auto kSchemaVersionKey = "key_server_sync/schema_version";
-constexpr auto kServersKey = "key_server_sync/servers";
-constexpr auto kDefaultServerKey = "key_server_sync/default_server";
+// Relative: the Host places them in this module's own settings group, which
+// is where they always were ("key_server_sync/..."), so nothing moves.
+constexpr auto kSchemaVersionKey = "schema_version";
+constexpr auto kServersKey = "servers";
+constexpr auto kDefaultServerKey = "default_server";
constexpr auto kSchemaVersion = 1;
constexpr auto kOpenPGPServer = "https://keys.openpgp.org";
-/// The settings object is shared with the host and with the network task
-/// runner, and QSettings is only reentrant, so every read-modify-write of our
-/// keys has to be serialized.
+/// A read-modify-write of the list is two calls; the mutex keeps two of this
+/// module's own threads from interleaving them. Every call reaches the Host's
+/// settings through the storage capability -- no settings object is shared.
Q_GLOBAL_STATIC(QMutex, settings_mutex)
-auto GlobalSettings() -> QSettings* {
- return qobject_cast<QSettings*>(
- static_cast<QObject*>(GFStorageSettingsRoot(GFModuleSdkContext())));
+auto Get(const char* key) -> QVariant {
+ return gf::sdk::Setting(GFModuleSdkContext(), GF_SETTING_MODULE, key);
+}
+
+void Put(const char* key, const QVariant& value) {
+ gf::sdk::SetSetting(GFModuleSdkContext(), GF_SETTING_MODULE, key, value);
}
/**
@@ -92,10 +96,7 @@ auto ResolveDefaultUrl(const QList<KeyServerEntry>& entries) -> QString {
QString stored;
{
QMutexLocker locker(settings_mutex());
- auto* settings = GlobalSettings();
- if (settings != nullptr) {
- stored = settings->value(kDefaultServerKey).toString();
- }
+ stored = Get(kDefaultServerKey).toString();
}
const auto listed = std::any_of(
@@ -155,18 +156,8 @@ namespace KeyServerList {
auto Load() -> QList<KeyServerEntry> {
QMutexLocker locker(settings_mutex());
- auto* settings = GlobalSettings();
- if (settings == nullptr) {
- LOG_ERROR("global settings unavailable, falling back to seed key servers");
- return SeedEntries();
- }
-
- // The host writes through its own short-lived QSettings objects, and this one
- // outlives them all; without a sync it would keep serving whatever it read at
- // startup.
- settings->sync();
-
- if (!settings->contains(kServersKey)) {
+ const auto stored = Get(kServersKey);
+ if (!stored.isValid()) {
locker.unlock();
auto seed = SeedEntries();
Store(seed, kOpenPGPServer);
@@ -174,7 +165,7 @@ auto Load() -> QList<KeyServerEntry> {
}
const auto document =
- QJsonDocument::fromJson(settings->value(kServersKey).toString().toUtf8());
+ QJsonDocument::fromJson(stored.toString().toUtf8());
QList<KeyServerEntry> entries;
if (document.isArray()) {
@@ -202,12 +193,6 @@ auto Load() -> QList<KeyServerEntry> {
void Store(const QList<KeyServerEntry>& entries, const QString& default_url) {
QMutexLocker locker(settings_mutex());
- auto* settings = GlobalSettings();
- if (settings == nullptr) {
- LOG_ERROR("global settings unavailable, key server list not stored");
- return;
- }
-
QJsonArray array;
for (const auto& entry : entries) {
if (entry.url.isEmpty()) continue;
@@ -225,15 +210,10 @@ void Store(const QList<KeyServerEntry>& entries, const QString& default_url) {
resolved_default = entries.isEmpty() ? QString() : entries.first().url;
}
- settings->setValue(kSchemaVersionKey, kSchemaVersion);
- settings->setValue(
- kServersKey,
- QString::fromUtf8(QJsonDocument(array).toJson(QJsonDocument::Compact)));
- settings->setValue(kDefaultServerKey, resolved_default);
-
- // Our QSettings is a different object from the host's, so without this the
- // host would keep reading the previous values.
- settings->sync();
+ Put(kSchemaVersionKey, kSchemaVersion);
+ Put(kServersKey, QString::fromUtf8(
+ QJsonDocument(array).toJson(QJsonDocument::Compact)));
+ Put(kDefaultServerKey, resolved_default);
}
auto DefaultUrl() -> QString { return ResolveDefaultUrl(Load()); }