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
|
/***************************************************************************
* Copyright (C) 2000 by Dimitri van Heesch *
* dimitri@stack.nl *
* Copyright (C) 2001 by Bernd Gehrmann *
* bernd@tdevelop.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. *
* *
***************************************************************************/
#include "doxygenconfigwidget.h"
#include <tqscrollview.h>
#include <tqvbox.h>
#include <tqwhatsthis.h>
#include <tqtextstream.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include "config.h"
#include "input.h"
#include "messages.h"
DoxygenConfigWidget::DoxygenConfigWidget(const TQString &fileName, TQWidget *parent, const char *name)
: TQTabWidget(parent, name)
{
m_hasChanged = false;
m_dependencies = new TQDict< TQPtrList<IInput> >(257);
m_dependencies->setAutoDelete(true);
m_inputWidgets = new TQDict< IInput >;
m_switches = new TQDict< TQObject >;
TQPtrListIterator<ConfigOption> options = Config::instance()->iterator();
TQScrollView *page = 0;
TQVBox *pagebox = 0;
ConfigOption *option = 0;
for (options.toFirst(); (option=options.current()); ++options) {
switch(option->kind())
{
case ConfigOption::O_Info:
page = new TQScrollView(this, option->name());
page->viewport()->setBackgroundMode(PaletteBackground);
pagebox = new TQVBox(0);
Q_ASSERT(pagebox!=0);
page->addChild(pagebox);
addTab(page, message(option->name()));
TQWhatsThis::add(page, option->docs().simplifyWhiteSpace() );
break;
case ConfigOption::O_String:
{
Q_ASSERT(pagebox!=0);
InputString::StringMode sm = InputString::StringFree;
switch (((ConfigString *)option)->widgetType()) {
case ConfigString::String: sm = InputString::StringFree; break;
case ConfigString::File: sm = InputString::StringFile; break;
case ConfigString::Dir: sm = InputString::StringDir; break;
}
InputString *inputString = new InputString
( message(option->name()), // name
pagebox, // widget
*((ConfigString *)option)->valueRef(), // variable
sm // type
);
TQWhatsThis::add(inputString, option->docs().simplifyWhiteSpace());
connect(inputString, TQT_SIGNAL(changed()), this, TQT_SLOT(changed()));
m_inputWidgets->insert(option->name(), inputString);
addDependency(m_switches, option->dependsOn(), option->name());
}
break;
case ConfigOption::O_Enum:
{
Q_ASSERT(pagebox!=0);
InputString *inputString = new InputString
( message(option->name()), // name
pagebox, // widget
*((ConfigEnum *)option)->valueRef(), // variable
InputString::StringFixed // type
);
TQStrListIterator sli=((ConfigEnum *)option)->iterator();
for (sli.toFirst(); sli.current(); ++sli)
inputString->addValue(sli.current());
TQWhatsThis::add(inputString, option->docs().simplifyWhiteSpace());
connect(inputString, TQT_SIGNAL(changed()), this, TQT_SLOT(changed()));
m_inputWidgets->insert(option->name(),inputString);
addDependency(m_switches, option->dependsOn(), option->name());
}
break;
case ConfigOption::O_List:
{
Q_ASSERT(pagebox!=0);
InputStrList::ListMode lm = InputStrList::ListString;
switch(((ConfigList *)option)->widgetType())
{
case ConfigList::String: lm=InputStrList::ListString; break;
case ConfigList::File: lm=InputStrList::ListFile; break;
case ConfigList::Dir: lm=InputStrList::ListDir; break;
case ConfigList::FileAndDir: lm=InputStrList::ListFileDir; break;
}
InputStrList *inputStrList = new InputStrList
( message(option->name()), // name
pagebox, // widget
*((ConfigList *)option)->valueRef(), // variable
lm // type
);
TQWhatsThis::add(inputStrList, option->docs().simplifyWhiteSpace());
connect(inputStrList, TQT_SIGNAL(changed()), this, TQT_SLOT(changed()));
m_inputWidgets->insert(option->name(),inputStrList);
addDependency(m_switches, option->dependsOn(), option->name());
}
break;
case ConfigOption::O_Bool:
{
Q_ASSERT(pagebox!=0);
InputBool *inputBool = new InputBool
( option->name(), // key
message(option->name()), // name
pagebox, // widget
*((ConfigBool *)option)->valueRef() // variable
);
TQWhatsThis::add(inputBool, option->docs().simplifyWhiteSpace());
connect(inputBool, TQT_SIGNAL(changed()), this, TQT_SLOT(changed()));
m_inputWidgets->insert(option->name(), inputBool);
addDependency(m_switches, option->dependsOn(), option->name());
}
break;
case ConfigOption::O_Int:
{
Q_ASSERT(pagebox!=0);
InputInt *inputInt = new InputInt
( message(option->name()), // name
pagebox, // widget
*((ConfigInt *)option)->valueRef(), // variable
((ConfigInt *)option)->minVal(), // min value
((ConfigInt *)option)->maxVal() // max value
);
TQWhatsThis::add(inputInt, option->docs().simplifyWhiteSpace());
connect(inputInt, TQT_SIGNAL(changed()), this, TQT_SLOT(changed()));
m_inputWidgets->insert(option->name(), inputInt);
addDependency(m_switches, option->dependsOn(), option->name());
}
break;
case ConfigOption::O_Obsolete:
break;
}
}
TQDictIterator<TQObject> di(*m_switches);
for (; di.current(); ++di) {
TQObject *obj = di.current();
connect(obj, TQT_SIGNAL(toggle(const TQString&, bool)), this, TQT_SLOT(toggle(const TQString&, bool)));
// UGLY HACK: assumes each item depends on a boolean without checking!
emit toggle(di.currentKey(), ((InputBool *)obj)->getState());
}
m_fileName = fileName;
loadFile();
}
DoxygenConfigWidget::~DoxygenConfigWidget()
{
delete m_dependencies;
delete m_inputWidgets;
delete m_switches;
}
TQSize DoxygenConfigWidget::tqsizeHint() const
{
// without this the whole dialog becomes much too large
return TQSize(TQTabWidget::tqsizeHint().width(), 1);
}
void DoxygenConfigWidget::addDependency(TQDict<TQObject> *switches,
const TQCString &dep, const TQCString &name)
{
if (dep.isEmpty())
return;
IInput *parent = m_inputWidgets->find(dep);
Q_ASSERT(parent!=0);
IInput *child = m_inputWidgets->find(name);
Q_ASSERT(child!=0);
if (!switches->find(dep))
switches->insert(dep, parent->qobject());
TQPtrList<IInput> *list = m_dependencies->find(dep);
if (!list) {
list = new TQPtrList<IInput>;
m_dependencies->insert(dep, list);
}
list->append(child);
}
void DoxygenConfigWidget::toggle(const TQString &name, bool state)
{
TQPtrList<IInput> *inputs = m_dependencies->find(name);
Q_ASSERT(inputs!=0);
IInput *input = inputs->first();
while (input) {
input->setEnabled(state);
input = inputs->next();
}
}
void DoxygenConfigWidget::changed()
{
m_hasChanged = true;
}
void DoxygenConfigWidget::init()
{
TQDictIterator<IInput> di(*m_inputWidgets);
for (; di.current(); ++di)
di.current()->init();
TQDictIterator<TQObject> dio(*m_switches);
for (; dio.current(); ++dio) {
TQObject *obj = dio.current();
connect(obj, TQT_SIGNAL(toggle(const TQString&, bool)), this, TQT_SLOT(toggle(const TQString&, bool)));
// UGLY HACK: assumes each item depends on a boolean without checking!
emit toggle(dio.currentKey(), ((InputBool *)obj)->getState());
}
}
void DoxygenConfigWidget::loadFile()
{
Config::instance()->init();
TQFile f(m_fileName);
if (f.open(IO_ReadOnly)) {
TQTextStream is(&f);
Config::instance()->parse(TQFile::encodeName(m_fileName));
Config::instance()->convertStrToVal();
f.close();
}
init();
}
void DoxygenConfigWidget::saveFile()
{
TQFile f(m_fileName);
if (!f.open(IO_WriteOnly)) {
KMessageBox::information(0, i18n("Cannot write Doxyfile."));
} else {
TQTextStream t(&f);
Config::instance()->writeTemplate(t, true, false);
f.close();
}
}
void DoxygenConfigWidget::accept()
{
if (m_hasChanged)
saveFile();
}
#include "doxygenconfigwidget.moc"
|