summaryrefslogtreecommitdiffstats
path: root/tdeioslave/cgi/kcmcgi/kcmcgi.cpp
blob: 95da88415bd72735340e3adaa06c95e810898706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
   Copyright (C) 2002 Cornelius Schumacher <schumacher@kde.org>

   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.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include <tdeconfig.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <tdeaboutdata.h>
#include <tdefiledialog.h>

#include <tqlayout.h>
#include <tqlistbox.h>
#include <tqpushbutton.h>
#include <tqgroupbox.h>
#include <tqhbox.h>

#include "kcmcgi.h"
#include "kcmcgi.moc"

extern "C"
{
  TDE_EXPORT TDECModule *create_cgi( TQWidget *parent, const char * )
  {
    TDEGlobal::locale()->insertCatalogue("kcmcgi");
    return new KCMCgi( parent, "kcmcgi" );
  }
}


KCMCgi::KCMCgi(TQWidget *parent, const char *name)
  : TDECModule(parent, name)
{
  setButtons(Default|Apply|Help);

  TQVBoxLayout *topLayout = new TQVBoxLayout(this, 0, KDialog::spacingHint());

  TQGroupBox *topBox = new TQGroupBox( 1, TQt::Horizontal, i18n("Paths to Local CGI Programs"), this );
  topLayout->addWidget( topBox );

  mListBox = new TQListBox( topBox );

  TQHBox *buttonBox = new TQHBox( topBox );
  buttonBox->setSpacing( KDialog::spacingHint() );

  mAddButton = new TQPushButton( i18n("Add..."), buttonBox );
  connect( mAddButton, TQ_SIGNAL( clicked() ), TQ_SLOT( addPath() ) );

  mRemoveButton = new TQPushButton( i18n("Remove"), buttonBox );
  connect( mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removePath() ) );
  connect( mListBox, TQ_SIGNAL( clicked ( TQListBoxItem * )),this, TQ_SLOT( slotItemSelected( TQListBoxItem *)));

  mConfig = new TDEConfig("kcmcgirc");

  load();
  updateButton();
  TDEAboutData *about =
    new TDEAboutData( I18N_NOOP("kcmcgi"),
                    I18N_NOOP("CGI TDEIO Slave Control Module"),
                    0, 0, TDEAboutData::License_GPL,
                    I18N_NOOP("(c) 2002 Cornelius Schumacher") );

  about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
  setAboutData(about);
}

KCMCgi::~KCMCgi()
{
  delete mConfig;
}

void KCMCgi::slotItemSelected( TQListBoxItem * )
{
    updateButton();
}

void KCMCgi::updateButton()
{
    mRemoveButton->setEnabled( mListBox->selectedItem ());
}

void KCMCgi::defaults()
{
  mListBox->clear();
  updateButton();
}

void KCMCgi::save()
{
  TQStringList paths;

  uint i;
  for( i = 0; i < mListBox->count(); ++i ) {
    paths.append( mListBox->text( i ) );
  }

  mConfig->setGroup( "General" );
  mConfig->writeEntry( "Paths", paths );

  mConfig->sync();
}

void KCMCgi::load()
{
  mConfig->setGroup( "General" );
  TQStringList paths = mConfig->readListEntry( "Paths" );

  mListBox->insertStringList( paths );
}

void KCMCgi::addPath()
{
  TQString path = KFileDialog::getExistingDirectory( TQString::null, this );

  if ( !path.isEmpty() ) {
    mListBox->insertItem( path );
    emit changed( true );
  }
  updateButton();
}

void KCMCgi::removePath()
{
  int index = mListBox->currentItem();
  if ( index >= 0 ) {
    mListBox->removeItem( index );
    emit changed( true );
  }
  updateButton();
}

TQString KCMCgi::quickHelp() const
{
  return i18n("<h1>CGI Scripts</h1> The CGI TDEIO slave lets you execute "
              "local CGI programs without the need to run a web server. "
              "In this control module you can configure the paths that "
              "are searched for CGI scripts.");
}