createpcsdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "createpcsdialog.h"
00013 #include "createpcsdialog.moc"
00014 #include "driver.h"
00015 #include "tag_creator.h"
00016 #include "cppsupportpart.h"
00017
00018 #include <catalog.h>
00019 #include <kdevpcsimporter.h>
00020 #include <kdevcoderepository.h>
00021
00022 #include <kparts/componentfactory.h>
00023
00024 #include <ktrader.h>
00025 #include <kdebug.h>
00026 #include <klibloader.h>
00027 #include <klistbox.h>
00028 #include <kiconloader.h>
00029 #include <klistview.h>
00030 #include <kapplication.h>
00031 #include <kinstance.h>
00032 #include <kstandarddirs.h>
00033
00034 #include <qprogressbar.h>
00035 #include <qheader.h>
00036 #include <qlabel.h>
00037 #include <qprocess.h>
00038 #include <qregexp.h>
00039 #include <qlayout.h>
00040
00041 #include <stdlib.h>
00042 #include <unistd.h>
00043
00044 class CreatePCSDialog::RppDriver: public Driver
00045 {
00046 public:
00047 RppDriver( Catalog* c )
00048 : catalog( c )
00049 {
00050 setup();
00051 }
00052
00053 virtual ~RppDriver()
00054 {
00055 #if 0
00056 TagCreator::destroyDocumentation();
00057 #endif
00058 }
00059
00060 #if 0
00061 void addDocDirectory( const QString& dir )
00062 {
00063 m_docDirectoryList.append( dir );
00064 TagCreator::setDocumentationDirectories( m_docDirectoryList );
00065 }
00066 #endif
00067
00068 void fileParsed( const QString& fileName )
00069 {
00071
00072 #if 0
00073 QValueList<Problem> l = problems( fileName );
00074 QValueList<Problem>::Iterator it = l.begin();
00075 while( it != l.end() ){
00076 const Problem& p = *it;
00077 ++it;
00078 }
00079 #endif
00080
00081 TranslationUnitAST::Node ast = takeTranslationUnit( fileName );
00082
00083 TagCreator w( fileName, catalog );
00084 w.parseTranslationUnit( ast.get() );
00085
00086
00087
00088 }
00089
00090
00091
00092 void setup()
00093 {
00094 QProcess proc;
00095 proc.addArgument( "gcc" );
00096 proc.addArgument( "-print-file-name=include" );
00097 if ( !proc.start() ) {
00099 return;
00100 }
00101
00102 while ( proc.isRunning() )
00103 usleep( 1 );
00104
00105 QString gccLibPath = proc.readStdout();
00106 gccLibPath = gccLibPath.replace( QRegExp("[\r\n]"), "" );
00107 addIncludePath( gccLibPath );
00108
00109
00110 proc.clearArguments();
00111 proc.addArgument( "gcc" );
00112 proc.addArgument( "-E" );
00113 proc.addArgument( "-dM" );
00114 proc.addArgument( "-ansi" );
00115 proc.addArgument( "-" );
00116
00117 if ( !proc.start() ) {
00119 return;
00120 }
00121
00122 while ( !proc.isRunning() )
00123 usleep( 1 );
00124 proc.closeStdin();
00125 while ( proc.isRunning() )
00126 usleep( 1 );
00127
00128 while ( proc.canReadLineStdout() ) {
00129 QString l = proc.readLineStdout();
00130 QStringList lst = QStringList::split( ' ', l );
00131 if ( lst.count() != 3 )
00132 continue;
00133
00134 addMacro( Macro( lst[1], lst[2] ) );
00135 }
00136 addMacro( Macro( "__cplusplus", "1" ) );
00137 }
00138
00139 private:
00140 Catalog* catalog;
00141 #if 0
00142 QStringList m_docDirectoryList;
00143 #endif
00144 };
00145
00146
00147 class PCSListViewItem: public KListViewItem
00148 {
00149 public:
00150 PCSListViewItem( KService::Ptr ptr, KDevPCSImporter* importer, QListViewItem* parent )
00151 : KListViewItem( parent ), m_importer( importer ) { init( ptr ); }
00152 PCSListViewItem( KService::Ptr ptr, KDevPCSImporter* importer, QListView* parent )
00153 : KListViewItem( parent ), m_importer( importer ) { init( ptr ); }
00154
00155 ~PCSListViewItem()
00156 {
00157 delete( m_importer );
00158 m_importer = 0;
00159 }
00160
00161 void init( KService::Ptr ptr )
00162 {
00163 setText( 0, ptr->comment() );
00164 setPixmap( 0, SmallIcon(ptr->icon()) );
00165 }
00166
00167 KDevPCSImporter* importer() { return m_importer; }
00168
00169 private:
00170 KDevPCSImporter* m_importer;
00171 };
00172
00173 CreatePCSDialog::CreatePCSDialog(CppSupportPart* part, QWidget* parent, const char* name, bool modal, WFlags fl)
00174 : CreatePCSDialogBase(parent,name, modal,fl), m_part( part )
00175 {
00176 m_settings = 0;
00177 importerListView->header()->hide();
00178
00179 KTrader::OfferList lst = KTrader::self()->query( "KDevelop/PCSImporter" );
00180 kdDebug(9007) << "====================> found " << lst.size() << " importers" << endl;
00181
00182 for( KTrader::OfferList::Iterator it=lst.begin(); it!=lst.end(); ++it )
00183 {
00184 KService::Ptr ptr = *it;
00185
00186 int error = 0;
00187 KDevPCSImporter* importer = KParts::ComponentFactory::createInstanceFromService<KDevPCSImporter>( ptr, this, ptr->name().latin1(), QStringList(), &error );
00188 if( importer ){
00189 new PCSListViewItem( ptr, importer, importerListView );
00190 }
00191 }
00192
00193 setNextEnabled( page, false );
00194
00195 QHBoxLayout* hbox = new QHBoxLayout( settingsPage );
00196 hbox->setAutoAdd( true );
00197
00198 if ( importerListView->firstChild() )
00199 {
00200 importerListView->setSelected( importerListView->firstChild(), true );
00201 setNextEnabled( page, true );
00202 }
00203 }
00204
00205 CreatePCSDialog::~CreatePCSDialog()
00206 {
00207 }
00208
00209
00210 void CreatePCSDialog::back()
00211 {
00212 QWizard::back();
00213 }
00214
00215 void CreatePCSDialog::next()
00216 {
00217 QWizard::next();
00218 }
00219
00220 void CreatePCSDialog::reject()
00221 {
00222 QWizard::reject();
00223 }
00224
00225 void CreatePCSDialog::accept()
00226 {
00227 QWizard::accept();
00228 }
00229
00230 void CreatePCSDialog::slotSelected( const QString & )
00231 {
00232 if( currentPage() == settingsPage ) {
00233 if( m_settings )
00234 delete( m_settings );
00235
00236 KDevPCSImporter* importer = static_cast<PCSListViewItem*>( importerListView->selectedItem() )->importer();
00237 m_settings = importer->createSettingsPage( settingsPage );
00238 setNextEnabled( currentPage(), false );
00239 setHelpEnabled( currentPage(), false );
00240 connect( m_settings, SIGNAL(enabled(int)), this, SLOT(setNextPageEnabled(int)) );
00241
00242 if( m_settings )
00243 setHelpEnabled( m_settings, false );
00244 m_settings->show();
00245 } else if( currentPage() == finalPage ) {
00246 setBackEnabled( currentPage(), false );
00247 setNextEnabled( currentPage(), false );
00248
00249 KDevPCSImporter* importer = static_cast<PCSListViewItem*>( importerListView->selectedItem() )->importer();
00250 QStringList fileList = importer->fileList();
00251 progressBar->setTotalSteps( fileList.size() );
00252 progressBar->setPercentageVisible( true );
00253 int n = 0;
00254
00255 KStandardDirs *dirs = m_part->instance()->dirs();
00256
00257 QString dbName = dirs->saveLocation( "data", "kdevcppsupport/pcs" ) + "/" + importer->dbName() + ".db";
00258 kdDebug(9007) << "================================> dbName = " << dbName << endl;
00259
00260 m_part->removeCatalog( dbName );
00261
00262 Catalog* c = new Catalog();
00263 c->open( dbName );
00264 c->addIndex( "kind" );
00265 c->addIndex( "name" );
00266 c->addIndex( "scope" );
00267 c->addIndex( "fileName" );
00268
00269 RppDriver driver( c );
00270 for( QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it )
00271 {
00272
00273 progressBar->setProgress( ++n );
00274 currentFile->setText( *it );
00275 driver.parseFile( *it );
00276 kapp->processEvents();
00277 }
00278
00279 currentFile->setText( "" );
00280 m_part->addCatalog( c );
00281
00282 setFinishEnabled( currentPage(), true );
00283 }
00284 }
00285
00286 void CreatePCSDialog::setNextPageEnabled( int enabled )
00287 {
00288 setNextEnabled( currentPage(), enabled );
00289 }
00290
00291 void CreatePCSDialog::slotSelectionChanged( QListViewItem * item )
00292 {
00293 setNextPageEnabled( item != 0 );
00294 }
This file is part of the documentation for KDevelop Version 3.1.2.