Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
qmltemplatetrust.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <sonde/global.h>
7#include <sonde/sonde_quick_export.h>
8
9#include <QtCore/QList>
10#include <QtCore/QObject>
11#include <QtCore/QString>
12
13#include <functional>
14#include <memory>
15
16namespace Sonde {
17
26
28struct SONDE_QUICK_EXPORT TrustFile
29{
32 QString name;
34 QString path;
37 QString reason;
39 QString sha256;
41 QString source;
42};
43
45
52class SONDE_QUICK_EXPORT TrustRequest
53{
54public:
56 TrustRequest() = default;
57
59 bool isValid() const { return d != nullptr; }
61 QString templateName() const;
63 QList<TrustFile> files() const;
65 bool isAnswered() const;
66
69 void grant(TrustScope scope = TrustScope::Everywhere) const;
71 void deny() const;
72
73private:
74 friend class TrustRequestPrivate;
76 explicit TrustRequest(std::shared_ptr<TrustRequestPrivate> state) : d(std::move(state)) { }
77 std::shared_ptr<TrustRequestPrivate> d;
78};
79
82using TrustApproval = std::function<void(const TrustRequest &request)>;
83
107class SONDE_QUICK_EXPORT QmlTemplateTrust : public QObject
108{
109 Q_OBJECT
110public:
112 explicit QmlTemplateTrust(QObject *parent = nullptr);
115
119 void setTrustApproval(TrustApproval approval);
121 bool hasApproval() const;
122
123private:
124 friend class TrustRequestPrivate;
126};
127
128} // namespace Sonde
~QmlTemplateTrust() override
Destroys it.
QmlTemplateTrust(QObject *parent=nullptr)
Created by installQmlWindowTools(), as a child of the server.
Definition qmltemplates.cpp:74
bool hasApproval() const
Whether an approval is set, so a request would reach the user.
Definition qmltemplates.cpp:84
TrustApproval m_approval
Asked for each request; empty if none.
Definition qmltemplatetrust.h:125
void setTrustApproval(TrustApproval approval)
Asks approval, on the server's thread, when a template needs the user's trust before it can open (des...
Definition qmltemplates.cpp:78
A request's shared state; TrustRequest is a handle to it.
Definition qmltemplates_p.h:30
A pending request for trust, from ui_open.
Definition qmltemplatetrust.h:53
TrustRequest()=default
An invalid request; every operation on it does nothing.
bool isValid() const
Whether this refers to a request.
Definition qmltemplatetrust.h:59
std::shared_ptr< TrustRequestPrivate > d
Shared request state.
Definition qmltemplatetrust.h:77
TrustRequest(std::shared_ptr< TrustRequestPrivate > state)
Wraps the shared state (created by the QML window tools).
Definition qmltemplatetrust.h:76
What every Sonde header includes: the version, and the deprecation macros (design 0031).
Embeddable Model Context Protocol server for Qt applications.
Definition dispatch.cpp:10
TrustScope
Where a grant of trust applies.
Definition qmltemplatetrust.h:19
@ Everywhere
The file's content is trusted in every checkout and project, as sonde trust records it.
Definition qmltemplatetrust.h:22
@ ThisCheckout
Only in this application's checkout (the directory that holds .sonde/).
Definition qmltemplatetrust.h:24
std::function< void(const TrustRequest &request)> TrustApproval
Decides about a request for trust: calls grant() or deny() on request, at once or later (after asking...
Definition qmltemplatetrust.h:82
One file that needs the user's trust before a template can open, and why.
Definition qmltemplatetrust.h:29
QString name
The template's name ("frame-times"), or the file's path in its library ("components/Plot....
Definition qmltemplatetrust.h:32
QString source
Its content, for showing to the user.
Definition qmltemplatetrust.h:41
QString sha256
The SHA-256 of its content, in hex: what a grant records.
Definition qmltemplatetrust.h:39
QString path
The full path on disk.
Definition qmltemplatetrust.h:34
QString reason
Why it isn't trusted: "new", "changed since you trusted it" or "saved in another checkout".
Definition qmltemplatetrust.h:37