kword

KWQtSqlMailMergeOpen.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
3
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.
8
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.
13
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KWQtSqlMailMergeOpen.h"
21#include "KWQtSqlMailMergeOpen.moc"
22#include <kcombobox.h>
23#include <klineedit.h>
24#include <kdebug.h>
25#include <tqlayout.h>
26#include <tdeconfig.h>
27#include <kpushbutton.h>
28#include <klineeditdlg.h>
29#include <kiconloader.h>
30#include <tqsqldatabase.h>
31#include <tqguardedptr.h>
32#include <tdelocale.h>
33
34/******************************************************************
35 *
36 * Class: KWQtSqlMailMergeOpen
37 *
38 ******************************************************************/
39
40KWQtSqlMailMergeOpen::KWQtSqlMailMergeOpen( TQWidget *parent, KWQtSqlSerialDataSourceBase *db_ )
41 :KDialogBase( Plain, i18n( "Mail Merge - Setup Database Connection" ), Ok | Cancel, Ok, parent, "", true ), db( db_ ){
42 (new TQVBoxLayout(plainPage()))->setAutoAdd(true);
43 setMainWidget(widget=new KWQtSqlOpenWidget(plainPage()));
44 widget->drivers->insertStringList(TQSqlDatabase::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,TQ_SIGNAL(okClicked()),this,TQ_SLOT(handleOk()));
51 connect(widget->savedProperties,TQ_SIGNAL(activated(const TQString&)),
52 this, TQ_SLOT(savedPropertiesChanged(const TQString&)));
53 connect(widget->rememberButton,TQ_SIGNAL(clicked()),
54 this, TQ_SLOT(slotSave()));
55}
56
57KWQtSqlMailMergeOpen::~KWQtSqlMailMergeOpen(){;}
58
59void KWQtSqlMailMergeOpen::savedPropertiesChanged(const TQString& name)
60{
61 if (name!=i18n("<not saved>"))
62 {
63 TDEConfig conf("kwmailmergerc");
64 conf.setGroup("KWSLTQTDB:"+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",""));
69 }
70 else
71 {
72 widget->hostname->setText("");
73 widget->username->setText("");
74 widget->port->setText(i18n("default"));
75 widget->databasename->setText("");
76 }
77
78}
79
80void KWQtSqlMailMergeOpen::fillSavedProperties()
81{
82 widget->savedProperties->clear();
83 widget->savedProperties->insertItem(i18n("<not saved>"));
84 //Read data from configuration file and add entries
85 TDEConfig conf("kwmailmergerc");
86 TQStringList list=conf.groupList();
87 for (TQStringList::Iterator it=list.begin();it!=list.end();++it)
88 {
89 if ((*it).startsWith("KWSLTQTDB:"))
90 widget->savedProperties->insertItem((*it).right((*it).length()-9));
91 }
92}
93
94void KWQtSqlMailMergeOpen::slotSave()
95{
96 TQString value;
97 bool ok;
98 value=KLineEditDlg::getText(i18n("Store Settings"),i18n("Name:"),
99 TQString(), &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()))
103 {
104 TDEConfig conf("kwmailmergerc");
105 conf.setGroup("KWSLTQTDB:"+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());
110 conf.sync();
111 fillSavedProperties();
112 widget->savedProperties->setCurrentText(value);
113 }
114}
115
116void KWQtSqlMailMergeOpen::handleOk()
117{
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();
123}