aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2026-09-22 21:19:01 +0200
committersaturneric <[email protected]>2026-09-22 21:19:01 +0200
commite4f0897a69e81c8f24c50ad86e88fc1a893d530e (patch)
tree8fe2d975369666ecd4759e3c86b2213138c8e647 /src
parentrefactor(key-server-sync): migrate to SDK APIs (diff)
downloadmodules-e4f0897a69e81c8f24c50ad86e88fc1a893d530e.tar.gz
modules-e4f0897a69e81c8f24c50ad86e88fc1a893d530e.zip
refactor(pgp-inspect): migrate to context-aware SDK APIs
- replace deprecated buffer and editor helpers with context-aware APIs - manage returned buffers explicitly without ownership wrappers - format human-readable sizes using a fixed local buffer - use context-aware theme color lookups - declare editor and PGP module capabilities
Diffstat (limited to 'src')
-rw-r--r--src/m_pgp_inspect/PGPInspectDialog.cpp56
-rw-r--r--src/m_pgp_inspect/module.json2
2 files changed, 43 insertions, 15 deletions
diff --git a/src/m_pgp_inspect/PGPInspectDialog.cpp b/src/m_pgp_inspect/PGPInspectDialog.cpp
index e8c58cf..e3bde03 100644
--- a/src/m_pgp_inspect/PGPInspectDialog.cpp
+++ b/src/m_pgp_inspect/PGPInspectDialog.cpp
@@ -37,6 +37,7 @@
#include <QLineEdit>
#include <QTreeWidget>
#include <QVBoxLayout>
+#include <array>
namespace {
@@ -45,18 +46,27 @@ namespace {
constexpr int kLabelColumn = 0;
constexpr int kValueColumn = 1;
-auto HumanSize(qint64 bytes) -> QString { return UDUP(GFUIHumanSize(bytes)); }
+auto HumanSize(qint64 bytes) -> QString {
+ // A pure helper: it writes into the caller's buffer rather than allocating,
+ // so there is no context and nothing to free. 64 bytes is far more than any
+ // formatted size needs.
+ std::array<char, 64> text{};
+ const auto written = GFUIHumanSize(bytes, text.data(), text.size());
+ return written < 0 ? QString() : QString::fromUtf8(text.data(), written);
+}
} // namespace
auto PGPInspectCurrentTabBytes() -> QByteArray {
- auto* content = GFUITakeCurrentEditorContent();
+ auto* content = GFEditorTakeCurrentContent(GFModuleSdkContext());
if (content == nullptr) return {};
- const auto* data = static_cast<const char*>(GFBufferData(content));
- const auto size = static_cast<qsizetype>(GFBufferSize(content));
+ const auto* data =
+ static_cast<const char*>(GFBufferData(GFModuleSdkContext(), content));
+ const auto size =
+ static_cast<qsizetype>(GFBufferSize(GFModuleSdkContext(), content));
auto bytes = QByteArray(data == nullptr ? "" : data, size);
- GFBufferRelease(content);
+ GFBufferRelease(GFModuleSdkContext(), content);
return bytes;
}
@@ -64,16 +74,23 @@ auto PGPInspectBytes(const QByteArray& data) -> PGPInspectDocument {
PGPInspectDocument document;
if (data.isEmpty()) return document;
- auto* buffer =
- GFBufferNewFromBytes(data.constData(), static_cast<size_t>(data.size()));
+ auto* buffer = GFBufferNewFromBytes(GFModuleSdkContext(), data.constData(),
+ static_cast<size_t>(data.size()));
if (buffer == nullptr) return document;
- char* json = nullptr;
- const auto status = GFPgpInspectData(buffer, &json);
- GFBufferRelease(buffer);
+ GFBufferRef json = nullptr;
+ const auto status = GFPgpInspectData(GFModuleSdkContext(), buffer, &json);
+ GFBufferRelease(GFModuleSdkContext(), buffer);
if (status != 0 || json == nullptr) return document;
- return ParsePGPInspectDocument(UDUP(json).toUtf8());
+
+ auto* ctx = GFModuleSdkContext();
+ const auto* text = static_cast<const char*>(GFBufferData(ctx, json));
+ const auto size = static_cast<qsizetype>(GFBufferSize(ctx, json));
+ auto parsed =
+ ParsePGPInspectDocument(QByteArray(text == nullptr ? "" : text, size));
+ GFBufferRelease(ctx, json);
+ return parsed;
}
PGPInspectDialog::PGPInspectDialog(const PGPInspectDocument& document,
@@ -152,9 +169,13 @@ void PGPInspectDialog::render_document() {
add_fields(item, facts);
if (block.has_armor && block.armor.crc24 == QLatin1String("mismatch")) {
- item->setForeground(kLabelColumn, QBrush(QColor(GFUIDangerColor(this))));
+ item->setForeground(
+ kLabelColumn, QBrush(QColor(GFUIThemeColor(
+ GFModuleSdkContext(), GF_UI_COLOR_DANGER, this))));
} else if (!block.error.isEmpty()) {
- item->setForeground(kLabelColumn, QBrush(QColor(GFUIWarningColor(this))));
+ item->setForeground(
+ kLabelColumn, QBrush(QColor(GFUIThemeColor(
+ GFModuleSdkContext(), GF_UI_COLOR_WARNING, this))));
}
add_packets(item, block.packets);
@@ -183,7 +204,9 @@ void PGPInspectDialog::add_packets(QTreeWidgetItem* parent,
item->setText(kLabelColumn, PGPInspectPacketSummary(packet, index++));
if (packet.Malformed()) {
- item->setForeground(kLabelColumn, QBrush(QColor(GFUIWarningColor(this))));
+ item->setForeground(
+ kLabelColumn, QBrush(QColor(GFUIThemeColor(
+ GFModuleSdkContext(), GF_UI_COLOR_WARNING, this))));
}
auto fields = packet.fields;
@@ -203,7 +226,10 @@ void PGPInspectDialog::add_fields(QTreeWidgetItem* parent,
auto* row = new QTreeWidgetItem(parent);
row->setText(kLabelColumn, field.label);
row->setText(kValueColumn, field.value);
- row->setForeground(kLabelColumn, QBrush(QColor(GFUIMutedTextColor(this))));
+ row->setForeground(
+ kLabelColumn,
+ QBrush(QColor(GFUIThemeColor(GFModuleSdkContext(),
+ GF_UI_COLOR_MUTED_TEXT, this))));
}
}
diff --git a/src/m_pgp_inspect/module.json b/src/m_pgp_inspect/module.json
index 92094bf..750b7da 100644
--- a/src/m_pgp_inspect/module.json
+++ b/src/m_pgp_inspect/module.json
@@ -6,6 +6,8 @@
"description": "Inspect the packet structure of any OpenPGP data.",
"author": "Saturneric",
"capabilities": [
+ "editor",
+ "pgp",
"ui"
],
"events": [