23
23
#include " qgsapplication.h"
24
24
25
25
#include < QPushButton>
26
+ #include < QMenu>
27
+ #include < QToolButton>
26
28
#include < QThread>
27
29
#include < QTimer>
30
+ #include < QGlobalStatic>
28
31
29
- QSet<QString> QgsCredentialDialog::sIgnoredConnectionsCache ;
30
32
QMutex QgsCredentialDialog::sIgnoredConnectionsCacheMutex ;
33
+ typedef QSet<QString> IgnoredConnectionsSet;
34
+
35
+ // ! Temporary cache for ignored connections, to avoid GUI freezing by multiple credentials requests to the same connection
36
+ Q_GLOBAL_STATIC ( IgnoredConnectionsSet, sIgnoredConnectionsCache );
31
37
32
38
33
39
static QString invalidStyle_ ( const QString &selector = QStringLiteral( " QLineEdit" ) )
@@ -50,25 +56,55 @@ QgsCredentialDialog::QgsCredentialDialog( QWidget *parent, Qt::WindowFlags fl )
50
56
connect ( this , &QgsCredentialDialog::credentialsRequestedMasterPassword,
51
57
this , &QgsCredentialDialog::requestCredentialsMasterPassword,
52
58
Qt::BlockingQueuedConnection );
53
- mOkButton = buttonBox->button ( QDialogButtonBox::Ok );
54
- QPushButton *ignoreButton { buttonBox->button ( QDialogButtonBox::StandardButton::Ignore ) };
55
- ignoreButton->setToolTip ( tr ( " All requests for this connection will be automatically rejected for the next 60 seconds." ) );
56
59
57
- // Keep a cache of ignored connections, and ignore them for 60 seconds.
58
- connect ( ignoreButton, &QPushButton::clicked, [ = ]( bool )
60
+ // Setup ignore button
61
+ mIgnoreButton ->setToolTip ( tr ( " All requests for this connection will be automatically rejected" ) );
62
+ QMenu *menu = new QMenu ( mIgnoreButton );
63
+ QAction *ignoreTemporarily = new QAction ( tr ( " Ignore for 10 seconds" ), menu );
64
+ ignoreTemporarily->setToolTip ( tr ( " All requests for this connection will be automatically rejected for 10 seconds" ) );
65
+ QAction *ignoreForSession = new QAction ( tr ( " Ignore for session" ), menu );
66
+ ignoreForSession->setToolTip ( tr ( " All requests for this connection will be automatically rejected for the duration of the current session" ) );
67
+ menu->addAction ( ignoreTemporarily );
68
+ menu->addAction ( ignoreForSession );
69
+ connect ( ignoreTemporarily, &QAction::triggered, [ = ]
70
+ {
71
+ mIgnoreMode = IgnoreTemporarily;
72
+ // mIgnoreButton->setText( ignoreTemporarily->text() );
73
+ mIgnoreButton ->setToolTip ( ignoreTemporarily->toolTip () );
74
+ } );
75
+ connect ( ignoreForSession, &QAction::triggered, [ = ]
76
+ {
77
+ mIgnoreMode = IgnoreForSession;
78
+ // mIgnoreButton->setText( ignoreForSession->text() );
79
+ mIgnoreButton ->setToolTip ( ignoreForSession->toolTip () );
80
+ } );
81
+ mIgnoreButton ->setText ( mIgnoreMode == IgnoreTemporarily ? ignoreTemporarily->text () : ignoreForSession->text () );
82
+ mIgnoreButton ->setToolTip ( mIgnoreMode == IgnoreTemporarily ? ignoreTemporarily->toolTip () : ignoreForSession->toolTip () );
83
+ mIgnoreButton ->setMenu ( menu );
84
+ mIgnoreButton ->setMaximumHeight ( mOkButton ->sizeHint ().height () );
85
+
86
+ // Connect ok and cancel buttons
87
+ connect ( mOkButton , &QPushButton::clicked, this , &QgsCredentialDialog::accept );
88
+ connect ( mCancelButton , &QPushButton::clicked, this , &QgsCredentialDialog::reject );
89
+
90
+ // Keep a cache of ignored connections, and ignore them for 10 seconds.
91
+ connect ( mIgnoreButton , &QPushButton::clicked, [ = ]( bool )
59
92
{
60
93
const QString realm { labelRealm->text () };
61
94
{
62
95
QMutexLocker locker ( &sIgnoredConnectionsCacheMutex );
63
96
// Insert the realm in the cache of ignored connections
64
- sIgnoredConnectionsCache . insert ( realm );
97
+ sIgnoredConnectionsCache -> insert ( realm );
65
98
}
66
- QTimer::singleShot ( 60000 , [ = ]( )
99
+ if ( mIgnoreMode == IgnoreTemporarily )
67
100
{
68
- QgsDebugMsgLevel ( QStringLiteral ( " Removing ignored connection from cache: %1" ).arg ( realm ), 4 );
69
- QMutexLocker locker ( &sIgnoredConnectionsCacheMutex );
70
- sIgnoredConnectionsCache .remove ( realm );
71
- } );
101
+ QTimer::singleShot ( 10000 , [ = ]()
102
+ {
103
+ QgsDebugMsgLevel ( QStringLiteral ( " Removing ignored connection from cache: %1" ).arg ( realm ), 4 );
104
+ QMutexLocker locker ( &sIgnoredConnectionsCacheMutex );
105
+ sIgnoredConnectionsCache ->remove ( realm );
106
+ } );
107
+ }
72
108
accept ( );
73
109
} );
74
110
@@ -100,15 +136,15 @@ void QgsCredentialDialog::requestCredentials( const QString &realm, QString *use
100
136
QgsDebugMsgLevel ( QStringLiteral ( " Entering." ), 4 );
101
137
{
102
138
QMutexLocker locker ( &sIgnoredConnectionsCacheMutex );
103
- if ( sIgnoredConnectionsCache . contains ( realm ) )
139
+ if ( sIgnoredConnectionsCache -> contains ( realm ) )
104
140
{
105
141
QgsDebugMsg ( QStringLiteral ( " Skipping ignored connection: " ) + realm );
106
142
*ok = false ;
107
143
return ;
108
144
}
109
145
}
110
146
stackedWidget->setCurrentIndex ( 0 );
111
- buttonBox-> button ( QDialogButtonBox::StandardButton::Ignore ) ->show ();
147
+ mIgnoreButton ->show ();
112
148
chkbxPasswordHelperEnable->setChecked ( QgsApplication::authManager ()->passwordHelperEnabled () );
113
149
labelRealm->setText ( realm );
114
150
leUsername->setText ( *username );
@@ -161,7 +197,7 @@ void QgsCredentialDialog::requestCredentialsMasterPassword( QString *password, b
161
197
QgsDebugMsgLevel ( QStringLiteral ( " Entering." ), 4 );
162
198
stackedWidget->setCurrentIndex ( 1 );
163
199
164
- buttonBox-> button ( QDialogButtonBox::StandardButton::Ignore ) ->hide ();
200
+ mIgnoreButton ->hide ();
165
201
leMasterPass->setFocus ();
166
202
167
203
QString titletxt ( stored ? tr ( " Enter CURRENT master authentication password" ) : tr ( " Set NEW master authentication password" ) );
0 commit comments