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     mActionImportAuthenticationConfigs = 
new QAction( tr( 
"Import authentication configurations from file" ), 
this );
 
   94     mActionExportSelectedAuthenticationConfigs = 
new QAction( tr( 
"Export selected authentication configurations to file" ), 
this );
 
   95     mActionSetMasterPassword = 
new QAction( QStringLiteral( 
"Input master password" ), 
this );
 
   96     mActionClearCachedMasterPassword = 
new QAction( QStringLiteral( 
"Clear cached master password" ), 
this );
 
   97     mActionResetMasterPassword = 
new QAction( QStringLiteral( 
"Reset master password" ), 
this );
 
   98     mActionClearCachedAuthConfigs = 
new QAction( QStringLiteral( 
"Clear cached authentication configurations" ), 
this );
 
   99     mActionRemoveAuthConfigs = 
new QAction( QStringLiteral( 
"Remove all authentication configurations" ), 
this );
 
  100     mActionEraseAuthDatabase = 
new QAction( QStringLiteral( 
"Erase authentication database" ), 
this );
 
  102     connect( mActionImportAuthenticationConfigs, &QAction::triggered, 
this, &QgsAuthConfigEditor::importAuthenticationConfigs );
 
  103     connect( mActionExportSelectedAuthenticationConfigs, &QAction::triggered, 
this, &QgsAuthConfigEditor::exportSelectedAuthenticationConfigs );
 
  104     connect( mActionSetMasterPassword, &QAction::triggered, 
this, &QgsAuthConfigEditor::setMasterPassword );
 
  105     connect( mActionClearCachedMasterPassword, &QAction::triggered, 
this, &QgsAuthConfigEditor::clearCachedMasterPassword );
 
  106     connect( mActionResetMasterPassword, &QAction::triggered, 
this, &QgsAuthConfigEditor::resetMasterPassword );
 
  107     connect( mActionClearCachedAuthConfigs, &QAction::triggered, 
this, &QgsAuthConfigEditor::clearCachedAuthenticationConfigs );
 
  108     connect( mActionRemoveAuthConfigs, &QAction::triggered, 
this, &QgsAuthConfigEditor::removeAuthenticationConfigs );
 
  109     connect( mActionEraseAuthDatabase, &QAction::triggered, 
this, &QgsAuthConfigEditor::eraseAuthenticationDatabase );
 
  111     mAuthUtilitiesMenu = 
new QMenu( 
this );
 
  112     mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
 
  113     mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
 
  114     mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
 
  115     mAuthUtilitiesMenu->addSeparator();
 
  116     mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
 
  117     mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
 
  118     mAuthUtilitiesMenu->addSeparator();
 
  119     mAuthUtilitiesMenu->addAction( mActionImportAuthenticationConfigs );
 
  120     mAuthUtilitiesMenu->addAction( mActionExportSelectedAuthenticationConfigs );
 
  121     mAuthUtilitiesMenu->addSeparator();
 
  122     mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
 
  124     btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
 
  125     lblAuthConfigDb->setVisible( 
false );
 
  129 void QgsAuthConfigEditor::importAuthenticationConfigs()
 
  134 void QgsAuthConfigEditor::exportSelectedAuthenticationConfigs()
 
  139 void QgsAuthConfigEditor::setMasterPassword()
 
  144 void QgsAuthConfigEditor::clearCachedMasterPassword()
 
  149 void QgsAuthConfigEditor::resetMasterPassword()
 
  154 void QgsAuthConfigEditor::clearCachedAuthenticationConfigs()
 
  159 void QgsAuthConfigEditor::removeAuthenticationConfigs()
 
  164 void QgsAuthConfigEditor::eraseAuthenticationDatabase()
 
  171   const int levelint = 
static_cast<int>( level );
 
  179     lblAuthConfigDb->setVisible( visible );
 
  186   const QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
 
  187   for ( 
const QModelIndex index : selection )
 
  189     ids << index.sibling( index.row(), 0 ).data().toString();
 
  198     btnAuthUtilities->setVisible( show );
 
  208   if ( relay == mRelayMessages )
 
  213   if ( mRelayMessages )
 
  216                 this, &QgsAuthConfigEditor::authMessageOut );
 
  217     mRelayMessages = relay;
 
  222            this, &QgsAuthConfigEditor::authMessageOut );
 
  223   mRelayMessages = relay;
 
  226 void QgsAuthConfigEditor::refreshTableView()
 
  228   mConfigModel->select();
 
  229   tableViewConfigs->reset();
 
  232 void QgsAuthConfigEditor::selectionChanged( 
const QItemSelection &selected, 
const QItemSelection &deselected )
 
  235   Q_UNUSED( deselected )
 
  239 void QgsAuthConfigEditor::checkSelection()
 
  241   const bool hasselection = tableViewConfigs->selectionModel()->selection().length() > 0;
 
  242   btnEditConfig->setEnabled( hasselection );
 
  243   btnRemoveConfig->setEnabled( hasselection );
 
  246 void QgsAuthConfigEditor::btnAddConfig_clicked()
 
  252   ace->setWindowModality( Qt::WindowModal );
 
  255     mConfigModel->select();
 
  260 void QgsAuthConfigEditor::btnEditConfig_clicked()
 
  262   const QString authcfg = selectedConfigId();
 
  264   if ( authcfg.isEmpty() )
 
  271   ace->setWindowModality( Qt::WindowModal );
 
  274     mConfigModel->select();
 
  279 void QgsAuthConfigEditor::btnRemoveConfig_clicked()
 
  281   const QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
 
  283   if ( selection.empty() )
 
  286   for ( 
const QModelIndex index : selection )
 
  288     const QString name = index.sibling( index.row(), 1 ).data().toString();
 
  290     if ( QMessageBox::warning( 
this, tr( 
"Remove Configuration" ),
 
  291                                tr( 
"Are you sure you want to remove '%1'?\n\n" 
  292                                    "Operation can NOT be undone!" ).arg( name ),
 
  293                                QMessageBox::Ok | QMessageBox::Cancel,
 
  294                                QMessageBox::Cancel ) == QMessageBox::Ok )
 
  296       mConfigModel->removeRow( index.row() );
 
  306 QString QgsAuthConfigEditor::selectedConfigId()
 
  308   const QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
 
  310   if ( selection.empty() )
 
  313   const QModelIndex indx = selection.at( 0 );
 
  314   return indx.sibling( indx.row(), 0 ).data().toString();