13#include <QtCore/QDateTime>
14#include <QtCore/QJsonObject>
15#include <QtCore/QJsonValue>
17#include <QtCore/QList>
18#include <QtCore/QMutex>
19#include <QtCore/QString>
20#include <QtCore/QStringList>
21#include <QtQml/QQmlAbstractUrlInterceptor>
48namespace QmlTemplates {
65QList<Trust::TrustedFile>
trusted(
const QList<TrustFile> &files);
118std::optional<Header>
parseHeader(
const QString &qml, QString *error);
144 bool check(
const QString &path) {
return check(path,
true); }
150 QUrl
intercept(
const QUrl &path, DataType type)
override;
154 bool check(
const QString &path,
bool record);
196bool checkName(
const QString &name,
bool component, QString *error);
199QString
untrustedReply(
const QString &templateName,
const QList<TrustFile> &files,
206 std::function<bool(
const QByteArray &,
const QString &, QString *)>
compiles;
A value of type T, or an error of type E, as std::expected.
Definition expected.h:106
Lets the application ask its own user to trust a QML template.
Definition qmltemplatetrust.h:108
Checks every file the QML engine loads from a library against the trust store.
Definition qmltemplates_p.h:133
bool check(const QString &path)
Checks path now, as intercept() would, recording it if it isn't trusted.
Definition qmltemplates_p.h:144
QUrl intercept(const QUrl &path, DataType type) override
See QQmlAbstractUrlInterceptor.
Definition qmltemplates.cpp:519
QList< TrustFile > m_untrusted
What was refused since begin().
Definition qmltemplates_p.h:159
bool m_active
Whether files are checked.
Definition qmltemplates_p.h:157
Locations m_where
The libraries and store being checked against.
Definition qmltemplates_p.h:158
QList< TrustFile > untrusted() const
The untrusted files recorded since begin().
Definition qmltemplates.cpp:468
void end()
Stops checking (for compiling a template before it is saved).
Definition qmltemplates.cpp:462
void begin(const Locations &where)
Starts checking, for the libraries and store in where; clears the record.
Definition qmltemplates.cpp:452
bool isTrusted(const QString &path)
Whether path is trusted, without recording it (looking for a file that may be passed over,...
Definition qmltemplates_p.h:147
QMutex m_mutex
Guards everything below.
Definition qmltemplates_p.h:156
An embeddable Model Context Protocol server.
Definition server.h:92
A request's shared state; TrustRequest is a handle to it.
Definition qmltemplates_p.h:30
static TrustRequest create(const QString &templateName, const QList< TrustFile > &files, Answer answer)
Creates a request for files of templateName, answered through answer.
Definition qmltemplates.cpp:27
QList< TrustFile > files
See TrustRequest::files().
Definition qmltemplates_p.h:44
static void ask(const QmlTemplateTrust *trust, const TrustRequest &request)
Gives request to trust's approval, if it has one.
Definition qmltemplates.cpp:89
std::function< void(bool granted, TrustScope scope)> Answer
The answer: whether the user granted, and where.
Definition qmltemplates_p.h:33
static void expire(const TrustRequest &request)
Answers request (if it wasn't yet), without calling its answer function.
Definition qmltemplates.cpp:37
Answer answer
Called once, by the first grant() or deny(); empty once answered.
Definition qmltemplates_p.h:45
QString templateName
See TrustRequest::templateName().
Definition qmltemplates_p.h:43
A pending request for trust, from ui_open.
Definition qmltemplatetrust.h:53
The trust store: which file contents the user trusts, and where.
Definition trust_p.h:102
Sonde::Expected, Sonde::Unexpected and Sonde::Error: results that are a value or an error (design 003...
Embeddable Model Context Protocol server for Qt applications.
Definition dispatch.cpp:10
TrustScope
Where a grant of trust applies.
Definition qmltemplatetrust.h:19
std::optional< LibraryFile > readCompiledFile(const CompiledLibrary &library, const QString &name, bool component)
Reads template or component name of compiled-in library library, if it has one by that name.
Definition qmltemplates.cpp:401
std::optional< LibraryFile > findTemplate(const Locations &where, const QString &name)
Finds template name: in the project library, the user library, then the compiled-in libraries,...
Definition qmltemplates.cpp:419
bool isObjectName(const QString &name)
Whether name can be the name of an object a template is given.
Definition qmltemplates.cpp:304
std::optional< Header > parseHeader(const QString &qml, QString *error)
Reads the header at the top of qml.
Definition qmltemplates.cpp:251
QList< Trust::TrustedFile > trusted(const QList< TrustFile > &files)
files as the trust store records them.
Definition qmltemplates.cpp:442
std::optional< QJsonObject > windowParams(const Header *header, const QJsonObject &given, QString *error)
The settings for a window from header's defaults and the call's given: unknown names and values of an...
Definition qmltemplates.cpp:311
bool isComponentName(const QString &name)
Whether name can be a component's name: a QML type name, at most 64.
Definition qmltemplates.cpp:296
bool checkName(const QString &name, bool component, QString *error)
Checks that name suits a template, or a component if component.
Definition qmltemplates.cpp:551
QString untrustedReply(const QString &templateName, const QList< TrustFile > &files, const Locations &where)
The refusal for files, with the commands that trust them.
Definition qmltemplates.cpp:566
bool isTemplateName(const QString &name)
Whether name can be a template's name: [a-z0-9][a-z0-9-]*, at most 64.
Definition qmltemplates.cpp:290
Locations locate()
Finds the libraries and the trust file now, searching for the project library above the executable,...
Definition qmltemplates.cpp:435
Expected< void > registerCompiledLibrary(const QString &name, const QString &root)
Registers a compiled-in library (addTemplateLibrary()).
Definition qmltemplates.cpp:363
QList< CompiledLibrary > compiledLibraries()
The compiled-in libraries, in the order they are searched: the application's, in the order they were ...
Definition qmltemplates.cpp:356
LibraryFile readLibraryFile(const Locations &where, const QString &name, Library library, bool component)
Reads template or component name of library, with its header and trust.
Definition qmltemplates.cpp:531
void installTemplateTools(Server &server, const TemplateEngine &engine)
Registers ui_template_list, ui_template_save and ui_template_delete (qmltemplatetools....
Definition qmltemplatetools.cpp:357
QString libraryName(Library library)
"project" or "user".
Definition trust.cpp:84
constexpr qsizetype kMaxFileBytes
Most bytes in one template or component.
Definition qmltemplates_p.h:68
Asking the application's user to trust a QML template (design 0023).
Sonde::Server, the embeddable MCP server.
A library compiled into the application as Qt resources: read-only, and needing no trust (design 0034...
Definition qmltemplates_p.h:104
QString root
Its resource directory, such as ":/sonde/instruments".
Definition qmltemplates_p.h:106
QString name
Its name, as ui_template_list shows it.
Definition qmltemplates_p.h:105
A template or component found in a library.
Definition qmltemplates_p.h:164
std::optional< Header > header
A template's header, if it parses.
Definition qmltemplates_p.h:170
QString path
Its file.
Definition qmltemplates_p.h:167
QString compiled
The compiled-in library it is in, or empty for project and user.
Definition qmltemplates_p.h:174
QString libraryLabel() const
The name of its library: "project", "user", or a compiled-in one's.
Definition qmltemplates_p.h:177
QByteArray data
Its content.
Definition qmltemplates_p.h:169
QString name
Template name, or component type name.
Definition qmltemplates_p.h:165
QUrl url() const
The URL the engine loads it from.
Definition qmltemplates.cpp:394
QString headerError
Why a template's header doesn't parse.
Definition qmltemplates_p.h:171
Library library
Which library it is in.
Definition qmltemplates_p.h:166
bool component
Whether it is a component.
Definition qmltemplates_p.h:168
bool hidden
A template hidden by one of the same name in an earlier library.
Definition qmltemplates_p.h:173
QString untrusted
Why it isn't trusted here; empty if it is.
Definition qmltemplates_p.h:172
An object a template expects, from its header.
Definition qmltemplates_p.h:72
bool optional
Whether it may be missing (then it is null).
Definition qmltemplates_p.h:75
QString name
The context property's name.
Definition qmltemplates_p.h:73
QString spec
The default object spec.
Definition qmltemplates_p.h:74
A setting a template declares, from its header (design 0034).
Definition qmltemplates_p.h:80
QString description
What it is for; may be empty.
Definition qmltemplates_p.h:83
QString name
The setting's name, as sonde.params has it.
Definition qmltemplates_p.h:81
QJsonValue defaultValue
Its default; its JSON type is the setting's type.
Definition qmltemplates_p.h:82
What the template tools need from ui_open's windows (qmlwindowtools.cpp).
Definition qmltemplates_p.h:204
std::function< void()> clearCache
Forgets compiled QML, so the next load reads the files again.
Definition qmltemplates_p.h:208
std::function< bool(const QByteArray &, const QString &, QString *)> compiles
Whether QML compiles as the file at a path would; if not, why, in the third argument.
Definition qmltemplates_p.h:206
Where the libraries and the trust file are.
Definition trust_p.h:38
QString libraryName(Library library)
"project" or "user".
Definition trust.cpp:84
QString sha256(const QByteArray &data)
The SHA-256 of data, in hex.
Definition trust.cpp:162
QString canonicalOrClean(const QString &path)
path made canonical if it exists, otherwise only absolute and clean.
Definition trust.cpp:105
QString filePath(const QString &directory, const QString &name, bool component)
The file of template or component name in directory.
Definition trust.cpp:156
Private: where the QML template libraries and the trust file are, and the trust store (designs 0023 a...
Library
The two libraries.
Definition trust_p.h:20
@ Project
.sonde/qml/ in the checkout.
Definition trust_p.h:21