1
/* This file is part of the KDE project
2
Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include "qtsqlopeneditor.h"
21
#include "qtsqlopeneditor.moc"
22
#include <kcombobox.h>
23
#include <klineedit.h>
27
#include <kpushbutton.h>
28
#include <klineeditdlg.h>
29
#include <kiconloader.h>
30
#include <qsqldatabase.h>
31
#include <qguardedptr.h>
34
/******************************************************************
36
* Class: KWQTSQLMailMergeOpen
38
******************************************************************/
40
KWQTSQLMailMergeOpen::KWQTSQLMailMergeOpen( QWidget *parent, KWQTSQLSerialDataSourceBase *db_ )
41
:KDialogBase( Plain, i18n( "Mail Merge - Setup Database Connection" ), Ok | Cancel, Ok, parent, "", true ), db( db_ ){
42
(new QVBoxLayout(plainPage()))->setAutoAdd(true);
43
setMainWidget(widget=new KWQTSQLOpenWidget(plainPage()));
44
widget->drivers->insertStringList(QSqlDatabase::drivers());
45
widget->hostname->setText(db->hostname);
46
widget->username->setText(db->username);
47
widget->port->setText(db->port);
48
widget->databasename->setText(db->databasename);
49
fillSavedProperties();
50
connect(this,SIGNAL(okClicked()),this,SLOT(handleOk()));
51
connect(widget->savedProperties,SIGNAL(activated(const QString&)),
52
this, SLOT(savedPropertiesChanged(const QString&)));
53
connect(widget->rememberButton,SIGNAL(clicked()),
54
this, SLOT(slotSave()));
57
KWQTSQLMailMergeOpen::~KWQTSQLMailMergeOpen(){;}
59
void KWQTSQLMailMergeOpen::savedPropertiesChanged(const QString& name)
61
if (name!=i18n("<not saved>"))
63
KConfig conf("kwmailmergerc");
64
conf.setGroup("KWSLQTDB:"+name);
65
widget->hostname->setText(conf.readEntry("hostname",""));
66
widget->username->setText(conf.readEntry("username",""));
67
widget->port->setText(conf.readEntry("port",""));
68
widget->databasename->setText(conf.readEntry("databasename",""));
72
widget->hostname->setText("");
73
widget->username->setText("");
74
widget->port->setText(i18n("default"));
75
widget->databasename->setText("");
80
void KWQTSQLMailMergeOpen::fillSavedProperties()
82
widget->savedProperties->clear();
83
widget->savedProperties->insertItem(i18n("<not saved>"));
84
//Read data from configuration file and add entries
85
KConfig conf("kwmailmergerc");
86
QStringList list=conf.groupList();
87
for (QStringList::Iterator it=list.begin();it!=list.end();++it)
89
if ((*it).startsWith("KWSLQTDB:"))
90
widget->savedProperties->insertItem((*it).right((*it).length()-9));
94
void KWQTSQLMailMergeOpen::slotSave()
98
value=KLineEditDlg::getText(i18n("Store Settings"),i18n("Name:"),
99
QString::null, &ok,this);
100
if (!ok) kdDebug()<<"Cancel was pressed"<<endl;
101
if (value.isEmpty()) kdDebug()<<"Name value was empty"<<endl;
102
if ((ok) && (!value.isEmpty()))
104
KConfig conf("kwmailmergerc");
105
conf.setGroup("KWSLQTDB:"+value);
106
conf.writeEntry("hostname",widget->hostname->text());
107
conf.writeEntry("username",widget->username->text());
108
conf.writeEntry("port",widget->port->text());
109
conf.writeEntry("databasename",widget->databasename->text());
111
fillSavedProperties();
112
widget->savedProperties->setCurrentText(value);
116
void KWQTSQLMailMergeOpen::handleOk()
118
db->hostname=widget->hostname->text();
119
db->username=widget->username->text();
120
db->port=widget->port->text();
121
db->databasename=widget->databasename->text();
122
db->driver=widget->drivers->currentText();