00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "doxygenpart.h"
00013
00014
#include <qvbox.h>
00015
#include <qfile.h>
00016
#include <qtextstream.h>
00017
00018
#include <kdebug.h>
00019
#include <klocale.h>
00020
#include <kdevgenericfactory.h>
00021
#include <kaction.h>
00022
#include <kmessagebox.h>
00023
#include <kprocess.h>
00024
00025
#include "kdevproject.h"
00026
#include "kdevmakefrontend.h"
00027
#include "kdevcore.h"
00028
#include "doxygenconfigwidget.h"
00029
#include "domutil.h"
00030
00031
00032
#include "config.h"
00033
00034
00035 typedef KDevGenericFactory<DoxygenPart> DoxygenFactory;
00036
static const KAboutData data(
"kdevdoxygen",
I18N_NOOP(
"Doxygen"),
"1.0");
00037 K_EXPORT_COMPONENT_FACTORY( libkdevdoxygen,
DoxygenFactory( &data ) )
00038
00039
DoxygenPart::
DoxygenPart(
QObject *parent, const
char *name, const
QStringList &)
00040 :
KDevPlugin("Doxgen", "doxygen", parent, name ? name : "
DoxygenPart")
00041 {
00042 setInstance(DoxygenFactory::instance());
00043 setXMLFile(
"kdevdoxygen.rc");
00044
00045
KAction *action;
00046
00047 action =
new KAction( i18n(
"Build API Documentation"), 0,
00048
this, SLOT(slotDoxygen()),
00049 actionCollection(),
"build_doxygen" );
00050 action->setToolTip(i18n(
"Build API documentation"));
00051 action->setWhatsThis(i18n(
"<b>Build API documentation</b><p>Runs doxygen on a project Doxyfile to generate API documentation. "
00052
"If the search engine is enabled in Doxyfile, this also runs doxytag to create it."));
00053
00054 action =
new KAction( i18n(
"Clean API Documentation"), 0,
00055
this, SLOT(slotDoxClean()),
00056 actionCollection(),
"clean_doxygen" );
00057 action->setToolTip(i18n(
"Clean API documentation"));
00058 action->setWhatsThis(i18n(
"<b>Clean API documentation</b><p>Removes all generated by doxygen files."));
00059
00060 connect( core(), SIGNAL(projectConfigWidget(
KDialogBase*)),
00061
this, SLOT(projectConfigWidget(
KDialogBase*)) );
00062 }
00063
00064
00065 DoxygenPart::~DoxygenPart()
00066 {
00067 }
00068
00069
00070 void DoxygenPart::projectConfigWidget(
KDialogBase *dlg)
00071 {
00072
adjustDoxyfile();
00073
00074
QVBox *vbox;
00075 vbox = dlg->
addVBoxPage(i18n(
"Doxygen"));
00076
DoxygenConfigWidget *w =
new DoxygenConfigWidget(
project()->projectDirectory() +
"/Doxyfile", vbox);
00077 connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
00078 }
00079
00080
00084 void DoxygenPart::adjustDoxyfile()
00085 {
00086
QString fileName =
project()->
projectDirectory() +
"/Doxyfile";
00087
if (QFile::exists(fileName))
00088
return;
00089
00090
00091
Config::instance()->
init();
00092
00093
00094
Config::instance()->
check();
00095
00096
QFile f(fileName);
00097
if (f.open(IO_ReadOnly))
00098 {
00099
QTextStream is(&f);
00100
00101
Config::instance()->
parse(QFile::encodeName(fileName));
00102
Config::instance()->
convertStrToVal();
00103
00104 f.close();
00105 }
00106
00107
00108
ConfigString *name = dynamic_cast<ConfigString*>(
Config::instance()->
get(
"PROJECT_NAME"));
00109
if (name)
00110 {
00111 name->setDefaultValue(
project()->projectName().latin1());
00112 name->init();
00113 }
00114
00115
00116
ConfigString *version = dynamic_cast<ConfigString*>(
Config::instance()->
get(
"PROJECT_NUMBER"));
00117
if (version)
00118 {
00119 version->setDefaultValue(DomUtil::readEntry(*
projectDom(),
"/general/version").latin1());
00120 version->init();
00121 }
00122
00123
00124
ConfigList *input_files = dynamic_cast<ConfigList*>(
Config::instance()->
get(
"INPUT"));
00125
if (input_files)
00126 {
00127 input_files->
init();
00128 input_files->
addValue(QFile::encodeName(
project()->projectDirectory()));
00129 }
00130
00131
00132
ConfigList *patterns = dynamic_cast<ConfigList*>(
Config::instance()->
get(
"FILE_PATTERNS"));
00133
if (patterns)
00134 {
00135
00136
00137
00138
00139 patterns->
addValue(
"*.C");
00140 patterns->
addValue(
"*.H");
00141 patterns->
addValue(
"*.tlh");
00142 patterns->
addValue(
"*.diff");
00143 patterns->
addValue(
"*.patch");
00144 patterns->
addValue(
"*.moc");
00145 patterns->
addValue(
"*.xpm");
00146 patterns->
addValue(
"*.dox");
00147 }
00148
00149
00150
ConfigBool *recursive = dynamic_cast<ConfigBool*>(
Config::instance()->
get(
"RECURSIVE"));
00151
if (recursive)
00152 {
00153 recursive->
setValueString(
"yes");
00154 }
00155
00156
00157
ConfigBool *gen_xml = dynamic_cast<ConfigBool*>(
Config::instance()->
get(
"GENERATE_XML"));
00158
if (gen_xml)
00159 {
00160 gen_xml->
setValueString(
"yes");
00161 }
00162
00163
00164
QFile f2(fileName);
00165
if (!f2.open(IO_WriteOnly))
00166 KMessageBox::information(0, i18n(
"Cannot write Doxyfile."));
00167
else
00168 {
00169
Config::instance()->
writeTemplate(&f2,
true,
true);
00170
00171 f2.close();
00172 }
00173 }
00174
00175
00176 void DoxygenPart::slotDoxygen()
00177 {
00178
bool searchDatabase =
false;
00179
QString outputDirectory;
00180
QString htmlDirectory;
00181
00182
adjustDoxyfile();
00183
00184
QString fileName =
project()->
projectDirectory() +
"/Doxyfile";
00185
00186
Config::instance()->
init();
00187
00188
QFile f(fileName);
00189
if (f.open(IO_ReadOnly))
00190 {
00191
QTextStream is(&f);
00192
00193
Config::instance()->
parse(QFile::encodeName(fileName));
00194
Config::instance()->
convertStrToVal();
00195
00196 f.close();
00197 }
00198
00199
00200
ConfigBool *search = dynamic_cast<ConfigBool*>(
Config::instance()->
get(
"SEARCHENGINE"));
00201
if (search)
00202 {
00203 searchDatabase =
Config_getBool(
"SEARCHENGINE");
00204
00205
if (searchDatabase)
00206 {
00207
00208 outputDirectory =
Config_getString(
"OUTPUT_DIRECTORY");
00209
if ( outputDirectory.isEmpty() ==
false )
00210 outputDirectory +=
"/";
00211 htmlDirectory =
Config_getString(
"HTML_OUTPUT");
00212
if ( htmlDirectory.isEmpty() ==
true )
00213 htmlDirectory =
"html";
00214 htmlDirectory.prepend(outputDirectory);
00215 }
00216 }
00217
00218
QString dir =
project()->
projectDirectory();
00219
QString cmdline =
"cd ";
00220 cmdline += KShellProcess::quote( dir );
00221 cmdline +=
" && doxygen Doxyfile";
00222
if (searchDatabase)
00223 {
00224
00225
if ( htmlDirectory.length() > 0 )
00226 cmdline +=
" && cd " + KShellProcess::quote( htmlDirectory );
00227 cmdline +=
" && doxytag -s search.idx ";
00228 }
00229
00230
kdDebug(9026) <<
"Doxygen command line: " << cmdline <<
endl;
00231
00232
makeFrontend()->
queueCommand(dir, cmdline);
00233 }
00234
00235
00236 void DoxygenPart::slotDoxClean()
00237 {
00238
bool could_be_dirty =
false;
00239
00240
QString outputDirectory =
Config_getString(
"OUTPUT_DIRECTORY");
00241
if ( outputDirectory.isEmpty() )
00242 outputDirectory =
project()->
projectDirectory();
00243
if ( outputDirectory.right(1) !=
"/" )
00244 outputDirectory +=
"/";
00245
QString cmdline =
"cd " + KShellProcess::quote( outputDirectory );
00246
00247
if (
Config_getBool(
"GENERATE_HTML") ) {
00248
QString htmlDirectory =
Config_getString(
"HTML_OUTPUT");
00249
if ( htmlDirectory.isEmpty() )
00250 htmlDirectory =
"html";
00251
if ( htmlDirectory.right(1) !=
"/" )
00252 htmlDirectory +=
"/";
00253 cmdline +=
" && rm -f " + KShellProcess::quote( htmlDirectory ) +
"*";
00254 could_be_dirty=
true;
00255 }
00256
00257
if (
Config_getBool(
"GENERATE_LATEX") ) {
00258
QString latexDirectory =
Config_getString(
"LATEX_OUTPUT");
00259
if ( latexDirectory.isEmpty() )
00260 latexDirectory =
"latex";
00261
if ( latexDirectory.right(1) !=
"/" )
00262 latexDirectory +=
"/";
00263 cmdline +=
" && rm -f " + KShellProcess::quote( latexDirectory ) +
"*";
00264 could_be_dirty=
true;
00265 }
00266
00267
if (
Config_getBool(
"GENERATE_RTF") ) {
00268
QString rtfDirectory =
Config_getString(
"RTF_OUTPUT");
00269
if ( rtfDirectory.isEmpty() )
00270 rtfDirectory =
"rtf";
00271
if ( rtfDirectory.right(1) !=
"/" )
00272 rtfDirectory +=
"/";
00273 cmdline +=
" && rm -f " + KShellProcess::quote( rtfDirectory ) +
"*";
00274 could_be_dirty=
true;
00275 }
00276
00277
if (
Config_getBool(
"GENERATE_MAN") ) {
00278
QString manDirectory =
Config_getString(
"MAN_OUTPUT");
00279
if ( manDirectory.isEmpty() )
00280 manDirectory =
"man";
00281
if ( manDirectory.right(1) !=
"/" )
00282 manDirectory +=
"/";
00283 cmdline +=
" && rm -f " + KShellProcess::quote( manDirectory ) +
"*";
00284 could_be_dirty=
true;
00285 }
00286
00287
if (
Config_getBool(
"GENERATE_XML") ) {
00288
QString xmlDirectory =
Config_getString(
"XML_OUTPUT");
00289
if ( xmlDirectory.isEmpty() )
00290 xmlDirectory =
"xml";
00291
if ( xmlDirectory.right(1) !=
"/" )
00292 xmlDirectory +=
"/";
00293 cmdline +=
" && rm -f " + KShellProcess::quote( xmlDirectory ) +
"*";
00294 could_be_dirty=
true;
00295 }
00296
00297
if (could_be_dirty) {
00298
kdDebug(9026) <<
"Cleaning Doxygen generated API documentation using: " << cmdline <<
endl;
00299
makeFrontend()->
queueCommand(KShellProcess::quote(
project()->projectDirectory()), cmdline);
00300 }
00301
else
00302
kdDebug(9026) <<
"No Doxygen generated API documentation exists. There's nothing to clean!" <<
endl;
00303
00304 }
00305
00306
00307
#include "doxygenpart.moc"