00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#include "genericproject_widget.h"
00015
#include "genericproject_part.h"
00016
00017
#include "kdevcore.h"
00018
#include "kdevmainwindow.h"
00019
00020
#include <kiconloader.h>
00021
#include <klocale.h>
00022
#include <kdevgenericfactory.h>
00023
#include <ktrader.h>
00024
#include <kdebug.h>
00025
#include <kmessagebox.h>
00026
#include <kparts/componentfactory.h>
00027
00028
#include <qwhatsthis.h>
00029
#include <qdir.h>
00030
00031
#include "kdevbuildsystem.h"
00032
00033
#include "genericlistviewitem.h"
00034
#include "variantserializer.h"
00035
00036
#if QT_VERSION < 0x030100
00037 inline QString QDomDocument_toString(
QDomDocument & cQDomDocument,
int indent )
00038 {
00039
QString str;
00040
QTextStream s( str, IO_WriteOnly );
00041 cQDomDocument.save( s, indent );
00042
00043
return str;
00044 };
00045
#endif // Qt<3.1.0
00046
00047 typedef KDevGenericFactory<GenericProjectPart> GenericProjectFactory;
00048
static const KAboutData data(
"kdevgenericproject",
I18N_NOOP(
"Build Tool"),
"1.0");
00049 K_EXPORT_COMPONENT_FACTORY( libkdevgenericproject,
GenericProjectFactory( &data ) )
00050
00051
GenericProjectPart::
GenericProjectPart(
QObject *parent, const
char *name, const
QStringList& )
00052 :
KDevProject("KDevPart", "kdevpart", parent, name ? name : "
GenericProjectPart" )
00053 {
00054 setInstance( GenericProjectFactory::instance() );
00055 setXMLFile(
"kdevgenericproject.rc" );
00056
00057 m_widget =
new GenericProjectWidget(
this );
00058
00059 QWhatsThis::add(m_widget, i18n(
"<b>Generic project manager</b><p>"
00060
"The project tree consists of two parts. The 'overview' "
00061
"in the upper half shows the groups, "
00062
"The 'details' view in the lower half shows the "
00063
"targets and files for the group selected in the overview."));
00064
00065 mainWindow()->embedSelectViewRight( m_widget, i18n(
"Project Manager"), i18n(
"Generic project manager") );
00066
00067 m_mainBuild =
new BuildGroupItem(
"/", 0);
00068 m_mainGroup = m_widget->addGroup(m_mainBuild);
00069 }
00070
00071 GenericProjectPart::~GenericProjectPart()
00072 {
00073
if (
m_widget )
00074
mainWindow()->
removeView(
m_widget );
00075
delete (
GenericProjectWidget*)
m_widget;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 void GenericProjectPart::openProject(
const QString & dirName,
const QString & projectName )
00085 {
00086
m_buildDir = dirName;
00087
m_projectDir = dirName;
00088
m_projectName = projectName;
00089
00090
QDomDocument &dom = *
projectDom();
00091
00092
QString bsName = DomUtil::readEntry(dom,
"/kdevgenericproject/backend");
00093
kdDebug() <<
"------------------------------------------------------" <<
endl;
00094
kdDebug() <<
"Looking for build system support for " << bsName <<
endl;
00095
00096 KTrader::OfferList buildBackendsOffers =
00097 KTrader::self()->query(QString::fromLatin1(
"KDevelop/BuildSystems"),
00098 QString::fromLatin1(
"[X-KDevelop-BuildSystem] == '%1'").arg(bsName));
00099
if (buildBackendsOffers.isEmpty()) {
00100 KMessageBox::sorry(0, i18n(
"No build system plugin for %1 found.").arg(bsName));
00101
return;
00102 }
00103
00104
QValueList<KService::Ptr>::ConstIterator it;
00105
for (it = buildBackendsOffers.begin(); it != buildBackendsOffers.end(); ++it) {
00106
kdDebug() << (*it)->property(
"Name").toString() <<
endl;
00107
kdDebug() << (*it)->property(
"X-KDevelop-BuildSystem").toString() <<
endl;
00108 }
00109
00110
kdDebug() <<
"Offers count: " << buildBackendsOffers.count() <<
endl;;
00111
00112
KService::Ptr buildSystemService;
00113 KTrader::OfferList::ConstIterator serviceIt = buildBackendsOffers.begin();
00114
for ( ; serviceIt != buildBackendsOffers.end(); ++serviceIt )
00115 buildSystemService = *serviceIt;
00116
00117
00118
00119
00120
00121
00122
00123
00124
int error;
00125
m_buildSystem = KParts::ComponentFactory
00126 ::createInstanceFromService<KDevBuildSystem>( buildSystemService, 0,
00127 buildSystemService->name().latin1(),
QStringList(), &error);
00128
kdDebug() <<
"error: " << error <<
endl;
00129
00130
if ( !
m_buildSystem ) {
00131 KMessageBox::sorry(0, i18n(
"Could not create build system plugin for %1.").arg(bsName));
00132
return;
00133 }
00134
m_buildSystem->
initProject(
this);
00135
00136
00137
00138
00139
00140
00141
loadProjectConfig(DomUtil::readEntry(dom,
"/kdevgenericproject/project"));
00142
00143 KDevProject::openProject( dirName, projectName );
00144 }
00145
00146 void GenericProjectPart::closeProject( )
00147 {
00148 }
00149
00150 QString GenericProjectPart::projectDirectory( )
const
00151
{
00152
return m_projectDir;
00153 }
00154
00155 QString GenericProjectPart::projectName( )
const
00156
{
00157
return m_projectName;
00158 }
00159
00160 DomUtil::PairList GenericProjectPart::runEnvironmentVars( )
const
00161
{
00162
return DomUtil::PairList();
00163 }
00164
00165 QString GenericProjectPart::mainProgram(
bool relative )
const
00166
{
00167
return "";
00168 }
00169
00170 QString GenericProjectPart::runDirectory( )
const
00171
{
00172
return m_runDir;
00173 }
00174
00175 QString GenericProjectPart::runArguments( )
const
00176
{
00177
return "";
00178 }
00179
00180 QString GenericProjectPart::activeDirectory( )
const
00181
{
00182
return m_activeDir;
00183 }
00184
00185 QString GenericProjectPart::buildDirectory( )
const
00186
{
00187
return m_buildDir;
00188 }
00189
00190 QStringList GenericProjectPart::allFiles( )
const
00191
{
00192
QStringList path;
00193
return allFiles(
m_mainBuild, path );
00194 }
00195
00196 void GenericProjectPart::addFiles(
const QStringList & fileList )
00197 {
00198
BuildTargetItem *tit =
m_widget->activeTarget();
00199
if (!tit)
00200
return;
00201
00202
for (QStringList::ConstIterator it = fileList.begin(); it != fileList.end(); ++it)
00203 {
00204
if( tit->
fileByName(
QFileInfo(*it).fileName()) != 0 )
00205
continue;
00206
00207
QString absFilename =
m_projectDir + QString::fromLatin1(
"/" ) + (*it);
00208
addFilePrivate( *it, tit );
00209 }
00210
00211
kdDebug() <<
"======> files: " << fileList.join(
", " ) <<
endl;
00212 emit addedFilesToProject( fileList );
00213 }
00214
00215 void GenericProjectPart::addFile(
const QString & fileName )
00216 {
00217
QStringList lst;
00218 lst << fileName;
00219
addFiles( lst );
00220 }
00221
00222 void GenericProjectPart::addFilePrivate(
const QString & fileName,
BuildTargetItem *tit )
00223 {
00224
kdDebug() <<
"GenericProjectPart::addFilePrivate " << fileName <<
endl;
00225
KURL url;
00226 url.
setPath(
projectDirectory() +
"/" + fileName);
00227
kdDebug() <<
"GenericProjectPart::addFilePrivate " << url.
prettyURL() <<
endl;
00228
BuildFileItem *fit =
new BuildFileItem(url, tit);
00229
m_widget->addFile(fit);
00230 }
00231
00232 void GenericProjectPart::removeFiles(
const QStringList & fileList )
00233 {
00234 }
00235
00236 void GenericProjectPart::removeFile(
const QString & fileName )
00237 {
00238
QStringList lst;
00239
removeFiles( lst );
00240 }
00241
00242 void GenericProjectPart::loadProjectConfig(
QString projectFile )
00243 {
00244
QDomDocument dom;
00245 DomUtil::openDOMFile(dom, QDir::cleanDirPath(
projectDirectory() +
"/" + projectFile));
00246
00247
#if QT_VERSION >= 0x030100
00248
kdDebug() << dom.toString(4) <<
endl;
00249
#else
00250
kdDebug() <<
QDomDocument_toString(dom, 4) <<
endl;
00251
#endif
00252
00253
QDomElement docElem = dom.documentElement();
00254
00255
QDomNode n = docElem.firstChild();
00256
while( !n.isNull() ) {
00257
QDomElement e = n.toElement();
00258
if( (!e.isNull()) && (e.tagName() ==
"group") )
00259 {
00260
kdDebug() <<
"GenericProjectPart: parsing group " << e.attribute(
"name") <<
endl;
00261
parseGroup(e,
m_mainGroup);
00262 }
00263 n = n.nextSibling();
00264 }
00265 }
00266
00267 void GenericProjectPart::parseGroup(
const QDomElement & el,
const GenericGroupListViewItem *parentGroup )
00268 {
00269
GenericGroupListViewItem *group =
createGroupItem(el, parentGroup);
00270
00271
QDomNode n = el.firstChild();
00272
while( !n.isNull() ) {
00273
QDomElement e = n.toElement();
00274
if (e.isNull())
00275
return;
00276
if (e.tagName() ==
"group")
00277 {
00278
kdDebug() <<
"GenericProjectPart: parsing group " << e.attribute(
"name") <<
endl;
00279
parseGroup(e, group);
00280 }
00281
else if (e.tagName() ==
"target")
00282 {
00283
kdDebug() <<
"GenericProjectPart: parsing target " << e.attribute(
"name") <<
endl;
00284
parseTarget(e, group->
groupItem());
00285 }
00286
00287 n = n.nextSibling();
00288 }
00289 }
00290
00291 void GenericProjectPart::parseTarget(
const QDomElement & el,
BuildGroupItem *group )
00292 {
00293
BuildTargetItem *ti =
createTargetItem(el, group);
00294
00295
QDomNode n = el.firstChild();
00296
while( !n.isNull() ) {
00297
QDomElement e = n.toElement();
00298
if (e.isNull())
00299
return;
00300
if (e.tagName() ==
"file")
00301 {
00302
kdDebug() <<
"GenericProjectPart: parsing file " << e.attribute(
"name") <<
endl;
00303
parseFile(e, ti);
00304 }
00305 n = n.nextSibling();
00306 }
00307 }
00308
00309 void GenericProjectPart::parseFile(
const QDomElement & el,
BuildTargetItem *target )
00310 {
00311
createFileItem(el, target);
00312 }
00313
00314 GenericGroupListViewItem *
GenericProjectPart::createGroupItem(
const QDomElement & el,
const GenericGroupListViewItem *parent )
00315 {
00316
BuildGroupItem *it =
new BuildGroupItem(el.attribute(
"name"), parent->
groupItem());
00317
kdDebug() <<
"adding group to widget " << el.attribute(
"name") <<
endl;
00318
GenericGroupListViewItem *git =
m_widget->addGroup(it);
00319
00320
QDomNode n = el.firstChild();
00321
while( !n.isNull() ) {
00322
QDomElement e = n.toElement();
00323
if (e.isNull())
00324
return 0;
00325
if (e.tagName() ==
"attribute")
00326 {
00327 it->
setAttribute(e.attribute(
"name") ,
VariantSerializer::loadValue(e));
00328
kdDebug() <<
"GenericProjectPart: parsing attribute " << e.tagName() <<
endl;
00329 }
00330 n = n.nextSibling();
00331 }
00332
00333
return git;
00334 }
00335
00336 BuildTargetItem *
GenericProjectPart::createTargetItem(
const QDomElement & el,
BuildGroupItem *group )
00337 {
00338
BuildTargetItem *it =
new BuildTargetItem(el.attribute(
"name"), group);
00339
return it;
00340 }
00341
00342 BuildFileItem *
GenericProjectPart::createFileItem(
const QDomElement & el,
BuildTargetItem *target )
00343 {
00344
KURL url;
00345
kdDebug() <<
"GenericProjectPart::createFileItem url" <<
endl;
00346 url.
setPath(QDir::cleanDirPath(
projectDirectory() +
"/" + target->
parentGroup()->
path() +
"/" + el.attribute(
"name")));
00347
kdDebug() <<
"GenericProjectPart::createFileItem new" <<
endl;
00348
BuildFileItem *it =
new BuildFileItem(url, target);
00349
return it;
00350 }
00351
00352 KDevBuildSystem *
GenericProjectPart::buildSystem( )
const
00353
{
00354
return m_buildSystem;
00355 }
00356
00357 QStringList GenericProjectPart::allFiles(
BuildGroupItem * group,
QStringList& path )
const
00358
{
00359
QStringList fileList;
00360
00361
if( group !=
m_mainBuild )
00362 path.push_back( group->
name() );
00363
00364
const QValueList<BuildTargetItem*> targets = group->
targets();
00365
for(
QValueList<BuildTargetItem*>::ConstIterator it=targets.begin(); it!=targets.end(); ++it )
00366 {
00367 fileList +=
allFiles( *it, path );
00368 }
00369
00370
const QValueList<BuildGroupItem*> groups = group->
groups();
00371
for(
QValueList<BuildGroupItem*>::ConstIterator it=groups.begin(); it!=groups.end(); ++it )
00372 {
00373 fileList +=
allFiles( *it, path );
00374 }
00375
00376
if( group !=
m_mainBuild )
00377 path.pop_back();
00378
00379
return fileList;
00380 }
00381
00382 QStringList GenericProjectPart::allFiles(
BuildTargetItem * target,
QStringList& path )
const
00383
{
00384
QStringList fileList;
00385
00386
int prjdir =
m_projectDir.length() + 1;
00387
const QValueList<BuildFileItem*> files = target->
files();
00388
for(
QValueList<BuildFileItem*>::ConstIterator it=files.begin(); it!=files.end(); ++it )
00389 {
00390
const BuildFileItem*
file = *it;
00391
QString fileName =
file->url().path().mid( prjdir );
00392
00393 fileList.push_back( fileName );
00394 }
00395
00396
return fileList;
00397 }
00398
00399
#include "genericproject_part.moc"