20 #include <QFileDialog> 22 #include <QPushButton> 39 , mAuthNotifyLayout( nullptr )
40 , mAuthNotify( nullptr )
48 mAuthNotifyLayout->
addWidget( mAuthNotify );
57 connect( teCertText, SIGNAL( textChanged() ),
this, SLOT( validateCertificates() ) );
59 connect( radioImportFile, SIGNAL( toggled(
bool ) ),
this, SLOT( updateGui() ) );
60 connect( radioImportText, SIGNAL( toggled(
bool ) ),
this, SLOT( updateGui() ) );
65 radioImportText->setHidden(
true );
66 teCertText->setHidden(
true );
70 radioImportFile->setHidden(
true );
71 frameImportFile->setHidden(
true );
74 radioImportFile->setChecked(
true );
79 grpbxImportCert->setTitle(
tr(
"Import Certificate Authorities" ) );
84 teValidation->setFocus();
107 if ( !radioImportFile->isChecked() )
110 return leImportFile->text();
119 if ( !radioImportText->isChecked() )
122 return teCertText->toPlainText().
trimmed();
131 return chkAllowInvalid->isChecked();
140 return cmbbxTrust->trustPolicy();
143 void QgsAuthImportCertDialog::updateGui()
145 frameImportFile->setEnabled( radioImportFile->isChecked() );
146 teCertText->setEnabled( radioImportText->isChecked() );
147 validateCertificates();
150 void QgsAuthImportCertDialog::validateCertificates()
153 teValidation->clear();
154 teValidation->setStyleSheet(
"" );
160 bool allowinvalid = chkAllowInvalid->isChecked();
161 bool filterCAs = ( mFilter ==
CaFilter );
164 if ( radioImportFile->isChecked() && !leImportFile->text().isEmpty() )
168 else if ( radioImportText->isChecked() && !teCertText->toPlainText().trimmed().isEmpty() )
173 int certssize = certs.
size();
193 valid = ( certssize > 0
194 && ( allowinvalid || certssize == validcerts )
195 && ( !filterCAs || nixcerts.
size() < certssize ) );
210 teValidation->setStyleSheet(
215 QString msg =
tr(
"Certificates found: %1\n" 216 "Certificates valid: %2" ).
arg( certssize ).
arg( validcerts );
220 msg +=
tr(
"\nAuthorities/Issuers: %1%2" ).
arg( cas )
221 .
arg( !nixcerts.
isEmpty() && nixcerts.
size() < certssize ?
" (others not imported)" :
"" );
224 teValidation->setText( msg );
229 void QgsAuthImportCertDialog::on_btnImportFile_clicked()
231 const QString& fn = getOpenFileName(
tr(
"Open Certificate File" ),
tr(
"PEM (*.pem);;DER (*.der)" ) );
234 leImportFile->setText( fn );
236 validateCertificates();
239 void QgsAuthImportCertDialog::on_chkAllowInvalid_toggled(
bool checked )
242 validateCertificates();
257 settings.
setValue(
"UI/lastAuthImportCertOpenFileDir",
QFileInfo( f ).absoluteDir().path() );
264 return buttonBox->button( QDialogButtonBox::Ok );
static QgsAuthManager * instance()
Enforce singleton pattern.
const QString certTextToImport()
Get certificate text to import.
static QList< QSslCertificate > certsFromFile(const QString &certspath)
Return list of concatenated certs from a PEM or DER formatted file.
static bool certificateIsAuthorityOrIssuer(const QSslCertificate &cert)
Get whether a certificate is an Authority or can at least sign other certificates.
bool allowInvalidCerts()
Whether to allow importation of invalid certificates (so trust policy can be overridden) ...
const QString certFileToImport()
Get the file path to a certificate to import.
QString tr(const char *sourceText, const char *disambiguation, int n)
CertInput
Type of inputs for certificates.
void setValue(const QString &key, const QVariant &value)
QgsAuthCertUtils::CertTrustPolicy certTrustPolicy()
Defined trust policy for imported certificates.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc.
~QgsAuthImportCertDialog()
static QList< QSslCertificate > certsFromString(const QString &pemtext)
Return list of concatenated certs from a PEM Base64 text block.
const QList< QSslCertificate > certificatesToImport()
Get list of certificate objects to import.
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc.
QVariant value(const QString &key, const QVariant &defaultValue) const
void setText(const QString &text)
CertTrustPolicy
Type of certificate trust policy.
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
CertFilter
Type of filter to apply to dialog.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsAuthImportCertDialog(QWidget *parent=nullptr, QgsAuthImportCertDialog::CertFilter filter=NoFilter, QgsAuthImportCertDialog::CertInput input=AllInputs)
Construct a dialog for importing certificates.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool removeOne(const T &value)