Skip to content
Permalink
Browse files

allow credential requests from threads

  • Loading branch information
jef-n committed May 12, 2013
1 parent fa0a9b7 commit 82e78fffd2cd2c31612b238cceba516e95334ea1
Showing with 37 additions and 11 deletions.
  1. +31 −11 src/gui/qgscredentialdialog.cpp
  2. +6 −0 src/gui/qgscredentialdialog.h
@@ -16,13 +16,19 @@
***************************************************************************/

#include "qgscredentialdialog.h"
#include "qgslogger.h"

#include <QSettings>
#include <QThread>

QgsCredentialDialog::QgsCredentialDialog( QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
setInstance( this );
connect( this, SIGNAL( credentialsRequested( QString, QString *, QString *, QString, bool * ) ),
this, SLOT( requestCredentials( QString, QString *, QString *, QString, bool * ) ),
Qt::BlockingQueuedConnection );
}

QgsCredentialDialog::~QgsCredentialDialog()
@@ -31,26 +37,40 @@ QgsCredentialDialog::~QgsCredentialDialog()

bool QgsCredentialDialog::request( QString realm, QString &username, QString &password, QString message )
{
bool ok;
if ( qApp->thread() != QThread::currentThread() )
{
QgsDebugMsg( "emitting signal" );
emit credentialsRequested( realm, &username, &password, message, &ok );
QgsDebugMsg( QString( "signal returned %1 (username=%2, password=%3)" ).arg( ok ? "true" : "false" ).arg( username ).arg( password ) );
}
else
{
requestCredentials( realm, &username, &password, message, &ok );
}
return ok;
}

void QgsCredentialDialog::requestCredentials( QString realm, QString *username, QString *password, QString message, bool *ok )
{
QgsDebugMsg( "Entering." );
labelRealm->setText( realm );
leUsername->setText( username );
lePassword->setText( password );
leUsername->setText( *username );
lePassword->setText( *password );
labelMessage->setText( message );
labelMessage->setHidden( message.isEmpty() );

QApplication::setOverrideCursor( Qt::ArrowCursor );

int res = exec();
QgsDebugMsg( "exec()" );
*ok = exec() == QDialog::Accepted;
QgsDebugMsg( QString( "exec(): %1" ).arg( ok ? "true" : "false" ) );

QApplication::restoreOverrideCursor();

if ( res == QDialog::Accepted )
{
username = leUsername->text();
password = lePassword->text();
return true;
}
else
if ( *ok )
{
return false;
*username = leUsername->text();
*password = lePassword->text();
}
}
@@ -34,6 +34,12 @@ class GUI_EXPORT QgsCredentialDialog : public QDialog, public QgsCredentials, pr
QgsCredentialDialog( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
~QgsCredentialDialog();

signals:
void credentialsRequested( QString, QString *, QString *, QString, bool * );

private slots:
void requestCredentials( QString, QString *, QString *, QString, bool * );

protected:
virtual bool request( QString realm, QString &username, QString &password, QString message = QString::null );
};

0 comments on commit 82e78ff

Please sign in to comment.
You can’t perform that action at this time.