00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#include "doxygenconfigwidget.h"
00015
00016
#include <qscrollview.h>
00017
#include <qvbox.h>
00018
#include <qwhatsthis.h>
00019
#include <qtextstream.h>
00020
00021
#include <klocale.h>
00022
#include <kdebug.h>
00023
#include <kmessagebox.h>
00024
00025
#include "config.h"
00026
#include "input.h"
00027
#include "messages.h"
00028
00029
00030 DoxygenConfigWidget::DoxygenConfigWidget(
const QString &fileName,
QWidget *parent,
const char *name)
00031 :
QTabWidget(parent, name)
00032 {
00033
m_hasChanged =
false;
00034
m_dependencies =
new QDict< QPtrList<IInput> >(257);
00035
m_dependencies->setAutoDelete(
true);
00036
m_inputWidgets =
new QDict< IInput >;
00037
m_switches =
new QDict< QObject >;
00038
00039
QPtrListIterator<ConfigOption> options =
Config::instance()->
iterator();
00040
QScrollView *page = 0;
00041
QVBox *pagebox = 0;
00042
ConfigOption *option = 0;
00043
for (options.toFirst(); (option=options.current()); ++options) {
00044
switch(option->
kind())
00045 {
00046
case ConfigOption::O_Info:
00047 page =
new QScrollView(
this, option->
name());
00048 page->viewport()->setBackgroundMode(PaletteBackground);
00049 pagebox =
new QVBox(0);
00050 Q_ASSERT(pagebox!=0);
00051 page->addChild(pagebox);
00052 addTab(page,
message(option->
name()));
00053 QWhatsThis::add(page, option->
docs().simplifyWhiteSpace() );
00054
break;
00055
case ConfigOption::O_String:
00056 {
00057 Q_ASSERT(pagebox!=0);
00058 InputString::StringMode sm = InputString::StringFree;
00059
switch (((
ConfigString *)option)->widgetType()) {
00060
case ConfigString::String: sm = InputString::StringFree;
break;
00061
case ConfigString::File: sm = InputString::StringFile;
break;
00062
case ConfigString::Dir: sm = InputString::StringDir;
break;
00063 }
00064
InputString *inputString =
new InputString
00065 (
message(option->
name()),
00066 pagebox,
00067 *((
ConfigString *)option)->valueRef(),
00068 sm
00069 );
00070 QWhatsThis::add(inputString, option->
docs().simplifyWhiteSpace());
00071 connect(inputString, SIGNAL(
changed()),
this, SLOT(
changed()));
00072
m_inputWidgets->insert(option->
name(), inputString);
00073
addDependency(
m_switches, option->
dependsOn(), option->
name());
00074 }
00075
break;
00076
case ConfigOption::O_Enum:
00077 {
00078 Q_ASSERT(pagebox!=0);
00079
InputString *inputString =
new InputString
00080 (
message(option->
name()),
00081 pagebox,
00082 *((
ConfigEnum *)option)->valueRef(),
00083 InputString::StringFixed
00084 );
00085
QStrListIterator sli=((
ConfigEnum *)option)->iterator();
00086
for (sli.toFirst(); sli.current(); ++sli)
00087 inputString->
addValue(sli.current());
00088 QWhatsThis::add(inputString, option->
docs().simplifyWhiteSpace());
00089 connect(inputString, SIGNAL(
changed()),
this, SLOT(
changed()));
00090
m_inputWidgets->insert(option->
name(),inputString);
00091
addDependency(
m_switches, option->
dependsOn(), option->
name());
00092 }
00093
break;
00094
case ConfigOption::O_List:
00095 {
00096 Q_ASSERT(pagebox!=0);
00097 InputStrList::ListMode lm = InputStrList::ListString;
00098
switch(((
ConfigList *)option)->widgetType())
00099 {
00100
case ConfigList::String: lm=InputStrList::ListString;
break;
00101
case ConfigList::File: lm=InputStrList::ListFile;
break;
00102
case ConfigList::Dir: lm=InputStrList::ListDir;
break;
00103
case ConfigList::FileAndDir: lm=InputStrList::ListFileDir;
break;
00104 }
00105
InputStrList *inputStrList =
new InputStrList
00106 (
message(option->
name()),
00107 pagebox,
00108 *((
ConfigList *)option)->valueRef(),
00109 lm
00110 );
00111 QWhatsThis::add(inputStrList, option->
docs().simplifyWhiteSpace());
00112 connect(inputStrList, SIGNAL(
changed()),
this, SLOT(
changed()));
00113
m_inputWidgets->insert(option->
name(),inputStrList);
00114
addDependency(
m_switches, option->
dependsOn(), option->
name());
00115 }
00116
break;
00117
case ConfigOption::O_Bool:
00118 {
00119 Q_ASSERT(pagebox!=0);
00120
InputBool *inputBool =
new InputBool
00121 ( option->
name(),
00122
message(option->
name()),
00123 pagebox,
00124 *((
ConfigBool *)option)->valueRef()
00125 );
00126 QWhatsThis::add(inputBool, option->
docs().simplifyWhiteSpace());
00127 connect(inputBool, SIGNAL(
changed()),
this, SLOT(
changed()));
00128
m_inputWidgets->insert(option->
name(), inputBool);
00129
addDependency(
m_switches, option->
dependsOn(), option->
name());
00130 }
00131
break;
00132
case ConfigOption::O_Int:
00133 {
00134 Q_ASSERT(pagebox!=0);
00135
InputInt *inputInt =
new InputInt
00136 (
message(option->
name()),
00137 pagebox,
00138 *((
ConfigInt *)option)->valueRef(),
00139 ((
ConfigInt *)option)->minVal(),
00140 ((
ConfigInt *)option)->maxVal()
00141 );
00142 QWhatsThis::add(inputInt, option->
docs().simplifyWhiteSpace());
00143 connect(inputInt, SIGNAL(
changed()),
this, SLOT(
changed()));
00144
m_inputWidgets->insert(option->
name(), inputInt);
00145
addDependency(
m_switches, option->
dependsOn(), option->
name());
00146 }
00147
break;
00148
case ConfigOption::O_Obsolete:
00149
break;
00150 }
00151 }
00152
00153
QDictIterator<QObject> di(*
m_switches);
00154
for (; di.current(); ++di) {
00155
QObject *obj = di.current();
00156 connect(obj, SIGNAL(
toggle(
const QString&,
bool)),
this, SLOT(
toggle(
const QString&,
bool)));
00157
00158 emit
toggle(di.currentKey(), ((
InputBool *)obj)->getState());
00159 }
00160
00161
m_fileName = fileName;
00162
loadFile();
00163 }
00164
00165
00166 DoxygenConfigWidget::~DoxygenConfigWidget()
00167 {
00168
delete m_dependencies;
00169
delete m_inputWidgets;
00170
delete m_switches;
00171 }
00172
00173
00174 QSize DoxygenConfigWidget::sizeHint()
const
00175
{
00176
00177
return QSize(QTabWidget::sizeHint().width(), 1);
00178 }
00179
00180
00181 void DoxygenConfigWidget::addDependency(
QDict<QObject> *switches,
00182
const QCString &dep,
const QCString &name)
00183 {
00184
if (dep.isEmpty())
00185
return;
00186
00187
IInput *parent =
m_inputWidgets->find(dep);
00188 Q_ASSERT(parent!=0);
00189
IInput *child =
m_inputWidgets->find(name);
00190 Q_ASSERT(child!=0);
00191
if (!switches->find(dep))
00192 switches->insert(dep, parent->
qobject());
00193
QPtrList<IInput> *list =
m_dependencies->find(dep);
00194
if (!list) {
00195 list =
new QPtrList<IInput>;
00196
m_dependencies->insert(dep, list);
00197 }
00198 list->append(child);
00199 }
00200
00201
00202 void DoxygenConfigWidget::toggle(
const QString &name,
bool state)
00203 {
00204
QPtrList<IInput> *inputs =
m_dependencies->find(name);
00205 Q_ASSERT(inputs!=0);
00206
IInput *input = inputs->first();
00207
while (input) {
00208 input->
setEnabled(state);
00209 input = inputs->next();
00210 }
00211 }
00212
00213
00214 void DoxygenConfigWidget::changed()
00215 {
00216
m_hasChanged =
true;
00217 }
00218
00219
00220 void DoxygenConfigWidget::init()
00221 {
00222
QDictIterator<IInput> di(*
m_inputWidgets);
00223
for (; di.current(); ++di)
00224 di.current()->init();
00225
00226
QDictIterator<QObject> dio(*
m_switches);
00227
for (; dio.current(); ++dio) {
00228
QObject *obj = dio.current();
00229 connect(obj, SIGNAL(
toggle(
const QString&,
bool)),
this, SLOT(
toggle(
const QString&,
bool)));
00230
00231 emit
toggle(dio.currentKey(), ((
InputBool *)obj)->getState());
00232 }
00233 }
00234
00235
00236 void DoxygenConfigWidget::loadFile()
00237 {
00238
Config::instance()->
init();
00239
00240
QFile f(
m_fileName);
00241
if (f.open(IO_ReadOnly)) {
00242
QTextStream is(&f);
00243
00244
Config::instance()->
parse(QFile::encodeName(
m_fileName));
00245
Config::instance()->
convertStrToVal();
00246
00247 f.close();
00248 }
00249
00250
init();
00251 }
00252
00253
00254 void DoxygenConfigWidget::saveFile()
00255 {
00256
QFile f(
m_fileName);
00257
if (!f.open(IO_WriteOnly)) {
00258 KMessageBox::information(0, i18n(
"Cannot write Doxyfile."));
00259 }
else {
00260
Config::instance()->
writeTemplate(&f,
true,
false);
00261
00262 f.close();
00263 }
00264 }
00265
00266
00267 void DoxygenConfigWidget::accept()
00268 {
00269
if (
m_hasChanged)
00270
saveFile();
00271 }
00272
00273
#include "doxygenconfigwidget.moc"