QGIS/tools/spit/qgsconnectiondialog.cpp
rawbytes ea2678bf5c added progress dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@343 c8812cc2-4d05-0410-92ff-de0c093fc19c
2003-12-24 02:05:43 +00:00

80 lines
3.0 KiB
C++

/***************************************************************************
qgsconnectiondialog.cpp - description
-------------------
begin : Thu Dec 10 2003
copyright : (C) 2003 by Denis Antipov
email :
***************************************************************************/
/***************************************************************************
* *
* 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 <iostream>
#include <qsettings.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qmessagebox.h>
#include <libpq++.h>
#include "qgsconnectiondialog.h"
QgsConnectionDialog::QgsConnectionDialog (QWidget* parent, QString connName, bool modal, WFlags fl)
: QgsConnectionDialogBase(parent,(const char *)connName,modal,fl)
{
if (!connName.isEmpty()) {
QSettings settings;
QString key = "/Qgis/connections/" + connName;
txtHost->setText(settings.readEntry(key + "/host"));
txtDatabase->setText(settings.readEntry(key + "/database"));
txtUsername->setText(settings.readEntry(key + "/username"));
if(settings.readEntry(key + "/save") == "true"){
txtPassword->setText(settings.readEntry(key + "/password"));
chkStorePassword->setChecked(true);
}
txtName->setText(connName);
}
setFixedSize(QSize(411, 230));
}
QgsConnectionDialog::~QgsConnectionDialog()
{
}
void QgsConnectionDialog::testConnection()
{
QString connInfo = "host=" + txtHost->text() + " dbname=" + txtDatabase->text() +
" user=" + txtUsername->text() + " password=" + txtPassword->text();
PgDatabase *pd = new PgDatabase((const char *) connInfo);
if (pd->Status() == CONNECTION_OK) {
// Database successfully opened; we can now issue SQL commands.
QMessageBox::information(this, "Test connection", "Connection to " + txtDatabase->text() + " was successfull");
} else {
QMessageBox::information(this, "Test connection", "Connection failed - Check settings and try again ");
}
delete pd;
}
void QgsConnectionDialog::saveConnection()
{
QSettings settings;
QString baseKey = "/Qgis/connections/";
baseKey += txtName->text();
settings.writeEntry(baseKey + "/host", txtHost->text());
settings.writeEntry(baseKey + "/database", txtDatabase->text());
settings.writeEntry(baseKey + "/username", txtUsername->text());
settings.writeEntry(baseKey + "/password", txtPassword->text());
if(chkStorePassword->isChecked()) settings.writeEntry(baseKey + "/save", "true");
else settings.writeEntry(baseKey + "/save", "false");
accept();
}