kword

KWQtSqlMailMergeOpen.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "KWQtSqlMailMergeOpen.h"
00021 #include "KWQtSqlMailMergeOpen.moc"
00022 #include <kcombobox.h>
00023 #include <klineedit.h>
00024 #include <kdebug.h>
00025 #include <qlayout.h>
00026 #include <kconfig.h>
00027 #include <kpushbutton.h>
00028 #include <klineeditdlg.h>
00029 #include <kiconloader.h>
00030 #include <qsqldatabase.h>
00031 #include <qguardedptr.h>
00032 #include <klocale.h>
00033 
00034 /******************************************************************
00035  *
00036  * Class: KWQtSqlMailMergeOpen
00037  *
00038  ******************************************************************/
00039 
00040 KWQtSqlMailMergeOpen::KWQtSqlMailMergeOpen( QWidget *parent, KWQtSqlSerialDataSourceBase *db_ )
00041         :KDialogBase( Plain, i18n( "Mail Merge - Setup Database Connection" ), Ok | Cancel, Ok, parent, "", true ), db( db_ ){
00042         (new QVBoxLayout(plainPage()))->setAutoAdd(true);
00043         setMainWidget(widget=new KWQtSqlOpenWidget(plainPage()));
00044         widget->drivers->insertStringList(QSqlDatabase::drivers());
00045         widget->hostname->setText(db->hostname);
00046         widget->username->setText(db->username);
00047         widget->port->setText(db->port);
00048         widget->databasename->setText(db->databasename);
00049         fillSavedProperties();
00050     connect(this,SIGNAL(okClicked()),this,SLOT(handleOk()));
00051     connect(widget->savedProperties,SIGNAL(activated(const QString&)),
00052         this, SLOT(savedPropertiesChanged(const QString&)));
00053     connect(widget->rememberButton,SIGNAL(clicked()),
00054         this, SLOT(slotSave()));
00055 }
00056 
00057 KWQtSqlMailMergeOpen::~KWQtSqlMailMergeOpen(){;}
00058 
00059 void KWQtSqlMailMergeOpen::savedPropertiesChanged(const QString& name)
00060 {
00061     if (name!=i18n("<not saved>"))
00062     {
00063         KConfig conf("kwmailmergerc");
00064         conf.setGroup("KWSLQTDB:"+name);
00065         widget->hostname->setText(conf.readEntry("hostname",""));
00066         widget->username->setText(conf.readEntry("username",""));
00067         widget->port->setText(conf.readEntry("port",""));
00068         widget->databasename->setText(conf.readEntry("databasename",""));
00069     }
00070     else
00071     {
00072         widget->hostname->setText("");
00073         widget->username->setText("");
00074         widget->port->setText(i18n("default"));
00075         widget->databasename->setText("");
00076     }
00077 
00078 }
00079 
00080 void KWQtSqlMailMergeOpen::fillSavedProperties()
00081 {
00082     widget->savedProperties->clear();
00083     widget->savedProperties->insertItem(i18n("<not saved>"));
00084     //Read data from configuration file and add entries
00085     KConfig conf("kwmailmergerc");
00086     QStringList list=conf.groupList();
00087     for (QStringList::Iterator it=list.begin();it!=list.end();++it)
00088     {
00089         if ((*it).startsWith("KWSLQTDB:"))
00090         widget->savedProperties->insertItem((*it).right((*it).length()-9));
00091     }
00092 }
00093 
00094 void KWQtSqlMailMergeOpen::slotSave()
00095 {
00096     QString value;
00097     bool ok;
00098     value=KLineEditDlg::getText(i18n("Store Settings"),i18n("Name:"),
00099         QString::null, &ok,this);
00100     if (!ok) kdDebug()<<"Cancel was pressed"<<endl;
00101     if (value.isEmpty()) kdDebug()<<"Name value was empty"<<endl;
00102     if ((ok) && (!value.isEmpty()))
00103     {
00104         KConfig conf("kwmailmergerc");
00105         conf.setGroup("KWSLQTDB:"+value);
00106         conf.writeEntry("hostname",widget->hostname->text());
00107         conf.writeEntry("username",widget->username->text());
00108         conf.writeEntry("port",widget->port->text());
00109         conf.writeEntry("databasename",widget->databasename->text());
00110         conf.sync();
00111         fillSavedProperties();
00112         widget->savedProperties->setCurrentText(value);
00113     }
00114 }
00115 
00116 void KWQtSqlMailMergeOpen::handleOk()
00117 {
00118         db->hostname=widget->hostname->text();
00119         db->username=widget->username->text();
00120         db->port=widget->port->text();
00121         db->databasename=widget->databasename->text();
00122         db->driver=widget->drivers->currentText();
00123 }
KDE Home | KDE Accessibility Home | Description of Access Keys