KDevelop API Documentation

scriptprojectpart.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001-2002 by Bernd Gehrmann                             *
00003  *   bernd@kdevelop.org                                                    *
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  ***************************************************************************/
00011 
00012 #include "scriptprojectpart.h"
00013 
00014 #include <qdir.h>
00015 #include <qregexp.h>
00016 #include <qstringlist.h>
00017 #include <qvaluestack.h>
00018 #include <qvbox.h>
00019 #include <qwhatsthis.h>
00020 #include <kaction.h>
00021 #include <kdebug.h>
00022 #include <kdialogbase.h>
00023 #include <kiconloader.h>
00024 #include <klocale.h>
00025 #include <kmessagebox.h>
00026 #include <kdevgenericfactory.h>
00027 
00028 #include "domutil.h"
00029 #include "kdevcore.h"
00030 #include "kdevmainwindow.h"
00031 #include "kdevpartcontroller.h"
00032 #include "kdevlanguagesupport.h"
00033 #include "scriptoptionswidget.h"
00034 #include "scriptnewfiledlg.h"
00035 
00036 
00037 typedef KDevGenericFactory<ScriptProjectPart> ScriptProjectFactory;
00038 static const KAboutData data("kdevscriptproject", I18N_NOOP("Build Tool"), "1.0");
00039 K_EXPORT_COMPONENT_FACTORY( libkdevscriptproject, ScriptProjectFactory( &data ) )
00040 
00041 ScriptProjectPart::ScriptProjectPart(QObject *parent, const char *name, const QStringList &)
00042     : KDevProject("ScriptProject", "scriptproject", parent, name ? name : "ScriptProjectPart")
00043 {
00044     setInstance(ScriptProjectFactory::instance());
00045 
00046     setXMLFile("kdevscriptproject.rc");
00047 
00048     // only create new file action if file creation part not available
00049     if (!createFileSupport()) {
00050       KAction *action;
00051       action = new KAction( i18n("New File..."), 0,
00052                             this, SLOT(slotNewFile()),
00053                             actionCollection(), "file_newfile" );
00054       action->setWhatsThis( i18n("<b>New file</b><p>Creates a new file.") );
00055       action->setToolTip( i18n("Create a new file") );
00056     }
00057 
00058     connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)),
00059              this, SLOT(projectConfigWidget(KDialogBase*)) );
00060 }
00061 
00062 
00063 ScriptProjectPart::~ScriptProjectPart()
00064 {}
00065 
00066 
00067 void ScriptProjectPart::projectConfigWidget(KDialogBase *dlg)
00068 {
00069     QVBox *vbox;
00070     vbox = dlg->addVBoxPage(i18n("Script Project Options"));
00071     ScriptOptionsWidget *w = new ScriptOptionsWidget(this, vbox);
00072     connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
00073 }
00074 
00075 
00080 static bool matchesPattern(const QString &fileName, const QStringList &patternList)
00081 {
00082     QStringList::ConstIterator it;
00083     for (it = patternList.begin(); it != patternList.end(); ++it) {
00084         QRegExp re(*it, true, true);
00085         if (re.search(fileName) == 0 && re.matchedLength() == (int)fileName.length())
00086             return true;
00087     }
00088 
00089     return false;
00090 }
00091 
00092 
00093 void ScriptProjectPart::openProject(const QString &dirName, const QString &projectName)
00094 {
00095     if (!languageSupport())
00096         kdDebug(9015) << "ScriptProjectPart::openProject: no language support found!" << endl;
00097 
00098     m_projectDirectory = dirName;
00099     m_projectName = projectName;
00100 
00101     QDomDocument &dom = *projectDom();
00102 
00103     // Set the default directory radio to "executable"
00104     if (DomUtil::readEntry(dom, "/kdevscriptproject/run/directoryradio") == "" ) {
00105         DomUtil::writeEntry(dom, "/kdevscriptproject/run/directoryradio", "executable");
00106     }
00107 
00108     QString includepatterns
00109         = DomUtil::readEntry(dom, "/kdevscriptproject/general/includepatterns");
00110     QStringList includepatternList;
00111     if ( includepatterns.isNull() ) {
00112     if ( languageSupport() ){
00113         KMimeType::List list = languageSupport()->mimeTypes();
00114         KMimeType::List::Iterator it = list.begin();
00115         while( it != list.end() ){
00116         includepatternList += (*it)->patterns();
00117         ++it;
00118         }
00119     }
00120     } else {
00121         includepatternList = QStringList::split(",", includepatterns);
00122     }
00123 
00124     QString excludepatterns
00125         = DomUtil::readEntry(dom, "/kdevscriptproject/general/excludepatterns");
00126     if (excludepatterns.isNull())
00127         excludepatterns = "*~";
00128     QStringList excludepatternList = QStringList::split(",", excludepatterns);
00129 
00130     // Put all files from all subdirectories into file list
00131     QValueStack<QString> s;
00132     int prefixlen = m_projectDirectory.length()+1;
00133     s.push(m_projectDirectory);
00134 
00135     QDir dir;
00136     do {
00137         dir.setPath(s.pop());
00138         kdDebug(9015) << "Examining: " << dir.path() << endl;
00139         const QFileInfoList *dirEntries = dir.entryInfoList();
00140         if ( dirEntries )
00141         {
00142             QPtrListIterator<QFileInfo> it(*dirEntries);
00143             for (; it.current(); ++it) {
00144                 QString fileName = it.current()->fileName();
00145                 if (fileName == "." || fileName == "..")
00146                    continue;
00147                 QString path = it.current()->absFilePath();
00148                 if (it.current()->isDir()) {
00149                     kdDebug(9015) << "Pushing: " << path << endl;
00150                     s.push(path);
00151                 }
00152                 else {
00153                    if (matchesPattern(path, includepatternList)
00154                         && !matchesPattern(path, excludepatternList)) {
00155                         kdDebug(9015) << "Adding: " << path << endl;
00156                         m_sourceFiles.append(path.mid(prefixlen));
00157                    } else {
00158                         kdDebug(9015) << "Ignoring: " << path << endl;
00159                    }
00160                 }
00161             }
00162         }
00163     } while (!s.isEmpty());
00164 
00165     KDevProject::openProject( dirName, projectName );
00166 }
00167 
00168 
00169 void ScriptProjectPart::closeProject()
00170 {
00171 }
00172 
00173 
00174 QString ScriptProjectPart::projectDirectory() const
00175 {
00176     return m_projectDirectory;
00177 }
00178 
00179 
00180 QString ScriptProjectPart::buildDirectory() const
00181 {
00182     return m_projectDirectory;
00183 }
00184 
00185 QString ScriptProjectPart::projectName() const
00186 {
00187     return m_projectName;
00188 }
00189 
00190 
00192 DomUtil::PairList ScriptProjectPart::runEnvironmentVars() const
00193 {
00194     return DomUtil::readPairListEntry(*projectDom(), "/kdevscriptproject/run/envvars", "envvar", "name", "value");
00195 }
00196 
00197 
00207 QString ScriptProjectPart::runDirectory() const
00208 {
00209     QDomDocument &dom = *projectDom();
00210 
00211     QString directoryRadioString = DomUtil::readEntry(dom, "/kdevscriptproject/run/directoryradio");
00212     QString DomMainProgram = DomUtil::readEntry(dom, "/kdevscriptproject/run/mainprogram");
00213 
00214     if ( directoryRadioString == "build" )
00215         return buildDirectory();
00216 
00217     if ( directoryRadioString == "custom" )
00218         return DomUtil::readEntry(dom, "/kdevscriptproject/run/customdirectory");
00219 
00220     int pos = DomMainProgram.findRev('/');
00221     if (pos != -1)
00222         return buildDirectory() + "/" + DomMainProgram.left(pos);
00223 
00224     return buildDirectory() + "/" + DomMainProgram;
00225 
00226 }
00227 
00228 
00238 QString ScriptProjectPart::mainProgram(bool relative) const
00239 {
00240     QDomDocument &dom = *projectDom();
00241 
00242     QString directoryRadioString = DomUtil::readEntry(dom, "/kdevscriptproject/run/directoryradio");
00243     QString DomMainProgram = DomUtil::readEntry(dom, "/kdevscriptproject/run/mainprogram");
00244 
00245     if ( directoryRadioString == "custom" )
00246         return DomMainProgram;
00247 
00248     if ( relative == false )
00249         return buildDirectory() + "/" + DomMainProgram;
00250 
00251     if ( directoryRadioString == "executable" ) {
00252         int pos = DomMainProgram.findRev('/');
00253         if (pos != -1)
00254             return DomMainProgram.mid(pos+1);
00255         return DomMainProgram;
00256     }
00257     else
00258         return DomMainProgram;
00259 }
00260 
00261 
00263 QString ScriptProjectPart::runArguments() const
00264 {
00265     return DomUtil::readEntry(*projectDom(), "/kdevscriptproject/run/programargs");
00266 }
00267 
00268 
00269 QString ScriptProjectPart::activeDirectory() const
00270 {
00271     QDomDocument &dom = *projectDom();
00272 
00273     return DomUtil::readEntry(dom, "/kdevscriptproject/general/activedir");
00274 }
00275 
00276 
00277 QStringList ScriptProjectPart::allFiles() const
00278 {
00279 /*    QStringList res;
00280 
00281     QStringList::ConstIterator it;
00282     for (it = m_sourceFiles.begin(); it != m_sourceFiles.end(); ++it)
00283         res += (m_projectDirectory + "/" + (*it));
00284 
00285     return res;*/
00286 
00287     // return all files relative to the project directory!
00288     return m_sourceFiles;
00289 }
00290 
00291 void ScriptProjectPart::addFile(const QString &fileName)
00292 {
00293     kdDebug(9015) << "AddFile2" << fileName << endl;
00294 
00295     QStringList fileList;
00296     fileList.append ( fileName );
00297 
00298     this->addFiles ( fileList );
00299 }
00300 
00301 void ScriptProjectPart::addFiles ( const QStringList& fileList )
00302 {
00303     QStringList::ConstIterator it;
00304 
00305     for ( it = fileList.begin(); it != fileList.end(); ++it )
00306     {
00307         m_sourceFiles.append ( ( *it ) );
00308     }
00309 
00310     emit addedFilesToProject ( fileList );
00311 }
00312 
00313 void ScriptProjectPart::removeFile(const QString &fileName)
00314 {
00315     QStringList fileList;
00316     fileList.append ( fileName );
00317 
00318     this->addFiles ( fileList );
00319 }
00320 
00321 void ScriptProjectPart::removeFiles ( const QStringList& fileList )
00322 {
00323     emit removedFilesFromProject ( fileList );
00324 
00325     QStringList::ConstIterator it;
00326 
00327     for ( it = fileList.begin(); it != fileList.end(); ++it )
00328     {
00329         m_sourceFiles.remove ( ( *it ) );
00330     }
00331 }
00332 
00333 void ScriptProjectPart::slotNewFile()
00334 {
00335     ScriptNewFileDialog dlg(this);
00336     dlg.exec();
00337 }
00338 
00339 #include "scriptprojectpart.moc"
00340 
00341 
00345 QStringList ScriptProjectPart::distFiles() const
00346 {
00347     QStringList sourceList = allFiles();
00348     // Scan current source directory for any .pro files.
00349     QString projectDir = projectDirectory();
00350     QDir dir(projectDir);
00351     QStringList files = dir.entryList( "*README*");
00352     return sourceList + files;
00353 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:23 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003