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();