18 #include "ui_qgsauthconfigeditor.h" 21 #include <QMessageBox> 22 #include <QSqlTableModel> 32 , mRelayMessages( relayMessages )
37 mAuthNotifyLayout =
new QVBoxLayout;
38 this->setLayout( mAuthNotifyLayout );
40 mAuthNotifyLayout->addWidget( mAuthNotify );
45 connect( btnAddConfig, &QToolButton::clicked,
this, &QgsAuthConfigEditor::btnAddConfig_clicked );
46 connect( btnEditConfig, &QToolButton::clicked,
this, &QgsAuthConfigEditor::btnEditConfig_clicked );
47 connect( btnRemoveConfig, &QToolButton::clicked,
this, &QgsAuthConfigEditor::btnRemoveConfig_clicked );
53 mConfigModel->select();
55 mConfigModel->setHeaderData( 0, Qt::Horizontal, tr(
"ID" ) );
56 mConfigModel->setHeaderData( 1, Qt::Horizontal, tr(
"Name" ) );
57 mConfigModel->setHeaderData( 2, Qt::Horizontal, tr(
"URI" ) );
58 mConfigModel->setHeaderData( 3, Qt::Horizontal, tr(
"Type" ) );
59 mConfigModel->setHeaderData( 4, Qt::Horizontal, tr(
"Version" ) );
60 mConfigModel->setHeaderData( 5, Qt::Horizontal, tr(
"Config" ) );
62 tableViewConfigs->setModel( mConfigModel );
63 tableViewConfigs->resizeColumnsToContents();
68 tableViewConfigs->hideColumn( 4 );
69 tableViewConfigs->hideColumn( 5 );
72 tableViewConfigs->sortByColumn( 1, Qt::AscendingOrder );
73 tableViewConfigs->setSortingEnabled(
true );
75 connect( tableViewConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
76 this, &QgsAuthConfigEditor::selectionChanged );
78 connect( tableViewConfigs, &QAbstractItemView::doubleClicked,
79 this, &QgsAuthConfigEditor::btnEditConfig_clicked );
84 this, &QgsAuthConfigEditor::authMessageOut );
88 this, &QgsAuthConfigEditor::refreshTableView );
93 mActionSetMasterPassword =
new QAction( QStringLiteral(
"Input master password" ),
this );
94 mActionClearCachedMasterPassword =
new QAction( QStringLiteral(
"Clear cached master password" ),
this );
95 mActionResetMasterPassword =
new QAction( QStringLiteral(
"Reset master password" ),
this );
96 mActionClearCachedAuthConfigs =
new QAction( QStringLiteral(
"Clear cached authentication configurations" ),
this );
97 mActionRemoveAuthConfigs =
new QAction( QStringLiteral(
"Remove all authentication configurations" ),
this );
98 mActionEraseAuthDatabase =
new QAction( QStringLiteral(
"Erase authentication database" ),
this );
100 connect( mActionSetMasterPassword, &QAction::triggered,
this, &QgsAuthConfigEditor::setMasterPassword );
101 connect( mActionClearCachedMasterPassword, &QAction::triggered,
this, &QgsAuthConfigEditor::clearCachedMasterPassword );
102 connect( mActionResetMasterPassword, &QAction::triggered,
this, &QgsAuthConfigEditor::resetMasterPassword );
103 connect( mActionClearCachedAuthConfigs, &QAction::triggered,
this, &QgsAuthConfigEditor::clearCachedAuthenticationConfigs );
104 connect( mActionRemoveAuthConfigs, &QAction::triggered,
this, &QgsAuthConfigEditor::removeAuthenticationConfigs );
105 connect( mActionEraseAuthDatabase, &QAction::triggered,
this, &QgsAuthConfigEditor::eraseAuthenticationDatabase );
107 mAuthUtilitiesMenu =
new QMenu(
this );
108 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
109 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
110 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
111 mAuthUtilitiesMenu->addSeparator();
112 mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
113 mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
114 mAuthUtilitiesMenu->addSeparator();
115 mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
117 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
118 lblAuthConfigDb->setVisible(
false );
122 void QgsAuthConfigEditor::setMasterPassword()
127 void QgsAuthConfigEditor::clearCachedMasterPassword()
132 void QgsAuthConfigEditor::resetMasterPassword()
137 void QgsAuthConfigEditor::clearCachedAuthenticationConfigs()
142 void QgsAuthConfigEditor::removeAuthenticationConfigs()
147 void QgsAuthConfigEditor::eraseAuthenticationDatabase()
154 int levelint =
static_cast<int>( level );
162 lblAuthConfigDb->setVisible( visible );
170 btnAuthUtilities->setVisible( show );
180 if ( relay == mRelayMessages )
185 if ( mRelayMessages )
188 this, &QgsAuthConfigEditor::authMessageOut );
189 mRelayMessages = relay;
194 this, &QgsAuthConfigEditor::authMessageOut );
195 mRelayMessages = relay;
198 void QgsAuthConfigEditor::refreshTableView()
200 mConfigModel->select();
201 tableViewConfigs->reset();
204 void QgsAuthConfigEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
207 Q_UNUSED( deselected )
211 void QgsAuthConfigEditor::checkSelection()
213 bool hasselection = tableViewConfigs->selectionModel()->selection().length() > 0;
214 btnEditConfig->setEnabled( hasselection );
215 btnRemoveConfig->setEnabled( hasselection );
218 void QgsAuthConfigEditor::btnAddConfig_clicked()
224 ace->setWindowModality( Qt::WindowModal );
227 mConfigModel->select();
232 void QgsAuthConfigEditor::btnEditConfig_clicked()
234 QString authcfg = selectedConfigId();
236 if ( authcfg.isEmpty() )
243 ace->setWindowModality( Qt::WindowModal );
246 mConfigModel->select();
251 void QgsAuthConfigEditor::btnRemoveConfig_clicked()
253 QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
255 if ( selection.empty() )
258 QModelIndex indx = selection.at( 0 );
259 QString name = indx.sibling( indx.row(), 1 ).data().toString();
261 if ( QMessageBox::warning(
this, tr(
"Remove Configuration" ),
262 tr(
"Are you sure you want to remove '%1'?\n\n" 263 "Operation can NOT be undone!" ).arg( name ),
264 QMessageBox::Ok | QMessageBox::Cancel,
265 QMessageBox::Cancel ) == QMessageBox::Ok )
267 mConfigModel->removeRow( indx.row() );
276 int QgsAuthConfigEditor::messageTimeout()
279 return settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
282 QString QgsAuthConfigEditor::selectedConfigId()
284 QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
286 if ( selection.empty() )
289 QModelIndex indx = selection.at( 0 );
290 return indx.sibling( indx.row(), 0 ).data().toString();
static void resetMasterPassword(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Reset the cached master password, updating its hash in authentication database and resetting all exis...
static void eraseAuthenticationDatabase(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Completely clear out the authentication database (configs and master password)
void messageOut(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level=QgsAuthManager::INFO) const
Custom logging signal to relay to console output and QgsMessageLog.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static void clearCachedMasterPassword(QgsMessageBar *msgbar, int timeout=0)
Clear the currently cached master password (not its hash in database)
static void removeAuthenticationConfigs(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Remove all authentication configs.
A bar for displaying non-blocking messages to the user.
static void setMasterPassword(QgsMessageBar *msgbar, int timeout=0)
Sets the cached master password (and verifies it if its hash is in authentication database) ...
MessageLevel
Level for messages This will be used both for message log and message bar in application.
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
static void clearCachedAuthenticationConfigs(QgsMessageBar *msgbar, int timeout=0)
Clear all cached authentication configs for session.
QgsAuthConfigEditor(QWidget *parent=nullptr, bool showUtilities=true, bool relayMessages=true)
Widget for editing authentication configurations directly in database.
void authDatabaseChanged()
Emitted when the authentication db is significantly changed, e.g. large record removal, erased, etc.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
void setShowUtilitiesButton(bool show=true)
Sets whether to show the widget's utilities button, e.g. when embedding.
void toggleTitleVisibility(bool visible)
Hide the widget's title, e.g. when embedding.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
Widget for editing an authentication configuration.
void setRelayMessages(bool relay=true)
Sets whether to relay auth manager messages to internal message bar, e.g. when embedding.