KDevelop API Documentation

buildtools/ada/adaproject_part.cpp

Go to the documentation of this file.
00001 /* $Id: adaproject_part.cpp,v 1.14 2003/12/16 22:49:44 dymo Exp $ 00002 * Copyright (C) 2003 Oliver Kellogg 00003 * okellogg@users.sourceforge.net 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 */ 00010 #include <qdom.h> 00011 #include <qfileinfo.h> 00012 #include <qdir.h> 00013 #include <qvaluestack.h> 00014 #include <qregexp.h> 00015 #include <qvbox.h> 00016 00017 #include <kiconloader.h> 00018 #include <klocale.h> 00019 #include <kaction.h> 00020 #include <kgenericfactory.h> 00021 #include <kdebug.h> 00022 #include <kdialogbase.h> 00023 #include <kmessagebox.h> 00024 #include <klibloader.h> 00025 #include <kservice.h> 00026 #include <kconfig.h> 00027 00028 #include "domutil.h" 00029 #include "kdevcore.h" 00030 #include "kdevmainwindow.h" 00031 #include "kdevmakefrontend.h" 00032 #include "kdevappfrontend.h" 00033 #include "kdevpartcontroller.h" 00034 #include "kdevlanguagesupport.h" 00035 #include "kdevcompileroptions.h" 00036 #include "kdevgenericfactory.h" 00037 00038 #include "adaproject_widget.h" 00039 #include "adaproject_part.h" 00040 #include "adaprojectoptionsdlg.h" 00041 #include "adaglobaloptionsdlg.h" 00042 00043 typedef KDevGenericFactory<AdaProjectPart> AdaProjectFactory; 00044 static const KAboutData data("kdevadaproject", I18N_NOOP("Build Tool"), "1.0"); 00045 K_EXPORT_COMPONENT_FACTORY( libkdevadaproject, AdaProjectFactory( &data ) ) 00046 00047 AdaProjectPart::AdaProjectPart(QObject *parent, const char *name, const QStringList& ) 00048 :KDevProject("AdaProject", "adaproject", parent, name ? name : "AdaProjectPart" ) 00049 { 00050 setInstance(AdaProjectFactory::instance()); 00051 setXMLFile("kdevadaproject.rc"); 00052 00053 KAction *action; 00054 action = new KAction( i18n("&Build Project"), "make_kdevelop", Key_F8, 00055 this, SLOT(slotBuild()), 00056 actionCollection(), "build_build" ); 00057 action = new KAction( i18n("Execute Program"), "exec", 0, 00058 this, SLOT(slotExecute()), 00059 actionCollection(), "build_execute" ); 00060 00061 connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)), 00062 this, SLOT(projectConfigWidget(KDialogBase*)) ); 00063 00064 connect( core(), SIGNAL(configWidget(KDialogBase*)), 00065 this, SLOT(configWidget(KDialogBase*)) ); 00066 00067 // m_widget = new AdaProjectWidget(this); 00068 00069 // QWhatsThis::add(m_widget, i18n("WHAT DOES THIS PART DO?")); 00070 00071 // now you decide what should happen to the widget. Take a look at kdevcore.h 00072 // or at other plugins how to embed it. 00073 00074 // if you want to embed your widget as an outputview, simply uncomment 00075 // the following line. 00076 00077 // mainWindow()->embedOutputView( m_widget, "name that should appear", "enter a tooltip" ); 00078 00079 } 00080 00081 AdaProjectPart::~AdaProjectPart() 00082 { 00083 // delete m_widget; 00084 } 00085 00090 static bool matchesPattern(const QString &fileName, const QStringList &patternList) 00091 { 00092 QStringList::ConstIterator it; 00093 for (it = patternList.begin(); it != patternList.end(); ++it) { 00094 QRegExp re(*it, true, true); 00095 if (re.search(fileName) == 0 && re.matchedLength() == (int)fileName.length()) 00096 return true; 00097 } 00098 00099 return false; 00100 } 00101 00102 void AdaProjectPart::openProject(const QString &dirName, const QString &projectName) 00103 { 00104 m_buildDir = dirName; 00105 m_projectDir = dirName; 00106 m_projectName = projectName; 00107 00108 QDomDocument &dom = *projectDom(); 00109 // Set the default directory radio to "executable" 00110 if (DomUtil::readEntry(dom, "/kdevadaproject/run/directoryradio") == "" ) { 00111 DomUtil::writeEntry(dom, "/kdevadaproject/run/directoryradio", "executable"); 00112 } 00113 00114 loadProjectConfig(); 00115 00116 // Put all files from all subdirectories into file list 00117 QValueStack<QString> s; 00118 int prefixlen = m_projectDir.length()+1; 00119 s.push(m_projectDir); 00120 00121 QStringList includepatternList; 00122 00123 if ( languageSupport() ) 00124 { 00125 KMimeType::List list = languageSupport()->mimeTypes(); 00126 KMimeType::List::Iterator it = list.begin(); 00127 while( it != list.end() ){ 00128 includepatternList += (*it)->patterns(); 00129 ++it; 00130 } 00131 } 00132 00133 QString excludepatterns = "*~"; 00134 QStringList excludepatternList = QStringList::split(",", excludepatterns); 00135 00136 QDir dir; 00137 do { 00138 dir.setPath(s.pop()); 00139 kdDebug() << "AdaProjectPart::openProject examining: " << dir.path() << endl; 00140 const QFileInfoList *dirEntries = dir.entryInfoList(); 00141 if( !dirEntries ) 00142 break; 00143 00144 QPtrListIterator<QFileInfo> it(*dirEntries); 00145 for (; it.current(); ++it) { 00146 QString fileName = it.current()->fileName(); 00147 if (fileName == "." || fileName == "..") 00148 continue; 00149 QString path = it.current()->absFilePath(); 00150 if (it.current()->isDir()) { 00151 kdDebug() << "AdaProjectPart::openProject pushing: " << path << endl; 00152 s.push(path); 00153 } 00154 else { 00155 if (matchesPattern(path, includepatternList) 00156 && !matchesPattern(path, excludepatternList)) { 00157 kdDebug() << "AdaProjectPart::openProject adding: " << path << endl; 00158 m_sourceFiles.append(path.mid(prefixlen)); 00159 } else { 00160 kdDebug() << "AdaProjectPart::openProject ignoring: " << path << endl; 00161 } 00162 } 00163 } 00164 } while (!s.isEmpty()); 00165 00166 KDevProject::openProject( dirName, projectName ); 00167 } 00168 00169 void AdaProjectPart::closeProject() 00170 { 00171 } 00172 00174 DomUtil::PairList AdaProjectPart::runEnvironmentVars() const 00175 { 00176 return DomUtil::readPairListEntry(*projectDom(), "/kdevadaproject/run/envvars", "envvar", "name", "value"); 00177 } 00178 00179 00189 QString AdaProjectPart::runDirectory() const 00190 { 00191 QDomDocument &dom = *projectDom(); 00192 00193 QString directoryRadioString = DomUtil::readEntry(dom, "/kdevadaproject/run/directoryradio"); 00194 QString DomMainProgram = DomUtil::readEntry(dom, "/kdevadaproject/run/mainprogram"); 00195 00196 if ( directoryRadioString == "build" ) 00197 return buildDirectory(); 00198 00199 if ( directoryRadioString == "custom" ) 00200 return DomUtil::readEntry(dom, "/kdevadaproject/run/customdirectory"); 00201 00202 int pos = DomMainProgram.findRev('/'); 00203 if (pos != -1) 00204 return buildDirectory() + "/" + DomMainProgram.left(pos); 00205 00206 return buildDirectory() + "/" + DomMainProgram; 00207 00208 } 00209 00210 00220 QString AdaProjectPart::mainProgram(bool relative) const 00221 { 00222 QFileInfo fi(mainSource()); 00223 return buildDirectory() + "/" + fi.baseName(); 00224 00226 QDomDocument &dom = *projectDom(); 00227 00228 QString directoryRadioString = DomUtil::readEntry(dom, "/kdevadaproject/run/directoryradio"); 00229 QString DomMainProgram = DomUtil::readEntry(dom, "/kdevadaproject/run/mainprogram"); 00230 00231 if ( directoryRadioString == "custom" ) 00232 return DomMainProgram; 00233 00234 if ( relative == false ) 00235 return buildDirectory() + "/" + DomMainProgram; 00236 00237 if ( directoryRadioString == "executable" ) { 00238 int pos = DomMainProgram.findRev('/'); 00239 if (pos != -1) 00240 return DomMainProgram.mid(pos+1); 00241 return DomMainProgram; 00242 } 00243 else 00244 return DomMainProgram; 00245 } 00246 00247 00249 QString AdaProjectPart::runArguments() const 00250 { 00251 return DomUtil::readEntry(*projectDom(), "/kdevadaproject/run/programargs"); 00252 } 00253 00254 QString AdaProjectPart::mainSource() const 00255 { 00256 return projectDirectory() + "/" + m_mainSource; 00257 } 00258 00259 void AdaProjectPart::setMainSource(QString fullPath) 00260 { 00261 m_mainSource = fullPath.replace(QRegExp(QString(projectDirectory() + QString("/"))),""); 00262 } 00263 00264 QString AdaProjectPart::projectDirectory() const 00265 { 00266 return m_projectDir; 00267 } 00268 00269 QString AdaProjectPart::projectName() const 00270 { 00271 return m_projectName; 00272 } 00273 00274 QString AdaProjectPart::activeDirectory() const 00275 { 00276 QFileInfo fi(mainSource()); 00277 return fi.dirPath(true).replace(QRegExp(projectDirectory()),""); 00278 } 00279 00280 QString AdaProjectPart::buildDirectory() const 00281 { 00282 QFileInfo fi(mainSource()); 00283 return fi.dirPath(true); 00284 } 00285 00286 void AdaProjectPart::listOfFiles(QStringList &result, QString path) const 00287 { 00288 QDir d(path); 00289 if (!d.exists()) 00290 return; 00291 00292 const QFileInfoList *entries = d.entryInfoList(QDir::Dirs | QDir::Files | QDir::Hidden); 00293 if( !entries ) 00294 return; 00295 00296 QFileInfoListIterator it( *entries ); 00297 while( const QFileInfo* fileInfo = it.current() ) 00298 { 00299 ++it; 00300 00301 if (fileInfo->isDir() && fileInfo->filePath() != path) 00302 { 00303 kdDebug() << "entering dir " << fileInfo->dirPath() << endl; 00304 listOfFiles(result, fileInfo->dirPath()); 00305 } 00306 else 00307 { 00308 kdDebug() << "adding to result: " << fileInfo->filePath() << endl; 00309 result << fileInfo->filePath(); 00310 } 00311 } 00312 } 00313 00314 QStringList AdaProjectPart::allFiles() const 00315 { 00316 // QStringList files; 00317 00318 // listOfFiles(files, projectDirectory()); 00319 00320 // return files; 00321 return m_sourceFiles; 00322 } 00323 00324 void AdaProjectPart::addFile(const QString& /*fileName*/) 00325 { 00326 } 00327 00328 void AdaProjectPart::addFiles(const QStringList& /*fileList*/) 00329 { 00330 } 00331 00332 void AdaProjectPart::removeFile(const QString& /*fileName*/) 00333 { 00334 } 00335 00336 void AdaProjectPart::removeFiles(const QStringList& /*fileList*/) 00337 { 00338 } 00339 00340 void AdaProjectPart::slotBuild() 00341 { 00342 partController()->saveAllFiles(); 00343 00344 QString cmdline = m_compilerExec + " " + m_compilerOpts + " "; 00345 00346 if (cmdline.isEmpty()) 00347 { 00348 KMessageBox::sorry(0, i18n("Could not find ada compiler.\nCheck if your compiler settings are correct.")); 00349 return; 00350 } 00351 00352 QFileInfo fi(mainSource()); 00353 cmdline += fi.fileName(); 00354 00355 QString dircmd = "cd "; 00356 dircmd += buildDirectory(); 00357 dircmd += " && "; 00358 00359 makeFrontend()->queueCommand(buildDirectory(), dircmd + cmdline); 00360 } 00361 00362 void AdaProjectPart::slotExecute() 00363 { 00364 partController()->saveAllFiles(); 00365 QString program = "./"; 00366 appFrontend()->startAppCommand(buildDirectory(), mainProgram(), true); 00367 } 00368 00369 void AdaProjectPart::changedFiles( const QStringList & fileList ) 00370 { 00371 KDevProject::changedFiles(fileList); 00372 } 00373 00374 void AdaProjectPart::changedFile( const QString & fileName ) 00375 { 00376 KDevProject::changedFile(fileName); 00377 } 00378 00379 void AdaProjectPart::projectConfigWidget( KDialogBase * dlg ) 00380 { 00381 QVBox *vbox; 00382 vbox = dlg->addVBoxPage(i18n("Ada Compiler")); 00383 AdaProjectOptionsDlg *w = new AdaProjectOptionsDlg(this, vbox); 00384 connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) ); 00385 connect( dlg, SIGNAL(okClicked()), this, SLOT(loadProjectConfig()) ); 00386 } 00387 00388 void AdaProjectPart::loadProjectConfig( ) 00389 { 00390 QDomDocument &dom = *(projectDom()); 00391 00392 QString config = DomUtil::readEntry(dom, "/kdevadaproject/general/useconfiguration", "default"); 00393 m_mainSource = DomUtil::readEntry(dom, QString("/kdevadaproject/configurations/") + config + QString("/mainsource") ); 00394 m_compilerOpts = DomUtil::readEntry(dom, QString("/kdevadaproject/configurations/") + config + QString("/compileroptions")); 00395 m_compilerExec = DomUtil::readEntry(dom, QString("/kdevadaproject/configurations/") + config + QString("/compilerexec")); 00396 00397 if (m_compilerExec.isEmpty()) 00398 { 00399 KTrader::OfferList offers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'Ada'"); 00400 QValueList<KService::Ptr>::ConstIterator it; 00401 for (it = offers.begin(); it != offers.end(); ++it) { 00402 if ((*it)->property("X-KDevelop-Default").toBool()) { 00403 m_compilerExec = (*it)->exec(); 00404 break; 00405 } 00406 } 00407 } 00408 } 00409 00410 void AdaProjectPart::configWidget( KDialogBase * dlg ) 00411 { 00412 QVBox *vbox; 00413 vbox = dlg->addVBoxPage(i18n("Ada Compiler")); 00414 AdaGlobalOptionsDlg *w = new AdaGlobalOptionsDlg(this, vbox); 00415 connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) ); 00416 } 00417 00418 KDevCompilerOptions *AdaProjectPart::createCompilerOptions(const QString &name) 00419 { 00420 KService::Ptr service = KService::serviceByDesktopName(name); 00421 if (!service) { 00422 kdDebug() << "AdaProjectPart::createCompilerOptions can't find service " << name; 00423 return 0; 00424 } 00425 00426 KLibFactory *factory = KLibLoader::self()->factory(QFile::encodeName(service->library())); 00427 if (!factory) { 00428 QString errorMessage = KLibLoader::self()->lastErrorMessage(); 00429 KMessageBox::error(0, i18n("There was an error loading the module %1.\n" 00430 "The diagnostics is:\n%2").arg(service->name()).arg(errorMessage)); 00431 exit(1); 00432 } 00433 00434 QStringList args; 00435 QVariant prop = service->property("X-KDevelop-Args"); 00436 if (prop.isValid()) 00437 args = QStringList::split(" ", prop.toString()); 00438 00439 QObject *obj = factory->create(this, service->name().latin1(), 00440 "KDevCompilerOptions", args); 00441 00442 if (!obj->inherits("KDevCompilerOptions")) { 00443 kdDebug() << "AdaProjectPart::createCompilerOptions: component does not inherit KDevCompilerOptions" << endl; 00444 return 0; 00445 } 00446 KDevCompilerOptions *dlg = (KDevCompilerOptions*) obj; 00447 00448 return dlg; 00449 } 00450 00451 QString AdaProjectPart::defaultOptions( const QString compiler ) 00452 { 00453 KConfig *config = KGlobal::config(); 00454 config->setGroup("Ada Compiler"); 00455 return config->readPathEntry(compiler); 00456 } 00457 00458 #include "adaproject_part.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:35 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003