Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::QmlTemplateTrust Class Reference

Lets the application ask its own user to trust a QML template. More...

#include <qmltemplatetrust.h>

Inheritance diagram for Sonde::QmlTemplateTrust:

Public Member Functions

 QmlTemplateTrust (QObject *parent=nullptr)
 Created by installQmlWindowTools(), as a child of the server.
 ~QmlTemplateTrust () override
 Destroys it.
void setTrustApproval (TrustApproval approval)
 Asks approval, on the server's thread, when a template needs the user's trust before it can open (design 0033 made this a handler: exactly one decides).
bool hasApproval () const
 Whether an approval is set, so a request would reach the user.

Private Attributes

TrustApproval m_approval
 Asked for each request; empty if none.

Friends

class TrustRequestPrivate

Detailed Description

Lets the application ask its own user to trust a QML template.

installQmlWindowTools() returns it. When ui_open is asked to open a template whose files aren't trusted, and an approval is set (setTrustApproval()), the call waits (up to two minutes) for the request to be answered. Without one, the call fails at once and tells the client to have the user run sonde trust.

How to ask is the application's choice: a dialog, a banner. Show the files' sources, or their paths, so the user can read what they trust. The agent can see and click such a dialog like any other window (design 0023 says why that is not guarded against). Debug builds only, like the rest of the QML window tools.

auto *trust = Sonde::installQmlWindowTools(server);
trust->setTrustApproval([window](const Sonde::TrustRequest &request) {
QStringList lines;
for (const Sonde::TrustFile &f : request.files())
lines << f.path + " (" + f.reason + ")";
const auto answer = QMessageBox::question(window, "Trust this QML?", lines.join('\n'));
answer == QMessageBox::Yes ? request.grant() : request.deny();
});
A pending request for trust, from ui_open.
Definition qmltemplatetrust.h:53
QList< TrustFile > files() const
The files that need trust: the template, or a component it imports.
Definition qmltemplates.cpp:48
void deny() const
Refuses: the tool call fails, saying the user declined.
Definition qmltemplates.cpp:66
void grant(TrustScope scope=TrustScope::Everywhere) const
Trusts every file in files() and opens the template.
Definition qmltemplates.cpp:58
QmlTemplateTrust * installQmlWindowTools(Server &server)
Registers ui_open, ui_close and the template library tools (ui_template_list, ui_template_save,...
Definition qmlwindowtools.cpp:950
One file that needs the user's trust before a template can open, and why.
Definition qmltemplatetrust.h:29

Member Function Documentation

◆ setTrustApproval()

void Sonde::QmlTemplateTrust::setTrustApproval ( TrustApproval approval)

Asks approval, on the server's thread, when a template needs the user's trust before it can open (design 0033 made this a handler: exactly one decides).

An empty one removes it.


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