18 #include "ui_qgsauthconfigeditor.h" 21 #include <QMessageBox> 23 #include <QSqlTableModel> 31 , mRelayMessages( relayMessages )
32 , mConfigModel( nullptr )
33 , mAuthUtilitiesMenu( nullptr )
34 , mActionSetMasterPassword( nullptr )
35 , mActionClearCachedMasterPassword( nullptr )
36 , mActionResetMasterPassword( nullptr )
37 , mActionClearCachedAuthConfigs( nullptr )
38 , mActionRemoveAuthConfigs( nullptr )
39 , mActionEraseAuthDatabase( nullptr )
41 , mAuthNotifyLayout( nullptr )
42 , mAuthNotify( nullptr )
50 mAuthNotifyLayout->
addWidget( mAuthNotify );
69 tableViewConfigs->setModel( mConfigModel );
70 tableViewConfigs->resizeColumnsToContents();
75 tableViewConfigs->hideColumn( 4 );
76 tableViewConfigs->hideColumn( 5 );
79 tableViewConfigs->sortByColumn( 1, Qt::AscendingOrder );
80 tableViewConfigs->setSortingEnabled(
true );
86 this, SLOT( on_btnEditConfig_clicked() ) );
95 this, SLOT( refreshTableView() ) );
100 mActionSetMasterPassword =
new QAction(
"Input master password",
this );
101 mActionClearCachedMasterPassword =
new QAction(
"Clear cached master password",
this );
102 mActionResetMasterPassword =
new QAction(
"Reset master password",
this );
103 mActionClearCachedAuthConfigs =
new QAction(
"Clear cached authentication configurations",
this );
104 mActionRemoveAuthConfigs =
new QAction(
"Remove all authentication configurations",
this );
105 mActionEraseAuthDatabase =
new QAction(
"Erase authentication database",
this );
107 connect( mActionSetMasterPassword, SIGNAL( triggered() ),
this, SLOT( setMasterPassword() ) );
108 connect( mActionClearCachedMasterPassword, SIGNAL( triggered() ),
this, SLOT( clearCachedMasterPassword() ) );
109 connect( mActionResetMasterPassword, SIGNAL( triggered() ),
this, SLOT( resetMasterPassword() ) );
110 connect( mActionClearCachedAuthConfigs, SIGNAL( triggered() ),
this, SLOT( clearCachedAuthenticationConfigs() ) );
111 connect( mActionRemoveAuthConfigs, SIGNAL( triggered() ),
this, SLOT( removeAuthenticationConfigs() ) );
112 connect( mActionEraseAuthDatabase, SIGNAL( triggered() ),
this, SLOT( eraseAuthenticationDatabase() ) );
114 mAuthUtilitiesMenu =
new QMenu(
this );
115 mAuthUtilitiesMenu->
addAction( mActionSetMasterPassword );
116 mAuthUtilitiesMenu->
addAction( mActionClearCachedMasterPassword );
117 mAuthUtilitiesMenu->
addAction( mActionResetMasterPassword );
119 mAuthUtilitiesMenu->
addAction( mActionClearCachedAuthConfigs );
120 mAuthUtilitiesMenu->
addAction( mActionRemoveAuthConfigs );
122 mAuthUtilitiesMenu->
addAction( mActionEraseAuthDatabase );
124 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
125 lblAuthConfigDb->setVisible(
false );
133 void QgsAuthConfigEditor::setMasterPassword()
138 void QgsAuthConfigEditor::clearCachedMasterPassword()
143 void QgsAuthConfigEditor::resetMasterPassword()
148 void QgsAuthConfigEditor::clearCachedAuthenticationConfigs()
153 void QgsAuthConfigEditor::removeAuthenticationConfigs()
158 void QgsAuthConfigEditor::eraseAuthenticationDatabase()
165 int levelint = ( int )level;
173 lblAuthConfigDb->setVisible( visible );
181 btnAuthUtilities->setVisible( show );
191 if ( relay == mRelayMessages )
196 if ( mRelayMessages )
200 mRelayMessages = relay;
206 mRelayMessages = relay;
209 void QgsAuthConfigEditor::refreshTableView()
212 tableViewConfigs->reset();
217 Q_UNUSED( selected );
218 Q_UNUSED( deselected );
222 void QgsAuthConfigEditor::checkSelection()
224 bool hasselection = tableViewConfigs->selectionModel()->selection().length() > 0;
225 btnEditConfig->setEnabled( hasselection );
226 btnRemoveConfig->setEnabled( hasselection );
229 void QgsAuthConfigEditor::on_btnAddConfig_clicked()
243 void QgsAuthConfigEditor::on_btnEditConfig_clicked()
245 QString authcfg = selectedConfigId();
262 void QgsAuthConfigEditor::on_btnRemoveConfig_clicked()
264 QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
266 if ( selection.empty() )
273 tr(
"Are you sure you want to remove '%1'?\n\n" 274 "Operation can NOT be undone!" ).arg( name ),
275 QMessageBox::Ok | QMessageBox::Cancel,
276 QMessageBox::Cancel ) == QMessageBox::Ok )
287 int QgsAuthConfigEditor::messageTimeout()
290 return settings.
value(
"/qgis/messageTimeout", 5 ).
toInt();
293 QString QgsAuthConfigEditor::selectedConfigId()
295 QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );
297 if ( selection.empty() )
301 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 reseting all exist...
static void eraseAuthenticationDatabase(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Completely clear out the authentication database (configs and master password)
static QgsAuthManager * instance()
Enforce singleton pattern.
bool removeRow(int row, const QModelIndex &parent)
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) ...
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
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.
const char * name() const
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
int toInt(bool *ok) const
QgsAuthConfigEditor(QWidget *parent=nullptr, bool showUtilities=true, bool relayMessages=true)
Widget for editing authentication configurations directly in database.
void setShowUtilitiesButton(bool show=true)
Set whether to show the widget's utilities button, e.g.
void toggleTitleVisibility(bool visible)
Hide the widget's title, e.g.
QVariant value(const QString &key, const QVariant &defaultValue) const
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
QModelIndex sibling(int row, int column) const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
Widget for editing an authentication configuration.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setRelayMessages(bool relay=true)
Set whether to relay auth manager messages to internal message bar, e.g.
virtual void setTable(const QString &tableName)