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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/***************************************************************************
* Copyright (C) 2002 by Bernd Gehrmann *
* [email protected] *
* Copyright (C) 2002 by Sebastian Kratzert *
* [email protected] *
* Copyright (C) 2003-2004 by Alexander Dymo *
* [email protected] *
* *
* 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 "docglobalconfigwidget.h"
#include <tqlayout.h>
#include <tqtoolbox.h>
#include <tqcheckbox.h>
#include <tqwidgetstack.h>
#include <kdebug.h>
#include <tdeconfig.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <tdeapplication.h>
#include <kurlrequester.h>
#include <tdefontcombo.h>
#include <tdehtml_part.h>
#include <tdehtml_settings.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include "kdevdocumentationplugin.h"
#include "kdevpartcontroller.h"
#include "docconfiglistview.h"
#include "documentation_part.h"
#include "documentation_widget.h"
#include "editcatalogdlg.h"
#include "addcatalogdlg.h"
#include "contentsview.h"
#include "indexview.h"
#include "docutils.h"
DocGlobalConfigWidget::DocGlobalConfigWidget(DocumentationPart *part,
DocumentationWidget *widget, TQWidget *parent, const char *name, WFlags fl)
:DocGlobalConfigWidgetBase(parent, name, fl), m_part(part), m_widget(widget)
{
m_View = new DocConfigListView( viewHolder );
viewHolder->addWidget( m_View );
viewHolder->raiseWidget( m_View );
for (TQValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
it != m_part->m_plugins.constEnd(); ++it)
{
(*it)->loadCatalogConfiguration( m_View );
}
connect( m_View, TQ_SIGNAL(itemActivated()), this, TQ_SLOT(editCollectionButtonClicked()) );
TDEConfig *config = m_part->config();
//read full text search settings
config->setGroup("htdig");
TQString databaseDir = kapp->dirs()->saveLocation("data",
"kdevdocumentation/search");
databaseDirEdit->setURL(config->readPathEntry("databaseDir", databaseDir));
htdigbinEdit->setURL(config->readPathEntry("htdigbin", kapp->dirs()->findExe("htdig")));
htmergebinEdit->setURL(config->readPathEntry("htmergebin", kapp->dirs()->findExe("htmerge")));
htsearchbinEdit->setURL(config->readPathEntry("htsearchbin", kapp->dirs()->findExe("htsearch")));
if (config->readBoolEntry("IsSetup", false) == false)
{
TQFileInfo fi(htsearchbinEdit->url());
if (!fi.exists())
{
//try to guess htsearch location on Debian
TQFileInfo fi("/usr/lib/cgi-bin/htsearch");
if (!fi.exists())
{
//try to guess htsearch location on SuSE
TQFileInfo fi("/srv/www/cgi-bin/htsearch");
if (fi.exists())
htsearchbinEdit->setURL("/srv/www/cgi-bin/htsearch");
}
else
htsearchbinEdit->setURL("/usr/lib/cgi-bin/htsearch");
}
}
find_box->setChecked(m_part->hasContextFeature(DocumentationPart::Finder));
index_box->setChecked(m_part->hasContextFeature(DocumentationPart::IndexLookup));
search_box->setChecked(m_part->hasContextFeature(DocumentationPart::FullTextSearch));
man_box->setChecked(m_part->hasContextFeature(DocumentationPart::GotoMan));
info_box->setChecked(m_part->hasContextFeature(DocumentationPart::GotoInfo));
useAssistant_box->setChecked(m_part->isAssistantUsed());
// Having app-specific settings isn't pretty, but this setting is nonsensical in kdevassistant
if ( kapp->instanceName().find("kdevassistant") != -1 )
useAssistant_box->hide();
//font sizes and zoom levels
TDEHTMLPart htmlpart;
TDEConfig *appConfig = TDEGlobal::config();
appConfig->setGroup("TDEHTMLPart");
standardFont_combo->setCurrentText(appConfig->readEntry("StandardFont",
htmlpart.settings()->stdFontName()));
fixedFont_combo->setCurrentText(appConfig->readEntry("FixedFont",
htmlpart.settings()->fixedFontName()));
zoom_combo->setCurrentText(appConfig->readEntry("Zoom", "100"));
}
DocGlobalConfigWidget::~DocGlobalConfigWidget()
{
}
/*$SPECIALIZATION$*/
void DocGlobalConfigWidget::collectionsBoxCurrentChanged(int // box
)
{
}
void DocGlobalConfigWidget::removeCollectionButtonClicked()
{
ConfigurationItem *item = dynamic_cast<ConfigurationItem*>(activeView()->currentItem());
if (!item)
return;
item->docPlugin()->deleteCatalogConfiguration(item);
delete activeView()->currentItem();
}
void DocGlobalConfigWidget::editCollectionButtonClicked()
{
ConfigurationItem *item = dynamic_cast<ConfigurationItem*>(activeView()->currentItem());
if (!item)
return;
EditCatalogDlg dlg( item->docPlugin(), this, "edit collection dlg", true);
dlg.setURL(item->url());
dlg.setTitle(item->title());
if (dlg.exec())
{
item->docPlugin()->deleteCatalogConfiguration(item); // this removes the old entry by name
item->docPlugin()->editCatalogConfiguration(item, dlg.title(), dlg.url());
activeView()->sort();
}
}
void DocGlobalConfigWidget::addCollectionButtonClicked()
{
AddCatalogDlg dlg( m_part->m_plugins, this, "add collection dlg", true);
if (dlg.exec())
{
dlg.plugin()->addCatalogConfiguration(activeView(), dlg.title(), dlg.url());
}
}
TDEListView *DocGlobalConfigWidget::activeView()
{
return m_View;
}
void DocGlobalConfigWidget::accept()
{
//write catalog settings
for (TQValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
it != m_part->m_plugins.constEnd(); ++it)
{
(*it)->saveCatalogConfiguration( m_View );
//@todo: take restrictions into account
(*it)->reinit(m_widget->contents(), m_widget->index(), TQStringList());
}
TDEConfig *config = m_part->config();
//write full text search settings
config->setGroup("htdig");
config->writePathEntry("databaseDir", DocUtils::envURL(databaseDirEdit));
config->writePathEntry("htdigbin", DocUtils::envURL(htdigbinEdit));
config->writePathEntry("htmergebin", DocUtils::envURL(htmergebinEdit));
config->writePathEntry("htsearchbin", DocUtils::envURL(htsearchbinEdit));
//write full text search locations file
TQString ftsLocationsFile = locateLocal("data", "kdevdocumentation/search/locations.txt");
TQFile f(ftsLocationsFile);
TQStringList locs;
if (f.open(IO_ReadWrite | IO_Truncate))
{
TQTextStream str(&f);
for (TQValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
it != m_part->m_plugins.constEnd(); ++ it)
{
TQStringList app = (*it)->fullTextSearchLocations();
for (TQStringList::const_iterator it2 = app.constBegin();
it2 != app.constEnd(); ++it2)
{
if (!locs.contains(*it2))
locs.append(*it2);
}
}
str << locs.join("\n");
f.close();
}
//write editor context menu configuration
m_part->setContextFeature(DocumentationPart::Finder, find_box->isChecked());
m_part->setContextFeature(DocumentationPart::IndexLookup, index_box->isChecked());
m_part->setContextFeature(DocumentationPart::FullTextSearch, search_box->isChecked());
m_part->setContextFeature(DocumentationPart::GotoMan, man_box->isChecked());
m_part->setContextFeature(DocumentationPart::GotoInfo, info_box->isChecked());
m_part->setAssistantUsed(useAssistant_box->isChecked());
//font sizes and zoom levels
TDEConfig *appConfig = TDEGlobal::config();
appConfig->setGroup("TDEHTMLPart");
appConfig->writeEntry("StandardFont", standardFont_combo->currentText());
appConfig->writeEntry("FixedFont", fixedFont_combo->currentText());
appConfig->writeEntry("Zoom", zoom_combo->currentText());
appConfig->sync();
updateConfigForHTMLParts();
config->sync();
//refill the index
kdDebug() << "refill the index" << endl;
if (m_part->m_hasIndex)
{
kdDebug() << "m_part->m_hasIndex" << endl;
m_part->m_widget->index()->refill();
}
}
void DocGlobalConfigWidget::updateConfigForHTMLParts()
{
KURL::List urls = m_part->partController()->openURLs();
for (KURL::List::const_iterator it = urls.constBegin(); it != urls.constEnd(); ++it)
{
TDEHTMLPart *htmlPart = dynamic_cast<TDEHTMLPart*>(m_part->partController()->partForURL(*it));
if (htmlPart)
{
TDEConfig *appConfig = TDEGlobal::config();
appConfig->setGroup("TDEHTMLPart");
htmlPart->setStandardFont(appConfig->readEntry("StandardFont"));
htmlPart->setFixedFont(appConfig->readEntry("FixedFont"));
//hack to force reloading the page
if (htmlPart->zoomFactor() == appConfig->readEntry("Zoom").toInt())
{
htmlPart->setZoomFactor(htmlPart->zoomFactor()-1);
htmlPart->setZoomFactor(htmlPart->zoomFactor()+1);
}
htmlPart->setZoomFactor(appConfig->readEntry("Zoom").toInt());
}
}
}
void DocGlobalConfigWidget::rescanCollectionButtonClicked()
{
if (KMessageBox::questionYesNo(this,
i18n("This will restore the default settings "
"for the following documentation plugins: "
"chm, devhelp, doxygen, kdevtoc, qt.\n"
"Any change made to documentation catalogs "
"belonging to those plugins will be lost. "
"Changes made to documentation catalogs "
"belonging to the custom plugin will be preserved.\n"
"Do you wish to continue?"),
i18n("Rescan documentation")) == KMessageBox::Yes)
{
reloadDocumentationPlugins();
}
}
void DocGlobalConfigWidget::reloadDocumentationPlugins()
{
// Clear current list
TQListViewItem *first = m_View->firstChild();
while (first)
{
m_View->takeItem(first);
delete first;
first = m_View->firstChild();
}
// Rescan configuration
TQValueList<DocumentationPlugin*>::iterator it;
for (it = m_part->m_plugins.begin(); it != m_part->m_plugins.end(); ++it)
{
DocumentationPlugin *plugin=*it;
plugin->clear();
plugin->autoSetupPlugin();
plugin->reinit(m_part->m_widget->contents(), m_part->m_widget->index(), TQStringList());
}
// Recreate list
for (TQValueList<DocumentationPlugin*>::const_iterator it = m_part->m_plugins.constBegin();
it != m_part->m_plugins.constEnd(); ++it)
{
(*it)->loadCatalogConfiguration(m_View);
}
}
#include "docglobalconfigwidget.moc"
|