32#include <QSvgRenderer>
34#include "moc_qgsprojecttrustdialog.cpp"
36using namespace Qt::StringLiterals;
39 : QDialog( parent, fl )
44 mButtonBox->button( QDialogButtonBox::StandardButton::YesToAll )->setText( tr(
"Always Trust" ) );
45 mButtonBox->button( QDialogButtonBox::StandardButton::Yes )->setText( tr(
"Trust" ) );
46 mButtonBox->button( QDialogButtonBox::StandardButton::No )->setText( tr(
"Deny" ) );
47 mButtonBox->button( QDialogButtonBox::StandardButton::NoToAll )->setText( tr(
"Always Deny" ) );
49 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsProjectTrustDialog::buttonBoxClicked );
51 connect( mScriptPreviewList, &QListWidget::itemDoubleClicked,
this, [
this]( QListWidgetItem *item ) {
52 const int row = mScriptPreviewList->row( item );
53 if ( row >= 0 && row < mEmbeddedScriptsVisitor.embeddedScripts().size() )
55 mScriptPreviewEditor->setText( mEmbeddedScriptsVisitor.embeddedScripts()[row].script() );
56 mScriptPreviewStackedWidget->setCurrentIndex( 1 );
60 connect( mScriptPreviewBackButton, &QAbstractButton::clicked,
this, [
this] { mScriptPreviewStackedWidget->setCurrentIndex( 0 ); } );
62 mScriptPreviewEditor->setReadOnly(
true );
63 mScriptPreviewEditor->setLineNumbersVisible(
false );
65 QSvgRenderer svg( u
":/images/themes/default/mIconPythonFile.svg"_s );
68 const double maxLength = 64.0;
69 QSizeF size( maxLength, maxLength );
70 const QRectF viewBox = svg.viewBoxF();
71 if ( viewBox.height() > viewBox.width() )
73 size.setWidth( maxLength * viewBox.width() / viewBox.height() );
77 size.setHeight( maxLength * viewBox.height() / viewBox.width() );
80 QPixmap pixmap(
static_cast<int>( maxLength ),
static_cast<int>( maxLength ) );
81 pixmap.fill( Qt::transparent );
84 painter.begin( &pixmap );
85 painter.setRenderHint( QPainter::SmoothPixmapTransform );
86 painter.translate( ( maxLength - size.width() ) / 2, ( maxLength - size.height() ) / 2 );
87 svg.render( &painter, QRectF( 0, 0, size.width(), size.height() ) );
90 mIconLabel->setPixmap( pixmap );
101 mProjectAbsoluteFilePath = projectFileInfo.absoluteFilePath();
102 mProjectAbsolutePath = projectFileInfo.absolutePath();
103 mProjectIsFile =
true;
107 mProjectAbsolutePath = project->
fileName();
108 mProjectIsFile =
false;
113 QFileInfo projectFileInfo( project->
fileName() );
114 mProjectAbsoluteFilePath = projectFileInfo.absoluteFilePath();
115 mProjectAbsolutePath = projectFileInfo.absolutePath();
116 mProjectIsFile =
true;
119 if ( mProjectIsFile )
121 mProjectDetailsLabel->setText( tr(
"The current project file path is ’%1’." ).arg( u
"<b>%1</b>"_s.arg( mProjectAbsoluteFilePath ) ) );
122 QDir dir( mProjectAbsolutePath );
123 mTrustProjectFolderCheckBox->setText( tr(
"Apply decision to all projects in folder ’%1’" ).arg( u
"%1"_s.arg( dir.dirName() ) ) );
127 mProjectDetailsLabel->setText( tr(
"The current project URI is ’%1’." ).arg( u
"<b>%1</b>"_s.arg( mProjectAbsoluteFilePath ) ) );
128 mTrustProjectFolderCheckBox->setVisible(
false );
136 QListWidgetItem *newItem =
new QListWidgetItem( mScriptPreviewList );
137 switch ( scriptDetails.type() )
155 newItem->setText( scriptDetails.name() );
156 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
157 mScriptPreviewList->addItem( newItem );
161void QgsProjectTrustDialog::buttonBoxClicked( QAbstractButton *button )
163 QDialogButtonBox::StandardButton buttonType = mButtonBox->standardButton( button );
164 if ( buttonType == QDialogButtonBox::StandardButton::Help )
170 bool accepted =
false;
171 QString path = !mProjectIsFile || mTrustProjectFolderCheckBox->isChecked() ? mProjectAbsolutePath : mProjectAbsoluteFilePath;
172 if ( !path.isEmpty() )
175 trustedProjectsFolders.removeAll( path );
177 untrustedProjectsFolders.removeAll( path );
180 temporarilyTrustedProjectsFolders.removeAll( path );
182 temporarilyUntrustedProjectsFolders.removeAll( path );
184 if ( buttonType == QDialogButtonBox::StandardButton::YesToAll )
186 trustedProjectsFolders << path;
189 else if ( buttonType == QDialogButtonBox::StandardButton::Yes )
191 temporarilyTrustedProjectsFolders << path;
194 else if ( buttonType == QDialogButtonBox::StandardButton::NoToAll )
196 untrustedProjectsFolders << path;
199 else if ( buttonType == QDialogButtonBox::StandardButton::No )
201 temporarilyUntrustedProjectsFolders << path;
205 trustedProjectsFolders.sort();
206 untrustedProjectsFolders.sort();
207 temporarilyTrustedProjectsFolders.sort();
208 temporarilyUntrustedProjectsFolders.sort();
217 done( accepted ? QDialog::Accepted : QDialog::Rejected );
220void QgsProjectTrustDialog::showHelp()
@ Action
Expression functions.
@ FormInitCode
Map layers' action.
@ ExpressionFunction
Project macros.
static void setTemporarilyUntrustedProjectsFolders(const QStringList &untrustedProjectsFolders)
Sets the list of projects and folders that have been temporarily determined as untrusted by the user.
static QgsProjectStorageRegistry * projectStorageRegistry()
Returns registry of available project storage implementations.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QStringList temporarilyTrustedProjectsFolders()
Returns the list of projects and folders that have been temporarily determined as trusted by the user...
static QStringList temporarilyUntrustedProjectsFolders()
Returns the list of projects and folders that have been temporarily determined as untrusted by the us...
static void setTemporarilyTrustedProjectsFolders(const QStringList &trustedProjectsFolders)
Sets the list of projects and folders that have been temporarily determined as trusted by the user.
A embedded script entity for QgsObjectEntityVisitorInterface.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
A QgsObjectEntityVisitorInterface context object.
QgsProjectStorage * projectStorageFromUri(const QString &uri)
Returns storage implementation if the URI matches one. Returns nullptr otherwise (it is a normal file...
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
virtual QString filePath(const QString &uri)
Extracts and returns the file path from a storage backend uri, filesystem-based storage backends shou...
QgsProjectTrustDialog(QgsProject *project, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsProjectTrustDialog using the specified project instance.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
static const QgsSettingsEntryStringList * settingsCodeExecutionTrustedProjectsFolders
Settings entry for projects and folders that are allowed execution of embedded scripts across session...
static const QgsSettingsEntryStringList * settingsCodeExecutionUntrustedProjectsFolders
Settings entry for projects and folders that are denied execution of embedded scripts across sessions...