Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / khelpcenter / htmlsearch / kcmhtmlsearch.cpp
blob2f1285778d420029af18a44dea6d2657c9a9bf26
1 /**
2 * kcmhtmlsearch.cpp
4 * Copyright (c) 2000 Matthias Hölzer-Klüpfel <hoelzer@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <QLayout>
22 #include <kstandarddirs.h>
23 #include <klocale.h>
24 #include <kurllabel.h>
25 #include <kapplication.h>
26 #include <QCheckBox>
27 #include <QWhatsThis>
28 #include <kfiledialog.h>
29 #include <k3process.h>
30 #include "klangcombo.h"
31 #include <kurlrequester.h>
32 #include <klineedit.h>
33 #include <ktoolinvocation.h>
34 #include <kgenericfactory.h>
36 #include "kcmhtmlsearch.moc"
38 typedef KGenericFactory<KHTMLSearchConfig> KHTMLSearchConfigFactory;
39 K_EXPORT_COMPONENT_FACTORY(htmlsearch, KHTMLSearchConfigFactory("kcmhtmlsearch"))
41 KHTMLSearchConfig::KHTMLSearchConfig(QWidget *parent, const QStringList &)
42 : KCModule(KHTMLSearchConfigFactory::componentData(), parent), indexProc(0)
44 QVBoxLayout *vbox = new QVBoxLayout(this);
45 vbox->setSpacing(5);
48 QGroupBox *gb = new QGroupBox(i18n("ht://dig"), this);
49 vbox->addWidget(gb);
51 QGridLayout *grid = new QGridLayout(gb);
52 grid->setSpacing(6);
53 grid->setMargin(6);
55 grid->addRowSpacing(0, gb->fontMetrics().lineSpacing());
57 QLabel *l = new QLabel(i18n("The fulltext search feature makes use of the "
58 "ht://dig HTML search engine. "
59 "You can get ht://dig at the"), gb);
60 l->setAlignment(QLabel::WordBreak);
61 l->setMinimumSize(l->sizeHint());
62 grid->addWidget(l, 1, 0, 1, 2 );
63 QWhatsThis::add( gb, i18n( "Information about where to get the ht://dig package." ) );
65 KUrlLabel *url = new KUrlLabel(gb);
66 url->setURL("http://www.htdig.org");
67 url->setText(i18n("ht://dig home page"));
68 url->setAlignment(QLabel::AlignHCenter);
69 grid->addWidget(url, 2, 0, 1, 2 );
70 connect(url, SIGNAL(leftClickedUrl(const QString&)),
71 this, SLOT(urlClicked(const QString&)));
73 gb = new QGroupBox(i18n("Program Locations"), this);
75 vbox->addWidget(gb);
76 grid = new QGridLayout(gb);
77 grid->setSpacing(6);
78 grid->setMargin(6);
79 grid->addRowSpacing(0, gb->fontMetrics().lineSpacing());
81 htdigBin = new KUrlRequester(gb);
82 l = new QLabel(i18n("ht&dig"),gb);
83 l->setBuddy(htdigBin);
84 grid->addWidget(l, 1,0);
85 grid->addWidget(htdigBin, 1,1);
86 connect(htdigBin->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(configChanged()));
87 QString wtstr = i18n( "Enter the path to your htdig program here, e.g. /usr/local/bin/htdig" );
88 QWhatsThis::add( htdigBin, wtstr );
89 QWhatsThis::add( l, wtstr );
91 htsearchBin = new KUrlRequester(gb);
92 l = new QLabel(i18n("ht&search"),gb);
93 l->setBuddy(htsearchBin);
94 grid->addWidget(l, 2,0);
95 grid->addWidget(htsearchBin, 2,1);
96 connect(htsearchBin->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(configChanged()));
97 wtstr = i18n( "Enter the path to your htsearch program here, e.g. /usr/local/bin/htsearch" );
98 QWhatsThis::add( htsearchBin, wtstr );
99 QWhatsThis::add( l, wtstr );
101 htmergeBin = new KUrlRequester(gb);
102 l = new QLabel(i18n("ht&merge"),gb);
103 l->setBuddy(htmergeBin);
104 grid->addWidget(l, 3,0);
105 grid->addWidget(htmergeBin, 3,1);
106 connect(htmergeBin->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(configChanged()));
107 wtstr = i18n( "Enter the path to your htmerge program here, e.g. /usr/local/bin/htmerge" );
108 QWhatsThis::add( htmergeBin, wtstr );
109 QWhatsThis::add( l, wtstr );
111 QHBoxLayout *hbox = new QHBoxLayout(vbox);
113 gb = new QGroupBox(i18n("Scope"), this);
114 hbox->addWidget(gb);
115 QWhatsThis::add( gb, i18n( "Here you can select which parts of the documentation should be included in the fulltext search index. Available options are the KDE Help pages, the installed man pages, and the installed info pages. You can select any number of these." ) );
117 QVBoxLayout *vvbox = new QVBoxLayout(gb);
118 vvbox->setSpacing(2);
119 vvbox->setMargin(6);
120 vvbox->addSpacing(gb->fontMetrics().lineSpacing());
122 indexKDE = new QCheckBox(i18n("&KDE help"), gb);
123 vvbox->addWidget(indexKDE);
124 connect(indexKDE, SIGNAL(clicked()), this, SLOT(configChanged()));
126 indexMan = new QCheckBox(i18n("&Man pages"), gb);
127 vvbox->addWidget(indexMan);
128 indexMan->setEnabled(false),
129 connect(indexMan, SIGNAL(clicked()), this, SLOT(configChanged()));
131 indexInfo = new QCheckBox(i18n("&Info pages"), gb);
132 vvbox->addWidget(indexInfo);
133 indexInfo->setEnabled(false);
134 connect(indexInfo, SIGNAL(clicked()), this, SLOT(configChanged()));
136 gb = new QGroupBox(i18n("Additional Search Paths"), this);
137 hbox->addWidget(gb);
138 QWhatsThis::add( gb, i18n( "Here you can add additional paths to search for documentation. To add a path, click on the <em>Add...</em> button and select the folder from where additional documentation should be searched. You can remove folders by clicking on the <em>Delete</em> button." ) );
140 grid = new QGridLayout(gb);
141 grid->setSpacing(2);
142 grid->setMargin(6);
143 grid->addRowSpacing(0, gb->fontMetrics().lineSpacing());
145 addButton = new QPushButton(i18n("Add..."), gb);
146 grid->addWidget(addButton, 1,0);
148 delButton = new QPushButton(i18n("Delete"), gb);
149 grid->addWidget(delButton, 2,0);
151 searchPaths = new KListWidget(gb);
152 grid->addWidget(searchPaths, 1, 1,3, 1);
153 grid->setRowStretch(2,2);
155 gb = new QGroupBox(i18n("Language Settings"), this);
156 vbox->addWidget(gb);
157 QWhatsThis::add(gb, i18n("Here you can select the language you want to create the index for."));
158 language = new KLanguageCombo(gb);
159 l = new QLabel(i18n("&Language"),gb);
160 l->setBuddy(language);
161 vvbox = new QVBoxLayout(gb);
162 vvbox->setSpacing(2);
163 vvbox->setMargin(6);
164 vvbox->addSpacing(gb->fontMetrics().lineSpacing());
165 hbox = new QHBoxLayout(vvbox);
166 hbox->setSpacing(6);
167 hbox->addWidget(l);
168 hbox->addWidget(language,1);
169 hbox->addStretch(1);
171 loadLanguages();
173 vbox->addStretch(1);
175 runButton = new QPushButton(i18n("Generate Index..."), this);
176 QWhatsThis::add( runButton, i18n( "Click this button to generate the index for the fulltext search." ) );
177 runButton->setFixedSize(runButton->sizeHint());
178 vbox->addWidget(runButton, AlignRight);
179 connect(runButton, SIGNAL(clicked()), this, SLOT(generateIndex()));
181 connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
182 connect(delButton, SIGNAL(clicked()), this, SLOT(delClicked()));
183 connect(searchPaths, SIGNAL(highlighted(const QString &)),
184 this, SLOT(pathSelected(const QString &)));
186 checkButtons();
188 load();
192 void KHTMLSearchConfig::loadLanguages()
194 // clear the list
195 language->clear();
197 // add all languages to the list
198 QStringList langs = KGlobal::dirs()->findAllResources("locale",
199 QLatin1String("*/entry.desktop"));
200 langs.sort();
202 for (QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it)
204 KSimpleConfig entry(*it);
205 entry.setGroup(QLatin1String("KCM Locale"));
206 QString name = entry.readEntry(QLatin1String("Name"), i18n("without name"));
208 QString path = *it;
209 int index = path.lastIndexOf('/');
210 path = path.left(index);
211 index = path.lastIndexOf('/');
212 path = path.mid(index+1);
213 language->insertLanguage(path, name);
218 QString KHTMLSearchConfig::quickHelp() const
220 return i18n( "<h1>Help Index</h1> This configuration module lets you configure the ht://dig engine which can be used for fulltext search in the KDE documentation as well as other system documentation like man and info pages." );
224 void KHTMLSearchConfig::pathSelected(const QString &)
226 checkButtons();
230 void KHTMLSearchConfig::checkButtons()
233 delButton->setEnabled(searchPaths->currentItem() >= 0);
237 void KHTMLSearchConfig::addClicked()
239 QString dir = KFileDialog::getExistingDirectory();
241 if (!dir.isEmpty())
243 for (uint i=0; i<searchPaths->count(); ++i)
244 if (searchPaths->text(i) == dir)
245 return;
246 searchPaths->insertItem(dir);
247 configChanged();
252 void KHTMLSearchConfig::delClicked()
254 searchPaths->removeItem(searchPaths->currentItem());
255 checkButtons();
256 configChanged();
260 KHTMLSearchConfig::~KHTMLSearchConfig()
265 void KHTMLSearchConfig::configChanged()
267 emit changed(true);
271 void KHTMLSearchConfig::load()
273 KConfig *config = new KConfig("khelpcenterrc", true);
275 config->setGroup("htdig");
276 htdigBin->lineEdit()->setText(config->readPathEntry("htdig", kapp->dirs()->findExe("htdig")));
277 htsearchBin->lineEdit()->setText(config->readPathEntry("htsearch", kapp->dirs()->findExe("htsearch")));
278 htmergeBin->lineEdit()->setText(config->readPathEntry("htmerge", kapp->dirs()->findExe("htmerge")));
280 config->setGroup("Scope");
281 indexKDE->setChecked(config->readEntry("KDE", true));
282 indexMan->setChecked(config->readEntry("Man", false));
283 indexInfo->setChecked(config->readEntry("Info", false));
285 QStringList l = config->readPathEntry("Paths", QStringList());
286 searchPaths->clear();
287 QStringList::Iterator it;
288 for (it=l.begin(); it != l.end(); ++it)
289 searchPaths->insertItem(*it);
291 config->setGroup("Locale");
292 QString lang = config->readEntry("Search Language", KGlobal::locale()->language());
293 language->setCurrentItem(lang);
294 delete config;
296 emit changed(false);
300 void KHTMLSearchConfig::save()
302 KConfig *config= new KConfig("khelpcenterrc", false);
304 config->setGroup("htdig");
305 config->writePathEntry("htdig", htdigBin->lineEdit()->text());
306 config->writePathEntry("htsearch", htsearchBin->lineEdit()->text());
307 config->writePathEntry("htmerge", htmergeBin->lineEdit()->text());
309 config->setGroup("Scope");
310 config->writeEntry("KDE", indexKDE->isChecked());
311 config->writeEntry("Man", indexMan->isChecked());
312 config->writeEntry("Info", indexInfo->isChecked());
314 QStringList l;
315 for (uint i=0; i<searchPaths->count(); ++i)
316 l.append(searchPaths->text(i));
317 config->writePathEntry("Paths", l);
319 config->setGroup("Locale");
320 config->writeEntry("Search Language", language->currentTag());
322 config->sync();
323 delete config;
325 emit changed(false);
329 void KHTMLSearchConfig::defaults()
331 htdigBin->lineEdit()->setText(kapp->dirs()->findExe("htdig"));
332 htsearchBin->lineEdit()->setText(kapp->dirs()->findExe("htsearch"));
333 htmergeBin->lineEdit()->setText(kapp->dirs()->findExe("htmerge"));
335 indexKDE->setChecked(true);
336 indexMan->setChecked(false);
337 indexInfo->setChecked(false);
339 searchPaths->clear();
341 language->setCurrentItem(KGlobal::locale()->language());
343 emit changed(true);
347 void KHTMLSearchConfig::urlClicked(const QString &url)
349 KToolInvocation::invokeBrowser(url);
353 void KHTMLSearchConfig::generateIndex()
355 save();
357 QString exe = kapp->dirs()->findExe("khtmlindex");
358 if (exe.isEmpty())
359 return;
361 delete indexProc;
363 indexProc = new K3Process;
364 *indexProc << exe << "--lang" << language->currentTag();
366 connect(indexProc, SIGNAL(processExited(K3Process *)),
367 this, SLOT(indexTerminated(K3Process *)));
369 runButton->setEnabled(false);
371 indexProc->start();
375 void KHTMLSearchConfig::indexTerminated(K3Process *)
377 runButton->setEnabled(true);