Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows Class Reference

The windows ui_open opened, their engine, and the tools' logic. More...

Inheritance diagram for Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows:

Public Member Functions

 QmlWindows (Server *server)
 State for server's tools (a child of the server).
 ~QmlWindows () override
 Closes every window before the engine (a child) goes.
TemplateEngine templateEngine ()
 What the template tools need: compiling as a file would, and clearing the cache.
QmlTemplateTrust * trust () const
 The object that asks the application's user for trust.
void open (const ToolCall &call)
 The ui_open tool.
ToolResult close (const QJsonObject &args)
 The ui_close tool.

Private Member Functions

QQmlEngine * engine ()
 The engine the windows run in, created on first use, with the library guard.
void clearCache ()
 Forgets compiled QML, so the next load reads the files (and checks them) again.
bool compiles (const QByteArray &data, const QString &path, QString *error)
 Compiles data as the file path would be, without creating it.
void openTemplate (const ToolCall &call, int round)
 ui_open with a template; round counts the trust requests so far.
void askForTrust (const ToolCall &call, const QList< TrustFile > &files, int round)
 Asks the application's user to trust files, or refuses the call.
ToolResult openWindow (const QJsonObject &args, const QmlSource &source, const QList< WindowObject > &objects, const QJsonObject &params, QList< TrustFile > *untrusted)
 Creates and shows a window from source.
qsizetype indexOf (const QString &spec, QString *error) const
 The index of the window named by spec (id, title or objectName) among ours, or -1 with error set.
qsizetype replacedIndex (const QJsonObject &args, QString *error) const
 The index of the window the "replace" argument names, -1 if none (with error set if invalid).
QUrl findVisualiser (const QString &typeName)
 The first components/values/<type>.qml for values of type typeName in the project, user and compiled-in libraries; a file on disk only if it is trusted.
QObject * create (const QmlSource &source, QQmlContext *context, QString *error)
 Compiles and creates source in context.
void show (QQuickWindow *w, const QJsonObject &args, const QString &defaultTitle)
 Applies the title, size and flags, sets the transient parent, and shows w.
void forget (const QQuickWindow *window)
 Forgets the window window (closed by the user) and deletes it later.

Static Private Member Functions

static std::optional< QList< WindowObject > > windowObjects (const QJsonObject &objects, const QList< ObjectSlot > &defaults, QString *error)
 The objects to give a window: defaults (a template's), replaced or added to by the call's objects.
static Expected< void > addObjects (const QList< WindowObject > &objects, OpenWindow *w, QStringList *missing, QVariantMap *byName)
 Makes objects context properties of w; optional ones not found are null and listed in missing.
static QQuickWindow * windowFor (QObject *root)
 The window to show for root: root itself, or a new window holding the Item.
static QWindow * applicationWindow ()
 The application's own main or focused window (not one of ours), or nullptr.
static ToolResult reply (const OpenWindow &w, const QStringList &notes, const QStringList &warnings)
 The reply to ui_open.
static void destroy (const OpenWindow &w)
 Destroys w's window (and with it the QML objects) and context.

Private Attributes

Server * m_server
 The server whose event sources the windows see.
QmlEventBridge * m_bridge
 The sonde context property (a child).
QmlTemplateTrust * m_trust
 Asks the application's user for trust (a child of the server).
LibraryGuard m_guard
 Checks library files as the engine loads them.
QQmlEngine * m_engine = nullptr
 Engine for the windows (a child), created on first use.
QList< OpenWindow > m_windows
 Open windows, oldest first.
QTimer m_followTimer
 Picks up event sources added later, while windows are open.
int m_created = 0
 Windows created so far, for names.

Detailed Description

The windows ui_open opened, their engine, and the tools' logic.

Member Function Documentation

◆ addObjects()

Expected< void > Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows::addObjects ( const QList< WindowObject > & objects,
OpenWindow * w,
QStringList * missing,
QVariantMap * byName )
inlinestaticprivate

Makes objects context properties of w; optional ones not found are null and listed in missing.

Returns
A failure if a required one isn't found.

◆ create()

QObject * Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows::create ( const QmlSource & source,
QQmlContext * context,
QString * error )
inlineprivate

Compiles and creates source in context.

Returns
The root object, or nullptr with error set.

◆ findVisualiser()

QUrl Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows::findVisualiser ( const QString & typeName)
inlineprivate

The first components/values/<type>.qml for values of type typeName in the project, user and compiled-in libraries; a file on disk only if it is trusted.

An empty URL if there is none (design 0034).

◆ openWindow()

ToolResult Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows::openWindow ( const QJsonObject & args,
const QmlSource & source,
const QList< WindowObject > & objects,
const QJsonObject & params,
QList< TrustFile > * untrusted )
inlineprivate

Creates and shows a window from source.

If a library file it loads isn't trusted, creates nothing and returns those files in untrusted.

◆ windowObjects()

std::optional< QList< WindowObject > > Sonde::anonymous_namespace{qmlwindowtools.cpp}::QmlWindows::windowObjects ( const QJsonObject & objects,
const QList< ObjectSlot > & defaults,
QString * error )
inlinestaticprivate

The objects to give a window: defaults (a template's), replaced or added to by the call's objects.

Nothing, with error set, if one is invalid.


The documentation for this class was generated from the following file: