The two drawn tab glyphs were judged not understandable enough; the switcher goes to the wide policy with titles only, and the glyphs, their gresource entries and the icon-naming code are removed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2026 Martino Ferrari
|
|
|
|
#pragma once
|
|
|
|
#include "source/data_source.hpp"
|
|
#include "source/source_config.hpp"
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace udpscope {
|
|
|
|
/// A kind's configuration UI, as pieces the chooser places in its own group. The widgets are
|
|
/// floating `AdwPreferencesRow`s; the closures capture them, so a form must not outlive its rows
|
|
/// (the chooser drops the form when it removes the rows).
|
|
struct ConfigForm {
|
|
std::vector<GtkWidget*> rows;
|
|
/// Shown under the group's title; empty for none.
|
|
std::string description;
|
|
/// The widget that takes focus when the form is shown; may be null.
|
|
GtkWidget* focus = nullptr;
|
|
/// Puts `cfg` into the widgets (absent keys leave the kind's defaults).
|
|
std::function<void(const SourceConfig&)> write;
|
|
/// The widgets as a `SourceConfig`.
|
|
std::function<SourceConfig()> read;
|
|
/// Whether the form is complete enough to connect.
|
|
std::function<bool()> valid;
|
|
/// Calls `fn` whenever any widget changes.
|
|
std::function<void(std::function<void()>)> on_change;
|
|
};
|
|
|
|
/// A capability panel (signal generator, digital I/O, ...) for the side area.
|
|
struct SourcePanel {
|
|
std::string id; ///< stack page name
|
|
std::string title;
|
|
GtkWidget* widget = nullptr;
|
|
};
|
|
|
|
/// One plugin type: its identity, factory and UI.
|
|
class SourceKind {
|
|
public:
|
|
virtual ~SourceKind() = default;
|
|
virtual std::string id() const = 0; ///< short, `[a-z0-9]+`; the CLI and session name
|
|
virtual std::string display_name() const = 0;
|
|
/// A stable, human-readable name for one configured source (`host:port`, a serial number).
|
|
virtual std::string identity(const SourceConfig& cfg) const = 0;
|
|
virtual std::unique_ptr<DataSource> make(const SourceConfig& cfg) const = 0;
|
|
virtual ConfigForm make_config_form() const = 0;
|
|
/// Panels for a live source. The widgets must reach the source only through `post()`.
|
|
virtual std::vector<SourcePanel> make_panels(DataSource& source) const {
|
|
(void)source;
|
|
return {};
|
|
}
|
|
/// Whether the source reports raw datagrams (enables the packet-capture UI).
|
|
virtual bool has_datagrams() const { return false; }
|
|
};
|
|
|
|
} // namespace udpscope
|