add more spacing
[personal-kdebase.git] / runtime / kioslave / cgi / kcmcgi / kcmcgi.cpp
blob1b6c05d5daa0a344eded58a09eeca82a8283a226
1 /*
2 Copyright (C) 2002 Cornelius Schumacher <schumacher@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "kcmcgi.h"
21 #include <KAboutData>
22 #include <KComponentData>
23 #include <KConfig>
24 #include <KFileDialog>
25 #include <KPluginFactory>
26 #include <KPluginLoader>
27 #include <KGlobal>
28 #include <KHBox>
29 #include <KLocale>
31 #include <QGroupBox>
32 #include <QLayout>
33 #include <QListWidget>
34 #include <QPushButton>
35 #include <QHBoxLayout>
37 #include "kcmcgi.moc"
39 K_PLUGIN_FACTORY(KCMCgiFactory, registerPlugin<KCMCgi>();)
40 K_EXPORT_PLUGIN(KCMCgiFactory("kcmcgi"))
42 KCMCgi::KCMCgi(QWidget *parent, const QVariantList &)
43 : KCModule(KCMCgiFactory::componentData(), parent)
45 setButtons(Default|Apply);
47 QVBoxLayout *topLayout = new QVBoxLayout(this);
48 topLayout->setSpacing(KDialog::spacingHint());
50 QGroupBox *topBox = new QGroupBox(i18n("Paths to Local CGI Programs"), this);
51 QVBoxLayout *vbox = new QVBoxLayout;
52 vbox->addStretch(1);
53 topBox->setLayout(vbox);
54 topLayout->addWidget(topBox);
56 mListBox = new QListWidget( topBox );
58 vbox->addWidget(mListBox);
59 KHBox *buttonBox = new KHBox( topBox );
60 buttonBox->setSpacing( KDialog::spacingHint() );
62 mAddButton = new QPushButton( i18n("Add..."), buttonBox );
63 connect( mAddButton, SIGNAL( clicked() ), SLOT( addPath() ) );
65 mRemoveButton = new QPushButton( i18n("Remove"), buttonBox );
66 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removePath() ) );
67 connect( mListBox, SIGNAL(itemClicked(QListWidgetItem*)),this, SLOT(slotItemSelected(QListWidgetItem*)));
69 vbox->addWidget(buttonBox);
70 mConfig = new KConfig("kcmcgirc", KConfig::NoGlobals);
72 load();
73 updateButton();
74 KAboutData *about =
75 new KAboutData( I18N_NOOP("kcmcgi"), 0,
76 ki18n("CGI KIO Slave Control Module"),
77 0, KLocalizedString(), KAboutData::License_GPL,
78 ki18n("(c) 2002 Cornelius Schumacher") );
80 about->addAuthor( ki18n("Cornelius Schumacher"), KLocalizedString(), "schumacher@kde.org" );
81 setAboutData(about);
84 KCMCgi::~KCMCgi()
86 delete mConfig;
89 void KCMCgi::slotItemSelected( QListWidgetItem * )
91 updateButton();
94 void KCMCgi::updateButton()
96 mRemoveButton->setEnabled( !mListBox->selectedItems().isEmpty() );
99 void KCMCgi::defaults()
101 mListBox->clear();
102 updateButton();
105 void KCMCgi::save()
107 QStringList paths;
109 int i;
110 for( i = 0; i < mListBox->count(); ++i ) {
111 paths.append( mListBox->item(i)->text() );
114 mConfig->group("General").writeEntry( "Paths", paths );
116 mConfig->sync();
119 void KCMCgi::load()
121 QStringList paths = mConfig->group("General").readEntry( "Paths" , QStringList() );
123 mListBox->addItems( paths );
126 void KCMCgi::addPath()
128 QString path = KFileDialog::getExistingDirectory( QString(), this );
130 if ( !path.isEmpty() ) {
131 mListBox->addItem( path );
132 emit changed( true );
134 updateButton();
137 void KCMCgi::removePath()
139 int index = mListBox->currentRow();
140 if ( index >= 0 ) {
141 delete mListBox->takeItem( index );
142 emit changed( true );
144 updateButton();
147 QString KCMCgi::quickHelp() const
149 return i18n("<h1>CGI Scripts</h1> The CGI KIO slave lets you execute "
150 "local CGI programs without the need to run a web server. "
151 "In this control module you can configure the paths that "
152 "are searched for CGI scripts.");