2005-05-28 23:23:13 +00:00
|
|
|
/***************************************************************************
|
|
|
|
qgsnewhttpconnection.cpp - selector for a new HTTP server for WMS, etc.
|
|
|
|
-------------------
|
|
|
|
begin : 3 April 2005
|
|
|
|
copyright : (C) 2005 by Brendan Morley
|
|
|
|
email : morb at ozemail dot com dot au
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
2008-08-23 21:37:31 +00:00
|
|
|
/* $Id$ */
|
2005-05-28 23:23:13 +00:00
|
|
|
#include "qgsnewhttpconnection.h"
|
2006-01-15 20:57:38 +00:00
|
|
|
#include "qgscontexthelp.h"
|
2005-12-30 04:56:31 +00:00
|
|
|
#include <QSettings>
|
2009-12-09 21:35:43 +00:00
|
|
|
#include <QMessageBox>
|
2011-02-17 12:57:38 +00:00
|
|
|
#include <QUrl>
|
2005-05-28 23:23:13 +00:00
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
QgsNewHttpConnection::QgsNewHttpConnection(
|
2008-08-23 21:37:31 +00:00
|
|
|
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl ):
|
|
|
|
QDialog( parent, fl ),
|
|
|
|
mBaseKey( baseKey ),
|
|
|
|
mOriginalConnName( connName )
|
2005-05-28 23:23:13 +00:00
|
|
|
{
|
2008-08-23 21:37:31 +00:00
|
|
|
setupUi( this );
|
2005-12-30 04:56:31 +00:00
|
|
|
|
2008-08-23 21:37:31 +00:00
|
|
|
if ( !connName.isEmpty() )
|
2008-06-15 22:35:03 +00:00
|
|
|
{
|
|
|
|
// populate the dialog with the information stored for the connection
|
|
|
|
// populate the fields with the stored setting parameters
|
2005-05-28 23:23:13 +00:00
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
QSettings settings;
|
2005-05-28 23:23:13 +00:00
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
QString key = mBaseKey + connName;
|
2009-04-21 07:46:54 +00:00
|
|
|
QString credentialsKey = "/Qgis/WMS/" + connName;
|
2008-08-23 21:37:31 +00:00
|
|
|
txtName->setText( connName );
|
|
|
|
txtUrl->setText( settings.value( key + "/url" ).toString() );
|
2009-04-21 07:46:54 +00:00
|
|
|
txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
|
|
|
|
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
|
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
}
|
2005-05-28 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
QgsNewHttpConnection::~QgsNewHttpConnection()
|
2005-05-28 23:23:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-15 22:35:03 +00:00
|
|
|
void QgsNewHttpConnection::accept()
|
2005-05-28 23:23:13 +00:00
|
|
|
{
|
2008-08-23 21:37:31 +00:00
|
|
|
QSettings settings;
|
2006-08-28 14:48:57 +00:00
|
|
|
QString key = mBaseKey + txtName->text();
|
2009-04-21 07:46:54 +00:00
|
|
|
QString credentialsKey = "/Qgis/WMS/" + txtName->text();
|
2008-06-15 22:35:03 +00:00
|
|
|
|
2009-12-09 21:35:43 +00:00
|
|
|
// warn if entry was renamed to an existing connection
|
|
|
|
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
|
|
|
|
settings.contains( key + "/url" ) &&
|
|
|
|
QMessageBox::question( this,
|
|
|
|
tr( "Save connection" ),
|
|
|
|
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on rename delete original entry first
|
2008-08-23 21:37:31 +00:00
|
|
|
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
|
2008-06-15 22:35:03 +00:00
|
|
|
{
|
2008-08-23 21:37:31 +00:00
|
|
|
settings.remove( mBaseKey + mOriginalConnName );
|
2009-06-02 19:06:37 +00:00
|
|
|
settings.remove( "/Qgis/WMS/" + mOriginalConnName );
|
2008-06-15 22:35:03 +00:00
|
|
|
}
|
2009-12-09 21:35:43 +00:00
|
|
|
|
2011-02-17 12:57:38 +00:00
|
|
|
QUrl url( txtUrl->text().trimmed() );
|
|
|
|
|
|
|
|
QList< QPair<QByteArray, QByteArray> > params = url.encodedQueryItems();
|
|
|
|
for ( int i = 0; i < params.size(); i++ )
|
|
|
|
{
|
|
|
|
if ( params[i].first.toUpper() == "SERVICE" ||
|
|
|
|
params[i].first.toUpper() == "REQUEST" ||
|
|
|
|
params[i].first.toUpper() == "FORMAT" )
|
|
|
|
{
|
|
|
|
params.removeAt( i-- );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
url.setEncodedQueryItems( params );
|
|
|
|
|
|
|
|
settings.setValue( key + "/url", url.toString() );
|
2009-04-21 07:46:54 +00:00
|
|
|
settings.setValue( credentialsKey + "/username", txtUserName->text() );
|
|
|
|
settings.setValue( credentialsKey + "/password", txtPassword->text() );
|
2008-06-15 22:35:03 +00:00
|
|
|
|
|
|
|
QDialog::accept();
|
2005-05-28 23:23:13 +00:00
|
|
|
}
|