forked from planetfederal/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgscredentialdialog.cpp
79 lines (67 loc) · 2.78 KB
/
qgscredentialdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/***************************************************************************
qgscredentialdialog.cpp - description
-------------------
begin : February 2010
copyright : (C) 2010 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#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()
{
}
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 );
labelMessage->setText( message );
labelMessage->setHidden( message.isEmpty() );
if ( !leUsername->text().isEmpty() )
lePassword->setFocus();
QApplication::setOverrideCursor( Qt::ArrowCursor );
QgsDebugMsg( "exec()" );
*ok = exec() == QDialog::Accepted;
QgsDebugMsg( QString( "exec(): %1" ).arg( *ok ? "true" : "false" ) );
QApplication::restoreOverrideCursor();
if ( *ok )
{
*username = leUsername->text();
*password = lePassword->text();
}
}