18 #include "ui_qgsauthidentitieseditor.h" 21 #include <QMessageBox> 36 , mAuthNotifyLayout( nullptr )
37 , mAuthNotify( nullptr )
38 , mRootCertIdentItem( nullptr )
46 mAuthNotifyLayout->
addWidget( mAuthNotify );
56 this, SLOT( refreshIdentitiesView() ) );
58 setupIdentitiesTree();
66 connect( btnViewRefresh, SIGNAL( clicked() ),
this, SLOT( refreshIdentitiesView() ) );
68 btnGroupByOrg->setChecked(
false );
71 btnGroupByOrg->setChecked( sortbyval.
toBool() );
73 populateIdentitiesView();
90 void QgsAuthIdentitiesEditor::setupIdentitiesTree()
92 treeIdentities->setColumnCount( 3 );
93 treeIdentities->setHeaderLabels(
96 <<
tr(
"Expiry Date" ) );
97 treeIdentities->setColumnWidth( 0, 300 );
98 treeIdentities->setColumnWidth( 1, 75 );
104 (
int )QgsAuthIdentitiesEditor::Section );
106 mRootCertIdentItem->
setFlags( Qt::ItemIsEnabled );
108 treeIdentities->insertTopLevelItem( 0, mRootCertIdentItem );
119 void QgsAuthIdentitiesEditor::populateIdentitiesView()
123 populateIdentitiesSection( mRootCertIdentItem,
125 QgsAuthIdentitiesEditor::CertIdentity );
128 void QgsAuthIdentitiesEditor::refreshIdentitiesView()
130 populateIdentitiesView();
134 QgsAuthIdentitiesEditor::IdentityType identype )
136 if ( btnGroupByOrg->isChecked() )
138 appendIdentitiesToGroup( certs, identype, item );
142 appendIdentitiesToItem( certs, identype, item );
147 QgsAuthIdentitiesEditor::IdentityType identype,
150 if ( certs.
size() < 1 )
155 parent = treeIdentities->currentItem();
163 for ( ; it != orgcerts.
constEnd(); ++it )
167 ( int )QgsAuthIdentitiesEditor::OrgName ) );
169 grpitem->setFlags( Qt::ItemIsEnabled );
170 grpitem->setExpanded(
true );
172 QBrush orgb( grpitem->foreground( 0 ) );
174 grpitem->setForeground( 0, orgb );
175 QFont grpf( grpitem->font( 0 ) );
177 grpitem->setFont( 0, grpf );
179 appendIdentitiesToItem( it.
value(), identype, grpitem );
186 QgsAuthIdentitiesEditor::IdentityType identype,
189 if ( certs.
size() < 1 )
194 parent = treeIdentities->currentItem();
218 item->
setData( 0, Qt::UserRole,
id );
233 QgsDebugMsg(
"Certificate identity does not exist in database" );
248 Q_UNUSED( selected );
249 Q_UNUSED( deselected );
253 void QgsAuthIdentitiesEditor::checkSelection()
256 if ( treeIdentities->selectionModel()->selection().length() > 0 )
260 switch (( QgsAuthIdentitiesEditor::IdentityType )item->
type() )
262 case QgsAuthIdentitiesEditor::CertIdentity:
270 btnRemoveIdentity->setEnabled( iscert );
271 btnInfoIdentity->setEnabled( iscert );
274 void QgsAuthIdentitiesEditor::handleDoubleClick(
QTreeWidgetItem *item,
int col )
279 switch (( QgsAuthIdentitiesEditor::IdentityType )item->
type() )
281 case QgsAuthIdentitiesEditor::Section:
284 case QgsAuthIdentitiesEditor::OrgName:
293 showCertInfo( item );
297 void QgsAuthIdentitiesEditor::on_btnAddIdentity_clicked()
309 messageBar()->
pushMessage(
tr(
"ERROR storing identity bundle in authentication database" ),
312 populateIdentitiesView();
319 void QgsAuthIdentitiesEditor::on_btnRemoveIdentity_clicked()
331 if ( digest.isEmpty() )
340 QgsDebugMsg(
"Certificate identity does not exist in database" );
345 this,
tr(
"Remove Certificate Identity" ),
346 tr(
"Are you sure you want to remove the selected " 347 "certificate identity from the database?\n\n" 348 "Operation can NOT be undone!" ),
349 QMessageBox::Ok | QMessageBox::Cancel,
350 QMessageBox::Cancel ) == QMessageBox::Cancel )
357 messageBar()->
pushMessage(
tr(
"ERROR removing cert identity from authentication database for id %1:" ).arg( digest ),
366 void QgsAuthIdentitiesEditor::on_btnInfoIdentity_clicked()
368 if ( treeIdentities->selectionModel()->selection().length() > 0 )
371 handleDoubleClick( item, 0 );
375 void QgsAuthIdentitiesEditor::on_btnGroupByOrg_toggled(
bool checked )
379 authMessageOut(
QObject::tr(
"Could not store sort by preference" ),
383 populateIdentitiesView();
388 int levelint = ( int )level;
396 treeIdentities->setFocus();
406 int QgsAuthIdentitiesEditor::messageTimeout()
409 return settings.
value(
"/qgis/messageTimeout", 5 ).
toInt();
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
QString toString(Qt::DateFormat format) const
static QgsAuthManager * instance()
Enforce singleton pattern.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
const_iterator constBegin() const
A bar for displaying non-blocking messages to the user.
Widget for importing an identity certificate/key bundle into the authentication database.
QgsAuthImportIdentityDialog::IdentityType identityType()
Get identity type.
QString tr(const char *sourceText, const char *disambiguation, int n)
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
QVariant getAuthSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
Get an authentication setting (retrieved as string and returned as QVariant( QString )) ...
void setBold(bool enable)
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
static QColor redColor()
Red color representing invalid, untrusted, etc.
static void removeChildren_(QTreeWidgetItem *item)
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain...
int toInt(bool *ok) const
void showEvent(QShowEvent *e) override
Overridden show event of base widget.
const_iterator constEnd() const
bool storeCertIdentity(const QSslCertificate &cert, const QSslKey &key)
Store a certificate identity.
void setItalic(bool enable)
const Key key(const T &value) const
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Get the sha1 hash for certificate.
QVariant value(const QString &key, const QVariant &defaultValue) const
QByteArray serialNumber() const
QDateTime expiryDate() const
static void setItemBold_(QTreeWidgetItem *item)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
static QMap< QString, QList< QSslCertificate > > certsGroupedByOrg(const QList< QSslCertificate > &certs)
Map certificates to their oraganization.
bool existsCertIdentity(const QString &id)
Check if a certificate identity exists.
const QPair< QSslCertificate, QSslKey > certBundleToImport()
Get certificate/key bundle to be imported.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setColor(const QColor &color)
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Get the general name via RFC 5280 resolution.
QgsAuthIdentitiesEditor(QWidget *parent=nullptr)
Widget for editing authentication configurations directly in database.
const T value(const Key &key) const
~QgsAuthIdentitiesEditor()