Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / settings / kio / socks.cpp
blob1a75408973302ff808f9d3a720d1ba851babbef7
1 /**
2 * socks.cpp
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.
22 // Own
23 #include "socks.h"
25 // std
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
28 #endif
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
32 #endif
34 #include <unistd.h>
36 // Qt
37 #include <QtGui/QLayout>
38 #include <QtGui/QLabel>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/QBoxLayout>
42 // KDE
43 #include <k3listview.h>
44 #include <kaboutdata.h>
45 #include <kapplication.h>
46 #include <kconfiggroup.h>
47 #include <kfiledialog.h>
48 #include <kglobal.h>
49 #include <klocale.h>
50 #include <kmessagebox.h>
52 #include <config-apps.h>
56 KSocksConfig::KSocksConfig(const KComponentData &componentData, QWidget *parent)
57 : KCModule(componentData, parent)
60 KAboutData *about =
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)));
77 // The custom library
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()));
93 // The "Test" button
94 connect(base->_c_test, SIGNAL(clicked()), this, SLOT(testClicked()));
96 // The config backend
97 load();
100 KSocksConfig::~KSocksConfig()
104 void KSocksConfig::configChanged()
106 emit changed(true);
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");
116 emit changed(true);
120 void KSocksConfig::methodChanged(int id)
122 if (id == 2) {
123 base->_c_customLabel->setEnabled(true);
124 base->_c_customPath->setEnabled(true);
125 } else {
126 base->_c_customLabel->setEnabled(false);
127 base->_c_customPath->setEnabled(false);
129 emit changed(true);
133 void KSocksConfig::customPathChanged(const QString&)
135 emit changed(true);
139 void KSocksConfig::testClicked()
141 save(); // we have to save before we can test! Perhaps
142 // it would be best to warn, though.
143 #ifdef Q_OS_UNIX
144 KDECORE_EXPORT bool kdeHasSocks(); // defined in kdecore/ksocks.cpp
145 if (kdeHasSocks()) {
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.
150 } else {
151 KMessageBox::information(this,
152 i18n("SOCKS could not be loaded."),
153 i18n("SOCKS Support"));
155 #endif
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);
165 emit changed(true);
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();
186 emit changed(true);
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);
201 delete thisitem;
202 base->_c_libs->clearSelection();
203 base->_c_remove->setEnabled(false);
204 emit changed(true);
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);
220 if (id == 4) {
221 base->_c_customLabel->setEnabled(true);
222 base->_c_customPath->setEnabled(true);
223 } else {
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);
232 delete thisitem;
235 QStringList libs = config.readPathEntry("SOCKS_lib_path", QStringList());
236 for(QStringList::Iterator it = libs.begin();
237 it != libs.end();
238 ++it ) {
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();
245 emit changed(false);
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();
256 QStringList libs;
257 while (thisitem) {
258 libs << thisitem->text(0);
259 thisitem = thisitem->itemBelow();
261 config.writePathEntry("SOCKS_lib_path", libs, KConfigBase::Normal | KConfigBase::Global);
263 KGlobal::config()->sync();
265 emit changed(false);
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);
279 delete 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>");
296 #include "socks.moc"