QGIS API Documentation  master-6227475
src/gui/qgscredentialdialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgscredentialdialog.cpp  -  description
00003                              -------------------
00004     begin                : February 2010
00005     copyright            : (C) 2010 by Juergen E. Fischer
00006     email                : jef at norbit dot de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgscredentialdialog.h"
00019 #include "qgslogger.h"
00020 
00021 #include <QSettings>
00022 #include <QThread>
00023 
00024 QgsCredentialDialog::QgsCredentialDialog( QWidget *parent, Qt::WFlags fl )
00025     : QDialog( parent, fl )
00026 {
00027   setupUi( this );
00028   setInstance( this );
00029   connect( this, SIGNAL( credentialsRequested( QString, QString *, QString *, QString, bool * ) ),
00030            this, SLOT( requestCredentials( QString, QString *, QString *, QString, bool * ) ),
00031            Qt::BlockingQueuedConnection );
00032 }
00033 
00034 QgsCredentialDialog::~QgsCredentialDialog()
00035 {
00036 }
00037 
00038 bool QgsCredentialDialog::request( QString realm, QString &username, QString &password, QString message )
00039 {
00040   bool ok;
00041   if ( qApp->thread() != QThread::currentThread() )
00042   {
00043     QgsDebugMsg( "emitting signal" );
00044     emit credentialsRequested( realm, &username, &password, message, &ok );
00045     QgsDebugMsg( QString( "signal returned %1 (username=%2, password=%3)" ).arg( ok ? "true" : "false" ).arg( username ).arg( password ) );
00046   }
00047   else
00048   {
00049     requestCredentials( realm, &username, &password, message, &ok );
00050   }
00051   return ok;
00052 }
00053 
00054 void QgsCredentialDialog::requestCredentials( QString realm, QString *username, QString *password, QString message, bool *ok )
00055 {
00056   QgsDebugMsg( "Entering." );
00057   labelRealm->setText( realm );
00058   leUsername->setText( *username );
00059   lePassword->setText( *password );
00060   labelMessage->setText( message );
00061   labelMessage->setHidden( message.isEmpty() );
00062 
00063   QApplication::setOverrideCursor( Qt::ArrowCursor );
00064 
00065   QgsDebugMsg( "exec()" );
00066   *ok = exec() == QDialog::Accepted;
00067   QgsDebugMsg( QString( "exec(): %1" ).arg( ok ? "true" : "false" ) );
00068 
00069   QApplication::restoreOverrideCursor();
00070 
00071   if ( *ok )
00072   {
00073     *username = leUsername->text();
00074     *password = lePassword->text();
00075   }
00076 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines