18 #include "ui_qgsauthserverseditor.h" 22 #include <QMessageBox> 34 , mAuthNotifyLayout( nullptr )
35 , mAuthNotify( nullptr )
36 , mRootSslConfigItem( nullptr )
44 mAuthNotifyLayout->
addWidget( mAuthNotify );
54 this, SLOT( refreshSslConfigsView() ) );
56 setupSslConfigsTree();
64 connect( btnViewRefresh, SIGNAL( clicked() ),
this, SLOT( refreshSslConfigsView() ) );
66 btnGroupByOrg->setChecked(
false );
69 btnGroupByOrg->setChecked( sortbyval.
toBool() );
71 populateSslConfigsView();
89 void QgsAuthServersEditor::setupSslConfigsTree()
91 treeServerConfigs->setColumnCount( 3 );
92 treeServerConfigs->setHeaderLabels(
95 <<
tr(
"Expiry Date" ) );
96 treeServerConfigs->setColumnWidth( 0, 275 );
97 treeServerConfigs->setColumnWidth( 1, 200 );
103 (
int )QgsAuthServersEditor::Section );
105 mRootSslConfigItem->
setFlags( Qt::ItemIsEnabled );
107 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
118 void QgsAuthServersEditor::populateSslConfigsView()
122 populateSslConfigsSection( mRootSslConfigItem,
124 QgsAuthServersEditor::ServerConfig );
127 void QgsAuthServersEditor::refreshSslConfigsView()
129 populateSslConfigsView();
132 void QgsAuthServersEditor::populateSslConfigsSection(
QTreeWidgetItem *item,
134 QgsAuthServersEditor::ConfigType conftype )
136 if ( btnGroupByOrg->isChecked() )
138 appendSslConfigsToGroup( configs, conftype, item );
142 appendSslConfigsToItem( configs, conftype, item );
147 QgsAuthServersEditor::ConfigType conftype,
150 if ( configs.
size() < 1 )
155 parent = treeServerConfigs->currentItem();
163 for ( ; it != orgconfigs.
constEnd(); ++it )
167 ( int )QgsAuthServersEditor::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 appendSslConfigsToItem( it.
value(), conftype, grpitem );
186 QgsAuthServersEditor::ConfigType conftype,
189 if ( configs.
size() < 1 )
194 parent = treeServerConfigs->currentItem();
208 coltxts << cert.expiryDate().toString();
213 if ( !cert.isValid() )
219 item->
setData( 0, Qt::UserRole,
id );
227 Q_UNUSED( selected );
228 Q_UNUSED( deselected );
232 void QgsAuthServersEditor::checkSelection()
234 bool isconfig =
false;
235 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
239 switch (( QgsAuthServersEditor::ConfigType )item->
type() )
241 case QgsAuthServersEditor::ServerConfig :
249 btnRemoveServer->setEnabled( isconfig );
250 btnEditServer->setEnabled( isconfig );
253 void QgsAuthServersEditor::handleDoubleClick(
QTreeWidgetItem *item,
int col )
256 bool isconfig =
true;
258 switch (( QgsAuthServersEditor::ConfigType )item->
type() )
260 case QgsAuthServersEditor::Section:
263 case QgsAuthServersEditor::OrgName:
272 on_btnEditServer_clicked();
276 void QgsAuthServersEditor::on_btnAddServer_clicked()
283 refreshSslConfigsView();
288 void QgsAuthServersEditor::on_btnRemoveServer_clicked()
301 if ( digest.isEmpty() )
303 messageBar()->
pushMessage(
tr(
"SSL custom config id missing" ),
307 if ( hostport.isEmpty() )
309 messageBar()->
pushMessage(
tr(
"SSL custom config host:port missing" ),
316 QgsDebugMsg(
QString(
"SSL custom config does not exist in database for host:port, id %1:" )
317 .arg( hostport, digest ) );
322 this,
tr(
"Remove SSL Custom Config" ),
323 tr(
"Are you sure you want to remove the selected " 324 "SSL custom config from the database?\n\n" 325 "Operation can NOT be undone!" ),
326 QMessageBox::Ok | QMessageBox::Cancel,
327 QMessageBox::Cancel ) == QMessageBox::Cancel )
334 messageBar()->
pushMessage(
tr(
"ERROR removing SSL custom config from authentication database for host:port, id %1:" )
335 .arg( hostport, digest ),
344 void QgsAuthServersEditor::on_btnEditServer_clicked()
357 if ( digest.isEmpty() )
359 messageBar()->
pushMessage(
tr(
"SSL custom config id missing" ),
363 if ( hostport.isEmpty() )
365 messageBar()->
pushMessage(
tr(
"SSL custom config host:port missing" ),
372 QgsDebugMsg(
"SSL custom config does not exist in database" );
380 dlg->sslCustomConfigWidget()->setConfigCheckable(
false );
381 dlg->setWindowModality( Qt::WindowModal );
382 dlg->resize( 500, 500 );
385 refreshSslConfigsView();
390 void QgsAuthServersEditor::on_btnGroupByOrg_toggled(
bool checked )
394 authMessageOut(
QObject::tr(
"Could not store sort by preference" ),
398 populateSslConfigsView();
403 int levelint = ( int )level;
411 treeServerConfigs->setFocus();
421 int QgsAuthServersEditor::messageTimeout()
424 return settings.
value(
"/qgis/messageTimeout", 5 ).
toInt();
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
static void setItemBold_(QTreeWidgetItem *item)
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.
Configuration container for SSL server connection exceptions or overrides.
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.
int toInt(bool *ok) const
const_iterator constEnd() const
static QMap< QString, QList< QgsAuthConfigSslServer > > sslConfigsGroupedByOrg(const QList< QgsAuthConfigSslServer > &configs)
Map SSL custom configs' certificates to their oraganization.
const QString sslHostPort() const
Server host:port string.
static void removeChildren_(QTreeWidgetItem *item)
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
const QSslCertificate sslCertificate() const
Server certificate object.
Dialog wrapper of widget for editing an SSL server configuration.
void showEvent(QShowEvent *e) override
Overridden show event of base widget.
QgsAuthServersEditor(QWidget *parent=nullptr)
Widget for editing authentication configurations directly in database.
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
Widget for importing an SSL server certificate exception into the authentication database.
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.
QString text(int column) const
const T value(const Key &key) const