4 * Copyright (c) 2001 George Staikos <staikos@kde.org>
5 * Copyright (c) 2001 Daniel Molkentin <molkentin@kde.org> (designer port)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
37 #include <QtGui/QLayout>
38 #include <QtGui/QLabel>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/QBoxLayout>
43 #include <k3listview.h>
44 #include <kaboutdata.h>
45 #include <kapplication.h>
46 #include <kconfiggroup.h>
47 #include <kfiledialog.h>
50 #include <kmessagebox.h>
52 #include <config-apps.h>
56 KSocksConfig::KSocksConfig(const KComponentData
&componentData
, QWidget
*parent
)
57 : KCModule(componentData
, parent
)
61 new KAboutData(I18N_NOOP("kcmsocks"), 0, ki18n("KDE SOCKS Control Module"),
62 0, KLocalizedString(), KAboutData::License_GPL
,
63 ki18n("(c) 2001 George Staikos"));
65 about
->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
67 setAboutData( about
);
70 QVBoxLayout
*layout
= new QVBoxLayout(this);
71 base
= new SocksBase(this);
72 layout
->addWidget(base
);
74 connect(base
->_c_enableSocks
, SIGNAL(toggled(bool)), this, SLOT(enableChanged()));
75 connect(base
->bg
, SIGNAL(clicked(int)), this, SLOT(methodChanged(int)));
78 connect(base
->_c_customPath
, SIGNAL(openFileDialog(KUrlRequester
*)), this, SLOT(chooseCustomLib(KUrlRequester
*)));
79 connect(base
->_c_customPath
, SIGNAL(textChanged(const QString
&)),
80 this, SLOT(customPathChanged(const QString
&)));
82 // Additional libpaths
83 base
->_c_newPath
->setMode(KFile::File
|KFile::ExistingOnly
|KFile::LocalOnly
);
84 connect(base
->_c_newPath
, SIGNAL(openFileDialog(KUrlRequester
*)), this, SLOT(chooseCustomLib(KUrlRequester
*)));
85 connect(base
->_c_newPath
, SIGNAL(returnPressed(const QString
&)),
86 this, SLOT(addThisLibrary(const QString
&)));
87 connect(base
->_c_newPath
, SIGNAL(textChanged(const QString
&)),
88 this, SLOT(libTextChanged(const QString
&)));
89 connect(base
->_c_add
, SIGNAL(clicked()), this, SLOT(addLibrary()));
90 connect(base
->_c_remove
, SIGNAL(clicked()), this, SLOT(removeLibrary()));
91 connect(base
->_c_libs
, SIGNAL(selectionChanged()), this, SLOT(libSelection()));
94 connect(base
->_c_test
, SIGNAL(clicked()), this, SLOT(testClicked()));
100 KSocksConfig::~KSocksConfig()
104 void KSocksConfig::configChanged()
109 void KSocksConfig::enableChanged()
111 KMessageBox::information(this,
112 i18n("These changes will only apply to newly "
113 "started applications."),
114 i18n("SOCKS Support"),
115 "SOCKSdontshowagain");
120 void KSocksConfig::methodChanged(int id
)
123 base
->_c_customLabel
->setEnabled(true);
124 base
->_c_customPath
->setEnabled(true);
126 base
->_c_customLabel
->setEnabled(false);
127 base
->_c_customPath
->setEnabled(false);
133 void KSocksConfig::customPathChanged(const QString
&)
139 void KSocksConfig::testClicked()
141 save(); // we have to save before we can test! Perhaps
142 // it would be best to warn, though.
144 KDECORE_EXPORT
bool kdeHasSocks(); // defined in kdecore/ksocks.cpp
146 KMessageBox::information(this,
147 i18n("Success: SOCKS was found and initialized."),
148 i18n("SOCKS Support"));
149 // Eventually we could actually attempt to connect to a site here.
151 KMessageBox::information(this,
152 i18n("SOCKS could not be loaded."),
153 i18n("SOCKS Support"));
159 void KSocksConfig::chooseCustomLib(KUrlRequester
* url
)
161 url
->setMode( KFile::Directory
);
162 /* QString newFile = KFileDialog::getOpenFileName();
163 if (newFile.length() > 0) {
164 base->_c_customPath->setPath(newFile);
171 void KSocksConfig::libTextChanged(const QString
& lib
)
173 if (lib
.length() > 0)
174 base
-> _c_add
->setEnabled(true);
175 else base
->_c_add
->setEnabled(false);
179 void KSocksConfig::addThisLibrary(const QString
& lib
)
181 if (lib
.length() > 0) {
182 new Q3ListViewItem(base
->_c_libs
, lib
);
183 base
->_c_newPath
->clear();
184 base
->_c_add
->setEnabled(false);
185 base
->_c_newPath
->setFocus();
191 void KSocksConfig::addLibrary()
193 addThisLibrary(base
->_c_newPath
->url().path());
197 void KSocksConfig::removeLibrary()
199 Q3ListViewItem
*thisitem
= base
->_c_libs
->selectedItem();
200 base
->_c_libs
->takeItem(thisitem
);
202 base
->_c_libs
->clearSelection();
203 base
->_c_remove
->setEnabled(false);
208 void KSocksConfig::libSelection()
210 base
->_c_remove
->setEnabled(true);
214 void KSocksConfig::load()
216 KConfigGroup
config(KGlobal::config(), "Socks");
217 base
->_c_enableSocks
->setChecked(config
.readEntry("SOCKS_enable", false));
218 int id
= config
.readEntry("SOCKS_method", 1);
219 base
->bg
->setButton(id
);
221 base
->_c_customLabel
->setEnabled(true);
222 base
->_c_customPath
->setEnabled(true);
224 base
->_c_customLabel
->setEnabled(false);
225 base
->_c_customPath
->setEnabled(false);
227 base
->_c_customPath
->setPath(config
.readPathEntry("SOCKS_lib", QString()));
229 Q3ListViewItem
*thisitem
;
230 while ((thisitem
= base
->_c_libs
->firstChild())) {
231 base
->_c_libs
->takeItem(thisitem
);
235 QStringList libs
= config
.readPathEntry("SOCKS_lib_path", QStringList());
236 for(QStringList::Iterator it
= libs
.begin();
239 new Q3ListViewItem(base
->_c_libs
, *it
);
241 base
->_c_libs
->clearSelection();
242 base
->_c_remove
->setEnabled(false);
243 base
->_c_add
->setEnabled(false);
244 base
->_c_newPath
->clear();
248 void KSocksConfig::save()
250 KConfigGroup
config(KGlobal::config(), "Socks");
251 config
.writeEntry("SOCKS_enable",base
-> _c_enableSocks
->isChecked(), KConfigBase::Normal
| KConfigBase::Global
);
252 config
.writeEntry("SOCKS_method", base
->bg
->id(base
->bg
->selected()), KConfigBase::Normal
| KConfigBase::Global
);
253 config
.writePathEntry("SOCKS_lib", base
->_c_customPath
->url().path(), KConfigBase::Normal
| KConfigBase::Global
);
254 Q3ListViewItem
*thisitem
= base
->_c_libs
->firstChild();
258 libs
<< thisitem
->text(0);
259 thisitem
= thisitem
->itemBelow();
261 config
.writePathEntry("SOCKS_lib_path", libs
, KConfigBase::Normal
| KConfigBase::Global
);
263 KGlobal::config()->sync();
268 void KSocksConfig::defaults()
271 base
->_c_enableSocks
->setChecked(false);
272 base
->bg
->setButton(1);
273 base
->_c_customLabel
->setEnabled(false);
274 base
->_c_customPath
->setEnabled(false);
275 base
->_c_customPath
->clear();
276 Q3ListViewItem
*thisitem
;
277 while ((thisitem
= base
->_c_libs
->firstChild())) {
278 base
->_c_libs
->takeItem(thisitem
);
281 base
->_c_newPath
->clear();
282 base
->_c_add
->setEnabled(false);
283 base
->_c_remove
->setEnabled(false);
286 QString
KSocksConfig::quickHelp() const
288 return i18n("<h1>SOCKS</h1><p>This module allows you to configure KDE support"
289 " for a SOCKS server or proxy.</p><p>SOCKS is a protocol to traverse firewalls"
290 " as described in <a href=\"http://rfc.net/rfc1928.html\">RFC 1928</a>.</p>"
291 " <p>If you have no idea what this is and if your system administrator does not"
292 " tell you to use it, leave it disabled.</p>");