KDevelop API Documentation

buildtools/autotools/autoprojectwidget.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 00004 * * 00005 * Copyright (C) 2002 by Victor Rder * 00006 * victor_roeder@gmx.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 ***************************************************************************/ 00014 00015 #include "autoprojectwidget.h" 00016 00017 #include <qcheckbox.h> 00018 #include <qdom.h> 00019 #include <qfile.h> 00020 #include <qheader.h> 00021 #include <qpainter.h> 00022 #include <qptrstack.h> 00023 #include <qregexp.h> 00024 #include <qsplitter.h> 00025 #include <qstringlist.h> 00026 #include <qtextstream.h> 00027 #include <qtoolbutton.h> 00028 #include <qtooltip.h> 00029 #include <qwhatsthis.h> 00030 #include <qtimer.h> 00031 00032 #include <kdebug.h> 00033 #include <kfiledialog.h> 00034 #include <klistview.h> 00035 #include <kmessagebox.h> 00036 #include <kregexp.h> 00037 #include <kurl.h> 00038 #include <kfile.h> 00039 #include <kaction.h> 00040 00041 #include "kdevcore.h" 00042 #include "domutil.h" 00043 #include "misc.h" 00044 #include "choosetargetdialog.h" 00045 00046 #include "autolistviewitems.h" 00047 00048 #include "autoprojectpart.h" 00049 #include "autosubprojectview.h" 00050 #include "autodetailsview.h" 00051 #include "urlutil.h" 00052 00053 static QString nicePrimary( const QString &primary ) 00054 { 00055 if ( primary == "PROGRAMS" ) 00056 return i18n( "Program" ); 00057 else if ( primary == "LIBRARIES" ) 00058 return i18n( "Library" ); 00059 else if ( primary == "LTLIBRARIES" ) 00060 return i18n( "Libtool Library" ); 00061 else if ( primary == "SCRIPTS" ) 00062 return i18n( "Script" ); 00063 else if ( primary == "HEADERS" ) 00064 return i18n( "Header" ); 00065 else if ( primary == "DATA" ) 00066 return i18n( "Data" ); 00067 else if ( primary == "JAVA" ) 00068 return i18n( "Java" ); 00069 else 00070 return QString::null; 00071 } 00072 00073 00074 AutoProjectWidget::AutoProjectWidget( AutoProjectPart *part, bool kde ) 00075 : QVBox( 0, "auto project widget" ) 00076 { 00077 m_part = part; 00078 m_kdeMode = kde; 00079 m_activeSubproject = 0; 00080 m_activeTarget = 0; 00081 m_shownSubproject = 0; 00082 m_choosenTarget = 0; 00083 00084 QSplitter *splitter = new QSplitter(Vertical, this); 00085 00086 initOverview ( splitter ); 00087 initDetailview ( splitter ); 00088 00089 initActions (); 00090 } 00091 00092 00093 AutoProjectWidget::~AutoProjectWidget() 00094 {} 00095 00096 void AutoProjectWidget::initOverview ( QWidget* parent ) 00097 { 00098 QVBox * overviewBox = new QVBox( parent, "vertical overview box" ); 00099 00100 QHBox *overviewButtonBox = new QHBox( overviewBox, "subproject button box" ); 00101 overviewButtonBox->setMargin( 2 ); 00102 overviewButtonBox->setSpacing( 2 ); 00103 00104 addSubprojectButton = new QToolButton( overviewButtonBox ); 00105 addSubprojectButton->setPixmap( SmallIcon( "folder_new" ) ); 00106 QToolTip::add 00107 ( addSubprojectButton, i18n( "Add subproject" ) ); 00108 QWhatsThis::add(addSubprojectButton, i18n("<b>Add subproject</b><p>Creates a new subproject in currently selected subproject.")); 00109 00110 /* addExistingSubprojectButton = new QToolButton(overviewButtonBox); 00111 addExistingSubprojectButton->setPixmap(SmallIcon("fileimport")); 00112 QToolTip::add(addExistingSubprojectButton, i18n("Add existing subproject to currently selected subproject...")); 00113 */ 00114 addTargetButton = new QToolButton( overviewButtonBox ); 00115 addTargetButton->setPixmap( SmallIcon( "targetnew_kdevelop" ) ); 00116 QToolTip::add 00117 ( addTargetButton, i18n( "Add target" ) ); 00118 QWhatsThis::add(addTargetButton, i18n("<b>Add target</b><p>Adds a new target to the currently selected subproject. Target can be a binary program, library, script, also a collection of data or header files.")); 00119 00120 addServiceButton = new QToolButton( overviewButtonBox ); 00121 addServiceButton->setPixmap( SmallIcon( "servicenew_kdevelop" ) ); 00122 QToolTip::add 00123 ( addServiceButton, i18n( "Add service" ) ); 00124 QWhatsThis::add(addServiceButton, i18n("<b>Add service</b><p>Creates a .desktop file describing the service.")); 00125 00126 addApplicationButton = new QToolButton( overviewButtonBox ); 00127 addApplicationButton->setPixmap( SmallIcon( "window_new" ) ); 00128 QToolTip::add 00129 ( addApplicationButton, i18n( "Add application" ) ); 00130 QWhatsThis::add(addApplicationButton, i18n("<b>Add application</b><p>Creates an application .desktop file.")); 00131 00132 buildSubprojectButton = new QToolButton( overviewButtonBox ); 00133 buildSubprojectButton->setPixmap( SmallIcon( "launch" ) ); 00134 QToolTip::add 00135 ( buildSubprojectButton, i18n( "Build" ) ); 00136 QWhatsThis::add(buildSubprojectButton, i18n("<b>Build</b><p>Runs <b>make</b> from the directory of the selected subproject.<br>" 00137 "Environment variables and make arguments can be specified " 00138 "in the project settings dialog, <b>Make Options</b> tab.")); 00139 00140 QWidget *spacer1 = new QWidget( overviewButtonBox ); 00141 overviewButtonBox->setStretchFactor( spacer1, 1 ); 00142 00143 subProjectOptionsButton = new QToolButton( overviewButtonBox ); 00144 subProjectOptionsButton->setPixmap( SmallIcon( "configure" ) ); 00145 QToolTip::add 00146 ( subProjectOptionsButton, i18n( "Options" ) ); 00147 QWhatsThis::add(subProjectOptionsButton, i18n("<b>Options</b><p>Shows subproject options dialog that provides settings for compiler, include paths, prefixes and build order.")); 00148 00149 overviewButtonBox->setMaximumHeight( subProjectOptionsButton->height() ); 00150 00151 m_subprojectView = new AutoSubprojectView( this, m_part, overviewBox, "project overview widget" ); 00152 00153 m_subprojectView->setResizeMode( QListView::LastColumn ); 00154 m_subprojectView->setSorting( -1 ); 00155 m_subprojectView->header() ->hide(); 00156 m_subprojectView->addColumn( QString::null ); 00157 } 00158 00159 void AutoProjectWidget::initDetailview ( QWidget* parent ) 00160 { 00161 QVBox * targetBox = new QVBox( parent, "vertical target box" ); 00162 00163 QHBox *targetButtonBox = new QHBox( targetBox, "target button box" ); 00164 targetButtonBox->setMargin( 2 ); 00165 targetButtonBox->setSpacing( 2 ); 00166 00167 addNewFileButton = new QToolButton( targetButtonBox ); 00168 addNewFileButton->setPixmap( SmallIcon( "filenew" ) ); 00169 QToolTip::add 00170 ( addNewFileButton, i18n( "Create new file" ) ); 00171 QWhatsThis::add(addNewFileButton, i18n("<b>Create new file</b><p>Creates a new file and adds it to a currently selected target.")); 00172 00173 addExistingFileButton = new QToolButton( targetButtonBox ); 00174 addExistingFileButton->setPixmap( SmallIcon( "fileimport" ) ); 00175 QToolTip::add 00176 ( addExistingFileButton, i18n( "Add existing files" ) ); 00177 QWhatsThis::add(addExistingFileButton, i18n("<b>Add existing files</b><p>Adds existing file to a currently selected target. Header files will not be included in SOURCES list of a target. " 00178 "They will be added to noinst_HEADERS instead.")); 00179 00180 removeButton = new QToolButton( targetButtonBox ); 00181 removeButton->setPixmap( SmallIcon( "editdelete" ) ); 00182 QToolTip::add 00183 ( removeButton, i18n( "Remove" ) ); 00184 QWhatsThis::add(removeButton, i18n("<b>Remove</b><p>Shows a list of targets dependent on the selected target or file and asks for removal. Also asks if the target or file should be removed from disk.")); 00185 00186 buildTargetButton = new QToolButton( targetButtonBox ); 00187 buildTargetButton->setPixmap( SmallIcon( "launch" ) ); 00188 QToolTip::add 00189 ( buildTargetButton, i18n( "Build" ) ); 00190 QWhatsThis::add(buildTargetButton, i18n("<b>Build target</b><p>Constructs a series of make commands to build the selected target. " 00191 "Also builds dependent targets.")); 00192 00193 QWidget *spacer2 = new QWidget( targetButtonBox ); 00194 targetButtonBox->setStretchFactor( spacer2, 1 ); 00195 00196 targetOptionsButton = new QToolButton( targetButtonBox ); 00197 targetOptionsButton->setPixmap( SmallIcon( "configure" ) ); 00198 QToolTip::add 00199 ( targetOptionsButton, i18n( "Show options" ) ); 00200 QWhatsThis::add(targetOptionsButton, i18n("<b>Options</b><p>Target options dialog that provides settings for linker flags and lists of dependencies and external libraries.")); 00201 00202 targetButtonBox->setMaximumHeight( addNewFileButton->height() ); 00203 00204 targetOptionsButton->setEnabled( false ); 00205 addNewFileButton->setEnabled( false ); 00206 addExistingFileButton->setEnabled( false ); 00207 removeButton->setEnabled( true ); 00208 buildTargetButton->setEnabled( true ); 00209 00210 m_detailView = new AutoDetailsView( this, m_part, targetBox, "project details widget" ); 00211 m_detailView->setRootIsDecorated( true ); 00212 m_detailView->setResizeMode( QListView::LastColumn ); 00213 m_detailView->setSorting( -1 ); 00214 m_detailView->header() ->hide(); 00215 m_detailView->addColumn( QString::null ); 00216 } 00217 00218 void AutoProjectWidget::initActions() 00219 { 00220 connect( subProjectOptionsButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotSubprojectOptions() ) ); 00221 connect( addSubprojectButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddSubproject() ) ); 00222 // connect( addExistingSubprojectButton, SIGNAL(clicked()), this, SLOT(slotAddExistingSubproject()) ); 00223 connect( addTargetButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddTarget() ) ); 00224 connect( addServiceButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddService() ) ); 00225 connect( addApplicationButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotAddApplication() ) ); 00226 connect( buildSubprojectButton, SIGNAL( clicked() ), m_subprojectView, SLOT( slotBuildSubproject() ) ); 00227 00228 connect( targetOptionsButton, SIGNAL( clicked() ), m_detailView, SLOT( slotTargetOptions() ) ); 00229 connect( addNewFileButton, SIGNAL( clicked() ), m_detailView, SLOT( slotAddNewFile() ) ); 00230 connect( addExistingFileButton, SIGNAL( clicked() ), m_detailView, SLOT( slotAddExistingFile() ) ); 00231 connect( removeButton , SIGNAL( clicked() ), m_detailView, SLOT( slotRemoveDetail() ) ); 00232 connect( buildTargetButton, SIGNAL( clicked() ), m_detailView, SLOT( slotBuildTarget() ) ); 00233 00234 connect( m_subprojectView, SIGNAL( selectionChanged( QListViewItem* ) ), 00235 this, SLOT( slotOverviewSelectionChanged( QListViewItem* ) ) ); 00236 00237 connect( m_detailView, SIGNAL( selectionChanged( QListViewItem* ) ), 00238 this, SLOT( slotDetailsSelectionChanged( QListViewItem* ) ) ); 00239 } 00240 00241 AutoSubprojectView* AutoProjectWidget::getSubprojectView () 00242 { 00243 return m_subprojectView; 00244 } 00245 00246 AutoDetailsView* AutoProjectWidget::getDetailsView () 00247 { 00248 return m_detailView; 00249 } 00250 00251 void AutoProjectWidget::openProject( const QString &dirName ) 00252 { 00253 m_subprojectView->loadMakefileams ( dirName ); 00254 } 00255 00256 00257 void AutoProjectWidget::closeProject() 00258 { 00259 m_shownSubproject = 0; 00260 m_subprojectView->clear(); 00261 m_detailView->clear(); 00262 } 00263 00264 SubprojectItem* AutoProjectWidget::activeSubproject () 00265 { 00266 return m_activeSubproject; 00267 } 00268 00269 TargetItem* AutoProjectWidget::activeTarget () 00270 { 00271 return m_activeTarget; 00272 } 00273 00274 QStringList AutoProjectWidget::allSubprojects() 00275 { 00276 int prefixlen = m_part->projectDirectory().length() + 1; 00277 QStringList res; 00278 00279 QListViewItemIterator it( m_subprojectView ); 00280 for ( ; it.current(); ++it ) 00281 { 00282 // Skip root subproject 00283 // if ( it.current() == m_subprojectView->firstChild() ) 00284 // continue; 00285 QString path = static_cast<SubprojectItem*>( it.current() ) ->path; 00286 res.append( path.mid( prefixlen ) ); 00287 } 00288 00289 return res; 00290 } 00291 00292 QPtrList <SubprojectItem> AutoProjectWidget::allSubprojectItems() 00293 { 00294 QPtrList <SubprojectItem> res; 00295 00296 QListViewItemIterator it ( m_subprojectView ); 00297 00298 for ( ; it.current(); ++it ) 00299 { 00300 // Skip root subproject 00301 // if ( it.current() == m_subprojectView->firstChild() ) 00302 // continue; 00303 00304 SubprojectItem* spitem = static_cast <SubprojectItem*> ( it.current() ); 00305 00306 res.append ( spitem ); 00307 } 00308 00309 return res; 00310 } 00311 00312 SubprojectItem* AutoProjectWidget::subprojectItemForPath(const QString & path, bool pathIsAbsolute) 00313 { 00314 kdDebug(9020) << "Looking for path " << path << endl; 00315 00316 int prefixLen = m_part->projectDirectory().length() + 1; 00317 for(QListViewItemIterator it = m_subprojectView;it.current();++it) 00318 { 00319 SubprojectItem* spitem = static_cast<SubprojectItem*>(it.current() ); 00320 QString relpath = (spitem->path).mid(prefixLen); 00321 relpath = (relpath.isNull()) ? QString("") : relpath; 00322 kdDebug(9020) << " ... checking -" << spitem->path << "-" << endl; 00323 kdDebug(9020) << " ... (tailored: -" << relpath << "- against -" << (pathIsAbsolute ? path.mid(prefixLen) : path) << "- )" << endl; 00324 if ( relpath == (pathIsAbsolute ? path.mid(prefixLen) : path)) 00325 { 00326 kdDebug(9020) << "Found it!" << endl; 00327 return spitem; 00328 } 00329 } 00330 kdDebug(9020) << "Not found" << endl; 00331 return NULL; 00332 } 00333 00334 QString AutoProjectWidget::pathForTarget(const TargetItem *titem) const { 00335 00336 if (!titem) return QString::null; 00337 00338 kdDebug(9020) << "Looking for target " << titem->name << endl; 00339 int prefixLen = m_part->projectDirectory().length() + 1; 00340 for(QListViewItemIterator it = m_subprojectView;it.current();++it) 00341 { 00342 SubprojectItem* spitem = static_cast<SubprojectItem*>(it.current() ); 00343 kdDebug(9020) << "Checking: " << spitem->path << endl; 00344 if (spitem->targets.containsRef(titem)) { 00345 kdDebug(9020) << "Found it!" << endl; 00346 QString relpath = (spitem->path).mid(prefixLen); 00347 return (relpath.isNull()) ? QString("") : relpath; 00348 } 00349 } 00350 kdDebug(9020) << "Not found" << endl; 00351 return QString::null; 00352 } 00353 00354 QStringList AutoProjectWidget::allLibraries() 00355 { 00356 int prefixlen = m_part->projectDirectory().length() + 1; 00357 QStringList res; 00358 00359 QListViewItemIterator it( m_subprojectView ); 00360 for ( ; it.current(); ++it ) 00361 { 00362 SubprojectItem *spitem = static_cast<SubprojectItem*>( it.current() ); 00363 QString path = spitem->path; 00364 QPtrListIterator<TargetItem> tit( spitem->targets ); 00365 for ( ; tit.current(); ++tit ) 00366 { 00367 QString primary = ( *tit ) ->primary; 00368 if ( primary == "LIBRARIES" || primary == "LTLIBRARIES" ) 00369 { 00370 QString fullname = path + "/" + ( *tit ) ->name; 00371 res.append( fullname.mid( prefixlen ) ); 00372 } 00373 } 00374 } 00375 00376 return res; 00377 } 00378 00379 00380 QStringList AutoProjectWidget::allFiles() 00381 { 00382 QPtrStack<QListViewItem> s; 00383 QMap<QString, bool> dict; 00384 00385 for ( QListViewItem * item = m_subprojectView->firstChild(); item; 00386 item = item->nextSibling() ? item->nextSibling() : s.pop() ) 00387 { 00388 if ( item->firstChild() ) 00389 s.push( item->firstChild() ); 00390 00391 SubprojectItem *spitem = static_cast<SubprojectItem*>( item ); 00392 // use URLUtil so paths in root project dir are worked out correctly 00393 QString relPath = URLUtil::relativePath(m_part->projectDirectory(), spitem->path, URLUtil::SLASH_SUFFIX); 00394 QPtrListIterator<TargetItem> tit( spitem->targets ); 00395 for ( ; tit.current(); ++tit ) 00396 { 00397 QPtrListIterator<FileItem> fit( tit.current() ->sources ); 00398 for ( ; fit.current(); ++fit ){ 00399 00400 QFileInfo fileInfo( (*fit)->name ); 00401 if( fileInfo.extension() == "ui" ){ 00402 dict.insert( relPath + fileInfo.baseName() + ".h", true ); 00403 dict.insert( relPath + fileInfo.baseName() + ".cpp", true ); 00404 } 00405 00406 dict.insert( relPath + ( *fit ) ->name, true ); 00407 } 00408 } 00409 } 00410 00411 // Files may be in multiple targets, so we have to remove 00412 // duplicates 00413 QStringList res; 00414 QMap<QString, bool>::Iterator it = dict.begin(); 00415 while( it != dict.end() ){ 00416 res << it.key(); 00417 ++it; 00418 } 00419 00420 return res; 00421 } 00422 00423 00424 QString AutoProjectWidget::subprojectDirectory() 00425 { 00426 if ( !selectedSubproject() ) 00427 return QString::null; 00428 00429 return selectedSubproject() ->path; 00430 } 00431 00432 00433 void AutoProjectWidget::setActiveTarget( const QString &targetPath ) 00434 { 00435 int prefixlen = m_part->projectDirectory().length() + 1; 00436 00437 m_activeSubproject = 0; 00438 m_activeTarget = 0; 00439 00440 QListViewItemIterator it( m_subprojectView ); 00441 for ( ; it.current(); ++it ) 00442 { 00443 SubprojectItem *spitem = static_cast<SubprojectItem*>( it.current() ); 00444 QString path = spitem->path; 00445 QPtrListIterator<TargetItem> tit( spitem->targets ); 00446 for ( ; tit.current(); ++tit ) 00447 { 00448 QString primary = ( *tit ) ->primary; 00449 if ( primary != "PROGRAMS" && primary != "LIBRARIES" 00450 && primary != "LTLIBRARIES" && primary != "JAVA" ) 00451 continue; 00452 00453 QString currentTargetPath = ( path + "/" + ( *tit ) ->name ).mid( prefixlen ); 00454 00455 bool hasTarget = ( targetPath == currentTargetPath ); 00456 ( *tit )->setBold( hasTarget ); 00457 if ( hasTarget ) 00458 { 00459 spitem->setBold( true ); 00460 m_activeSubproject = spitem; 00461 m_activeTarget = ( *tit ); 00462 m_subprojectView->setSelected( m_activeSubproject, true ); 00463 m_subprojectView->ensureItemVisible ( m_activeSubproject ); 00464 m_subprojectView->viewport() ->update(); 00465 m_detailView->setSelected ( m_activeTarget, true ); 00466 m_detailView->ensureItemVisible ( m_activeTarget ); 00467 m_detailView->viewport()->update(); 00468 } 00469 else 00470 { 00471 // to avoid a setBold ( false ) if there's another target in the current Subproject (i.e. spitem) ... 00472 spitem->setBold ( ( m_activeSubproject == spitem ) ); 00473 m_detailView->viewport()->update(); 00474 } 00475 } 00476 } 00477 00478 if ( m_activeSubproject == 0 && 00479 m_activeTarget == 0 ) 00480 { 00481 m_subprojectView->setSelected ( m_subprojectView->firstChild(), true ); 00482 m_subprojectView->ensureItemVisible ( m_subprojectView->firstChild() ); 00483 m_subprojectView->viewport()->update(); 00484 } 00485 } 00486 00487 00488 QString AutoProjectWidget::activeDirectory() 00489 { 00490 if ( m_activeSubproject ) 00491 return m_activeSubproject->path.mid( m_part->projectDirectory().length() + 1 ); 00492 else 00493 { 00494 /* if ( selectedSubproject() ) 00495 return selectedSubproject()->path; 00496 else*/ 00497 return QString::null; 00498 } 00499 } 00500 00501 00502 void AutoProjectWidget::addFiles( const QStringList &list ) 00503 { 00504 QDomDocument &dom = *m_part->projectDom(); 00505 QStringList fileList = list; 00506 00507 if ( DomUtil::readBoolEntry( dom, "/kdevautoproject/general/useactivetarget" ) ) 00508 { 00509 QStringList::iterator it; 00510 00511 QString fileName; 00512 00513 for ( it = fileList.begin(); it != fileList.end(); ++it ) 00514 { 00515 int pos = ( *it ).findRev('/'); 00516 if (pos != -1) 00517 { 00518 fileName = ( *it ).mid(pos+1); 00519 } 00520 else 00521 { 00522 fileName = ( *it ); 00523 } 00524 00525 //FileItem * fitem = createFileItem( fileName,m_activeSubproject ); 00526 //m_activeTarget->sources.append( fitem ); 00527 //m_activeTarget->insertItem( fitem ); 00528 00530 addToTarget(fileName, m_activeSubproject, m_activeTarget); 00531 // QString canontargetname = AutoProjectTool::canonicalize( m_activeTarget->name ); 00532 // QString varname = canontargetname + "_SOURCES"; 00533 // m_activeSubproject->variables[ varname ] += ( " " + fileName ); 00534 // 00535 // QMap<QString, QString> replaceMap; 00536 // replaceMap.insert( varname, m_activeSubproject->variables[ varname ] ); 00537 // 00538 // AutoProjectTool::modifyMakefileam( m_activeSubproject->path + "/Makefile.am", replaceMap ); 00539 } 00540 00541 emitAddedFiles ( list ); 00542 } 00543 else 00544 { 00545 // See if we can figure out the target for each file without asking the user 00546 // I think it's a valid assumption that if a directory contains only one target 00547 // the file can be added to that target (Julian Rockey linux at jrockey.com) 00548 QStringList doManually, doneAutomatically; 00549 for(QStringList::iterator it = fileList.begin();it!=fileList.end();++it) 00550 { 00551 bool autoAdded = false; 00552 QString relativeDir = URLUtil::directory(*it); 00553 SubprojectItem* spitem = subprojectItemForPath(relativeDir); 00554 if (spitem) 00555 { 00556 QPtrList<TargetItem> titemList = spitem->targets; 00557 if (titemList.count()==1) { 00558 addToTarget( URLUtil::filename(*it), spitem, titemList.first() ); 00559 doneAutomatically.append(*it); 00560 autoAdded = true; 00561 } 00562 } 00563 // add to manual list if this file wasn't auto-added 00564 if (!autoAdded) doManually.append(*it); 00565 } 00566 if (doneAutomatically.count()>0) emitAddedFiles(doneAutomatically); 00567 00568 // raise dialog for any files that weren't added automatically 00569 if (doManually.count()>0) { 00570 ChooseTargetDialog chooseTargetDlg ( this, m_part, doManually, this, "choose target dialog" ); 00571 00572 //chooseTargetDlg = new ChooseTargetDialog ( this, this, "choose target dialog" ); 00573 00574 if ( chooseTargetDlg.exec() && chooseTargetDlg.neverAskAgainCheckBox->isChecked() ) 00575 { 00576 DomUtil::writeBoolEntry( dom, "/kdevautoproject/general/useactivetarget", true ); 00577 } 00578 } 00579 } 00580 } 00581 00582 void AutoProjectWidget::addToTarget(const QString & fileName, SubprojectItem* spitem, TargetItem* titem) 00583 { 00584 QString varname; 00586 if (AutoProjectPrivate::isHeader(fileName) && 00587 ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES" || titem->primary == "LTLIBRARIES" ) ) 00588 { 00589 kdDebug ( 9020 ) << "Ignoring header file and adding it to noinst_HEADERS: " << fileName << endl; 00590 TargetItem* noinst_HEADERS_item = getSubprojectView()->findNoinstHeaders(spitem); 00591 FileItem *fitem = createFileItem( fileName, spitem ); 00592 noinst_HEADERS_item->sources.append( fitem ); 00593 noinst_HEADERS_item->insertItem( fitem ); 00594 varname = "noinst_HEADERS"; 00595 } 00596 else 00597 { 00598 FileItem * fitem = createFileItem( fileName, spitem ); 00599 titem->sources.append( fitem ); 00600 titem->insertItem( fitem ); 00601 00602 QString canontargetname = AutoProjectTool::canonicalize( titem->name ); 00603 varname = canontargetname + "_SOURCES"; 00604 } 00605 spitem->variables[ varname ] += ( " " + fileName ); 00606 00607 QMap<QString, QString> replaceMap; 00608 replaceMap.insert( varname, spitem->variables[ varname ] ); 00609 00610 AutoProjectTool::modifyMakefileam( spitem->path + "/Makefile.am", replaceMap ); 00611 00612 slotDetailsSelectionChanged(spitem); 00613 } 00614 00615 void AutoProjectWidget::removeFiles( const QStringList &list ) 00616 { 00617 ( void ) list; 00618 } 00619 00620 00621 void AutoProjectWidget::slotOverviewSelectionChanged( QListViewItem *item ) 00622 { 00623 if ( !item ) 00624 return; 00625 00626 // Delete the items from the details view first. 00627 if ( m_shownSubproject ) 00628 { 00629 // Remove all TargetItems and all of their children from the view 00630 kdDebug ( 9020 ) << "m_shownSubproject (before takeItem()): " << m_shownSubproject->subdir << endl; 00631 00632 QPtrListIterator<TargetItem> it1( m_shownSubproject->targets ); 00633 for ( ; it1.current(); ++it1 ) 00634 { 00635 // After AddTargetDialog, it can happen that an 00636 // item is not yet in the list view, so better check... 00637 kdDebug ( 9020 ) << "take child items of " << ( *it1 )->name << endl; 00638 if ( it1.current() ->parent() ) 00639 { 00640 while ( ( *it1 ) ->firstChild() ) 00641 { 00642 kdDebug ( 9020 ) << "take FileItem " << ( *it1 ) ->firstChild()->text(0) << endl; 00643 ( *it1 ) ->takeItem( ( *it1 ) ->firstChild() ); 00644 } 00645 } 00646 m_detailView->takeItem( *it1 ); 00647 } 00648 } 00649 00650 // We assume here that ALL items in the over list view 00651 // are SubprojectItem's 00652 m_shownSubproject = static_cast<SubprojectItem*>( item ); 00653 00654 kdDebug ( 9020 ) << "m_shownSubproject (after takeItem()): " << selectedSubproject()->subdir << endl; 00655 00656 // Insert all TargetItems and all of their children into the view 00657 QPtrListIterator<TargetItem> it2( selectedSubproject()->targets ); 00658 for ( ; it2.current(); ++it2 ) 00659 { 00660 kdDebug ( 9020 ) << "insertItem in detail " << ( *it2 )->name << endl; 00661 m_detailView->insertItem( *it2 ); 00662 QPtrListIterator<FileItem> it3( ( *it2 ) ->sources ); 00663 for ( ; it3.current(); ++it3 ) 00664 ( *it2 ) ->insertItem( *it3 ); 00665 QString primary = ( *it2 ) ->primary; 00666 if ( primary == "PROGRAMS" || primary == "LIBRARIES" 00667 || primary == "LTLIBRARIES" || primary == "JAVA" ) 00668 ( *it2 ) ->setOpen( true ); 00669 } 00670 00671 targetOptionsButton->setEnabled ( false ); 00672 addNewFileButton->setEnabled ( false ); 00673 addExistingFileButton->setEnabled ( false ); 00674 removeButton->setEnabled ( false ); 00675 buildTargetButton->setEnabled ( false ); 00676 } 00677 00678 00679 void AutoProjectWidget::slotDetailsSelectionChanged( QListViewItem *item ) 00680 { 00681 bool isTarget = false; 00682 bool isRegularTarget = false; 00683 bool isFile = false; 00684 00685 if ( item ) 00686 { 00687 // We assume here that ALL items in the detail list view 00688 // are ProjectItem's 00689 ProjectItem * pvitem = static_cast<ProjectItem*>( item ); 00690 TargetItem* titem = 0; 00691 00692 if ( pvitem->type() == ProjectItem::File ) 00693 { 00694 titem = static_cast <TargetItem*> ( pvitem->parent() ); 00695 00696 QString primary = titem->primary; 00697 if ( primary == "PROGRAMS" || primary == "LIBRARIES" 00698 || primary == "LTLIBRARIES" || primary == "JAVA" ) 00699 { 00700 isRegularTarget = true; // not a data group 00701 isFile = true; 00702 } 00703 } 00704 else 00705 { 00706 titem = static_cast <TargetItem*> ( pvitem ); 00707 isTarget = true; 00708 } 00709 00710 QString primary = titem->primary; 00711 if ( primary == "PROGRAMS" || primary == "LIBRARIES" 00712 || primary == "LTLIBRARIES" || primary == "JAVA" ) 00713 isRegularTarget = true; // not a data group 00714 00715 /* if ( isRegularTarget && pvitem->type() == ProjectItem::File ) 00716 { 00717 isRegularFile = true; 00718 }*/ 00719 } 00720 00721 targetOptionsButton->setEnabled( isRegularTarget && !isFile ); 00722 addNewFileButton->setEnabled( isTarget ); 00723 addExistingFileButton->setEnabled( isTarget ); 00724 removeButton->setEnabled ( true ); 00725 00726 if ( isRegularTarget && isFile || isRegularTarget ) 00727 buildTargetButton->setEnabled ( true ); 00728 else 00729 buildTargetButton->setEnabled ( false ); 00730 } 00731 00732 TargetItem *AutoProjectWidget::selectedTarget() 00733 { 00734 ProjectItem * pvitem = static_cast<ProjectItem*>( m_detailView->selectedItem() ); 00735 if ( !pvitem || ( pvitem->type() != ProjectItem::Target ) ) 00736 return 0; 00737 00738 return static_cast<TargetItem*>( pvitem ); 00739 } 00740 00741 00742 FileItem *AutoProjectWidget::selectedFile() 00743 { 00744 ProjectItem * pvitem = static_cast<ProjectItem*>( m_detailView->selectedItem() ); 00745 if ( !pvitem || ( pvitem->type() != ProjectItem::File ) ) 00746 return 0; 00747 00748 return static_cast<FileItem*>( pvitem ); 00749 } 00750 00751 SubprojectItem* AutoProjectWidget::selectedSubproject() 00752 { 00753 ProjectItem * pvitem = static_cast <SubprojectItem*> ( m_subprojectView->selectedItem() ); 00754 00755 if ( !pvitem || ( pvitem->type() != ProjectItem::Subproject ) ) 00756 return 0; 00757 00758 return static_cast <SubprojectItem*> ( pvitem ); 00759 } 00760 00761 TargetItem *AutoProjectWidget::createTargetItem( const QString &name, 00762 const QString &prefix, const QString &primary, 00763 bool take ) 00764 { 00765 bool group = !( primary == "PROGRAMS" || primary == "LIBRARIES" 00766 || primary == "LTLIBRARIES" || primary == "JAVA" ); 00767 bool docgroup = ( primary == "KDEDOCS" ); 00768 bool icongroup = ( primary == "KDEICON" ); 00769 00770 QString text; 00771 if ( docgroup ) 00772 text = i18n( "Documentation data" ); 00773 else if ( icongroup ) 00774 text = i18n( "Icon data in %1" ).arg( prefix ); 00775 else if ( group ) 00776 text = i18n( "%1 in %2" ).arg( nicePrimary( primary ) ).arg( prefix ); 00777 else 00778 text = i18n( "%1 (%2 in %3)" ).arg( name ).arg( nicePrimary( primary ) ).arg( prefix ); 00779 00780 // Workaround because of QListView not being able to create 00781 // items without actually inserting them 00782 TargetItem *titem = new TargetItem( m_detailView, group, text ); 00783 titem->name = name; 00784 titem->prefix = prefix; 00785 titem->primary = primary; 00786 if( take ) 00787 m_detailView->takeItem( titem ); 00788 00789 return titem; 00790 } 00791 00792 00793 FileItem *AutoProjectWidget::createFileItem( const QString &name, SubprojectItem *subproject ) 00794 { 00795 FileItem * fitem = new FileItem( m_subprojectView, name ); 00796 fitem->uiFileLink = m_detailView->getUiFileLink(subproject->relativePath()+"/", name ); 00797 m_subprojectView->takeItem( fitem ); 00798 fitem->name = name; 00799 00800 return fitem; 00801 } 00802 00803 00804 void AutoProjectWidget::emitAddedFiles( const QStringList &fileList ) 00805 { 00806 emit m_part->addedFilesToProject( fileList ); 00807 } 00808 00809 void AutoProjectWidget::emitAddedFile( const QString &name ) 00810 { 00811 QStringList fileList; 00812 fileList.append ( name ); 00813 emit m_part->addedFilesToProject( fileList ); 00814 } 00815 00816 void AutoProjectWidget::emitRemovedFiles( const QStringList &fileList ) 00817 { 00818 emit m_part->removedFilesFromProject( fileList ); 00819 } 00820 00821 void AutoProjectWidget::emitRemovedFile( const QString &name ) 00822 { 00823 QStringList fileList; 00824 fileList.append ( name ); 00825 emit m_part->removedFilesFromProject( fileList ); 00826 } 00827 00828 void AutoProjectWidget::restoreSession ( const QDomElement* el ) 00829 { 00830 Q_UNUSED( el ); 00831 } 00832 00833 void AutoProjectWidget::saveSession ( QDomElement* el ) 00834 { 00835 kdDebug ( 9020 ) << "************** Saving session data of AutoProjectWidget: " << endl; 00836 00837 if ( m_activeTarget && m_activeSubproject ) 00838 { 00839 QDomDocument domDoc = el->ownerDocument(); 00840 00841 QString activeTargetPath = m_activeSubproject->path.mid ( m_part->project()->projectDirectory().length() + 1 ); 00842 activeTargetPath = activeTargetPath + "/" + m_activeTarget->name; 00843 00844 QDomElement generalEl = domDoc.createElement("general"); 00845 00846 kdDebug ( 9020 ) << "************** Saving session data of AutoProjectWidget: " << activeTargetPath << endl; 00847 00848 generalEl.setAttribute("activetarget", activeTargetPath); 00849 el->appendChild(generalEl); 00850 } 00851 } 00852 00853 void AutoProjectWidget::setActiveSubproject( SubprojectItem * spitem ) 00854 { 00855 m_activeSubproject = spitem; 00856 } 00857 00858 00859 #include "autoprojectwidget.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 Wed Oct 6 17:38:53 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003